From 617cc54de9a79f573600a4113275fc31180546f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 19 Jan 2021 14:36:07 +0100 Subject: [PATCH] - Pass instance of AuthorizePaymentDriver.php as $gateway instead of CompanyGateway record - Define required fields for AuthorizePaymentDriver.php - Update references to $gateway (CompanyGateway) - Pass $countries to required-client-info.blade.php - Handle country submission for required-client-info.blade.php - Only show non-filled fields in RequiredClientInfo.php --- app/Http/Livewire/RequiredClientInfo.php | 33 ++++++++++++------- .../Authorize/AuthorizeCreditCard.php | 2 +- app/PaymentDrivers/AuthorizePaymentDriver.php | 6 ++++ .../livewire/required-client-info.blade.php | 26 +++++++++++---- .../authorize/credit_card/pay.blade.php | 4 +-- .../ninja2020/layout/payments.blade.php | 2 +- 6 files changed, 52 insertions(+), 21 deletions(-) diff --git a/app/Http/Livewire/RequiredClientInfo.php b/app/Http/Livewire/RequiredClientInfo.php index c68b1ef354..e57ed12297 100644 --- a/app/Http/Livewire/RequiredClientInfo.php +++ b/app/Http/Livewire/RequiredClientInfo.php @@ -27,6 +27,11 @@ class RequiredClientInfo extends Component */ public $contact; + /** + * @var array + */ + public $countries; + /** * Mappings for updating the database. Left side is mapping from gateway, * right side is column in database. @@ -58,16 +63,18 @@ class RequiredClientInfo extends Component 'contact_phone' => 'phone', ]; - public $show_form = true; + public $show_form = false; public function handleSubmit(array $data): bool { $rules = []; collect($this->fields)->map(function ($field) use (&$rules) { - $rules[$field['name']] = array_key_exists('validation_rules', $field) - ? $field['validation_rules'] - : 'required'; + if (!array_key_exists('filled', $field)) { + $rules[$field['name']] = array_key_exists('validation_rules', $field) + ? $field['validation_rules'] + : 'required'; + } }); $validator = Validator::make($data, $rules); @@ -120,19 +127,23 @@ class RequiredClientInfo extends Component public function checkFields() { - foreach ($this->fields as $field) { + foreach ($this->fields as $index => $field) { $_field = $this->mappings[$field['name']]; if (Str::startsWith($field['name'], 'client_')) { - (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field})) - ? $this->show_form = true - : $this->show_form = false; + if (empty($this->contact->client->{$_field}) || is_null($this->contact->client->{$_field})) { + $this->show_form = true; + } else { + $this->fields[$index]['filled'] = true; + } } if (Str::startsWith($field['name'], 'contact_')) { - (empty($this->contact->{$_field}) || is_null($this->contact->{$_field})) - ? $this->show_form = true - : $this->show_form = false; + if ((empty($this->contact->{$_field}) || is_null($this->contact->{$_field}))) { + $this->show_form = true; + } else { + $this->fields[$index]['filled'] = true; + } } } } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 1e30cfb42d..543d3d46ee 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -44,7 +44,7 @@ class AuthorizeCreditCard ->get(); $data['tokens'] = $tokens; - $data['gateway'] = $this->authorize->company_gateway; + $data['gateway'] = $this->authorize; $data['public_client_id'] = $this->authorize->init()->getPublicClientKey(); $data['api_login_id'] = $this->authorize->company_gateway->getConfigField('apiLoginId'); diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 3f516c9f81..06204a1563 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -68,6 +68,12 @@ class AuthorizePaymentDriver extends BaseDriver return [ ['name' => 'client_name', 'label' => ctrans('texts.name'), 'type' => 'text', 'validation' => 'required|min:2'], ['name' => 'contact_email', 'label' => ctrans('texts.email'), 'type' => 'text', 'validation' => 'required|email:rfc'], + ['name' => 'client_address_line_1', 'label' => ctrans('texts.address1'), 'type' => 'text', 'validation' => 'required'], + ['name' => 'client_address_line_2', 'label' => ctrans('texts.address1'), 'type' => 'text', 'validation' => 'sometimes'], + ['name' => 'client_city', 'label' => ctrans('texts.city'), 'type' => 'text', 'validation' => 'required'], + ['name' => 'client_state', 'label' => ctrans('texts.state'), 'type' => 'text', 'validation' => 'required'], + ['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required'], + ['name' => 'client_country_id', 'label' => ctrans('texts.country'), 'type' => 'select', 'validation' => 'required'], ]; } 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 index b320145fa1..3928e40e6e 100644 --- a/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php +++ b/resources/views/portal/ninja2020/components/livewire/required-client-info.blade.php @@ -12,13 +12,27 @@
@foreach($fields as $field) - @component('portal.ninja2020.components.general.card-element', ['title' => $field['label']]) - + @if(!array_key_exists('filled', $field)) + @component('portal.ninja2020.components.general.card-element', ['title' => $field['label']]) + @if($field['name'] == 'client_country_id' || $field['name'] == 'client_shipping_country_id') + + @else + + @endif + + @if(session()->has('validation_errors') && array_key_exists($field['name'], session('validation_errors'))) +

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

+ @endif + @endcomponent + @endif @endforeach @component('portal.ninja2020.components.general.card-element-single') diff --git a/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php b/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php index 4cb169fed9..2a1e841b36 100644 --- a/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/authorize/credit_card/pay.blade.php @@ -14,7 +14,7 @@ @csrf - + @@ -45,7 +45,7 @@ @endsection @section('gateway_footer') - @if($gateway->getConfigField('testMode')) + @if($gateway->company_gateway->getConfigField('testMode')) @else diff --git a/resources/views/portal/ninja2020/layout/payments.blade.php b/resources/views/portal/ninja2020/layout/payments.blade.php index bcfe7e4bb4..7266b7992a 100644 --- a/resources/views/portal/ninja2020/layout/payments.blade.php +++ b/resources/views/portal/ninja2020/layout/payments.blade.php @@ -11,7 +11,7 @@ @endpush @section('body') - @livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth('contact')->user()]) + @livewire('required-client-info', ['fields' => method_exists($gateway, 'getClientRequiredFields') ? $gateway->getClientRequiredFields() : [], 'contact' => auth('contact')->user(), 'countries' => $countries])