diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index dd2bf843e0..6215ded701 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -151,7 +151,9 @@ 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() { MultiDB::setDb($this->company->db); @@ -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() diff --git a/app/Services/Subscription/SubscriptionService.php b/app/Services/Subscription/SubscriptionService.php index f0c64316df..c24e97ccaf 100644 --- a/app/Services/Subscription/SubscriptionService.php +++ b/app/Services/Subscription/SubscriptionService.php @@ -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,7 +655,9 @@ 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); $credit->line_items = array_merge($line_items, $this->calculateProRataRefundItems($last_invoice, $last_invoice_is_credit)); diff --git a/resources/views/portal/ninja2020/components/general/card-element.blade.php b/resources/views/portal/ninja2020/components/general/card-element.blade.php index b7b5289877..c97949137d 100644 --- a/resources/views/portal/ninja2020/components/general/card-element.blade.php +++ b/resources/views/portal/ninja2020/components/general/card-element.blade.php @@ -1,4 +1,4 @@ -
+
{{ $title }}
diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php index 4f66491104..a228e6fcfe 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchasev2.blade.php @@ -284,6 +284,7 @@ @endif + @if($is_eligible)
+ @else + {{ $this->not_eligible_message }} + @endif