1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00

Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop

This commit is contained in:
David Bomba 2022-09-10 09:44:47 +10:00
commit bc8525641b
4 changed files with 80 additions and 3 deletions

View File

@ -292,7 +292,7 @@ class PreviewPurchaseOrderController extends BaseController
{ {
LightLogs::create(new LivePreview()) LightLogs::create(new LivePreview())
->increment() ->increment()
->queue(); ->batch();
} }

View File

@ -329,6 +329,24 @@ class MultiDB
return false; 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 public static function findAndSetDbByContactKey($contact_key) :bool
{ {
$current_db = config('database.default'); $current_db = config('database.default');

View 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();
}
}

View File

@ -1,5 +1,6 @@
<?php <?php
use App\Listeners\Subscription\AppStoreRenewSubscription;
use Imdhemy\Purchases\Events\AppStore\Cancel; use Imdhemy\Purchases\Events\AppStore\Cancel;
use Imdhemy\Purchases\Events\AppStore\DidChangeRenewalPref; use Imdhemy\Purchases\Events\AppStore\DidChangeRenewalPref;
use Imdhemy\Purchases\Events\AppStore\DidChangeRenewalStatus; 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\SubscriptionExpired;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionInGracePeriod; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionInGracePeriod;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionOnHold; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionOnHold;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPaused;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPauseScheduleChanged; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPauseScheduleChanged;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPaused;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPriceChangeConfirmed; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPriceChangeConfirmed;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPurchased; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionPurchased;
use Imdhemy\Purchases\Events\GooglePlay\SubscriptionRecovered; use Imdhemy\Purchases\Events\GooglePlay\SubscriptionRecovered;
@ -62,7 +63,7 @@ return [
DidChangeRenewalStatus::class => [], DidChangeRenewalStatus::class => [],
DidFailToRenew::class => [], DidFailToRenew::class => [],
DidRecover::class => [], DidRecover::class => [],
DidRenew::class => [], DidRenew::class => [AppStoreRenewSubscription::class],
InitialBuy::class => [], InitialBuy::class => [],
InteractiveRenewal::class => [], InteractiveRenewal::class => [],
PriceIncreaseConsent::class => [], PriceIncreaseConsent::class => [],