diff --git a/README.md b/README.md index 19005b1..34ed0cb 100755 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ $client->setApplicationName('...'); $client->setAuthConfig('...'); $client->setScopes('...'); -$validator = new PlayValidator(new \Google_Service_AndroidPublisher($client)); +$validator = new PlayValidator(new \Google\Service\AndroidPublisher($client)); try { $response = $validator->setPackageName('PACKAGE_NAME') @@ -89,11 +89,11 @@ Create service account [Service Account flow](https://developers.google.com/iden ```php $googleClient = new \Google_Client(); -$googleClient->setScopes([\Google_Service_AndroidPublisher::ANDROIDPUBLISHER]); +$googleClient->setScopes([\Google\Service\AndroidPublisher::ANDROIDPUBLISHER]); $googleClient->setApplicationName('Your_Purchase_Validator_Name'); $googleClient->setAuthConfig($pathToServiceAccountJsonFile); -$googleAndroidPublisher = new \Google_Service_AndroidPublisher($googleClient); +$googleAndroidPublisher = new \Google\Service\AndroidPublisher($googleClient); $validator = new \ReceiptValidator\GooglePlay\Validator($googleAndroidPublisher); try { diff --git a/composer.json b/composer.json index eacfada..cc627a2 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "ext-json": "*", "guzzlehttp/guzzle": "^6.3|^7.0", "nesbot/carbon": "^1.0|^2.0", - "google/apiclient": "^2.0", + "google/apiclient": "^2.10", "robrichards/xmlseclibs": "^3.0.4" }, "require-dev": { diff --git a/examples/test_play_receipt.php b/examples/test_play_receipt.php index 9d2f4b6..054dad2 100644 --- a/examples/test_play_receipt.php +++ b/examples/test_play_receipt.php @@ -28,7 +28,7 @@ $client->setAuthConfig($configLocation); $client->setScopes($scope); -$validator = new PlayValidator(new \Google_Service_AndroidPublisher($client)); +$validator = new PlayValidator(new \Google\Service\AndroidPublisher($client)); try { $response = $validator->setPackageName($packageName)->setProductId($productId)->setPurchaseToken($purchaseToken)->validatePurchase(); diff --git a/src/GooglePlay/AbstractResponse.php b/src/GooglePlay/AbstractResponse.php index ed16f8f..aa87bae 100644 --- a/src/GooglePlay/AbstractResponse.php +++ b/src/GooglePlay/AbstractResponse.php @@ -2,6 +2,9 @@ namespace ReceiptValidator\GooglePlay; +use Google\Service\AndroidPublisher\ProductPurchase; +use Google\Service\AndroidPublisher\SubscriptionPurchase; + /** * Class AbstractResponse. */ @@ -15,14 +18,14 @@ abstract class AbstractResponse const ACKNOWLEDGEMENT_STATE_DONE = 1; /** - * @var \Google_Service_AndroidPublisher_ProductPurchase|\Google_Service_AndroidPublisher_SubscriptionPurchase + * @var ProductPurchase|SubscriptionPurchase */ protected $response; /** * Constructor. * - * @param \Google_Service_AndroidPublisher_ProductPurchase|\Google_Service_AndroidPublisher_SubscriptionPurchase $response + * @param ProductPurchase|SubscriptionPurchase $response */ public function __construct($response) { @@ -62,7 +65,7 @@ public function getKind() } /** - * @return \Google_Service_AndroidPublisher_ProductPurchase|\Google_Service_AndroidPublisher_SubscriptionPurchase + * @return ProductPurchase|SubscriptionPurchase */ public function getRawResponse() { diff --git a/src/GooglePlay/Acknowledger.php b/src/GooglePlay/Acknowledger.php index 73f9e22..5baac1e 100644 --- a/src/GooglePlay/Acknowledger.php +++ b/src/GooglePlay/Acknowledger.php @@ -3,7 +3,9 @@ namespace ReceiptValidator\GooglePlay; use Exception; -use Google_Service_AndroidPublisher; +use Google\Service\AndroidPublisher; +use Google\Service\AndroidPublisher\ProductPurchasesAcknowledgeRequest; +use Google\Service\AndroidPublisher\SubscriptionPurchasesAcknowledgeRequest; use ReceiptValidator\RunTimeException; /** @@ -20,7 +22,7 @@ class Acknowledger const PRODUCT = 'PRODUCT'; /** - * @var Google_Service_AndroidPublisher + * @var AndroidPublisher */ protected $androidPublisherService; /** @@ -43,16 +45,16 @@ class Acknowledger /** * Acknowledger constructor. * - * @param Google_Service_AndroidPublisher $googleServiceAndroidPublisher - * @param string $packageName - * @param string $purchaseToken - * @param string $productId - * @param string $strategy + * @param AndroidPublisher $googleServiceAndroidPublisher + * @param string $packageName + * @param string $purchaseToken + * @param string $productId + * @param string $strategy * * @throws RunTimeException */ public function __construct( - Google_Service_AndroidPublisher $googleServiceAndroidPublisher, + AndroidPublisher $googleServiceAndroidPublisher, $packageName, $productId, $purchaseToken, @@ -86,7 +88,7 @@ public function acknowledge(string $type = self::SUBSCRIPTION, string $developer $this->packageName, $this->productId, $this->purchaseToken, - new \Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest( + new SubscriptionPurchasesAcknowledgeRequest( ['developerPayload' => $developerPayload] ) ); @@ -102,7 +104,7 @@ public function acknowledge(string $type = self::SUBSCRIPTION, string $developer $this->packageName, $this->productId, $this->purchaseToken, - new \Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest( + new SubscriptionPurchasesAcknowledgeRequest( ['developerPayload' => $developerPayload] ) ); @@ -116,7 +118,7 @@ public function acknowledge(string $type = self::SUBSCRIPTION, string $developer $this->packageName, $this->productId, $this->purchaseToken, - new \Google_Service_AndroidPublisher_ProductPurchasesAcknowledgeRequest( + new ProductPurchasesAcknowledgeRequest( ['developerPayload' => $developerPayload] ) ); @@ -132,7 +134,7 @@ public function acknowledge(string $type = self::SUBSCRIPTION, string $developer $this->packageName, $this->productId, $this->purchaseToken, - new \Google_Service_AndroidPublisher_ProductPurchasesAcknowledgeRequest( + new ProductPurchasesAcknowledgeRequest( ['developerPayload' => $developerPayload] ) ); diff --git a/src/GooglePlay/PurchaseResponse.php b/src/GooglePlay/PurchaseResponse.php index e63be7c..ab6b113 100644 --- a/src/GooglePlay/PurchaseResponse.php +++ b/src/GooglePlay/PurchaseResponse.php @@ -2,13 +2,15 @@ namespace ReceiptValidator\GooglePlay; +use Google\Service\AndroidPublisher\ProductPurchase; + /** * Class PurchaseResponse. */ class PurchaseResponse extends AbstractResponse { /** - * @var \Google_Service_AndroidPublisher_ProductPurchase + * @var ProductPurchase */ protected $response; diff --git a/src/GooglePlay/SubscriptionResponse.php b/src/GooglePlay/SubscriptionResponse.php index 10a6f23..793375f 100644 --- a/src/GooglePlay/SubscriptionResponse.php +++ b/src/GooglePlay/SubscriptionResponse.php @@ -2,13 +2,15 @@ namespace ReceiptValidator\GooglePlay; +use Google\Service\AndroidPublisher\SubscriptionPurchase; + /** * Class SubscriptionResponse. */ class SubscriptionResponse extends AbstractResponse { /** - * @var \Google_Service_AndroidPublisher_SubscriptionPurchase + * @var SubscriptionPurchase */ protected $response; diff --git a/src/GooglePlay/Validator.php b/src/GooglePlay/Validator.php index 8b13adb..a587dc4 100644 --- a/src/GooglePlay/Validator.php +++ b/src/GooglePlay/Validator.php @@ -2,13 +2,15 @@ namespace ReceiptValidator\GooglePlay; +use Google\Service\AndroidPublisher; + /** * Class Validator. */ class Validator { /** - * @var \Google_Service_AndroidPublisher + * @var AndroidPublisher */ protected $_androidPublisherService = null; /** @@ -31,11 +33,11 @@ class Validator /** * Validator constructor. * - * @param \Google_Service_AndroidPublisher $googleServiceAndroidPublisher - * @param bool $validationModePurchase + * @param AndroidPublisher $googleServiceAndroidPublisher + * @param bool $validationModePurchase */ public function __construct( - \Google_Service_AndroidPublisher $googleServiceAndroidPublisher, + AndroidPublisher $googleServiceAndroidPublisher, $validationModePurchase = true ) { $this->_androidPublisherService = $googleServiceAndroidPublisher; @@ -127,7 +129,7 @@ public function validateSubscription() } /** - * @return \Google_Service_AndroidPublisher + * @return AndroidPublisher */ public function getPublisherService() { diff --git a/tests/GooglePlay/GooglePlayAcknowledgerTest.php b/tests/GooglePlay/GooglePlayAcknowledgerTest.php index b441351..8c4bf37 100755 --- a/tests/GooglePlay/GooglePlayAcknowledgerTest.php +++ b/tests/GooglePlay/GooglePlayAcknowledgerTest.php @@ -2,11 +2,13 @@ namespace ReceiptValidator\Tests\GooglePlay; -use Google_Service_AndroidPublisher; -use Google_Service_AndroidPublisher_ProductPurchase; -use Google_Service_AndroidPublisher_Resource_PurchasesProducts; -use Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions; -use Google_Service_AndroidPublisher_SubscriptionPurchase; +use Google\Service\AndroidPublisher; +use Google\Service\AndroidPublisher\ProductPurchase; +use Google\Service\AndroidPublisher\ProductPurchasesAcknowledgeRequest; +use Google\Service\AndroidPublisher\Resource\PurchasesProducts; +use Google\Service\AndroidPublisher\Resource\PurchasesSubscriptions; +use Google\Service\AndroidPublisher\SubscriptionPurchase; +use Google\Service\AndroidPublisher\SubscriptionPurchasesAcknowledgeRequest; use PHPUnit\Framework\TestCase; use ReceiptValidator\GooglePlay\Acknowledger; @@ -22,24 +24,24 @@ public function testValidateWithNonAcknowledgedPurchase(): void $purchaseToken = 'testPurchaseToken'; // mock objects - $googleServiceAndroidPublisherMock = $this->getMockBuilder(Google_Service_AndroidPublisher::class) + $googleServiceAndroidPublisherMock = $this->getMockBuilder(AndroidPublisher::class) ->disableOriginalConstructor()->getMock(); // products $purchasesProductsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesProducts::class + PurchasesProducts::class ) ->disableOriginalConstructor()->getMock(); - $productPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_ProductPurchase::class) + $productPurchaseMock = $this->getMockBuilder(ProductPurchase::class) ->disableOriginalConstructor()->getMock(); $productPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(0); // subscriptions $purchasesSubscriptionsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions::class + PurchasesSubscriptions::class ) ->disableOriginalConstructor()->getMock(); - $subscriptionPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_SubscriptionPurchase::class) + $subscriptionPurchaseMock = $this->getMockBuilder(SubscriptionPurchase::class) ->disableOriginalConstructor()->getMock(); $subscriptionPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(0); @@ -52,7 +54,7 @@ public function testValidateWithNonAcknowledgedPurchase(): void $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_ProductPurchasesAcknowledgeRequest( + new ProductPurchasesAcknowledgeRequest( ['developerPayload' => 'bar'] ) ); @@ -62,7 +64,7 @@ public function testValidateWithNonAcknowledgedPurchase(): void $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest( + new SubscriptionPurchasesAcknowledgeRequest( ['developerPayload' => 'foo'] ) ); @@ -85,24 +87,24 @@ public function testValidateWithAcknowledgedPurchaseAndImplicitStrategy(): void $purchaseToken = 'testPurchaseToken'; // mock objects - $googleServiceAndroidPublisherMock = $this->getMockBuilder(Google_Service_AndroidPublisher::class) + $googleServiceAndroidPublisherMock = $this->getMockBuilder(AndroidPublisher::class) ->disableOriginalConstructor()->getMock(); // products $purchasesProductsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesProducts::class + PurchasesProducts::class ) ->disableOriginalConstructor()->getMock(); - $productPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_ProductPurchase::class) + $productPurchaseMock = $this->getMockBuilder(ProductPurchase::class) ->disableOriginalConstructor()->getMock(); $productPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(1); // subscriptions $purchasesSubscriptionsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions::class + PurchasesSubscriptions::class ) ->disableOriginalConstructor()->getMock(); - $subscriptionPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_SubscriptionPurchase::class) + $subscriptionPurchaseMock = $this->getMockBuilder(SubscriptionPurchase::class) ->disableOriginalConstructor()->getMock(); $subscriptionPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(1); @@ -121,7 +123,7 @@ public function testValidateWithAcknowledgedPurchaseAndImplicitStrategy(): void $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_ProductPurchasesAcknowledgeRequest( + new ProductPurchasesAcknowledgeRequest( ['developerPayload' => 'bar'] ) ); @@ -137,7 +139,7 @@ public function testValidateWithAcknowledgedPurchaseAndImplicitStrategy(): void $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest( + new SubscriptionPurchasesAcknowledgeRequest( ['developerPayload' => 'foo'] ) ); @@ -161,17 +163,17 @@ public function testValidateWithAcknowledgedPurchaseAndExplicitStrategyForSubscr $purchaseToken = 'testPurchaseToken'; // mock objects - $googleServiceAndroidPublisherMock = $this->getMockBuilder(Google_Service_AndroidPublisher::class) + $googleServiceAndroidPublisherMock = $this->getMockBuilder(AndroidPublisher::class) ->disableOriginalConstructor() ->getMock(); // subscriptions $purchasesSubscriptionsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions::class + PurchasesSubscriptions::class ) ->disableOriginalConstructor() ->getMock(); - $subscriptionPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_SubscriptionPurchase::class) + $subscriptionPurchaseMock = $this->getMockBuilder(SubscriptionPurchase::class) ->disableOriginalConstructor() ->getMock(); $subscriptionPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(1); @@ -184,7 +186,7 @@ public function testValidateWithAcknowledgedPurchaseAndExplicitStrategyForSubscr $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_SubscriptionPurchasesAcknowledgeRequest( + new SubscriptionPurchasesAcknowledgeRequest( ['developerPayload' => 'foo'] ) ); @@ -206,15 +208,15 @@ public function testValidateWithAcknowledgedPurchaseAndExplicitStrategyForProduc $purchaseToken = 'testPurchaseToken'; // mock objects - $googleServiceAndroidPublisherMock = $this->getMockBuilder(Google_Service_AndroidPublisher::class) + $googleServiceAndroidPublisherMock = $this->getMockBuilder(AndroidPublisher::class) ->disableOriginalConstructor()->getMock(); // products $purchasesProductsMock = $this->getMockBuilder( - Google_Service_AndroidPublisher_Resource_PurchasesProducts::class + PurchasesProducts::class ) ->disableOriginalConstructor()->getMock(); - $productPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_ProductPurchase::class) + $productPurchaseMock = $this->getMockBuilder(ProductPurchase::class) ->disableOriginalConstructor()->getMock(); $productPurchaseMock->expects($this->any())->method('getAcknowledgementState')->willReturn(1); @@ -226,7 +228,7 @@ public function testValidateWithAcknowledgedPurchaseAndExplicitStrategyForProduc $packageName, $productId, $purchaseToken, - new \Google_Service_AndroidPublisher_ProductPurchasesAcknowledgeRequest( + new ProductPurchasesAcknowledgeRequest( ['developerPayload' => 'bar'] ) ); diff --git a/tests/GooglePlay/GooglePlayPurchaseResponseTest.php b/tests/GooglePlay/GooglePlayPurchaseResponseTest.php index 6be1268..8049936 100644 --- a/tests/GooglePlay/GooglePlayPurchaseResponseTest.php +++ b/tests/GooglePlay/GooglePlayPurchaseResponseTest.php @@ -2,7 +2,6 @@ namespace ReceiptValidator\Tests\GooglePlay; -use Google_Service_AndroidPublisher_ProductPurchase; use PHPUnit\Framework\TestCase; use ReceiptValidator\GooglePlay\AbstractResponse; use ReceiptValidator\GooglePlay\PurchaseResponse; @@ -22,7 +21,7 @@ public function testParsedResponse(): void $purchaseTimeMillis = '234346'; // mock objects - $productPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_ProductPurchase::class) + $productPurchaseMock = $this->getMockBuilder(ProductPurchase::class) ->disableOriginalConstructor()->getMock(); $productPurchaseMock->consumptionState = PurchaseResponse::CONSUMPTION_STATE_YET_TO_BE_CONSUMED; diff --git a/tests/GooglePlay/GooglePlaySubscriptionResponseTest.php b/tests/GooglePlay/GooglePlaySubscriptionResponseTest.php index fa6ea52..cc92ea6 100644 --- a/tests/GooglePlay/GooglePlaySubscriptionResponseTest.php +++ b/tests/GooglePlay/GooglePlaySubscriptionResponseTest.php @@ -2,7 +2,7 @@ namespace ReceiptValidator\Tests\GooglePlay; -use Google_Service_AndroidPublisher_SubscriptionPurchase; +use Google\Service\AndroidPublisher\SubscriptionPurchase; use PHPUnit\Framework\TestCase; use ReceiptValidator\GooglePlay\AbstractResponse; use ReceiptValidator\GooglePlay\SubscriptionResponse; @@ -40,7 +40,7 @@ public function testParsedResponse(): void 'paymentState' => $paymentState, ]; - $subscriptionPurchase = new Google_Service_AndroidPublisher_SubscriptionPurchase($data); + $subscriptionPurchase = new SubscriptionPurchase($data); $subscriptionResponse = new SubscriptionResponse($subscriptionPurchase); $this->assertInstanceOf(AbstractResponse::class, $subscriptionResponse); diff --git a/tests/GooglePlay/GooglePlayValidatorTest.php b/tests/GooglePlay/GooglePlayValidatorTest.php index 572b55b..18311ed 100755 --- a/tests/GooglePlay/GooglePlayValidatorTest.php +++ b/tests/GooglePlay/GooglePlayValidatorTest.php @@ -2,11 +2,11 @@ namespace ReceiptValidator\Tests\GooglePlay; -use Google_Service_AndroidPublisher; -use Google_Service_AndroidPublisher_ProductPurchase; -use Google_Service_AndroidPublisher_Resource_PurchasesProducts; -use Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions; -use Google_Service_AndroidPublisher_SubscriptionPurchase; +use Google\Service\AndroidPublisher; +use Google\Service\AndroidPublisher\ProductPurchase; +use Google\Service\AndroidPublisher\Resource\PurchasesProducts; +use Google\Service\AndroidPublisher\Resource\PurchasesSubscriptions; +use Google\Service\AndroidPublisher\SubscriptionPurchase; use PHPUnit\Framework\TestCase; use ReceiptValidator\GooglePlay\PurchaseResponse; use ReceiptValidator\GooglePlay\SubscriptionResponse; @@ -24,15 +24,15 @@ public function testValidate(): void $purchaseToken = 'testPurchaseToken'; // mock objects - $productResponseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_ProductPurchase::class) + $productResponseMock = $this->getMockBuilder(ProductPurchase::class) ->disableOriginalConstructor()->getMock(); - $subscriptionResponseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_SubscriptionPurchase::class) + $subscriptionResponseMock = $this->getMockBuilder(SubscriptionPurchase::class) ->disableOriginalConstructor()->getMock(); - $googleServiceAndroidPublisherMock = $this->getMockBuilder(Google_Service_AndroidPublisher::class) + $googleServiceAndroidPublisherMock = $this->getMockBuilder(AndroidPublisher::class) ->disableOriginalConstructor()->getMock(); - $productPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_Resource_PurchasesProducts::class) + $productPurchaseMock = $this->getMockBuilder(PurchasesProducts::class) ->disableOriginalConstructor()->getMock(); - $subscriptionPurchaseMock = $this->getMockBuilder(Google_Service_AndroidPublisher_Resource_PurchasesSubscriptions::class) + $subscriptionPurchaseMock = $this->getMockBuilder(PurchasesSubscriptions::class) ->disableOriginalConstructor()->getMock(); // mock expectations