Skip to content

Commit

Permalink
Merge pull request #171 from yankers/master
Browse files Browse the repository at this point in the history
Add support purchases.subscriptionsv2 for Google API
  • Loading branch information
Stafox authored Apr 20, 2023
2 parents 142793d + abcce7f commit f93f0e9
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions src/GooglePlay/AbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Google\Service\AndroidPublisher\ProductPurchase;
use Google\Service\AndroidPublisher\SubscriptionPurchase;
use Google\Service\AndroidPublisher\SubscriptionPurchaseV2;

/**
* Class AbstractResponse.
Expand All @@ -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)
{
Expand Down Expand Up @@ -65,7 +66,7 @@ public function getKind()
}

/**
* @return ProductPurchase|SubscriptionPurchase
* @return ProductPurchase|SubscriptionPurchase|SubscriptionPurchaseV2
*/
public function getRawResponse()
{
Expand Down
16 changes: 16 additions & 0 deletions src/GooglePlay/SubscriptionV2Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace ReceiptValidator\GooglePlay;

use Google\Service\AndroidPublisher\SubscriptionPurchaseV2;

/**
* Class SubscriptionResponse.
*/
class SubscriptionV2Response extends AbstractResponse
{
/**
* @var SubscriptionPurchaseV2
*/
protected $response;
}
36 changes: 35 additions & 1 deletion src/GooglePlay/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class Validator
*/
private $validationModePurchase = true;

/**
* @var bool
*/
private $validationSubscriptionV2 = false;

/**
* Validator constructor.
*
Expand Down Expand Up @@ -92,12 +97,31 @@ public function setValidationModePurchase($validationModePurchase)
return $this;
}

/**
* @param bool
*
* @return Validator
*/
public function setValidationSubscriptionV2(bool $validationSubscriptionV2)
{
$this->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;
}

/**
Expand Down Expand Up @@ -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
*/
Expand Down

0 comments on commit f93f0e9

Please sign in to comment.