From 8247ff41e410ad18a0013a57b0171e5365703475 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 1 Mar 2023 14:47:04 +1100 Subject: [PATCH] Add validation to coupon code --- app/Http/Livewire/BillingPortalPurchasev2.php | 7 +++++++ lang/en/texts.php | 1 + .../livewire/billing-portal-purchasev2.blade.php | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Livewire/BillingPortalPurchasev2.php b/app/Http/Livewire/BillingPortalPurchasev2.php index ae9c980d082c..f37475836c92 100644 --- a/app/Http/Livewire/BillingPortalPurchasev2.php +++ b/app/Http/Livewire/BillingPortalPurchasev2.php @@ -271,6 +271,10 @@ class BillingPortalPurchasev2 extends Component */ public function handleCoupon() { + + $this->resetErrorBag('coupon'); + $this->resetValidation('coupon'); + if ($this->coupon == $this->subscription->promo_code) { $this->valid_coupon = true; $this->buildBundle(); @@ -278,6 +282,9 @@ class BillingPortalPurchasev2 extends Component $this->discount = 0; $this->valid_coupon = false; $this->buildBundle(); + $errors = $this->getErrorBag(); + $errors->add('coupon', ctrans('texts.invalid_coupon')); + return $this; } } diff --git a/lang/en/texts.php b/lang/en/texts.php index 18fa7cc2195a..c9ec4d4daa47 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5010,6 +5010,7 @@ $LANG = array( 'change_plan_description' => 'Upgrade or downgrade your current plan.', 'add_company_logo' => 'Add Logo', 'add_stripe' => 'Add Stripe', + 'invalid_coupon' => 'Invalid Coupon', ); 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 2adb5cfcf1e4..81346b33798c 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 @@ -253,6 +253,14 @@ {{ ctrans('texts.apply') }} + @if($errors && $errors->has('coupon')) + @error("coupon") + + @enderror + @endif @endif @@ -347,7 +355,6 @@ @enderror - @endif