Last active
March 3, 2022 17:51
-
-
Save IliasHad/60f863245052158ad68b9bfd7773ab6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% if checkout.shipping_method.title == 'BNPL' %} | |
<script> | |
document.body.innerHTML = "Commande {{ order.name }}<center>Redirection vers la plateforme eProgram <br> Vous pourrez demander votre facilité de paiement "; | |
const queryString = window.location.search | |
const urlParams = new URLSearchParams(queryString); | |
if(urlParams.get('done')) { | |
fetch("https://eprogram-bnpl-app.herokuapp.com/api/request", { | |
"method": "PUT", | |
"headers": { | |
"Content-Type": "application/json", | |
"Access-Control-Allow-Origin": "*", | |
}, | |
"body": JSON.stringify({orderId: {{ checkout.order_id }}, status: "filled"}) | |
}) | |
.then(response => response.json()) | |
.then((data) => { | |
document.querySelector(".heading-2.os-step__title").innerText = "Your order is waiting the approval" | |
Shopify.Checkout.OrderStatus.addContentBox( | |
`<p>Okay, you'll get an email notifications when your application has been updated.</p>` | |
) | |
}) | |
} else { | |
fetch("https://eprogram-bnpl-app.herokuapp.com/api/request", { | |
"method": "POST", | |
"headers": { | |
"Content-Type": "application/json", | |
"Access-Control-Allow-Origin": "*", | |
}, | |
"body": JSON.stringify({id: {{ checkout.order_id }}, thankYouPage: window.location.href }) | |
}) | |
.then(response => response.json()) | |
.then(data => { | |
if(data.filled ) { | |
Shopify.Checkout.OrderStatus.addContentBox( | |
`<p>Okay, you'll get an email notifications when your application has been updated.</p>` | |
) | |
} | |
else if(data.success && !data.filled) { | |
window.location.href =data.redirectUrl | |
} else { | |
window.location.href =`https://novdistyep.myshopify.com/pages/sorry-page?redirect_url=${data.redirectUrl}&unMatchedConditions=${JSON.stringify(data. unMatchedConditions)}` | |
} | |
}) | |
.catch(err => { | |
console.error(err); | |
}); | |
} | |
</script> | |
{% endif %} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment