From ecefa336d29a07d906ca25b3e458661cba4d69e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 7 Feb 2024 17:30:52 +0100 Subject: [PATCH 1/3] Add RFF functionality to BillingPortalPurchase class --- app/Livewire/BillingPortalPurchase.php | 42 ++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/app/Livewire/BillingPortalPurchase.php b/app/Livewire/BillingPortalPurchase.php index 0889c2fc88a1..8ba6fe855d35 100644 --- a/app/Livewire/BillingPortalPurchase.php +++ b/app/Livewire/BillingPortalPurchase.php @@ -106,6 +106,7 @@ class BillingPortalPurchase extends Component public $steps = [ 'passed_email' => false, 'existing_user' => false, + 'check_rff' => false, 'fetched_payment_methods' => false, 'fetched_client' => false, 'show_start_trial' => false, @@ -181,6 +182,12 @@ class BillingPortalPurchase extends Component */ public $campaign; + public ?string $contact_first_name; + + public ?string $contact_last_name; + + public ?string $contact_email; + public function mount() { MultiDB::setDb($this->db); @@ -316,10 +323,14 @@ class BillingPortalPurchase extends Component */ protected function getPaymentMethods(ClientContact $contact): self { - Auth::guard('contact')->loginUsingId($contact->id, true); - $this->contact = $contact; + if ($contact->showRff()) { + return $this->rff(); + } + + Auth::guard('contact')->loginUsingId($contact->id, true); + if ($this->subscription->trial_enabled) { $this->heading_text = ctrans('texts.plan_trial'); $this->steps['show_start_trial'] = true; @@ -340,6 +351,33 @@ class BillingPortalPurchase extends Component return $this; } + protected function rff() + { + $this->contact_first_name = $this->contact->first_name; + $this->contact_last_name = $this->contact->last_name; + $this->contact_email = $this->contact->email; + + $this->steps['check_rff'] = true; + + return $this; + } + + public function handleRff() + { + $validated = $this->validate([ + 'contact_first_name' => ['required'], + 'contact_last_name' => ['required'], + 'contact_email' => ['required', 'email'], + ]); + + $this->contact->first_name = $validated['contact_first_name']; + $this->contact->last_name = $validated['contact_last_name']; + $this->contact->email = $validated['contact_email']; + $this->contact->save(); + + return $this->getPaymentMethods($this->contact); + } + /** * Middle method between selecting payment method & * submitting the from to the backend. From af27cd0b4e54716118be18cad841c15811aff124 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 7 Feb 2024 17:30:55 +0100 Subject: [PATCH 2/3] Add hidden input fields for contact information in billing portal purchase form --- .../billing-portal-purchase.blade.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 704a98323f4b..7bd196087c70 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -138,6 +138,9 @@ + + + @if($steps['started_payment'] == false) @@ -174,7 +177,39 @@ {{ ctrans('texts.trial_call_to_action') }} + @elseif($steps['check_rff']) + @if($errors->any()) +
+ @foreach($errors->all() as $error) +

{{ $error }}

+ @endforeach +
+ @endif +
+ @csrf + +
+ + +
+ +
+ + +
+ + + + +
@else
@csrf From a86a8d9fad9783ddc3f9adf72abee1c534ce3c20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 7 Feb 2024 17:52:54 +0100 Subject: [PATCH 3/3] Add conditional rendering for contact fields in billing portal purchase form --- .../components/livewire/billing-portal-purchase.blade.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php index 7bd196087c70..abd31174910b 100644 --- a/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/billing-portal-purchase.blade.php @@ -189,20 +189,26 @@ @csrf + @if(strlen($contact->first_name) === 0)
+ @endif -
+ @if(strlen($contact->last_name) === 0) + + @endif + @if(strlen($contact->email) === 0) + @endif