From ac842d0d830e9e808f1fedbca72b35387b40bbce Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 29 Jun 2021 16:05:03 +1000 Subject: [PATCH 1/2] 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 adc7f4408cda..1b9926c9b08f 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 6960b8dd73ae..be96f56ea20f 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}"); From 8e43eaa99dacec65e6dc9e711701155e432175ce Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 29 Jun 2021 17:26:21 +1000 Subject: [PATCH 2/2] minor fixes --- app/Http/Controllers/ClientPortal/PaymentController.php | 2 -- app/Services/Subscription/SubscriptionService.php | 2 +- config/ninja.php | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 1b9926c9b08f..7e78b6aceeef 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -320,8 +320,6 @@ class PaymentController extends Controller */ public function credit_response(Request $request) { - nlog("credit response"); - nlog($request->all()); $payment_hash = PaymentHash::whereRaw('BINARY `hash`= ?', [$request->input('payment_hash')])->first(); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index be96f56ea20f..348b0573938e 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -522,7 +522,7 @@ class SubscriptionService */ private function handlePlanChange($payment_hash) { - +nlog("handle plan change"); $old_recurring_invoice = RecurringInvoice::find($payment_hash->data->billing_context->recurring_invoice); $recurring_invoice = $this->createNewRecurringInvoice($old_recurring_invoice); diff --git a/config/ninja.php b/config/ninja.php index d0afe5adc806..675ce11ae92d 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -15,7 +15,7 @@ return [ 'app_url' => rtrim(env('APP_URL', ''), '/'), 'app_domain' => env('APP_DOMAIN', 'invoicing.co'), 'app_version' => '5.2.7', - 'app_tag' => '5.2.7-release', + 'app_tag' => '5.2.7', 'minimum_client_version' => '5.0.16', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''),