Skip to content
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,11 @@ If you only want a run the tests you can run the following command:
```sh
composer run-tests
```

---
> [!IMPORTANT]
>
>The Google API will append `..[random number]` at the end of the orderId when a subscriber renews a subscription.
>
> If you plan doing any sort of validation using the `orderId`, the bundle offers a helper `Trait` [HasStripOrderId](src/Traits/HasStripOrderId.php) which removes the appending data from the Order ID.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "immediate/android-services-bundle",
"version": "1.0.0",
"version": "1.1.0",
"description": "This bundle allows for interaction with the Android Publisher services specifically",
"type": "symfony-bundle",
"license": "MIT",
Expand Down
6 changes: 6 additions & 0 deletions src/AndroidServicesApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public function __construct(

/**
* @throws AndroidServiceException|JsonException
* @phpcs:disable
* @link https://developers.google.com/android-publisher/api-ref/rest/v3/purchases.subscriptionsv2 Purchases.subscriptionsV2
* @phpcs:enable
* */
public function getPurchaseSubscriptionV2(
AndroidPublisherModelInterface $androidPublisherModel
Expand Down Expand Up @@ -66,7 +68,9 @@ public function getPurchaseSubscriptionV2(

/**
* @throws AndroidServiceException|JsonException
* @phpcs:disable
* @link https://developers.google.com/android-publisher/api-ref/rest/v3/monetization.subscriptions.basePlans.offers Monetization.subscriptions.basePlans.offers
* @phpcs:enable
* */
public function getBasePlanOffers(
AndroidPublisherModelInterface $androidPublisherModel
Expand Down Expand Up @@ -99,7 +103,9 @@ public function getBasePlanOffers(

/**
* @throws AndroidServiceException|JsonException
* @phpcs:disable
* @link https://developers.google.com/android-publisher/api-ref/rest/v3/monetization.subscriptions Monetization.subscriptions
* @phpcs:enable
*/
public function getPackageSubscriptions(
AndroidPublisherModelInterface $androidPublisherModel
Expand Down
6 changes: 6 additions & 0 deletions src/Traits/HasDDErrorEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ private function sendDDErrorEvent(
'purchaseToken' => $androidPublisherModel->subscriptionNotification->purchaseToken ?? ''
], JSON_THROW_ON_ERROR),
Event::ALERT_ERROR,
[
'packageName' => $androidPublisherModel->packageName ?? '',
'subscriptionId' => $androidPublisherModel->subscriptionNotification->subscriptionId ?? '',
'productId' => $androidPublisherModel->getProductId() ?? '',
'appName' => 'android-services-bundle',
]
);
} catch (Throwable $throwable) {
$logger->warning('Failed to send event to Datadog', [
Expand Down
25 changes: 25 additions & 0 deletions src/Traits/HasStripOrderId.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace IM\Fabric\Bundle\AndroidServicesBundle\Traits;

trait HasStripOrderId
{
private function stripOrderId(?string $orderId): ?string
{
if ($orderId === null) {
return null;
}

$parts = explode('.', $orderId, 3);

if (count($parts) === 3) {
array_pop($parts);

return implode('.', $parts);
}

return $orderId;
}
}
31 changes: 31 additions & 0 deletions tests/phpunit/Traits/HasStripOrderIdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace IM\Fabric\Bundle\AndroidServicesBundle\Test\Traits;

use IM\Fabric\Bundle\AndroidServicesBundle\Traits\HasStripOrderId;
use PHPUnit\Framework\TestCase;

class HasStripOrderIdTest extends TestCase
{
use HasStripOrderId;

private string $orderId = 'GPA.3392-3423-5904-58629..3';
private string $expected = 'GPA.3392-3423-5904-58629';

public function testCanStripOrderId(): void
{
$this->assertSame($this->expected, $this->stripOrderId($this->orderId));
}

public function testReturnsNullForNullOrderId(): void
{
$this->assertNull($this->stripOrderId(null));
}

public function testReturnsOriginalOrderIdIfNoExtraPart(): void
{
$this->assertSame($this->expected, $this->stripOrderId($this->expected));
}
}