Skip to content

Commit 03385c0

Browse files
committed
The DidChangeRenewalStatus Event from the App Store can get the change renewal status data
- isAutoRenewal() - getAutoRenewStatusChangeDate()
1 parent ed03a4a commit 03385c0

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

src/Events/AppStore/DidChangeRenewalStatus.php

+16
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@
44
namespace Imdhemy\Purchases\Events\AppStore;
55

66
use Imdhemy\Purchases\Events\PurchaseEvent;
7+
use Imdhemy\Purchases\ValueObjects\Time;
78

89
class DidChangeRenewalStatus extends PurchaseEvent
910
{
11+
/**
12+
* @return bool
13+
*/
14+
public function isAutoRenewal(): bool
15+
{
16+
return $this->serverNotification->isAutoRenewal();
17+
}
18+
19+
/**
20+
* @return Time|null
21+
*/
22+
public function getAutoRenewStatusChangeDate(): ?Time
23+
{
24+
return $this->serverNotification->getAutoRenewStatusChangeDate();
25+
}
1026
}

src/Events/PurchaseEvent.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
use Imdhemy\Purchases\Contracts\PurchaseEventContract;
99
use Imdhemy\Purchases\Contracts\ServerNotificationContract;
1010
use Imdhemy\Purchases\Contracts\SubscriptionContract;
11+
use Imdhemy\Purchases\ServerNotifications\AppStoreServerNotification;
12+
use Imdhemy\Purchases\ServerNotifications\GoogleServerNotification;
1113

1214
abstract class PurchaseEvent implements PurchaseEventContract
1315
{
1416
use Dispatchable, SerializesModels;
1517

1618
/**
17-
* @var ServerNotificationContract
19+
* @var ServerNotificationContract|AppStoreServerNotification|GoogleServerNotification
1820
*/
19-
private $serverNotification;
21+
protected $serverNotification;
2022

2123
/**
2224
* SubscriptionPurchased constructor.

src/ServerNotifications/AppStoreServerNotification.php

+22
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Imdhemy\Purchases\Contracts\ServerNotificationContract;
99
use Imdhemy\Purchases\Contracts\SubscriptionContract;
1010
use Imdhemy\Purchases\Subscriptions\AppStoreSubscription;
11+
use Imdhemy\Purchases\ValueObjects\Time;
1112

1213
class AppStoreServerNotification implements ServerNotificationContract
1314
{
@@ -56,4 +57,25 @@ private function getFirstReceipt(): ReceiptInfo
5657
{
5758
return $this->notification->getUnifiedReceipt()->getLatestReceiptInfo()[0];
5859
}
60+
61+
/**
62+
* @return bool
63+
*/
64+
public function isAutoRenewal(): bool
65+
{
66+
return $this->notification->isAutoRenewStatus();
67+
}
68+
69+
/**
70+
* @return Time|null
71+
*/
72+
public function getAutoRenewStatusChangeDate(): ?Time
73+
{
74+
$time = $this->notification->getAutoRenewStatusChangeDate();
75+
if (! is_null($time)) {
76+
return Time::fromAppStoreTime($time);
77+
}
78+
79+
return null;
80+
}
5981
}

tests/ServerNotifications/AppStoreServerNotificationTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Imdhemy\Purchases\Contracts\SubscriptionContract;
88
use Imdhemy\Purchases\ServerNotifications\AppStoreServerNotification;
99
use Imdhemy\Purchases\Tests\TestCase;
10+
use Imdhemy\Purchases\ValueObjects\Time;
1011

1112
class AppStoreServerNotificationTest extends TestCase
1213
{
@@ -54,4 +55,16 @@ public function test_get_subscription()
5455
{
5556
$this->assertInstanceOf(SubscriptionContract::class, $this->appStoreServerNotification->getSubscription());
5657
}
58+
59+
/**
60+
* @test
61+
*/
62+
public function test_get_change_renewal_status_data()
63+
{
64+
$isAutoRenewal = $this->appStoreServerNotification->isAutoRenewal();
65+
$changeDate = $this->appStoreServerNotification->getAutoRenewStatusChangeDate();
66+
67+
$this->assertFalse($isAutoRenewal);
68+
$this->assertInstanceOf(Time::class, $changeDate);
69+
}
5770
}

0 commit comments

Comments
 (0)