diff --git a/app/Libraries/MultiDB.php b/app/Libraries/MultiDB.php index 56f3d1d9ac..dabc5fc647 100644 --- a/app/Libraries/MultiDB.php +++ b/app/Libraries/MultiDB.php @@ -329,6 +329,24 @@ class MultiDB return false; } + public static function findAndSetDbByInappTransactionId($transaction_id) :bool + { + $current_db = config('database.default'); + + foreach (self::$dbs as $db) { + if (Account::on($db)->where('inapp_transaction_id', $transaction_id)->exists()) { + self::setDb($db); + + return true; + } + } + + self::setDB($current_db); + + return false; + } + + public static function findAndSetDbByContactKey($contact_key) :bool { $current_db = config('database.default'); diff --git a/app/Listeners/Subscription/AppStoreRenewSubscription.php b/app/Listeners/Subscription/AppStoreRenewSubscription.php new file mode 100644 index 0000000000..d304b2ebe2 --- /dev/null +++ b/app/Listeners/Subscription/AppStoreRenewSubscription.php @@ -0,0 +1,58 @@ +getSubscriptionId(); //$subscription_id + + MultiDB::findAndSetDbByInappTransactionId($inapp_transaction_id); + + $account = Account::where('inapp_transaction_id', $inapp_transaction_id)->first(); + + if($account->plan_term == 'month') + $account->plan_expires = now()->addMonth(); + elseif($account->plan_term == 'year') + $account->plan_expires = now()->addYear(); + + $account->save(); + + // $server_notification = $event->getServerNotification(); + // $subscription = $event->getSubscription(); + // $subscription_identifier = $event->getSubscriptionIdentifier(); + + } + +} \ No newline at end of file diff --git a/config/purchase.php b/config/purchase.php index 38a6c52dd3..2791bd8682 100644 --- a/config/purchase.php +++ b/config/purchase.php @@ -1,5 +1,6 @@ [], DidFailToRenew::class => [], DidRecover::class => [], - DidRenew::class => [], + DidRenew::class => [AppStoreRenewSubscription::class], InitialBuy::class => [], InteractiveRenewal::class => [], PriceIncreaseConsent::class => [],