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/Services/ClientPortal/InstantPayment.php b/app/Services/ClientPortal/InstantPayment.php index 6d17873c8668..bd7b89378645 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 */ 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.