Fixes for using credits in subscriptions

This commit is contained in:
David Bomba 2023-02-04 16:28:03 +11:00
parent 5e68199396
commit 079889a711
3 changed files with 9 additions and 4 deletions

View File

@ -138,7 +138,7 @@ class DeletePayment
private function updateCreditables()
{
if ($this->payment->credits()->exists()) {
$this->payment->credits()->each(function ($paymentable_credit) {
$this->payment->credits()->where('is_deleted',0)->each(function ($paymentable_credit) {
$multiplier = 1;
if ($paymentable_credit->pivot->amount < 0) {

View File

@ -540,7 +540,12 @@ class SubscriptionService
$last_invoice->payments->each(function ($payment){
$this->credit_payments += $payment->credits->sum('amount');
$payment->credits()->where('is_deleted', 0)->each(function ($credit){
$this->credit_payments += $credit->pivot->sum('amount');
});
});
@ -556,7 +561,7 @@ class SubscriptionService
}
//if there are existing credit payments, then we refund directly to the credit.
if($this->calculateProRataRefundForSubscription($last_invoice) > 0 && $this->credit_payments == 0)
$credit = $this->createCredit($last_invoice, $target_subscription, false);

View File

@ -101,7 +101,7 @@
<div class="mt-4">
@foreach($subscription->service()->getPlans() as $_subscription)
<button class="mt-8 mr-2">
<a class="border mt-4 bg-white rounded py-2 px-4 hover:bg-gray-100 text-sm" target="_blank" href="{{ route('client.subscription.purchase', $_subscription->hashed_id) }}">{{ $_subscription->name }}</a>
<a class="border mt-4 bg-white rounded py-2 px-4 hover:bg-gray-100 text-sm" href="{{ route('client.subscription.purchase', $_subscription->hashed_id) }}">{{ $_subscription->name }}</a>
</button>
@endforeach
</div>