diff --git a/app/Listeners/Subscription/AppStoreRenewSubscription.php b/app/Listeners/Subscription/AppStoreRenewSubscription.php index 958fd6292..4ab490e37 100644 --- a/app/Listeners/Subscription/AppStoreRenewSubscription.php +++ b/app/Listeners/Subscription/AppStoreRenewSubscription.php @@ -59,10 +59,6 @@ class AppStoreRenewSubscription implements ShouldQueue $account->save(); - // $server_notification = $event->getServerNotification(); - // $subscription = $event->getSubscription(); - // $subscription_identifier = $event->getSubscriptionIdentifier(); - } } \ No newline at end of file diff --git a/app/Listeners/Subscription/PlayStoreRenewSubscription.php b/app/Listeners/Subscription/PlayStoreRenewSubscription.php new file mode 100644 index 000000000..75a1561c9 --- /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 5dbbbe8a6..83d6651fa 100644 --- a/app/Notifications/Ninja/RenewalFailureNotification.php +++ b/app/Notifications/Ninja/RenewalFailureNotification.php @@ -29,7 +29,9 @@ class RenewalFailureNotification extends Notification * @return void */ - public function __construct(protected string $notification_message){} + public function __construct(protected ?string $notification_message) + { + } /** * Get the notification's delivery channels. diff --git a/config/purchase.php b/config/purchase.php index d61999023..d740da055 100644 --- a/config/purchase.php +++ b/config/purchase.php @@ -1,30 +1,32 @@ [], @@ -40,7 +42,7 @@ return [ * -------------------------------------------------------- */ SubscriptionPurchased::class => [], - SubscriptionRenewed::class => [], + SubscriptionRenewed::class => [PlayStoreRenewSubscription::class], SubscriptionInGracePeriod::class => [], SubscriptionExpired::class => [], SubscriptionCanceled::class => [],