mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Configuration for in app purchases
This commit is contained in:
parent
29d6a56296
commit
48f46dbd45
@ -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');
|
||||
|
58
app/Listeners/Subscription/AppStoreRenewSubscription.php
Normal file
58
app/Listeners/Subscription/AppStoreRenewSubscription.php
Normal file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Listeners\Subscription;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Account;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Imdhemy\Purchases\Events\AppStore\DidRenew;
|
||||
|
||||
class AppStoreRenewSubscription implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @param ActivityRepository $activity_repo
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(DidRenew $event)
|
||||
{
|
||||
|
||||
$inapp_transaction_id = $event->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();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Listeners\Subscription\AppStoreRenewSubscription;
|
||||
use Imdhemy\Purchases\Events\AppStore\Cancel;
|
||||
use Imdhemy\Purchases\Events\AppStore\DidChangeRenewalPref;
|
||||
use Imdhemy\Purchases\Events\AppStore\DidChangeRenewalStatus;
|
||||
@ -16,8 +17,8 @@ use Imdhemy\Purchases\Events\GooglePlay\SubscriptionDeferred;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionExpired;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionInGracePeriod;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionOnHold;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPaused;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPauseScheduleChanged;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPaused;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPriceChangeConfirmed;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPurchased;
|
||||
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionRecovered;
|
||||
@ -62,7 +63,7 @@ return [
|
||||
DidChangeRenewalStatus::class => [],
|
||||
DidFailToRenew::class => [],
|
||||
DidRecover::class => [],
|
||||
DidRenew::class => [],
|
||||
DidRenew::class => [AppStoreRenewSubscription::class],
|
||||
InitialBuy::class => [],
|
||||
InteractiveRenewal::class => [],
|
||||
PriceIncreaseConsent::class => [],
|
||||
|
Loading…
Reference in New Issue
Block a user