From ce0c2dc8e8b36ab6974cb0a999292a25af1aa8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 12 Oct 2021 18:56:20 +0200 Subject: [PATCH] Ability to select presaved token --- resources/js/clients/payments/stripe-sepa.js | 59 +++++++++++++------ .../gateways/stripe/sepa/pay.blade.php | 53 ++++++++++++++++- 2 files changed, 92 insertions(+), 20 deletions(-) diff --git a/resources/js/clients/payments/stripe-sepa.js b/resources/js/clients/payments/stripe-sepa.js index 8c62df2d7c..f5e4fe33f8 100644 --- a/resources/js/clients/payments/stripe-sepa.js +++ b/resources/js/clients/payments/stripe-sepa.js @@ -57,31 +57,52 @@ class ProcessSEPA { }; 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) => { + 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 === "") { - document.getElementById('sepa-name').focus(); - errors.textContent = "Name required."; - errors.hidden = false; - return; - } + if (document.getElementById('sepa-name').value === "") { + document.getElementById('sepa-name').focus(); + errors.textContent = "Name required."; + errors.hidden = false; + return; + } - if (document.getElementById('sepa-email-address').value === "") { - document.getElementById('sepa-email-address').focus(); - errors.textContent = "Email required."; - errors.hidden = false; - return ; - } + if (document.getElementById('sepa-email-address').value === "") { + document.getElementById('sepa-email-address').focus(); + errors.textContent = "Email required."; + errors.hidden = false; + return; + } - if (!document.getElementById('sepa-mandate-acceptance').checked) { - errors.textContent = "Accept Terms"; - errors.hidden = false; - console.log("Terms"); - return ; - } + if (!document.getElementById('sepa-mandate-acceptance').checked) { + errors.textContent = "Accept Terms"; + errors.hidden = false; + console.log("Terms"); + return; + } document.getElementById('pay-now').disabled = true; document.querySelector('#pay-now > svg').classList.remove('hidden'); diff --git a/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php index dd8ff6b605..3acd81f4fd 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/sepa/pay.blade.php @@ -10,6 +10,16 @@ @endsection @section('gateway_content') +
+ @csrf + + + + + + +
+ @include('portal.ninja2020.gateways.includes.payment_details') @@ -18,7 +28,48 @@ {{ ctrans('texts.sepa') }} ({{ ctrans('texts.bank_transfer') }}) @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) + + @endforeach + @endisset + + + @endcomponent + + @component('portal.ninja2020.components.general.card-element-single') +
+ + + +
+ + +
+
+ @endcomponent + @include('portal.ninja2020.gateways.includes.save_card') @include('portal.ninja2020.gateways.includes.pay_now') @endsection