From d4943703c89d3438faa370b9fe0ddf7bfe8a85e3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 17 Feb 2023 15:46:07 +1100 Subject: [PATCH] Move google play listener in place --- .../AppStoreRenewSubscription.php | 3 -- .../PlayStoreRenewSubscription.php | 49 +++++++++++++++++++ .../Ninja/RenewalFailureNotification.php | 2 +- config/purchase.php | 37 +++++++------- 4 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 app/Listeners/Subscription/PlayStoreRenewSubscription.php diff --git a/app/Listeners/Subscription/AppStoreRenewSubscription.php b/app/Listeners/Subscription/AppStoreRenewSubscription.php index 26c2b41df179..8b6ee587dae0 100644 --- a/app/Listeners/Subscription/AppStoreRenewSubscription.php +++ b/app/Listeners/Subscription/AppStoreRenewSubscription.php @@ -59,8 +59,5 @@ class AppStoreRenewSubscription implements ShouldQueue $account->save(); - // $server_notification = $event->getServerNotification(); - // $subscription = $event->getSubscription(); - // $subscription_identifier = $event->getSubscriptionIdentifier(); } } diff --git a/app/Listeners/Subscription/PlayStoreRenewSubscription.php b/app/Listeners/Subscription/PlayStoreRenewSubscription.php new file mode 100644 index 000000000000..75a1561c9151 --- /dev/null +++ b/app/Listeners/Subscription/PlayStoreRenewSubscription.php @@ -0,0 +1,49 @@ +getServerNotification(); + nlog("google"); + nlog($notification); + $in_app_identifier = $event->getSubscriptionIdentifier(); + + MultiDB::findAndSetDbByInappTransactionId($in_app_identifier); + + $expirationTime = $event->getSubscription()->getExpiryTime(); + + $account = Account::where('inapp_transaction_id', $in_app_identifier)->first(); + + if ($account) { + $account->update(['plan_expires' => Carbon::parse($expirationTime)]); + } + + if (!$account) { + $ninja_company = Company::on('db-ninja-01')->find(config('ninja.ninja_default_company_id')); + $ninja_company->notification(new RenewalFailureNotification("{$in_app_identifier}"))->ninja(); + return; + } + } + + +} diff --git a/app/Notifications/Ninja/RenewalFailureNotification.php b/app/Notifications/Ninja/RenewalFailureNotification.php index 1ed7b15aed1f..34a5942feb25 100644 --- a/app/Notifications/Ninja/RenewalFailureNotification.php +++ b/app/Notifications/Ninja/RenewalFailureNotification.php @@ -23,7 +23,7 @@ class RenewalFailureNotification extends Notification * @return void */ - public function __construct(protected string $notification_message) + public function __construct(protected ?string $notification_message) { } diff --git a/config/purchase.php b/config/purchase.php index e3e4f2fb08b8..4b735d6457ef 100644 --- a/config/purchase.php +++ b/config/purchase.php @@ -1,30 +1,31 @@ [], @@ -40,7 +41,7 @@ return [ * -------------------------------------------------------- */ SubscriptionPurchased::class => [], - SubscriptionRenewed::class => [], + SubscriptionRenewed::class => [PlayStoreRenewSubscription::class], SubscriptionInGracePeriod::class => [], SubscriptionExpired::class => [], SubscriptionCanceled::class => [],