Skip to content

Commit

Permalink
Merge pull request #11 from chekalskiy/google-play-subscriptions
Browse files Browse the repository at this point in the history
Validate Google Play subscriptions
  • Loading branch information
aporat committed Feb 25, 2015
2 parents 4f1344b + b051b05 commit 2f6cdc9
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 2f6cdc9

Please sign in to comment.