From ad203ac2288d127840a7bf7389008d5a441e641e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 18 May 2022 14:22:04 +1000 Subject: [PATCH] ACH refactor --- .../gateways/stripe/ach/pay.blade.php | 147 ++++++++++++------ 1 file changed, 103 insertions(+), 44 deletions(-) diff --git a/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php b/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php index 3c4dd4e332eb..5a1fc11b44cb 100644 --- a/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php +++ b/resources/views/portal/ninja2020/gateways/stripe/ach/pay.blade.php @@ -52,11 +52,6 @@ @else - @component('portal.ninja2020.components.general.card-element-single') - - - @endcomponent - @component('portal.ninja2020.components.general.card-element', ['title' => ctrans('texts.account_holder_name')]) @endcomponent @@ -76,11 +71,74 @@ {{ $slot ?? ctrans('texts.new_bank_account') }} + +
+
+ + + +
+
+ @endif @endsection + + + @push('footer') @@ -88,6 +146,23 @@ let payNow = document.getElementById('pay-now'); + let stripePaymentIntent = ''; + + let stripe; + + let response; + + let publishableKey = document.querySelector('meta[name="stripe-publishable-key"]').content + let stripeConnect = document.querySelector('meta[name="stripe-account-id"]')?.content + + if(stripeConnect){ + stripe = Stripe(publishableKey, { stripeAccount: stripeConnect}); + } + else { + stripe = Stripe(publishableKey); + } + + if(payNow) { @@ -113,27 +188,8 @@ document.getElementById('new-bank').addEventListener('click', (ev) => { - if (!document.getElementById('accept-terms').checked) { - errors.textContent = "You must accept the mandate terms prior to making payment."; - errors.hidden = false; - - return; - } - errors.hidden = true; - let stripe; - - let publishableKey = document.querySelector('meta[name="stripe-publishable-key"]').content - let stripeConnect = document.querySelector('meta[name="stripe-account-id"]')?.content - - if(stripeConnect){ - stripe = Stripe(publishableKey, { stripeAccount: stripeConnect}); - } - else { - stripe = Stripe(publishableKey); - } - let newBankButton = document.getElementById('new-bank'); newBankButton.disabled = true; newBankButton.querySelector('svg').classList.remove('hidden'); @@ -174,16 +230,23 @@ // manually-entered. Display payment method details and mandate text // to the customer and confirm the intent once they accept // the mandate. + stripePaymentIntent = paymentIntent; + showModal(paymentIntent); - - confirmPayment(stripe, clientSecret); } }); }); - function confirmPayment(stripe, clientSecret){ + function showModal(paymentIntent) + { + document.getElementById('open-delete-popup').click(); + } + + function confirmPayment(){ + + const clientSecret = document.querySelector('meta[name="client_secret"]')?.content; stripe.confirmUsBankAccountPayment(clientSecret) .then(({paymentIntent, error}) => { @@ -204,35 +267,31 @@ // Confirmation succeeded! The account will be debited. // Display a message to customer. - // let gateway_response = document.querySelector('input[name="gateway_response"]'); - // gateway_response.value = JSON.stringify(paymentIntent.id); - - var wait = paymentIntent => new Promise(resolve => setTimeout(resolve, paymentIntent)); - - // document.getElementById('server-response').submit(); - - } else if (paymentIntent.next_action?.type === "verify_with_microdeposits") { // The account needs to be verified via microdeposits. // Display a message to consumer with next steps (consumer waits for // microdeposits, then enters a statement descriptor code on a page sent to them via email). } + }).finally((promise) => { + + console.log(promise); + console.log("and we are finished") + }); - + + resetButtons(); + finalize(); + } + function finalize() + { - function setTimeout(paymentIntent){ - - let gateway_response = document.getElementById('gateway_response'); - gateway_response.value = JSON.stringify( - paymentIntent - ); - document.getElementById('server-response').submit(); - + document.getElementById('server-response').submit(); + } function resetButtons()