mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
- Add getClientRequiredFields in BaseDriver.php
- Pass $fields in @required-client-info - Don't show form if fields are satisfied - Remove $gateway reference in RequiredClientInfo.php - StripePaymentDriver.php required fields - Removed old-redirect logic for required fields
This commit is contained in:
parent
0b4e85957c
commit
b014aecc7d
@ -27,14 +27,6 @@ class RequiredClientInfo extends Component
|
|||||||
*/
|
*/
|
||||||
public $contact;
|
public $contact;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Instance of payment gateway. Used for getting the required fields.
|
|
||||||
*
|
|
||||||
* @var mixed
|
|
||||||
*/
|
|
||||||
private $gateway;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mappings for updating the database. Left side is mapping from gateway,
|
* Mappings for updating the database. Left side is mapping from gateway,
|
||||||
* right side is column in database.
|
* right side is column in database.
|
||||||
@ -66,6 +58,8 @@ class RequiredClientInfo extends Component
|
|||||||
'contact_phone' => 'phone',
|
'contact_phone' => 'phone',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public $show_form = true;
|
||||||
|
|
||||||
public function handleSubmit(array $data): bool
|
public function handleSubmit(array $data): bool
|
||||||
{
|
{
|
||||||
$rules = [];
|
$rules = [];
|
||||||
@ -124,24 +118,28 @@ class RequiredClientInfo extends Component
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkFields()
|
||||||
|
{
|
||||||
|
foreach ($this->fields as $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 (Str::startsWith($field['name'], 'contact_')) {
|
||||||
|
(empty($this->contact->{$_field}) || is_null($this->contact->{$_field}))
|
||||||
|
? $this->show_form = true
|
||||||
|
: $this->show_form = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
// This will be coming from the gateway itself. Something like $gateway->getRequiredRules();
|
$this->checkFields();
|
||||||
|
|
||||||
$this->fields = [
|
|
||||||
[
|
|
||||||
'name' => 'client_name',
|
|
||||||
'label' => ctrans('texts.name'),
|
|
||||||
'type' => 'text',
|
|
||||||
'validation_rules' => 'required|min:3'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'contact_phone',
|
|
||||||
'label' => ctrans('texts.phone'),
|
|
||||||
'type' => 'number',
|
|
||||||
'validation_rules' => 'required|min:2',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return render('components.livewire.required-client-info');
|
return render('components.livewire.required-client-info');
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,16 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
$this->client = $client;
|
$this->client = $client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required fields for client to fill, to proceed with gateway actions.
|
||||||
|
*
|
||||||
|
* @return array[]
|
||||||
|
*/
|
||||||
|
public function getClientRequiredFields(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authorize a payment method.
|
* Authorize a payment method.
|
||||||
*
|
*
|
||||||
|
@ -149,6 +149,13 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getClientRequiredFields(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Proxy method to pass the data into payment method authorizeView().
|
* Proxy method to pass the data into payment method authorizeView().
|
||||||
*
|
*
|
||||||
@ -157,12 +164,6 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
*/
|
*/
|
||||||
public function authorizeView(array $data)
|
public function authorizeView(array $data)
|
||||||
{
|
{
|
||||||
if (count($this->required_fields) > 0) {
|
|
||||||
return redirect()
|
|
||||||
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
|
||||||
->with('missing_required_fields', $this->required_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->payment_method->authorizeView($data);
|
return $this->payment_method->authorizeView($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,12 +175,6 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
*/
|
*/
|
||||||
public function authorizeResponse($request)
|
public function authorizeResponse($request)
|
||||||
{
|
{
|
||||||
if (count($this->required_fields) > 0) {
|
|
||||||
return redirect()
|
|
||||||
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
|
||||||
->with('missing_required_fields', $this->required_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->payment_method->authorizeResponse($request);
|
return $this->payment_method->authorizeResponse($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,23 +186,11 @@ class StripePaymentDriver extends BaseDriver
|
|||||||
*/
|
*/
|
||||||
public function processPaymentView(array $data)
|
public function processPaymentView(array $data)
|
||||||
{
|
{
|
||||||
if (count($this->required_fields) > 0) {
|
|
||||||
return redirect()
|
|
||||||
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
|
||||||
->with('missing_required_fields', $this->required_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->payment_method->paymentView($data);
|
return $this->payment_method->paymentView($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function processPaymentResponse($request) //We never have to worry about unsuccessful payments as failures are handled at the front end for this driver.
|
public function processPaymentResponse($request) //We never have to worry about unsuccessful payments as failures are handled at the front end for this driver.
|
||||||
{
|
{
|
||||||
if (count($this->required_fields) > 0) {
|
|
||||||
return redirect()
|
|
||||||
->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id])
|
|
||||||
->with('missing_required_fields', $this->required_fields);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->payment_method->paymentResponse($request);
|
return $this->payment_method->paymentResponse($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,4 +30,13 @@
|
|||||||
@endcomponent
|
@endcomponent
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@if(!$show_form)
|
||||||
|
<script>
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
document.querySelector('div[data-ref="required-fields-container"]').classList.add('hidden');
|
||||||
|
document.querySelector('div[data-ref="gateway-container"]').classList.remove('hidden');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
@endpush
|
@endpush
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
@livewire('required-client-info', ['gateway' => $gateway, 'contact' => auth('contact')->user()])
|
@livewire('required-client-info', ['fields' => $gateway->getClientRequiredFields(), 'contact' => auth('contact')->user()])
|
||||||
|
|
||||||
<div class="container mx-auto grid grid-cols-12 hidden" data-ref="gateway-container">
|
<div class="container mx-auto grid grid-cols-12 hidden" data-ref="gateway-container">
|
||||||
<div class="col-span-12 lg:col-span-6 lg:col-start-4 overflow-hidden bg-white shadow rounded-lg">
|
<div class="col-span-12 lg:col-span-6 lg:col-start-4 overflow-hidden bg-white shadow rounded-lg">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user