diff --git a/src/ReceiptValidator/GooglePlay/Validator.php b/src/ReceiptValidator/GooglePlay/Validator.php index d332f2c..48e8368 100755 --- a/src/ReceiptValidator/GooglePlay/Validator.php +++ b/src/ReceiptValidator/GooglePlay/Validator.php @@ -5,6 +5,9 @@ class Validator { + const TYPE_PURCHASE = 1; + const TYPE_SUBSCRIPTION = 2; + /** * google client * @@ -27,6 +30,11 @@ class Validator */ protected $_purchase_token = null; + /** + * @var int + */ + protected $_purchase_type = self::TYPE_PURCHASE; + /** * @var string */ @@ -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 @@ -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; }