From ac842d0d830e9e808f1fedbca72b35387b40bbce Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 29 Jun 2021 16:05:03 +1000 Subject: [PATCH] Fixes for subscriptions --- .../Controllers/ClientPortal/PaymentController.php | 5 ++++- app/Services/Subscription/SubscriptionService.php | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index adc7f4408c..1b9926c9b0 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -319,7 +319,10 @@ class PaymentController extends Controller * @return Response The response view */ public function credit_response(Request $request) - { + { + nlog("credit response"); + nlog($request->all()); + $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first(); /* Hydrate the $payment */ diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 6960b8dd73..be96f56ea2 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -309,6 +309,9 @@ class SubscriptionService */ private function calculateProRataRefundItems($invoice, $is_credit = false) :array { + if(!$invoice) + return []; + /* depending on whether we are creating an invoice or a credit*/ $multiplier = $is_credit ? 1 : -1; @@ -444,6 +447,8 @@ class SubscriptionService ->withTrashed() ->orderBy('id', 'desc') ->first(); + if(!$last_invoice) + return true; if($last_invoice->balance > 0) { @@ -489,7 +494,10 @@ class SubscriptionService ->orderBy('id', 'desc') ->first(); - if($last_invoice->balance > 0) + if(!$last_invoice){ + //do nothing + } + else if($last_invoice->balance > 0) { $pro_rata_charge_amount = $this->calculateProRataCharge($last_invoice, $old_subscription); nlog("pro rata charge = {$pro_rata_charge_amount}");