From 7feb3b091c2012079d4154646caa03b5c19ee464 Mon Sep 17 00:00:00 2001 From: Dominik Hebeler <dominik@hebeler.club> Date: Fri, 14 Apr 2023 21:46:10 +0200 Subject: [PATCH] disabling pay now button long enough to complete --- pass/public/styles/key/checkout-payment.less | 9 +- pass/resources/js/checkout_paypal.js | 86 ++++++++++---------- 2 files changed, 45 insertions(+), 50 deletions(-) diff --git a/pass/public/styles/key/checkout-payment.less b/pass/public/styles/key/checkout-payment.less index 900f316..2705ea0 100644 --- a/pass/public/styles/key/checkout-payment.less +++ b/pass/public/styles/key/checkout-payment.less @@ -105,7 +105,6 @@ margin: 1rem 0; } #paypal-payment-card #paypal-card-form { - @paypal-card-form-breakpoint-1: 920px; display: grid; grid-template-columns: 1fr calc(7ch + 1.5rem) calc(4ch + 1.5rem); grid-template-rows: 1fr auto auto; @@ -146,7 +145,7 @@ } } > button#submit-credit-card { - grid-column: span 2; + grid-column: span 3; padding: 0.5rem; justify-self: center; display: flex; @@ -162,11 +161,5 @@ display: block; } } - @media (max-width: @paypal-card-form-breakpoint-1) { - grid-template-columns: 1fr; - > button#submit-credit-card { - grid-column: auto; - } - } } } diff --git a/pass/resources/js/checkout_paypal.js b/pass/resources/js/checkout_paypal.js index 9eecdf7..ee19b9e 100644 --- a/pass/resources/js/checkout_paypal.js +++ b/pass/resources/js/checkout_paypal.js @@ -91,7 +91,7 @@ function get_paypal_checkout_data(funding_source) { return; } }, - createOrder: (data, actions) => { + createOrder: () => { let checkout_paypal_create_order_url = document.querySelector( "#paypal-checkout input[name=paypal-order-base-url]" @@ -111,17 +111,15 @@ function get_paypal_checkout_data(funding_source) { return order.paypal_order_id; }); }, - onCancel: () => + onCancel: (data, actions) => cancelPayment( document.getElementById("paypal-checkout").dataset.payment_reference_id ), - onError: (err) => { - return cancelPayment( + onError: (err) => + cancelPayment( document.getElementById("paypal-checkout").dataset.payment_reference_id - ); - }, - onApprove: (data, actions) => { - console.log(data); + ), + onApprove: () => { let checkout_paypal_capture_order_url = document.querySelector( "#paypal-checkout input[name=paypal-order-base-url]" @@ -258,41 +256,45 @@ function loadCardPayment(checkout_data) { cardFields .submit(cardfield_data) .then((payload) => { - checkout_data.onApprove().catch((reason) => { - let payment_failed = false; - reason.errors.forEach((error) => { - if (error.type && error.type === "PAYPAL_CARD_3D_ERROR") { - payment_failed = true; - document - .getElementById("paypal-card-errors-3d") - .classList.remove("hidden"); - cancelPayment( - document.getElementById("paypal-checkout").dataset - .payment_reference_id - ); - } else if ( - error.type && - error.type === "PAYMENT_NOT_COMPLETED_ERROR" - ) { - payment_failed = true; - document - .getElementById("paypal-card-errors-generic") - .classList.remove("hidden"); - cancelPayment( - document.getElementById("paypal-checkout").dataset - .payment_reference_id - ); - } else { - // Capture was not yet possible ToDo redirect user to Order - // There is a chance that webhooks will capture the payment - console.error(reason); - console.log("Fehlgeschlagen"); - } + checkout_data + .onApprove() + .then(() => { + // Enable Button + submit_button.disabled = undefined; + submit_button.classList.remove("loading"); + }) + .catch((reason) => { + let payment_failed = false; + reason.errors.forEach((error) => { + if (error.type && error.type === "PAYPAL_CARD_3D_ERROR") { + payment_failed = true; + document + .getElementById("paypal-card-errors-3d") + .classList.remove("hidden"); + cancelPayment( + document.getElementById("paypal-checkout").dataset + .payment_reference_id + ); + } else if ( + error.type && + error.type === "PAYMENT_NOT_COMPLETED_ERROR" + ) { + payment_failed = true; + document + .getElementById("paypal-card-errors-generic") + .classList.remove("hidden"); + cancelPayment( + document.getElementById("paypal-checkout").dataset + .payment_reference_id + ); + } else { + // Capture was not yet possible ToDo redirect user to Order + // There is a chance that webhooks will capture the payment + console.error(reason); + console.log("Fehlgeschlagen"); + } + }); }); - }); - // Enable Button - submit_button.disabled = undefined; - submit_button.classList.remove("loading"); }) .catch((reason) => { reason.details.forEach((detail) => { -- GitLab