From f8c5285b53502fd087e7ed8ea3770c93639c295f Mon Sep 17 00:00:00 2001 From: Tom Schneider-Swales Date: Fri, 22 Mar 2024 11:36:07 +0100 Subject: [PATCH] Added better error handling to onBeforeError --- docs/index.js | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/docs/index.js b/docs/index.js index c76bc72..3da238e 100644 --- a/docs/index.js +++ b/docs/index.js @@ -185,10 +185,21 @@ async function initPayment() { preload: ["cards", "afterpay"], // loads cards and afterpay script as soon as page loads so that rendering using dropIn is fast onBeforeError: async(_checkout, componentName, errorData) => { console.error("On before error called",_checkout, componentName, errorData); - document.getElementById("payment-methods").style.display = "none"; - const message = document.getElementById("custom-override-message"); - message.innerHTML = `onBeforeError called in ${componentName}`; - message.style = "background-color: red; display: flex;"; + switch(componentName) { + case "cards": + document.getElementById("cards-payment-method").style.display = "none"; + break; + case "afterpay": + document.getElementById("afterpay-payment-method").style.display = "none"; + break; + default: + document.getElementById("payment-methods").style.display = "none"; + const message = document.getElementById("custom-override-message"); + message.innerHTML = `onBeforeError called in ${componentName}`; + message.style = "background-color: red; display: flex;"; + break; + } + return new Promise((resolve) => { resolve(false); }); @@ -214,6 +225,8 @@ async function initPayment() { // Initialises the SDK const checkout = await new Payoneer.CheckoutWeb(configs); + window.checkout = checkout; + document.getElementById("loading-message").style.display = "none"; function createPaymentListener(paymentComponent) { @@ -293,8 +306,6 @@ async function initPayment() { hidePaymentButton: !(payButtonType === "default") }).mount(container); - console.log(afterpay) - afterpayRadio.addEventListener("change", (event) => { if(event.target.checked) { updateCustomPaymentButton(afterpay);