Skip to content

Commit 78297b2

Browse files
authored
Merge pull request #154 from imdhemy/feat-get-notification-subtype
[1.x]: get notification subtype
2 parents 37a487d + ce0d535 commit 78297b2

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

src/Contracts/HasSubtype.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Imdhemy\Purchases\Contracts;
4+
5+
interface HasSubtype
6+
{
7+
/**
8+
* Gets subscription subtype
9+
*
10+
* @return string
11+
*/
12+
public function getSubtype(): string;
13+
}

src/ServerNotifications/AppStoreV2ServerNotification.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44

55
use GuzzleHttp\Client;
66
use Imdhemy\AppStore\ServerNotifications\V2DecodedPayload;
7+
use Imdhemy\Purchases\Contracts\HasSubtype;
78
use Imdhemy\Purchases\Contracts\ServerNotificationContract;
89
use Imdhemy\Purchases\Contracts\SubscriptionContract;
910
use Imdhemy\Purchases\Subscriptions\AppleSubscription;
1011

11-
class AppStoreV2ServerNotification implements ServerNotificationContract
12+
class AppStoreV2ServerNotification implements ServerNotificationContract, HasSubtype
1213
{
1314
/**
1415
* @var V2DecodedPayload
@@ -80,4 +81,14 @@ public function getPayload(): array
8081
{
8182
return $this->payload->toArray();
8283
}
84+
85+
/**
86+
* Gets subscription subtype
87+
*
88+
* @return string
89+
*/
90+
public function getSubtype(): string
91+
{
92+
return (string)$this->payload->getSubType();
93+
}
8394
}

tests/Unit/ServerNotifications/AppStoreV2ServerNotificationTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ protected function setUp(): void
2020
parent::setUp();
2121

2222
$claims = [
23-
'notificationType' => V2DecodedPayload::TYPE_TEST,
23+
'notificationType' => V2DecodedPayload::TYPE_SUBSCRIBED,
24+
'subtype' => V2DecodedPayload::SUBTYPE_INITIAL_BUY,
2425
'data' => [
2526
'bundleId' => 'com.example.app',
2627
],
@@ -36,7 +37,7 @@ protected function setUp(): void
3637
*/
3738
public function get_type(): void
3839
{
39-
$this->assertEquals(V2DecodedPayload::TYPE_TEST, $this->sut->getType());
40+
$this->assertEquals(V2DecodedPayload::TYPE_SUBSCRIBED, $this->sut->getType());
4041
}
4142

4243
/**
@@ -55,7 +56,7 @@ public function get_subscription(): void
5556
*/
5657
public function is_test(): void
5758
{
58-
$this->assertTrue($this->sut->isTest());
59+
$this->assertFalse($this->sut->isTest());
5960
}
6061

6162
/**
@@ -73,4 +74,12 @@ public function get_payload(): void
7374
{
7475
$this->assertSame($this->payload->toArray(), $this->sut->getPayload());
7576
}
77+
78+
/**
79+
* @test
80+
*/
81+
public function get_subtype(): void
82+
{
83+
$this->assertEquals(V2DecodedPayload::SUBTYPE_INITIAL_BUY, $this->sut->getSubtype());
84+
}
7685
}

0 commit comments

Comments
 (0)