mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Fixes for change plan with subscriptions
This commit is contained in:
parent
c753aaecd9
commit
fd789ffddc
@ -151,6 +151,8 @@ class BillingPortalPurchasev2 extends Component
|
||||
public $valid_coupon = false;
|
||||
public $payable_invoices = [];
|
||||
public $payment_confirmed = false;
|
||||
public $is_eligible = true;
|
||||
public $not_eligible_message = '';
|
||||
|
||||
public function mount()
|
||||
{
|
||||
@ -449,8 +451,6 @@ class BillingPortalPurchasev2 extends Component
|
||||
|
||||
$this->buildBundle();
|
||||
|
||||
nlog($this->bundle);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -489,9 +489,20 @@ nlog($this->bundle);
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handleBeforePaymentEvents() :void
|
||||
public function handleBeforePaymentEvents() :self
|
||||
{
|
||||
|
||||
$eligibility_check = $this->subscription->service()->isEligible($this->contact);
|
||||
|
||||
if(is_array($eligibility_check) && $eligibility_check['message'] != 'Success'){
|
||||
|
||||
$this->is_eligible = false;
|
||||
$this->not_eligible_message =$eligibility_check['message'];
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
$data = [
|
||||
'client_id' => $this->contact->client->id,
|
||||
'date' => now()->format('Y-m-d'),
|
||||
@ -501,19 +512,9 @@ nlog($this->bundle);
|
||||
]],
|
||||
'user_input_promo_code' => $this->coupon,
|
||||
'coupon' => empty($this->subscription->promo_code) ? '' : $this->coupon,
|
||||
// 'quantity' => $this->quantity,
|
||||
|
||||
];
|
||||
|
||||
$is_eligible = $this->subscription->service()->isEligible($this->contact);
|
||||
|
||||
// if (is_array($is_eligible) && $is_eligible['message'] != 'Success') {
|
||||
// $this->steps['not_eligible'] = true;
|
||||
// $this->steps['not_eligible_message'] = $is_eligible['message'];
|
||||
// $this->steps['show_loading_bar'] = false;
|
||||
|
||||
// return;
|
||||
// }
|
||||
|
||||
$this->invoice = $this->subscription
|
||||
->service()
|
||||
->createInvoiceV2($this->bundle, $this->contact->client_id, $this->valid_coupon)
|
||||
@ -534,6 +535,9 @@ nlog($this->bundle);
|
||||
], now()->addMinutes(60));
|
||||
|
||||
$this->emit('beforePaymentEventsCompleted');
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
public function handleTrial()
|
||||
|
@ -289,11 +289,8 @@ class SubscriptionService
|
||||
|
||||
$days_in_frequency = $this->getDaysInFrequency();
|
||||
|
||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $this->subscription->price ,2);
|
||||
|
||||
// nlog("days in frequency = {$days_in_frequency} - days of subscription used {$days_of_subscription_used}");
|
||||
// nlog("invoice amount = {$invoice->amount}");
|
||||
// nlog("pro rata refund = {$pro_rata_refund}");
|
||||
//18-12-2022 - change $this->subscription->price => $invoice->amount if there was a discount on the invoice, we should not use the subscription price.
|
||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
||||
|
||||
return $pro_rata_refund;
|
||||
|
||||
@ -323,10 +320,6 @@ class SubscriptionService
|
||||
|
||||
$pro_rata_refund = round((($days_in_frequency - $days_of_subscription_used)/$days_in_frequency) * $invoice->amount ,2);
|
||||
|
||||
// nlog("days in frequency = {$days_in_frequency} - days of subscription used {$days_of_subscription_used}");
|
||||
// nlog("invoice amount = {$invoice->amount}");
|
||||
// nlog("pro rata refund = {$pro_rata_refund}");
|
||||
|
||||
return $pro_rata_refund;
|
||||
|
||||
}
|
||||
@ -353,7 +346,6 @@ class SubscriptionService
|
||||
|
||||
$days_of_subscription_used = $start_date->diffInDays($current_date);
|
||||
|
||||
// $days_in_frequency = $this->getDaysInFrequency();
|
||||
$days_in_frequency = $invoice->subscription->service()->getDaysInFrequency();
|
||||
|
||||
$ratio = ($days_in_frequency - $days_of_subscription_used)/$days_in_frequency;
|
||||
@ -663,6 +655,8 @@ class SubscriptionService
|
||||
$credit = CreditFactory::create($this->subscription->company_id, $this->subscription->user_id);
|
||||
$credit->date = now()->format('Y-m-d');
|
||||
$credit->subscription_id = $this->subscription->id;
|
||||
$credit->discount = $last_invoice->discount;
|
||||
$credit->is_amount_discount = $last_invoice->is_amount_discount;
|
||||
|
||||
$line_items = $subscription_repo->generateLineItems($target, false, true);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<div class="px-4 py-5 sm:px-6 lg:grid lg:grid-cols-3 lg:gap-4 lg:flex lg:items-center">
|
||||
<div class="px-4 py-2 sm:px-6 lg:grid lg:grid-cols-3 lg:gap-4 lg:flex lg:items-center">
|
||||
<dt class="text-sm leading-5 font-medium text-gray-500 mr-4">
|
||||
{{ $title }}
|
||||
</dt>
|
||||
|
@ -284,6 +284,7 @@
|
||||
</form>
|
||||
@endif
|
||||
|
||||
@if($is_eligible)
|
||||
<div class="mt-4 container mx-auto flex w-full justify-center" x-show.important="toggle" x-transition>
|
||||
<span class="">
|
||||
<svg class="animate-spin h-8 w-8 text-primary mx-auto justify-center w-full" xmlns="http://www.w3.org/2000/svg"
|
||||
@ -295,6 +296,9 @@
|
||||
</svg>
|
||||
</span>
|
||||
</div>
|
||||
@else
|
||||
<small class="mt-4 block">{{ $this->not_eligible_message }}</small>
|
||||
@endif
|
||||
|
||||
</div>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user