mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Ability to select primary payment method
This commit is contained in:
parent
d7525f93cb
commit
cca78a9d38
56
app/Http/Livewire/PaymentMethods/UpdateDefaultMethod.php
Normal file
56
app/Http/Livewire/PaymentMethods/UpdateDefaultMethod.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Http\Livewire\PaymentMethods;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use Livewire\Component;
|
||||
|
||||
class UpdateDefaultMethod extends Component
|
||||
{
|
||||
/** @var \App\Models\Company */
|
||||
public $company;
|
||||
|
||||
/** @var \App\Models\ClientGatewayToken */
|
||||
public $token;
|
||||
|
||||
/** @var \App\Models\Client */
|
||||
public $client;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->company = $this->client->company;
|
||||
|
||||
MultiDB::setDb($this->company->db);
|
||||
|
||||
$this->is_disabled = $this->token->is_default;
|
||||
}
|
||||
|
||||
public function makeDefault(): void
|
||||
{
|
||||
if ($this->token->is_default) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->client->gateway_tokens()->update(['is_default' => 0]);
|
||||
|
||||
$this->token->is_default = 1;
|
||||
$this->token->save();
|
||||
|
||||
$this->emit('UpdateDefaultMethod::method-updated');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return render('components.livewire.update-default-payment-method');
|
||||
}
|
||||
}
|
@ -4268,6 +4268,9 @@ $LANG = array(
|
||||
'company_import_failure_body' => 'There was an error importing the company data, the error message was:',
|
||||
'recurring_invoice_due_date' => 'Due Date',
|
||||
'amount_cents' => 'Amount in pennies,pence or cents',
|
||||
'default_payment_method_label' => 'Default Payment Method',
|
||||
'default_payment_method' => 'Make this your preferred way of paying.',
|
||||
'already_default_payment_method' => 'This is your preferred way of paying.',
|
||||
);
|
||||
|
||||
return $LANG;
|
||||
|
@ -0,0 +1,25 @@
|
||||
<div class="mt-4 mb-4 bg-white shadow sm:rounded-lg">
|
||||
<div class="px-4 py-5 sm:p-6">
|
||||
<div class="sm:flex sm:items-start sm:justify-between">
|
||||
<div>
|
||||
<h3 class="text-lg font-medium leading-6 text-gray-900">
|
||||
{{ ctrans('texts.default_payment_method_label') }}
|
||||
</h3>
|
||||
<div class="max-w-xl mt-2 text-sm leading-5 text-gray-500 flex items-center">
|
||||
<span class="text-primary mr-1 hidden" data-ref="success-label">{{ ctrans('texts.success') }}!</span>
|
||||
|
||||
<p>
|
||||
{{ $token->is_default ? ctrans('texts.already_default_payment_method') : ctrans('texts.default_payment_method') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-5 sm:mt-0 sm:ml-6 sm:flex-shrink-0 sm:flex sm:items-center">
|
||||
<form wire:submit.prevent="makeDefault">
|
||||
<button class="button button-primary bg-primary" {{ $token->is_default ? 'disabled' : '' }}>
|
||||
{{ ctrans('texts.save_as_default') }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -15,61 +15,61 @@
|
||||
<div>
|
||||
<dl>
|
||||
@if(!empty($payment_method->gateway_type->name) && !is_null($payment_method->gateway_type->name))
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.payment_type') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ ucfirst($payment_method->gateway_type->name) }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.payment_type') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ ucfirst($payment_method->gateway_type->name) }}
|
||||
</dd>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(!empty($payment_method->meta) && !is_null($payment_method->meta))
|
||||
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.type') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ optional($payment_method->meta)->brand }}
|
||||
{{ optional($payment_method->meta)->scheme }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.type') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ optional($payment_method->meta)->brand }}
|
||||
{{ optional($payment_method->meta)->scheme }}
|
||||
</dd>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(!empty($payment_method->meta->last4) && !is_null($payment_method->meta->last4))
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.card_number') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
**** {{ ucfirst($payment_method->meta->last4) }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.card_number') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
**** {{ ucfirst($payment_method->meta->last4) }}
|
||||
</dd>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@if(!empty($payment_method->created_at) && !is_null($payment_method->created_at))
|
||||
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.date_created') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ $payment_method->formatDateTimestamp($payment_method->created_at, auth()->user()->client->date_format()) }}
|
||||
</dd>
|
||||
</div>
|
||||
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.date_created') }}
|
||||
</dt>
|
||||
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ $payment_method->formatDateTimestamp($payment_method->created_at, auth()->user()->client->date_format()) }}
|
||||
</dd>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if(!empty($payment_method->is_default) && !is_null($payment_method->is_default))
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.default') }}
|
||||
</dt>
|
||||
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ $payment_method->is_default ? ctrans('texts.yes') : ctrans('texts.no') }}
|
||||
<div class="px-4 py-5 bg-gray-50 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
{{ ctrans('texts.default') }}
|
||||
</dt>
|
||||
<div class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
|
||||
{{ $payment_method->is_default ? ctrans('texts.yes') : ctrans('texts.no') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
@isset($payment_method->meta->exp_month)
|
||||
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
|
||||
<dt class="text-sm font-medium leading-5 text-gray-500">
|
||||
@ -83,7 +83,10 @@
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 mb-4 bg-white shadow sm:rounded-lg" translate>
|
||||
|
||||
@livewire('payment-methods.update-default-method', ['token' => $payment_method, 'client' => $client])
|
||||
|
||||
<div class="mt-4 mb-4 bg-white shadow sm:rounded-lg">
|
||||
<div class="px-4 py-5 sm:p-6">
|
||||
<div class="sm:flex sm:items-start sm:justify-between">
|
||||
<div>
|
||||
@ -109,3 +112,11 @@
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('footer')
|
||||
<script>
|
||||
Livewire.on('UpdateDefaultMethod::method-updated', event => {
|
||||
document.querySelector('span[data-ref=success-label]').classList.remove('hidden');
|
||||
});
|
||||
</script>
|
||||
@endsection
|
||||
|
Loading…
Reference in New Issue
Block a user