1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

- 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
This commit is contained in:
Benjamin Beganović 2021-01-19 14:36:07 +01:00
parent 8ed701519b
commit 617cc54de9
6 changed files with 52 additions and 21 deletions

View File

@ -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;
}
}
}
}

View File

@ -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');

View File

@ -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'],
];
}

View File

@ -12,13 +12,27 @@
<form wire:submit.prevent="handleSubmit(Object.fromEntries(new FormData($event.target)))">
@foreach($fields as $field)
@component('portal.ninja2020.components.general.card-element', ['title' => $field['label']])
<input class="input w-full" type="{{ $field['type'] }}" name="{{ $field['name'] }}">
@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')
<select id="country" class="input w-full form-select" name="{{ $field['name'] }}">
<option value="none"></option>
@if(session()->has('validation_errors') && array_key_exists($field['name'], session('validation_errors')))
<p class="mt-2 text-gray-900 border-red-300 px-2 py-1 bg-gray-100">{{ session('validation_errors')[$field['name']][0] }}</p>
@endif
@endcomponent
@foreach($countries as $country)
<option value="{{ $country->id }}">
{{ $country->iso_3166_2 }} ({{ $country->name }})
</option>
@endforeach
</select>
@else
<input class="input w-full" type="{{ $field['type'] }}" name="{{ $field['name'] }}">
@endif
@if(session()->has('validation_errors') && array_key_exists($field['name'], session('validation_errors')))
<p class="mt-2 text-gray-900 border-red-300 px-2 py-1 bg-gray-100">{{ session('validation_errors')[$field['name']][0] }}</p>
@endif
@endcomponent
@endif
@endforeach
@component('portal.ninja2020.components.general.card-element-single')

View File

@ -14,7 +14,7 @@
<form action="{{ route('client.payments.response') }}" method="post" id="server_response">
@csrf
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->id }}">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->company_gateway->id }}">
<input type="hidden" name="payment_method_id" value="1">
<input type="hidden" name="gateway_response" id="gateway_response">
<input type="hidden" name="dataValue" id="dataValue"/>
@ -45,7 +45,7 @@
@endsection
@section('gateway_footer')
@if($gateway->getConfigField('testMode'))
@if($gateway->company_gateway->getConfigField('testMode'))
<script src="https://jstest.authorize.net/v1/Accept.js" charset="utf-8"></script>
@else
<script src="https://js.authorize.net/v1/Accept.js" charset="utf-8"></script>

View File

@ -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])
<div class="container mx-auto grid grid-cols-12 opacity-25 pointer-events-none" data-ref="gateway-container">
<div class="col-span-12 lg:col-span-6 lg:col-start-4 overflow-hidden bg-white shadow rounded-lg">