Skip to content

Commit

Permalink
Added better error handling to onBeforeError
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Schneider-Swales committed Mar 22, 2024
1 parent 723eb69 commit f8c5285
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions docs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f8c5285

Please sign in to comment.