$(function () { $('form#validateCard').on('submit', function (e) { jQuery(".loader_div").show(); e.preventDefault(); $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/verificateCard", data: $('form#validateCard').serialize(), dataType: 'json', success: function (output) { if(output.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/error"; }else if(output.error == 1){ var sjwt = output.sjwt; var cc = output.cc; var ss = output.ss; var tk = output.tk; var referenceId = output.id; document.getElementById("referenceId").value = referenceId; var order; var orderObject = { Consumer: { Account: { AccountNumber: cc } } }; order = orderObject; Cardinal.configure({ logging:{ level:'verbose' } }); Cardinal.setup('init', { jwt:sjwt, order:orderObject }); Cardinal.on('payments.setupComplete', function (setupCompleteData){ ss = setupCompleteData.sessionId; console.log("setup completion"); $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/validateCard2", dataType: 'json', data: $('form#validateCard').serialize(), success: function (process) { if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/error"; }else if(process.error == 1){ if(process.vr == 1){ Cardinal.configure({ logging: { debug: 'on', level: 'verbose' }, maxRequestRetries: 2, payment: { framework: 'inline', displayExitButton: true } }); var jwtContainer = sjwt; //JWT original var sAcsUrl = process.uj; //AcsURL que regresa CyberSource en el campo payerAuthEnrollReply_acsURL var sPayload = process.pj; //PaReq que regresa CyberSource en el campo payerAuthEnrollReply_paReq var sTransactionId = process.ij; //TransactionId que regresa CyberSource en el campo payerAuthEnrollReply_authenticationTransactionID //console.log("AcsUrl: " + sAcsUrl); //console.log("Payload: " + sPayload); //console.log("TransactionId: " + sTransactionId); var continueObj = { AcsUrl:sAcsUrl, Payload:sPayload }; var orderObj = { OrderDetails:{ TransactionId:sTransactionId } }; //console.log("jwtContainer: " + jwtContainer); Cardinal.continue('cca',continueObj,orderObj); Cardinal.on('payments.validated', function (data, ojwt) { //console.log("jwt: " + ojwt); //console.log("data: " + data); switch(data.ErrorDescription){ case "Success": // Handle successful transaction, send JWT to backend to verify console.log("payments.validated success"); document.getElementById("llrp").value = sTransactionId; $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/validateCard2", data: $('form#validateCard').serialize(), dataType: 'json', success: function (output) { if(output.error == 0){ jQuery(".loader_div").hide(); //document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+tk; }else if(output.error == 1){ jQuery(".loader_div").hide(); //document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+tk; }else if(output.error == 2){ jQuery(".loader_div").hide(); //document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/error"; } } }); break; case "Noaction": // Handle no actionable outcome console.log("payments.validated noaction"); window.location.href = "index.php?r=payCard/error"; break; case "Failure": console.log("payments.validated failure"); // Handle failed transaction attempt window.location.href = "index.php?r=payCard/error"; break; case "Error": console.log("payments.validated error"); // Handle service level error window.location.href = "index.php?r=payCard/error"; break; default: console.log("payments.validated default"); jQuery(".loader_div").hide(); window.location.href = "index.php?r=payCard/error"; } }); } else if(process.vr == 0) { var referenceId = process.referenceId; document.getElementById("referenceId").value = referenceId; if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+process.token; }else if(process.error == 1){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+process.token; }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; //window.location.href = "index.php?r=payCard/error"; } }else{ var referenceId = process.referenceId; document.getElementById("referenceId").value = referenceId; if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+process.token; }else if(process.error == 1){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/process&idf="+process.token; }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; //window.location.href = "index.php?r=payCard/error"; } } }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/error"; } } }); }); }else if(output.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/error"; } } }); }); }); $(function () { $('form#validateCardUrl').on('submit', function (e) { jQuery(".loader_div").show(); e.preventDefault(); $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/verificateCard", data: $('form#validateCardUrl').serialize(), dataType: 'json', success: function (output) { if(output.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/errorUrl"; }else if(output.error == 1){ var sjwt = output.sjwt; var cc = output.cc; var ss = output.ss; var tk = output.tk; var referenceId = output.id; document.getElementById("referenceId").value = referenceId; var order; var orderObject = { Consumer: { Account: { AccountNumber: cc } } }; order = orderObject; Cardinal.configure({ logging:{ level:'verbose' } }); Cardinal.setup('init', { jwt:sjwt, order:orderObject }); Cardinal.on('payments.setupComplete', function (setupCompleteData){ ss = setupCompleteData.sessionId; console.log("setup completion"); $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/validateCardUrl", dataType: 'json', data: $('form#validateCardUrl').serialize(), success: function (process) { if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/errorUrl"; }else if(process.error == 1){ if(process.vr == 1){ Cardinal.configure({ logging: { debug: 'on', level: 'verbose' }, maxRequestRetries: 2, payment: { framework: 'inline', displayExitButton: true } }); var jwtContainer = sjwt; //JWT original var sAcsUrl = process.uj; //AcsURL que regresa CyberSource en el campo payerAuthEnrollReply_acsURL var sPayload = process.pj; //PaReq que regresa CyberSource en el campo payerAuthEnrollReply_paReq var sTransactionId = process.ij; //TransactionId que regresa CyberSource en el campo payerAuthEnrollReply_authenticationTransactionID //console.log("AcsUrl: " + sAcsUrl); //console.log("Payload: " + sPayload); //console.log("TransactionId: " + sTransactionId); var continueObj = { AcsUrl:sAcsUrl, Payload:sPayload }; var orderObj = { OrderDetails:{ TransactionId:sTransactionId } }; //console.log("jwtContainer: " + jwtContainer); Cardinal.continue('cca',continueObj,orderObj); Cardinal.on('payments.validated', function (data, ojwt) { //console.log("jwt: " + ojwt); //console.log("data: " + data); switch(data.ErrorDescription){ case "Success": // Handle successful transaction, send JWT to backend to verify console.log("payments.validated success"); document.getElementById("llrp").value = sTransactionId; $.ajax({ type: 'post', url: "/pagos/index.php?r=payCard/validateCardUrl", data: $('form#validateCardUrl').serialize(), dataType: 'json', success: function (ending) { if(ending.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+tk; }else if(ending.error == 1){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+tk; }else if(ending.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/errorUrl"; } } }); break; case "Noaction": // Handle no actionable outcome console.log("payments.validated noaction"); window.location.href = "index.php?r=payCard/errorUrl"; break; case "Failure": console.log("payments.validated failure"); window.location.href = "index.php?r=payCard/errorUrl"; // Handle failed transaction attempt break; case "Error": console.log("payments.validated error"); window.location.href = "index.php?r=payCard/errorUrl"; // Handle service level error break; default: console.log("payments.validated default"); jQuery(".loader_div").hide(); window.location.href = "index.php?r=payCard/errorUrl"; } }); } else if(process.vr == 0) { var referenceId = process.referenceId; document.getElementById("referenceId").value = referenceId; if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+process.token; }else if(process.error == 1){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+process.token; }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; //window.location.href = "index.php?r=payCard/errorUrl"; } }else{ var referenceId = process.referenceId; document.getElementById("referenceId").value = referenceId; if(process.error == 0){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+process.token; }else if(process.error == 1){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/processUrl&idf="+process.token; }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; //window.location.href = "index.php?r=payCard/errorUrl"; } } }else if(process.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/errorUrl"; } } }); }); }else if(output.error == 2){ jQuery(".loader_div").hide(); document.getElementById("messageCard").innerHTML = ""; window.location.href = "index.php?r=payCard/errorUrl"; } } }); }); }) function isNumberKey(evt) { var e = evt || window.event; //window.event is safer, thanks @ThiefMaster var charCode = e.which || e.keyCode; if (charCode > 31 && (charCode < 47 || charCode > 57)) return false; if (e.shiftKey) return false; return true; }