1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Ability to select presaved token

This commit is contained in:
Benjamin Beganović 2021-10-12 18:56:20 +02:00
parent 0ff902d90f
commit ce0c2dc8e8
2 changed files with 92 additions and 20 deletions

View File

@ -57,31 +57,52 @@ class ProcessSEPA {
}; };
handle = () => { handle = () => {
Array
.from(document.getElementsByClassName('toggle-payment-with-token'))
.forEach((element) => element.addEventListener('click', (element) => {
document.getElementById('stripe--payment-container').classList.add('hidden');
document.getElementById('save-card--container').style.display = 'none';
document.querySelector('input[name=token]').value = element.target.dataset.token;
}));
document
.getElementById('toggle-payment-with-new-bank-account')
.addEventListener('click', (element) => {
document.getElementById('stripe--payment-container').classList.remove('hidden');
document.getElementById('save-card--container').style.display = 'grid';
document.querySelector('input[name=token]').value = "";
});
document.getElementById('pay-now').addEventListener('click', (e) => { document.getElementById('pay-now').addEventListener('click', (e) => {
if (document.querySelector('input[name=token]').value.length !== 0) {
document.querySelector('#errors').hidden = true;
return document.querySelector('#server-response').submit();
}
let errors = document.getElementById('errors'); let errors = document.getElementById('errors');
if (document.getElementById('sepa-name').value === "") { if (document.getElementById('sepa-name').value === "") {
document.getElementById('sepa-name').focus(); document.getElementById('sepa-name').focus();
errors.textContent = "Name required."; errors.textContent = "Name required.";
errors.hidden = false; errors.hidden = false;
return; return;
} }
if (document.getElementById('sepa-email-address').value === "") { if (document.getElementById('sepa-email-address').value === "") {
document.getElementById('sepa-email-address').focus(); document.getElementById('sepa-email-address').focus();
errors.textContent = "Email required."; errors.textContent = "Email required.";
errors.hidden = false; errors.hidden = false;
return ; return;
} }
if (!document.getElementById('sepa-mandate-acceptance').checked) { if (!document.getElementById('sepa-mandate-acceptance').checked) {
errors.textContent = "Accept Terms"; errors.textContent = "Accept Terms";
errors.hidden = false; errors.hidden = false;
console.log("Terms"); console.log("Terms");
return ; return;
} }
document.getElementById('pay-now').disabled = true; document.getElementById('pay-now').disabled = true;
document.querySelector('#pay-now > svg').classList.remove('hidden'); document.querySelector('#pay-now > svg').classList.remove('hidden');

View File

@ -10,6 +10,16 @@
@endsection @endsection
@section('gateway_content') @section('gateway_content')
<form action="{{ route('client.payments.response') }}" method="post" id="server-response">
@csrf
<input type="hidden" name="gateway_response">
<input type="hidden" name="company_gateway_id" value="{{ $gateway->getCompanyGatewayId() }}">
<input type="hidden" name="payment_method_id" value="{{ $payment_method_id }}">
<input type="hidden" name="payment_hash" value="{{ $payment_hash }}">
<input type="hidden" name="store_card">
<input type="hidden" name="token">
</form>
<div class="alert alert-failure mb-4" hidden id="errors"></div> <div class="alert alert-failure mb-4" hidden id="errors"></div>
@include('portal.ninja2020.gateways.includes.payment_details') @include('portal.ninja2020.gateways.includes.payment_details')
@ -18,7 +28,48 @@
{{ ctrans('texts.sepa') }} ({{ ctrans('texts.bank_transfer') }}) {{ ctrans('texts.sepa') }} ({{ ctrans('texts.bank_transfer') }})
@endcomponent @endcomponent
@include('portal.ninja2020.gateways.stripe.sepa.sepa_debit') @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.pay_with')])
@if (count($tokens) > 0)
@foreach ($tokens as $token)
<label class="mr-4">
<input type="radio" data-token="{{ $token->token }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
</label>
@endforeach
@endisset
<label>
<input type="radio" id="toggle-payment-with-new-bank-account" class="form-radio cursor-pointer" name="payment-type"
checked />
<span class="ml-1 cursor-pointer">{{ __('texts.new_bank_account') }}</span>
</label>
@endcomponent
@component('portal.ninja2020.components.general.card-element-single')
<div id="stripe--payment-container">
<label for="sepa-name">
<input class="input w-full" id="sepa-name" type="text"
placeholder="{{ ctrans('texts.bank_account_holder') }}">
</label>
<label for="sepa-email" class="mt-4">
<input class="input w-full" id="sepa-email-address" type="email"
placeholder="{{ ctrans('texts.email') }}">
</label>
<label>
<div class="border p-3 rounded mt-2">
<div id="sepa-iban"></div>
</div>
</label>
<div id="mandate-acceptance" class="mt-4">
<input type="checkbox" id="sepa-mandate-acceptance" class="input mr-4">
<label for="sepa-mandate-acceptance" class="cursor-pointer">
{{ ctrans('texts.sepa_mandat', ['company' => $contact->company->present()->name()]) }}
</label>
</div>
</div>
@endcomponent
@include('portal.ninja2020.gateways.includes.save_card') @include('portal.ninja2020.gateways.includes.save_card')
@include('portal.ninja2020.gateways.includes.pay_now') @include('portal.ninja2020.gateways.includes.pay_now')
@endsection @endsection