document.addEventListener("DOMContentLoaded", function(){ var cle_abonnement_value = document.getElementById("ngpay-api-btn").getAttribute("subscription_key"); var methode_de_paiement = document.getElementById("ngpay-api-btn").getAttribute("payment_method"); var nom_du_client_value = document.getElementById("ngpay-api-btn").getAttribute("customer_name"); var prenom_du_client_value = document.getElementById("ngpay-api-btn").getAttribute("prenom_du_client"); var numero_du_payeur_value = document.getElementById("ngpay-api-btn").getAttribute("payer_phone_number"); var operateur_gsm_value = document.getElementById("ngpay-api-btn").getAttribute("network_operator"); var prestation_value = document.getElementById("ngpay-api-btn").getAttribute("prestation"); var montant_value = document.getElementById("ngpay-api-btn").getAttribute("amount"); var currency_value = document.getElementById("ngpay-api-btn").getAttribute("currency"); var replace_espace = montant_value.replace(" ", ""); var replace_point = replace_espace.replace(",", "."); var number_formated = replace_point.replace(/(.)(?=(\d{3})+$)/g,"$1."); var btn_show_modal_value = document.getElementById("ngpay-api-btn").getAttribute("button_value"); var class_string = document.getElementById("ngpay-api-btn").getAttribute("button_class"); var id_div_contain_button_string = document.getElementById("ngpay-api-btn").getAttribute("div_container_id"); var appliquer_frais_transaction_au_client = document.getElementById("ngpay-api-btn").getAttribute("apply_transaction_cost_to_customer"); var inclure_un_demarcheur = document.getElementById("ngpay-api-btn").getAttribute("include_canvasser"); var numero_du_demarcheur = document.getElementById("ngpay-api-btn").getAttribute("canvasser_phone_number"); var pourcentage_du_demarcheur = document.getElementById("ngpay-api-btn").getAttribute("canvasser_percentage"); var myTimeout; //var timer_load_structures = setInterval(GetPublicKey,1000); GetPublicKey(); var capt_result_status; function GetPublicKey() { //clearInterval(timer_load_structures); var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { //alert("REQUEST TO PAY SUCCESS"); var statut_result; var get_statut_element_value; statut_result = xmlhttp.responseText; get_statut_element_value = statut_result; var result = get_statut_element_value.indexOf(""); var final_result = get_statut_element_value.substr(result + 7, 1000); var public_key = final_result; //document.getElementById("id_response_contain_get").innerHTML = final_result; if(final_result.length > 2) { if(methode_de_paiement == "mobile") { ///////////////////////////////////////////////////////////////////////////////////// // PIEMENT MOBILE MONEY ///////////////////////////////////////////////////////////////////////////////////// if(btn_show_modal_value != "") { var openModalBtn = document.createElement("a"); openModalBtn.setAttribute("id", id_div_contain_button_string); openModalBtn.setAttribute("class", class_string); //document.getElementById("ngpay-api-btn").value=get_statut_element_value; openModalBtn.innerHTML = btn_show_modal_value; //document.body.appendChild(openModalBtn); document.getElementById(id_div_contain_button_string).appendChild(openModalBtn); /* openModalBtn.setAttribute("id", "myPayBouton_id"); openModalBtn.setAttribute("class", "myPayBouton_class"); */ /* openModalBtn.style.backgroundColor = "royalblue"; openModalBtn.style.fontWeight = "bold"; openModalBtn.style.border = "0px solid royalblue"; openModalBtn.style.width = "140px"; openModalBtn.style.height = "32px"; openModalBtn.style.color = "white"; openModalBtn.style.borderRadius = "5px"; openModalBtn.style.marginLeft = "5px"; openModalBtn.style.marginTop = "10px"; */ openModalBtn.style.cursor = "pointer"; openModalBtn.addEventListener("click", function(){ display_modal_pay(); }); } else { display_modal_pay(); } function display_modal_pay(){ var MyReferenceId = generateUUID(); /* alert("Clé d'abonnement : " + cle_abonnement_value + "\n" + "Nom du client : " + nom_du_client_value + "\n" + "Contact du client : " + numero_du_payeur_value + "\n" + "Montant à payer : " + montant_value + "\n" ); */ var mainModal = document.createElement("div"); mainModal.setAttribute("id", "mainModal"); // assign an id var modal_content = document.createElement("div"); var myframe = document.createElement("iframe"); myframe.setAttribute("id", "myframeId"); // assign an id var wait_modal_content = document.createElement("img"); wait_modal_content.src = "https://ngpservices.org/ngpay/img/loading.gif?q=" + Math.random(); wait_modal_content.width = 50; wait_modal_content.style.marginTop = "200px"; wait_modal_content.style.marginLeft = "140px"; var modal_header = document.createElement("div"); var title_modal_header = document.createElement("div"); var logo_modal_header = document.createElement("img"); var fa_user_modal_header = document.createElement("img"); var fa_hand_hold_dollar_modal_header = document.createElement("img"); var modal_close = document.createElement("span"); modal_close.setAttribute("id", "modal_close"); // assign an id modal_close.innerHTML = "Annuler le paiement"; var h2_modal_header = document.createElement("h2"); h2_modal_header.innerHTML = "NGPay"; var modal_body = document.createElement("div"); var hr1_modal_body = document.createElement("hr"); var hr2_modal_body = document.createElement("hr"); var amount_modal_body = document.createElement("div"); var img_amount_modal_body = document.createElement("img"); var p3_modal_body = document.createElement("p"); p3_modal_body.innerHTML = "1 FCFA"; var p1_modal_body = document.createElement("p"); p1_modal_body.innerHTML = "Effectuer un paiement à :"; var p2_modal_body = document.createElement("p"); p2_modal_body.innerHTML = "ZAKARI ADAMOU"; var modal_footer = document.createElement("div"); var h3_modal_footer = document.createElement("h3"); h3_modal_footer.innerHTML = "Modal Footer"; //myframe.appendChild(wait_modal_content); if(btn_show_modal_value != "") { modal_content.appendChild(wait_modal_content); modal_content.appendChild(myframe); mainModal.appendChild(modal_content); //mainModal.style.display = "none"; mainModal.style.position = "fixed"; mainModal.style.zIndex = "1000000"; mainModal.style.paddingTop = "100px"; mainModal.style.left = "0"; mainModal.style.top = "0"; mainModal.style.width = "100%"; mainModal.style.height = "100%"; mainModal.style.overflow = "auto"; //mainModal.style.backgroundColor = "rgb(0,0,0)"; mainModal.style.backgroundColor = "rgba(0,0,0,0.65)"; /*if(screen.width <= 400){ } else if(screen.width > 400 && screen.width <= 1000){ } else {*/ modal_content.style.position = "relative"; modal_content.style.backgroundColor = "transparent"; modal_content.style.margin = "auto"; modal_content.style.marginTop = "-95px"; modal_content.style.paddingTop = "4px"; modal_content.style.paddingLeft = "0px"; modal_content.style.paddingRight = "0px"; modal_content.style.paddingBottom = "0px"; //modal_content.style.border = "1px solid #888"; modal_content.style.width = "321px"; modal_content.style.borderRadius = "15px"; //modal_content.style.boxShadow = "0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19)"; } else { document.getElementById(id_div_contain_button_string).appendChild(wait_modal_content); document.getElementById(id_div_contain_button_string).appendChild(myframe); myframe.style.display = "none"; wait_modal_content.style.display = ""; } //alert("https://ngpservices.org/ngpay/startpay.php?q=" + numero_du_payeur_value + ":~1~:" + montant_value + ":~2~:" + currency_value + ":~3~:" + nom_du_client_value + ":~4~:" + MyReferenceId + ":~5~:" + prestation_value + ":~6~:" + public_key + ":~7~:" + appliquer_frais_transaction_au_client + ":~8~:" + operateur_gsm_value + ":~9~:" + inclure_un_demarcheur + ":~10~:" + numero_du_demarcheur + ":~11~:"+ pourcentage_du_demarcheur + ":~12~:"+ methode_de_paiement); myframe.src = "https://ngpservices.org/ngpay/startpay.php?q=" + numero_du_payeur_value + ":~1~:" + montant_value + ":~2~:" + currency_value + ":~3~:" + nom_du_client_value + ":~4~:" + MyReferenceId + ":~5~:" + prestation_value + ":~6~:" + public_key + ":~7~:" + appliquer_frais_transaction_au_client + ":~8~:" + operateur_gsm_value + ":~9~:" + inclure_un_demarcheur + ":~10~:" + numero_du_demarcheur + ":~11~:"+ pourcentage_du_demarcheur + ":~12~:"+ methode_de_paiement; //myframe.src = "http://192.168.43.192/ngpay/startpay.php?q=" + numero_du_payeur_value + ":~1~:" + montant_value + ":~2~:" + currency_value + ":~3~:" + nom_du_client_value + ":~4~:" + MyReferenceId + ":~5~:" + prestation_value + ":~6~:" + public_key + ":~7~:" + appliquer_frais_transaction_au_client + ":~8~:" + operateur_gsm_value + ":~9~:" + inclure_un_demarcheur + ":~10~:" + numero_du_demarcheur + ":~11~:"+ pourcentage_du_demarcheur + ":~12~:"+ methode_de_paiement; /* myframe.style.borderRadius = "15px"; myframe.style.borderWidth = "3px"; myframe.style.borderColor = "lime"; myframe.style.backgroundColor = "rgba(0,255,0,0.2)"; */ myframe.style.marginLeft = "-15px"; //myframe.style.zIndex = "-1"; myframe.scrolling = "no"; myframe.overflow = "hidden"; myframe.height = "680px"; myframe.width = "343px"; myframe.style.borderStyle = "none"; myframe.style.paddingLeft = "0px"; myframe.style.backgroundColor = "transparent"; myframe.style.display = "none"; wait_modal_content.style.display = ""; modal_close.style.color = "rgba(255,255,255,1)"; //modal_close.style.float = "right"; modal_close.style.fontSize = "15px"; modal_close.style.fontWeight = "bold"; modal_close.style.paddingTop = "5px"; modal_close.style.paddingBottom = "5px"; modal_close.style.marginTop = "-5px"; //modal_close.style.marginLeft = "-15px"; modal_close.style.cursor = "pointer"; modal_close.style.zIndex = "-1"; modal_close.style.width = "310px"; modal_close.style.borderRadius = "5px"; modal_close.style.borderColor = "rgba(255,255,255,0.8)"; modal_close.style.borderStyle = "solid"; modal_close.style.borderWidth = "1px"; modal_close.style.textAlign = "center"; //modal_close.style.position = "absolute" modal_close.style.display = "block" modal_close.style.backgroundColor = "rgba(255,0,0,1)"; //} // mainModal.appendChild(modal_close); //modal_content.appendChild(modal_close); document.body.appendChild(mainModal); /* modal_close.onclick = function () { if(confirm("Êtes-vous sûr de vouloir abandonner l'opération en cours ?")) { mainModal.style.display = "none"; clearTimeout(myTimeout); clearInterval(timer_load_structures); } }; */ var i = 0; window.addEventListener("message", e => { ///////////////////////////////////////////////////////////////////////// if(e.data == "page_loaded") { i=i+1; //alert(i); if(i<2) { myframe.style.display = ""; wait_modal_content.style.display = "none"; //clearTimeout(myTimeout); //clearInterval(timer_load_structures); i=0; } } /////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////// if(e.data == "Close") { i=i+1; //alert(i); if(i<2) { if(confirm("Êtes-vous sûr de vouloir annuler le paiement en cours ?")) { mainModal.style.display = "none"; clearTimeout(myTimeout); clearInterval(timer_load_structures); } else { i = 0; } } } /////////////////////////////////////////////////////////////////// if(e.data == "SUCCESSFUL") { i=i+1; //alert(i); if(i<2) { wait_modal_content.style.display = ""; myframe.style.display = "none"; document.getElementById("statut").value = "SUCCESS"; //mainModal.style.display = "none"; document.getElementById("payForm").submit(); } } /////////////////////////////////////////////////////////////////////// if(e.data == "FAILED") { i=i+1; //alert(i); if(i<2) { wait_modal_content.style.display = ""; myframe.style.display = "none"; document.getElementById("statut").value = "ECHEC"; //mainModal.style.display = "none"; document.getElementById("payForm").submit(); } } ///////////////////////////////////////////////////////////////// if(e.data == "INTERNAL_PROCESSING_ERROR") { i=i+1; //alert(i); if(i<2) { alert("Désolé ! Le paiement a échoué. Problème de réseau ou fonds insuffisant. Merci de réessayer."); mainModal.style.display = "none"; } } ///////////////////////////////////////////////////////////////// if(e.data == "NETWORK_ERROR") { i=i+1; //alert(i); if(i<2) { alert("Désolé ! Réseau non disponible"); mainModal.style.display = "none"; } } ///////////////////////////////////////////////////////////////// if(e.data == "PAYER_NOT_FOUND") { i=i+1; //alert(i); if(i<2) { alert("Désolé ! L'abonné n'existe pas."); mainModal.style.display = "none"; } } ///////////////////////////////////////////////////////////////// if(e.data == "PAYER_LIMIT_REACHED") { i=i+1; //alert(i); if(i<2) { alert("Désolé ! Le compte mobile money de cet abonné est limité. Le montant de l'opération dépasse le plafond autorisé."); mainModal.style.display = "none"; } } ///////////////////////////////////////////////////////////////// if(e.data == "NOT_ENOUGH_FUNDS") { i=i+1; //alert(i); if(i<2) { alert("Désolé ! L'abonné ne dispose pas suffisamment de fonds pour cette opération."); mainModal.style.display = "none"; } } ///////////////////////////////////////////////////////////////// }, false); function submit_form(){ if(document.getElementById("statut").value == "SUCCESS" || document.getElementById("statut").value == "ECHEC") { clearTimeout(myTimeout); mainModal.style.display = "none"; document.getElementById("payForm").submit(); } else { if(capt_result_status != "" && capt_result_status == "SUCCESS" || capt_result_status != "" && capt_result_status == "ECHEC") { clearTimeout(myTimeout); document.getElementById("statut").value = capt_result_status; mainModal.style.display = "none"; document.getElementById("payForm").submit(); } } } } } else if(methode_de_paiement == "card") { alert("Désolé, le paiement par carte bancaire n'est pas disponible pour le moment."); ///////////////////////////////////////////////////////////////////////////////////// // PIEMENT PAR CARTE BANCAIRE ///////////////////////////////////////////////////////////////////////////////////// } else if(methode_de_paiement == "mixed") { alert("Désolé, le paiement mixte par mobile money et carte bancaire n'est pas disponible pour le moment."); ///////////////////////////////////////////////////////////////////////////////////// // PIEMENT "mixed" PAR MOBILE MONEY ET CARTE BANCAIRE ///////////////////////////////////////////////////////////////////////////////////// } else { alert("Désolé, le moyen de paiement défini dans les paramètres n'est pas valide."); ///////////////////////////////////////////////////////////////////////////////////// // MOYEN DE PAIEMENT NON VALIDE ///////////////////////////////////////////////////////////////////////////////////// } } //var result_coockie = getCookie("ngpcashpayerCoockie"); //alert(result_coockie + "==" + result_coockie.length); //alert(final_result); //document.getElementById("username").value = final_result; //var result_coockie = getCookie("coockieResultValue"); //alert(result_coockie); } }; xmlhttp.open("GET", "https://ngpservices.org/ngpay/get-public-key.php?q=" + cle_abonnement_value, true); //xmlhttp.open("GET", "http://192.168.43.192/ngpay/get-public-key.php?q=" + cle_abonnement_value, true); xmlhttp.send(); } }); function generateUUID() { // Public Domain/MIT var d = new Date().getTime();//Timestamp var d2 = ((typeof performance !== "undefined") && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) { var r = Math.random() * 16;//random number between 0 and 16 if(d > 0){//Use timestamp until depleted r = (d + r)%16 | 0; d = Math.floor(d/16); } else {//Use microseconds since page-load if supported r = (d2 + r)%16 | 0; d2 = Math.floor(d2/16); } return (c === "x" ? r : (r & 0x3 | 0x8)).toString(16); }); } function setCookie(c_name, value, exdays) { var exdate = new Date(); exdate.setDate(exdate.getDate() + exdays); var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString()); document.cookie = c_name + "=" + c_value; } function getCookie(c_name) { var i, x, y, ARRcookies = document.cookie.split(";"); for (i = 0; i < ARRcookies.length; i++) { x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("=")); y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1); x = x.replace(/^\s+|\s+$/g, ""); if (x == c_name) { return unescape(y); } } } function min_sweetAlert_success(){ const Toast = Swal.mixin({ toast: true, color: "#339d11", position: "top-end", showConfirmButton: false, timer: 100000, timerProgressBar: false, /* didOpen: (toast) => { toast.addEventListener("mouseenter", Swal.stopTimer) toast.addEventListener("mouseleave", Swal.resumeTimer) } */ }) Toast.fire({ icon: "success", title: "Paiement réussi" }) } function min_sweetAlert_success(){ const Toast = Swal.mixin({ toast: true, color: "#339d11", position: "top-end", showConfirmButton: false, timer: 100000, timerProgressBar: false, /* didOpen: (toast) => { toast.addEventListener("mouseenter", Swal.stopTimer) toast.addEventListener("mouseleave", Swal.resumeTimer) } */ }) Toast.fire({ icon: "success", title: "Paiement réussi" }) } function min_sweetAlert_error(){ const Toast = Swal.mixin({ toast: true, color: "#ff3339", position: "top-end", showConfirmButton: false, timer: 100000, timerProgressBar: false, /* didOpen: (toast) => { toast.addEventListener("mouseenter", Swal.stopTimer) toast.addEventListener("mouseleave", Swal.resumeTimer) } */ }) Toast.fire({ icon: "error", title: "Echec du paiement" }) } function max_sweetAlert_success(){ Swal.fire({ position: "top-center", icon: "success", title: "Paiement réussi", showConfirmButton: false, timer: 100000 }) } function max_sweetAlert_error(){ Swal.fire({ position: "top-center", icon: "error", title: "Echec du paiement", showConfirmButton: false, timer: 100000 }) }