Skip to content

Commit

Permalink
Validate Google Play subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Chekalskiy committed Feb 25, 2015
1 parent 4f1344b commit b051b05
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/ReceiptValidator/GooglePlay/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

class Validator
{
const TYPE_PURCHASE = 1;
const TYPE_SUBSCRIPTION = 2;

/**
* google client
*
Expand All @@ -27,6 +30,11 @@ class Validator
*/
protected $_purchase_token = null;

/**
* @var int
*/
protected $_purchase_type = self::TYPE_PURCHASE;

/**
* @var string
*/
Expand Down Expand Up @@ -87,6 +95,18 @@ public function setPurchaseToken($purchase_token)
return $this;
}

/**
*
* @param int $purchase_type
* @return \ReceiptValidator\GooglePlay\Validator
*/
public function setPurchaseType($purchase_type)
{
$this->_purchase_type = $purchase_type;

return $this;
}

/**
*
* @param string $product_id
Expand All @@ -102,10 +122,17 @@ public function setProductId($product_id)

public function validate()
{
$response = $this->_androidPublisherService
->purchases_products->get(
$this->_package_name, $this->_product_id, $this->_purchase_token
);
switch ($this->_purchase_type) {
case self::TYPE_SUBSCRIPTION:
$request = $this->_androidPublisherService->purchases_subscriptions;
break;
default:
$request = $this->_androidPublisherService->purchases_products;
}

$response = $request->get(
$this->_package_name, $this->_product_id, $this->_purchase_token
);

return $response;
}
Expand Down

0 comments on commit b051b05

Please sign in to comment.