File tree 4 files changed +55
-2
lines changed
tests/ServerNotifications
4 files changed +55
-2
lines changed Original file line number Diff line number Diff line change 4
4
namespace Imdhemy \Purchases \Events \AppStore ;
5
5
6
6
use Imdhemy \Purchases \Events \PurchaseEvent ;
7
+ use Imdhemy \Purchases \ValueObjects \Time ;
7
8
8
9
class DidChangeRenewalStatus extends PurchaseEvent
9
10
{
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
+ }
10
26
}
Original file line number Diff line number Diff line change 8
8
use Imdhemy \Purchases \Contracts \PurchaseEventContract ;
9
9
use Imdhemy \Purchases \Contracts \ServerNotificationContract ;
10
10
use Imdhemy \Purchases \Contracts \SubscriptionContract ;
11
+ use Imdhemy \Purchases \ServerNotifications \AppStoreServerNotification ;
12
+ use Imdhemy \Purchases \ServerNotifications \GoogleServerNotification ;
11
13
12
14
abstract class PurchaseEvent implements PurchaseEventContract
13
15
{
14
16
use Dispatchable, SerializesModels;
15
17
16
18
/**
17
- * @var ServerNotificationContract
19
+ * @var ServerNotificationContract|AppStoreServerNotification|GoogleServerNotification
18
20
*/
19
- private $ serverNotification ;
21
+ protected $ serverNotification ;
20
22
21
23
/**
22
24
* SubscriptionPurchased constructor.
Original file line number Diff line number Diff line change 8
8
use Imdhemy \Purchases \Contracts \ServerNotificationContract ;
9
9
use Imdhemy \Purchases \Contracts \SubscriptionContract ;
10
10
use Imdhemy \Purchases \Subscriptions \AppStoreSubscription ;
11
+ use Imdhemy \Purchases \ValueObjects \Time ;
11
12
12
13
class AppStoreServerNotification implements ServerNotificationContract
13
14
{
@@ -56,4 +57,25 @@ private function getFirstReceipt(): ReceiptInfo
56
57
{
57
58
return $ this ->notification ->getUnifiedReceipt ()->getLatestReceiptInfo ()[0 ];
58
59
}
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
+ }
59
81
}
Original file line number Diff line number Diff line change 7
7
use Imdhemy \Purchases \Contracts \SubscriptionContract ;
8
8
use Imdhemy \Purchases \ServerNotifications \AppStoreServerNotification ;
9
9
use Imdhemy \Purchases \Tests \TestCase ;
10
+ use Imdhemy \Purchases \ValueObjects \Time ;
10
11
11
12
class AppStoreServerNotificationTest extends TestCase
12
13
{
@@ -54,4 +55,16 @@ public function test_get_subscription()
54
55
{
55
56
$ this ->assertInstanceOf (SubscriptionContract::class, $ this ->appStoreServerNotification ->getSubscription ());
56
57
}
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
+ }
57
70
}
You can’t perform that action at this time.
0 commit comments