//var idopenpay= '${fld:idopenpay}';
//var autopenpay = '${fld:autopenpay}';
//var redirect = '${fld:redirectopenpay}';
//var urlop = '${fld:dparurlop}';
function enviapaypedopenpay(monto,orderid,customername,customerlastname,customeremail,customerphone,customeraddress,dpedtvid){
// document.getElementById("statusbar").style.display=''
ajaxCall(
httpMethod="GET",
uri="/tienda/index/send?monto="+monto+"&orderid="+orderid+"&customername="+customername+"&customerlastname="+customerlastname+"&customeremail="+customeremail+"&customerphone="+customerphone+"&customeraddress="+customeraddress+"&dpedtvid="+dpedtvid,
divResponse=null,
divProgress="statusbar",
formName=null,
afterResponseFn=null,
onErrorFn=null);
}
function enviapaypedopenpayBKK(monto,orderid,customername,customerlastname,customeremail,customerphone,customeraddress,dpedtvid){
var settings = {
"url": urlop+idopenpay+"/charges",
"method": "POST",
"timeout": 0,
"headers": {
"Authorization": "Basic "+autopenpay,
// "Authorization": "Basic "+autopenpay,
"Content-Type": "application/json"
},
"data": JSON.stringify({
"method":"card",
"amount": monto,
"currency":"PEN",
"description":orderid,
"order_id": orderid,
"customer":
{
"name":customername,
"last_name":customerlastname,
"email":customeremail,
"phone_number":customerphone
},
"confirm":"false",
"use_3d_secure" : true,
"redirect_url":redirect}),
};
$.ajax(settings)
.done(function (response) {
var rptaopenpay = response;
var redirect_url_op = rptaopenpay.payment_method.url;
var idop = rptaopenpay.id;
console.log("Redirige a :" + redirect_url_op);
//llamada Ajax...
return ajaxCall(httpMethod="GET",
uri="/tienda/index/saveidop?orderid="+dpedtvid+"&idop="+idop+"&redirecturl="+redirect_url_op,
divResponse=null, divProgress=null,
formName=null,
afterResponseFn=null,
onErrorFn=null);
// $(location).attr('href',redirect_url_op);
})
.fail(function(response) {
// alert( "error" );
var rptaopenpay = response;
var error = rptaopenpay.responseJSON.description;
var errorcode = rptaopenpay.responseJSON.error_code;
var acumulador=1;
console.log("Error:" + error);
if (errorcode==1006){
var uborderid = orderid.search("-");
if (uborderid == -1){
var neworderid = orderid.toString() + '-' +acumulador.toString();
enviapaypedopenpayBKK(monto,neworderid,customername,customerlastname,customeremail,customerphone,customeraddress,dpedtvid)
}else{
var orderidtext = orderid.toString();
var newvalorfirst = parseInt(orderidtext.substr(0, uborderid));
var newvalorsec = parseInt(orderidtext.substr(uborderid+1, orderidtext.length));
var neworder_idmod = newvalorsec+1;
var neworderid = newvalorfirst.toString() + '-' +neworder_idmod.toString();
enviapaypedopenpayBKK(monto,neworderid,customername,customerlastname,customeremail,customerphone,customeraddress,dpedtvid)
}
}
});
}
window.onload = function() {
}