Skip to content
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

[1.x] Support supscription v2 #132

Draft
wants to merge 20 commits into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
<a href="https://github.com/imdhemy/google-play-billing/actions/workflows/ci.yaml"><img src="https://github.com/imdhemy/google-play-billing/actions/workflows/ci.yaml/badge.svg" alt="Continuous Integration"></a>
</p>

## About Google Play Billing
## PHP Google Play Billing

Google Play Billing is a PHP package to handle App Store purchase verification and Server Notifications with expressive
and elegant syntax. This package takes the pain out of development by allowing you to mock receipts and implement their
business logic without actual Google Play receipts!
PHP Google Play Billing provides a simple and easy-to-use interface to interact with
the [Google Play Billing Ecosystem](https://developer.android.com/google/play/billing), whether you want to monetize
through one-time purchases or offer subscriptions to your services. This package covers the Subscriptions and In-App
Purchases API.

## Installation

Expand All @@ -29,10 +30,6 @@ composer require imdhemy/google-play-billing
The Google Play Billing documentation can be found in
the [Google Play Billing manual](https://imdhemy.com/laravel-iap-docs/docs/category/google-play-billing/).

# Versions and Changelog

All notable changes to `imdhemy/google-play-billing` will be documented on [Changelog](/CHANGELOG.md).

## Contributing

Feel free to check the [contributing guide](/CONTRIBUTING.md).
Expand Down
28 changes: 14 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions src/Normalizer/Normalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\Normalizer;

use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;

final readonly class Normalizer
{
public function __construct(private SerializerInterface $serializer)
{
}

public static function create(): self
{
return new self(new Serializer([
new TimeNormalizer(),
new ObjectNormalizer(),
], [new JsonEncoder()]));
}

/**
* Deserializes data into the given type.
*
* @template TObject of object
* @template TType of string|class-string<TObject>
*
* @param TType $type
*
* @psalm-return (TType is class-string<TObject> ? TObject : mixed)
*
* @phpstan-return ($type is class-string<TObject> ? TObject : mixed)
*
* @psalm-suppress MixedReturnStatement
*/
public function normalize(array $data, string $type): mixed
{
$json = json_encode($data, JSON_PARTIAL_OUTPUT_ON_ERROR);

return $this->serializer->deserialize($json, $type, 'json');
}
}
32 changes: 32 additions & 0 deletions src/Normalizer/TimeNormalizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Imdhemy\GooglePlay\Normalizer;

use Imdhemy\GooglePlay\ValueObjects\Time;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

final class TimeNormalizer implements DenormalizerInterface
{
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): Time
{
assert(is_string($data));

return new Time($data);
}

public function supportsDenormalization(
mixed $data,
string $type,
?string $format = null,
array $context = [],
): bool {
return Time::class === $type && is_string($data);
}

public function getSupportedTypes(?string $format): array
{
return [
Time::class => true,
];
}
}
19 changes: 19 additions & 0 deletions src/Purchase/Subscription/SubscriptionPurchase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\Purchase\Subscription;

/**
* Indicates the status of a user's subscription purchase.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#resource:-subscriptionpurchasev2
*/
final readonly class SubscriptionPurchase
{
public function __construct(
public string $kind,
public string $regionCode,
) {
}
}
32 changes: 0 additions & 32 deletions src/Serializer/DataConverter.php

This file was deleted.

22 changes: 0 additions & 22 deletions src/Serializer/DataConverterInterface.php

This file was deleted.

14 changes: 14 additions & 0 deletions src/ValueObjects/AutoRenewingPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* Information related to an auto renewing plan.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#autorenewingplan
*/
final class AutoRenewingPlan
{
}
21 changes: 21 additions & 0 deletions src/ValueObjects/InstallmentPlan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* Information to a installment plan.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#installmentplan
*/
final readonly class InstallmentPlan
{
public function __construct(
public int $initialCommittedPaymentsCount,
public int $subsequentCommittedPaymentsCount,
public int $remainingCommittedPaymentsCount,
public ?PendingCancellation $pendingCancellation,
) {
}
}
14 changes: 14 additions & 0 deletions src/ValueObjects/LineItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* Item-level info for a subscription purchase.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#subscriptionpurchaselineitem
*/
final class LineItem
{
}
20 changes: 20 additions & 0 deletions src/ValueObjects/Money.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* Represents an amount of money with its currency type.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/Money
*/
final readonly class Money
{
public function __construct(
public string $currencyCode,
public string $units,
public int $nanos,
) {
}
}
14 changes: 14 additions & 0 deletions src/ValueObjects/PendingCancellation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* This type has no fields.
* This is an indicator of whether there is a pending cancellation on the virtual installment plan. The cancellation
* will happen only after the user finished all committed payments.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#pendingcancellation
*/
final class PendingCancellation
{
}
21 changes: 21 additions & 0 deletions src/ValueObjects/SubscriptionItemPriceChangeDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Imdhemy\GooglePlay\ValueObjects;

/**
* Price change related information of a subscription item.
*
* @see https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2#subscriptionitempricechangedetails
*/
final readonly class SubscriptionItemPriceChangeDetails
{
public function __construct(
public Money $newPrice,
public string $priceChangeMode,
public string $priceChangeState,
public ?Time $expectedNewPriceChargeTime,
) {
}
}
Loading
Loading