-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for GooglePlay subscriptionsv2 #374
Comments
This issue is stale because it has been open 60 days with no |
Is this still planned? |
Hey @willbrowningme |
That's awesome, thank you! I have manged to get it working with subscriptionsv2 by overriding a few classes e.g. <?php
namespace App\Iap;
use Imdhemy\GooglePlay\Subscriptions\SubscriptionPurchase;
use Imdhemy\GooglePlay\ValueObjects\Time;
use JsonSerializable;
class CustomSubscriptionPurchase extends SubscriptionPurchase implements JsonSerializable
{
/**
* @var string|null
*/
protected $kind;
/**
* @var string|null
*/
protected $regionCode;
/**
* @var array|null
*/
protected $lineItems;
/**
* @var string|null
*/
protected $startTime;
/**
* @var string|null
*/
protected $subscriptionState;
/**
* @var string|null
*/
protected $latestOrderId;
/**
* @var string|null
*/
protected $linkedPurchaseToken;
/**
* @var array|null
*/
protected $pausedStateContext;
/**
* @var array|null
*/
protected $canceledStateContext;
/**
* @var array|null
*/
protected $testPurchase;
/**
* @var string|null
*/
protected $acknowledgementState;
/**
* @var array|null
*/
protected $externalAccountIdentifiers;
/**
* @var array|null
*/
protected $subscribeWithGoogleInfo;
/**
* @var array
*/
protected $plainResponse;
/**
* Subscription Purchase Constructor.
*/
public function __construct(array $responseBody = [])
{
$attributes = array_keys(get_class_vars(self::class));
foreach ($attributes as $attribute) {
if (isset($responseBody[$attribute])) {
$this->$attribute = $responseBody[$attribute];
}
}
$this->plainResponse = $responseBody;
}
public static function fromArray(array $responseBody): self
{
return new self($responseBody);
}
/**
* @ return string|null
*/
public function getKind(): ?string
{
return $this->kind;
}
/**
* @ return string|null
*/
public function getRegionCode(): ?string
{
return $this->regionCode;
}
/**
* @ return array|null
*/
public function getLineItems(): ?array
{
return $this->lineItems;
}
// Override expiryTime
public function getExpiryTime(): ?Time
{
return isset($this->lineItems[0]['expiryTime']) ? new Time($this->lineItems[0]['expiryTime']) : null;
}
/**
* @ return string|null
*/
/* public function getStartTime(): ?string
{
return $this->startTime;
} */
public function getStartTime(): ?Time
{
return is_null($this->startTime) ? null : new Time($this->startTime);
}
/**
* @ return string|null
*/
public function getSubscriptionState(): ?string
{
return $this->subscriptionState;
}
/**
* @ return string|null
*/
public function getLatestOrderId(): ?string
{
return $this->latestOrderId;
}
/**
* @ return string|null
*/
public function getLinkedPurchaseToken(): ?string
{
return $this->linkedPurchaseToken;
}
/**
* @ return array|null
*/
public function getPausedStateContext(): ?array
{
return $this->pausedStateContext;
}
/**
* @ return array|null
*/
public function getCanceledStateContext(): ?array
{
return $this->canceledStateContext;
}
/**
* @ return array|null
*/
public function getTestPurchase(): ?array
{
return $this->testPurchase;
}
/**
* @ return string|null
*/
public function getAcknowledgementStatev2(): ?string
{
return $this->acknowledgementState;
}
/**
* @ return array|null
*/
public function getExternalAccountIdentifiers(): ?array
{
return $this->externalAccountIdentifiers;
}
/**
* @ return array|null
*/
public function getSubscribeWithGoogleInfo(): ?array
{
return $this->subscribeWithGoogleInfo;
}
public function getPlainResponse(): array
{
return $this->plainResponse;
}
public function toArray(): array
{
return $this->getPlainResponse();
}
public function jsonSerialize(): array
{
return $this->toArray();
}
}
<?php
namespace App\Iap;
use Imdhemy\GooglePlay\Subscriptions\SubscriptionClient as BaseSubscriptionClient;
class CustomSubscriptionClient extends BaseSubscriptionClient
{
public const URI_GET = 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications/%s/purchases/subscriptionsv2/tokens/%s';
/**
* @var ClientInterface
*/
protected $client;
/**
* @throws GuzzleException
*/
public function get(): CustomSubscriptionPurchase
{
$uri = $this->getEndpoint(self::URI_GET);
$response = $this->client->get($uri);
$responseBody = json_decode((string) $response->getBody(), true);
return CustomSubscriptionPurchase::fromArray($responseBody);
}
private function getEndpoint(string $template): string
{
return sprintf($template, $this->packageName, $this->token);
}
} but it would be very welcome without the need for these overrides. |
Description
The purchases.subscriptions.get method is deprecated. Add support for purchases.subscriptionsv2.get is necessary
Example
No response
The text was updated successfully, but these errors were encountered: