From b92f16bfe5fe13a5904ea26bc6af7d7faddeab86 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 22 Oct 2021 10:55:58 +1100 Subject: [PATCH 1/3] Minor fixes for subscriptions --- app/Http/Controllers/ClientPortal/NinjaPlanController.php | 3 +-- app/Models/PaymentType.php | 2 +- app/Services/Invoice/MarkPaid.php | 8 +++++--- app/Services/Subscription/SubscriptionService.php | 7 +++++-- .../2021_10_15_00000_stripe_payment_gateways.php | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/NinjaPlanController.php b/app/Http/Controllers/ClientPortal/NinjaPlanController.php index 539c03572838..739f573f3556 100644 --- a/app/Http/Controllers/ClientPortal/NinjaPlanController.php +++ b/app/Http/Controllers/ClientPortal/NinjaPlanController.php @@ -39,7 +39,6 @@ class NinjaPlanController extends Controller else $account = $company->account; - if (MultiDB::findAndSetDbByContactKey($contact_key) && $client_contact = ClientContact::where('contact_key', $contact_key)->first()) { @@ -49,7 +48,7 @@ class NinjaPlanController extends Controller /* Current paid users get pushed straight to subscription overview page*/ if($account->isPaidHostedClient()) - return redirect('/client/subscriptions'); + return redirect('/client/dashboard'); /* Users that are not paid get pushed to a custom purchase page */ return $this->render('subscriptions.ninja_plan', ['settings' => $client_contact->company->settings]); diff --git a/app/Models/PaymentType.php b/app/Models/PaymentType.php index 6a6f29360892..4370b321715c 100644 --- a/app/Models/PaymentType.php +++ b/app/Models/PaymentType.php @@ -51,7 +51,7 @@ class PaymentType extends StaticModel const PRZELEWY24 = 40; const EPS = 41; const DIRECT_DEBIT = 42; - ` const BECS = 43; + const BECS = 43; const ACSS = 44; public static function parseCardType($cardName) diff --git a/app/Services/Invoice/MarkPaid.php b/app/Services/Invoice/MarkPaid.php index 408a71b52b92..a9b45ef1fa86 100644 --- a/app/Services/Invoice/MarkPaid.php +++ b/app/Services/Invoice/MarkPaid.php @@ -39,7 +39,7 @@ class MarkPaid extends AbstractService public function run() { if ($this->invoice->status_id == Invoice::STATUS_DRAFT) { - $this->invoice->service()->markSent(); + $this->invoice->service()->markSent()->save(); } /*Don't double pay*/ @@ -77,14 +77,16 @@ class MarkPaid extends AbstractService $this->invoice->next_send_date = null; - $this->invoice->service() + $this->invoice + ->service() ->setExchangeRate() ->updateBalance($payment->amount * -1) ->updatePaidToDate($payment->amount) ->setStatus(Invoice::STATUS_PAID) ->save(); - $this->invoice->service() + $this->invoice + ->service() ->applyNumber() ->deletePdf() ->save(); diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index 0d6cd9f553a0..ef3f618d6c4c 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -223,6 +223,7 @@ class SubscriptionService ->first(); } + if ($outstanding->count() == 0){ //nothing outstanding return $target->price - $this->calculateProRataRefundForSubscription($outstanding_invoice); @@ -426,7 +427,9 @@ class SubscriptionService nlog("total payable = {$total_payable}"); - $credit = $this->createCredit($last_invoice, $target_subscription, $is_credit); + /* Only generate a credit if the previous invoice was paid in full. */ + if($last_invoice->balance == 0) + $credit = $this->createCredit($last_invoice, $target_subscription, $is_credit); $new_recurring_invoice = $this->createNewRecurringInvoice($recurring_invoice); @@ -575,7 +578,7 @@ class SubscriptionService $old_recurring_invoice->service()->stop()->save(); $recurring_invoice_repo = new RecurringInvoiceRepository(); - $recurring_invoice_repo->archive($old_recurring_invoice); + $recurring_invoice_repo->delete($old_recurring_invoice); $recurring_invoice = $this->convertInvoiceToRecurring($old_recurring_invoice->client_id); $recurring_invoice = $recurring_invoice_repo->save([], $recurring_invoice); diff --git a/database/migrations/2021_10_15_00000_stripe_payment_gateways.php b/database/migrations/2021_10_15_00000_stripe_payment_gateways.php index 432ad64c7e95..a05bae1e0c56 100644 --- a/database/migrations/2021_10_15_00000_stripe_payment_gateways.php +++ b/database/migrations/2021_10_15_00000_stripe_payment_gateways.php @@ -6,7 +6,7 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -class AddStripePaymentsToPaymentTypes extends Migration +class StripePaymentGateways extends Migration { /** * Run the migrations. From 29a7225d641d31dd4e3aaf57b3f40ed202594c22 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 22 Oct 2021 20:55:40 +1100 Subject: [PATCH 2/3] Mark as sent when we get to the payment screen --- app/Services/ClientPortal/InstantPayment.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index 6d17873c8668..dfb41fa78c97 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -70,7 +70,10 @@ class InstantPayment $invoices = Invoice::whereIn('id', $this->transformKeys($payable_invoices->pluck('invoice_id')->toArray()))->withTrashed()->get(); $invoices->each(function($invoice){ - $invoice->service()->removeUnpaidGatewayFees()->save(); + $invoice->service() + ->marksent() + ->removeUnpaidGatewayFees() + ->save(); }); /* pop non payable invoice from the $payable_invoices array */ From 002108b152ab204ea440ede367098de09cc2eb72 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 22 Oct 2021 20:56:47 +1100 Subject: [PATCH 3/3] minor fixes --- app/Services/ClientPortal/InstantPayment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index dfb41fa78c97..bd7b89378645 100644 --- a/app/Services/ClientPortal/InstantPayment.php +++ b/app/Services/ClientPortal/InstantPayment.php @@ -71,7 +71,7 @@ class InstantPayment $invoices->each(function($invoice){ $invoice->service() - ->marksent() + ->markSent() ->removeUnpaidGatewayFees() ->save(); });