diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php new file mode 100644 index 000000000000..d01a3e54fae4 --- /dev/null +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -0,0 +1,68 @@ +fields)->map(function ($field) use (&$rules) { + $rules[$field['name']] = $field['validation_rules']; + }); + + + $validator = Validator::make($data, $rules); + + if ($validator->fails()) { + session()->flash('validation_errors', $validator->getMessageBag()->getMessages()); + + return false; + } + + $this->emit('passed-required-fields-check'); + + return true; + } + + public function render() + { + // This will be coming from the gateway itself. Something like $gateway->getRequiredRules(); + + $this->fields = [ + [ + 'name' => 'client_first_name', + 'label' => ctrans('texts.first_name'), + 'type' => 'text', + 'validation_rules' => 'required|min:3' + ], + [ + 'name' => 'client_billing_address_zip', + 'label' => ctrans('texts.postal_code'), + 'type' => 'number', + 'validation_rules' => 'required|min:2', + ], + ]; + + return render('components.livewire.required-client-info'); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 871f57b567b2..c042c79b484d 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -3366,4 +3366,7 @@ return [ 'no_action_provided' => 'No action provided. If you believe this is wrong, please contact the support.', 'no_payable_invoices_selected' => 'No payable invoices selected. Make sure you are not trying to pay draft invoice or invoice with zero balance due.', + + 'required_payment_information' => 'Required payment details', + 'required_payment_information_more' => 'To complete a payment we need more details about you.', ]; diff --git a/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php b/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php new file mode 100644 index 000000000000..6fc5543b5e26 --- /dev/null +++ b/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php @@ -0,0 +1,33 @@ +
+
+
+

+ {{ ctrans('texts.required_payment_information') }} +

+ +

+ {{ ctrans('texts.required_payment_information_more') }} +

+
+ +
+ @foreach($fields as $field) + @component('portal.ninja2020.components.general.card-element', ['title' => $field['label']]) + + + @if(session()->has('validation_errors') && array_key_exists($field['name'], session('validation_errors'))) +

{{ session('validation_errors')[$field['name']][0] }}

+ @endif + @endcomponent + @endforeach + + @component('portal.ninja2020.components.general.card-element-single') +
+ +
+ @endcomponent +
+
+
diff --git a/resources/views/portal/ninja2020/layout/payments.blade.php b/resources/views/portal/ninja2020/layout/payments.blade.php index 000c968f9b52..8460f80612bd 100644 --- a/resources/views/portal/ninja2020/layout/payments.blade.php +++ b/resources/views/portal/ninja2020/layout/payments.blade.php @@ -11,7 +11,9 @@ @endpush @section('body') -
+ @livewire('required-client-info', ['gateway' => $gateway]) + +