deegipay
Version:
all in one payment
112 lines (91 loc) • 3.39 kB
JavaScript
function initPayment(client_id, client_secret, montant, reference_produit, lang, successUrl, failedUrl, urlCalback) {
const data = {
client_id: client_id,
client_secret: client_secret,
montant: montant,
reference_produit: reference_produit,
lang: lang,
successUrl: successUrl, // URL Success Uniquement pour le front
failedUrl: failedUrl, // Url Failed uniquement pour le front
urlCalback: urlCalback, // Url Callback
};
console.log(data);
fetch("https://deegipay.com/payment/api/v1/marchands/test/pay/all", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
if (result.status == 1) {
openPayWidget("https://webpayment.deegipay.com/webpayment/checkout/sandbox/" + result.resultat.payment_token);
// openPayWidget(result.resultat.checkout);
// openPayWidget("http://localhost:51674/webpayment/checkout/" + result.resultat.payment_token);
}else{
console.log(result);
alert(result.message)
}
})
.catch(error => {
console.error("Erreur :", error);
});
}
function openPayWidget(url) {
const backdrop = document.createElement('div');
backdrop.style.position = 'fixed';
backdrop.style.top = 0;
backdrop.style.left = 0;
backdrop.style.width = '100%';
backdrop.style.height = '100%';
backdrop.style.backgroundColor = 'rgba(0,0,0,0.5)';
backdrop.style.backdropFilter = 'blur(1px)';
backdrop.style.zIndex = 9998;
document.body.appendChild(backdrop);
const iframeContainer = document.createElement('div');
iframeContainer.style.position = 'fixed';
iframeContainer.style.top = '50%';
iframeContainer.style.left = '50%';
iframeContainer.style.transform = 'translate(-50%, -50%)';
iframeContainer.style.width = '90%';
iframeContainer.style.maxWidth = '700px';
iframeContainer.style.height = '80%';
iframeContainer.style.zIndex = 9999;
iframeContainer.style.backgroundColor = 'white';
iframeContainer.style.borderRadius = '10px';
iframeContainer.style.overflow = 'hidden';
iframeContainer.style.boxShadow = '0 0 20px rgba(0,0,0,0.5)';
const iframe = document.createElement('iframe');
iframe.src = url;
iframe.width = '100%';
iframe.height = '100%';
iframe.style.border = 'none';
const closeButton = document.createElement('button');
closeButton.innerHTML = '×';
closeButton.style.position = 'absolute';
closeButton.style.top = '10px';
closeButton.style.right = '15px';
closeButton.style.fontSize = '30px';
closeButton.style.background = 'transparent';
closeButton.style.border = 'none';
closeButton.style.cursor = 'pointer';
closeButton.style.zIndex = 10000;
closeButton.style.color = 'red';
closeButton.style.fontWeight = 'bold';
// backdrop.onclick = () => {
// backdrop.remove();
// iframeContainer.remove();
// };
closeButton.onclick = () => {
backdrop.remove();
iframeContainer.remove();
};
iframeContainer.appendChild(closeButton);
iframeContainer.appendChild(iframe);
document.body.appendChild(iframeContainer);
}
// module.exports = {
// initPayment
// }
module.exports = initPayment, openPayWidget