diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 17cffd12971b..bf4a8ad7821f 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -23,6 +23,7 @@ use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentHash; use App\Models\SystemLog; +use App\Services\Subscription\SubscriptionService; use App\Utils\Number; use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesHash; @@ -342,6 +343,12 @@ class PaymentController extends Controller $payment = $payment->service()->applyCredits($payment_hash)->save(); + if (property_exists($payment_hash->data, 'billing_context')) { + $billing_subscription = \App\Models\Subscription::find($payment_hash->data->billing_context->subscription_id); + + return (new SubscriptionService($billing_subscription))->completePurchase($payment_hash); + } + return redirect()->route('client.payments.show', ['payment' => $this->encodePrimaryKey($payment->id)]); } diff --git a/app/Services/Credit/ApplyPayment.php b/app/Services/Credit/ApplyPayment.php index d7a91a924559..944e75cf46b7 100644 --- a/app/Services/Credit/ApplyPayment.php +++ b/app/Services/Credit/ApplyPayment.php @@ -148,7 +148,7 @@ class ApplyPayment if ((int)$this->invoice->balance == 0) { $this->invoice->service()->deletePdf(); - event(new InvoiceWasPaid($this->invoice, $payment, $this->payment->company, Ninja::eventVars(auth()->user()->id))); + event(new InvoiceWasPaid($this->invoice, $this->payment, $this->payment->company, Ninja::eventVars(auth()->user()->id))); } } }