From abcce7fec4ee9c560ceda13908cf583a5c987a18 Mon Sep 17 00:00:00 2001 From: Alexei Yanochkin Date: Wed, 19 Apr 2023 15:12:38 +0200 Subject: [PATCH] Add support purchases.subscriptionsv2 for Google API --- composer.json | 1 + src/GooglePlay/AbstractResponse.php | 7 +++-- src/GooglePlay/SubscriptionV2Response.php | 16 ++++++++++ src/GooglePlay/Validator.php | 36 ++++++++++++++++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 src/GooglePlay/SubscriptionV2Response.php diff --git a/composer.json b/composer.json index cc627a2..36ad33a 100755 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "guzzlehttp/guzzle": "^6.3|^7.0", "nesbot/carbon": "^1.0|^2.0", "google/apiclient": "^2.10", + "google/apiclient-services": "~0.249", "robrichards/xmlseclibs": "^3.0.4" }, "require-dev": { diff --git a/src/GooglePlay/AbstractResponse.php b/src/GooglePlay/AbstractResponse.php index aa87bae..186e6ee 100644 --- a/src/GooglePlay/AbstractResponse.php +++ b/src/GooglePlay/AbstractResponse.php @@ -4,6 +4,7 @@ use Google\Service\AndroidPublisher\ProductPurchase; use Google\Service\AndroidPublisher\SubscriptionPurchase; +use Google\Service\AndroidPublisher\SubscriptionPurchaseV2; /** * Class AbstractResponse. @@ -18,14 +19,14 @@ abstract class AbstractResponse const ACKNOWLEDGEMENT_STATE_DONE = 1; /** - * @var ProductPurchase|SubscriptionPurchase + * @var ProductPurchase|SubscriptionPurchase|SubscriptionPurchaseV2 */ protected $response; /** * Constructor. * - * @param ProductPurchase|SubscriptionPurchase $response + * @param ProductPurchase|SubscriptionPurchase|SubscriptionPurchaseV2 $response */ public function __construct($response) { @@ -65,7 +66,7 @@ public function getKind() } /** - * @return ProductPurchase|SubscriptionPurchase + * @return ProductPurchase|SubscriptionPurchase|SubscriptionPurchaseV2 */ public function getRawResponse() { diff --git a/src/GooglePlay/SubscriptionV2Response.php b/src/GooglePlay/SubscriptionV2Response.php new file mode 100644 index 0000000..deaf5e3 --- /dev/null +++ b/src/GooglePlay/SubscriptionV2Response.php @@ -0,0 +1,16 @@ +validationModePurchase = $validationSubscriptionV2; + + return $this; + } + /** * @return PurchaseResponse|SubscriptionResponse */ public function validate() { - return ($this->validationModePurchase) ? $this->validatePurchase() : $this->validateSubscription(); + if ($this->validationModePurchase) { + $result = $this->validatePurchase(); + } elseif ($this->validateSubscriptionV2()) { + $result = $this->validateSubscriptionV2(); + } else { + $result = $this->validateSubscription(); + } + return $result; } /** @@ -128,6 +152,16 @@ public function validateSubscription() ); } + public function validateSubscriptionV2() + { + return new SubscriptionV2Response( + $this->_androidPublisherService->purchases_subscriptionsv2->get( + $this->_package_name, + $this->_purchase_token + ) + ); + } + /** * @return AndroidPublisher */