Configuração da autenticação 3DS para cartão de crédito em produção na Wake
Clique em Configurações e selecione Gestor de scripts:
Clique em + Adicionar script:
Preencha os campos de acordo com a tabela:
| Campos | Valores |
|---|---|
| Nome do script | Insira "MPI". |
| Data inicial de exibição do Script | Deixe o campo em branco. |
| Data final de exibição do Script | Deixe o campo em branco. |
| Status do Script | Selecione Script ativo. |
| Prioridade do script | Insira 0 (zero) |
| Posição do Script na página | Escolha Header - Última linha. |
| Páginas que o script será inserido | Escolha Todas. |
| Identificador de Página | Insira "*Fechamento". |
Em Conteúdo do Script, insira o script:
<script>
var dict = {
bpmpi_auth: "true", // fixo
bpmpi_accesstoken: "", //buscar na api
bpmpi_ordernumber: "0", // pegar na tela
bpmpi_currency: "986", // fixo
bpmpi_totalamount: "", //total da compra na tela
bpmpi_installments: "", // pegar na tela
bpmpi_paymentmethod: "", // recebe o parametro do back-end
bpmpi_cardnumber: "", // pegar na tela
bpmpi_cardexpirationmonth: "", // pegar na tela
bpmpi_cardexpirationyear: "",// pegar na tela
bpmpi_billto_name: "",// pegar na tela
bpmpi_billto_phonenumber: "",// pegar na tela
bpmpi_billto_email: "",// pegar na tela
bpmpi_billto_street1: "",// pegar na tela
bpmpi_billto_street2: "",// pegar na tela
bpmpi_billto_city: "",// pegar na tela
bpmpi_billto_state: "",// pegar na tela
bpmpi_billto_country: "BR",// fixo
bpmpi_billto_zipcode: "",// pegar na tela
bpmpi_shipto_name: "", // pegar na tela
bpmpi_merchant_url: "", // url da loja
bpmpi_order_productcode: "PHY", // fixo
bpmpi_auth_notifyonly: ""
}
function bpmpi_authenticate() {
BP.Mpi.authenticate()
}
function bpmpi_load() {
Fbits.Carrinho.Loading(true);
BP.Mpi.load()
}
var BP = function() {
function e(e) {
return dict[e] !== undefined && dict[e] !== null
}
function n(n) {
return e(n) ? dict[n] : null
}
function r(n, r) {
return e(n) ? dict[n] : r
}
function i(e) {
return e.replace("bpmpi_", "").replace(/\_/g, "")
}
function t(e) {
return /\#/.test(e)
}
function o(e, n) {
return e.replace(/\#/, n)
}
function a(e) {
var n = i(e),
r = n.split("#");
return {
enumerable: r[0],
field: r[1]
}
}
function s() {
const e = window && window.screen ? window.screen.width : "",
n = window && window.screen ? window.screen.height : "",
r = window && window.screen ? window.screen.colorDepth : "",
i = window && window.navigator ? window.navigator.userAgent : "",
t = window && window.navigator && window.navigator.javaEnabled() ? "Y" : "N";
var o = "";
window && window.navigator && (o = window.navigator.language ? window.navigator.language : window.navigator.browserLanguage);
const a = (new Date).getTimezoneOffset(),
s = {
userAgent: i,
screenWidth: e,
screenHeight: n,
colorDepth: r,
timeZoneOffset: a,
language: o,
javaEnabled: t,
javascriptEnabled: "Y"
};
return s
}
function p() {
for (var r = { }, p = 0; p < N.length; p++) {
var c = N[p];
if (t(c) === !1) {
var d = i(c),
u = n(c);
u && (r[d] = n(c))
} else
for (var l = 1, m = o(c, l); e(m);) {
var _ = a(c);
r[_.enumerable] || (r[_.enumerable] = []), u = n(m), r[_.enumerable][l - 1] || (r[_.enumerable][l - 1] = { }), r[_.enumerable][l - 1][_.field] = u, l++, m = o(c, l)
}
}
return r.browserInfo = s(), r
}
function c() {
return "undefined" != typeof bpmpi_config ? bpmpi_config() : {
Debug: !0,
Environment: "PRD"
}
}
function d() {
return D.Environment || "PRD"
}
function u() {
var e = d(),
n = {
TST: "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js",
SDB: "https://songbirdstag.cardinalcommerce.com/edge/v1/songbird.js",
PRD: "https://songbird.cardinalcommerce.com/edge/v1/songbird.js"
};
return n[e]
}
function l() {
return {
orderNumber: n("bpmpi_ordernumber"),
currency: n("bpmpi_currency"),
amount: n("bpmpi_totalamount")
}
}
function m(e) {
var n = d(),
r = {
TST: "https://localhost:44351",
SDB: "https://mpisandbox.braspag.com.br",
PRD: "https://mpi.braspag.com.br"
};
return r[n] + e
}
function _(e, n) {
var r = document.getElementsByTagName("head")[0],
i = document.createElement("script");
i.type = "text/javascript", i.src = e, i.onreadystatechange = n, i.onload = n, r.appendChild(i)
}
function b() {
return "undefined" !== D.Debug ? D.Debug : !1
}
function g() {
b() && console.log.apply(null, arguments)
}
function h() {
return b() ? "verbose" : "off"
}
function f(e, n) {
T = n, g("[MPI]", "Initializing..."), g("[MPI]", "Token =", e), g("[MPI]", "ReferenceId =", T), Cardinal.configure({
timeout: "8000",
maxRequestRetries: "10",
logging: {
level: h()
}
}), Cardinal.setup("init", {
jwt: e
}), Cardinal.on("payments.setupComplete", function (e) {
g("[MPI]", "Setup complete."), g("[MPI]", "SetupCompleteData =", e), M("onReady")
}), Cardinal.on("payments.validated", function (e) {
switch (g("[MPI]", "Payment validated."), g("[MPI]", "ActionCode =", e.ActionCode), g("[MPI]", "Data =", e), e.ActionCode) {
case "SUCCESS":
case "NOACTION":
case "FAILURE":
w(e.Payment.ProcessorTransactionId);
break;
case "ERROR":
k.Number = e.ErrorNumber, k.Description = e.ErrorDescription, e.Payment && e.Payment.ProcessorTransactionId ? w(e.Payment.ProcessorTransactionId) : M("onError", {
Xid: null,
Eci: null,
ReturnCode: k.HasError() ? k.Number : "MPI901",
ReturnMessage: k.HasError() ? k.Description : "Unexpected error",
ReferenceId: null
});
break;
default:
k.Number = e.ErrorNumber, k.Description = e.ErrorDescription, "Success" === e.ErrorDescription && e.Payment && e.Payment.ProcessorTransactionId ? w(e.Payment.ProcessorTransactionId) : M("onError", {
Xid: null,
Eci: null,
ReturnCode: k.HasError() ? k.Number : "MPI902",
ReturnMessage: k.HasError() ? k.Description : "Unexpected authentication response",
ReferenceId: null
})
}
})
}
function C(e, r, i) {
var t = JSON.stringify(r),
o = new XMLHttpRequest;
o.onreadystatechange = function() {
if (4 === this.readyState)
if (200 === this.status) {
var e = JSON.parse(o.responseText);
i(e, this)
} else M("onError", {
Xid: null,
Eci: null,
ReturnCode: "MPI900",
ReturnMessage: "An error has occurred (" + this.status + ")",
ReferenceId: null
})
}, o.open("POST", m(e)), o.setRequestHeader("Content-Type", "application/json"), o.setRequestHeader("Authorization", "Bearer " + n("bpmpi_accesstoken")), o.send(t)
}
function E() {
var e = r("bpmpi_auth", "true");
return g("[MPI]", "Authentication Enabled =", e), "false" === e ? (M("onDisabled"), !1) : !0
}
function v() {
if (g("[MPI]", "Debug =", b()), g("[MPI]", "Enviroment =", d()), E()) {
if (O) return void g("[MPI]", "Resources already loaded...");
g("[MPI]", "Loading resources..."), O = !0, _(u(), function() {
g("[MPI]", "Cardinal script loaded."), C("/v2/3ds/init", l(), function (e) {
f(e.Token, e.ReferenceId)
})
})
}
}
function I() {
if (E()) {
if (!O) return void g("[MPI]", "Resources not loaded...");
g("[MPI]", "Enrolling..."), Cardinal.trigger("accountNumber.update", n("bpmpi_cardnumber")), C("/v2/3ds/enroll", p(), function(e) {
g("[MPI]", "Enrollment result =", e), e.Version && (X = e.Version[0]);
var n = e.Authentication;
switch (e.Status) {
case "ENROLLED":
R(e);
break;
case "VALIDATION_NEEDED":
w(e.AuthenticationTransactionId);
break;
case "AUTHENTICATION_CHECK_NEEDED":
A(n);
break;
case "NOT_ENROLLED":
M("onUnenrolled", {
Xid: n.Xid,
Eci: n.Eci,
Version: X,
ReferenceId: n.DirectoryServerTransactionId
});
alert("Cartão não autenticável!");
location.replace(location.href);
break;
case "FAILED":
M("onFailure", {
Xid: n.Xid,
Eci: n.Eci || n.EciRaw,
Version: X,
ReferenceId: n.DirectoryServerTransactionId
});
alert("Falha ao autenticar!");
location.replace(location.href);
break;
case "UNSUPPORTED_BRAND":
M("onUnsupportedBrand", {
Xid: null,
Eci: null,
ReturnCode: e.ReturnCode,
ReturnMessage: e.ReturnMessage,
ReferenceId: null
});
alert("Bandeira não suportada para autenticação!");
location.replace(location.href);
break;
default:
M("onError", {
Xid: null,
Eci: null,
ReturnCode: e.ReturnCode,
ReturnMessage: e.ReturnMessage,
ReferenceId: null
})
alert("Erro desconhecido ao autenticar!");
location.replace(location.href);
}
})
}
}
function y(e, n) {
return e[n] || null
}
function P(e) {
g("[MPI] Building order object...");
var n = p(),
r = {
OrderDetails: {
TransactionId: e,
OrderNumber: n.ordernumber,
CurrencyCode: y(n, "currency"),
OrderChannel: n.transactionmode || "S"
},
Consumer: {
Account: {
AccountNumber: n.cardnumber,
ExpirationMonth: n.cardexpirationmonth,
ExpirationYear: n.cardexpirationyear
},
Email1: y(n, "shiptoemail"),
Email2: y(n, "billtoemail"),
ShippingAddress: {
FullName: null,
Address1: null,
Address2: null,
City: null,
State: null,
PostalCode: null,
CountryCode: null,
Phone1: null
},
BillingAddress: {
FullName: y(n, "billtocontactname"),
Address1: y(n, "billtostreet1"),
Address2: y(n, "billtostreet2"),
City: y(n, "billtocity"),
State: null === y(n, "billtostate") ? null : y(n, "billtostate").toUpperCase(),
PostalCode: y(n, "billtozipcode"),
CountryCode: y(n, "billtocountry"),
Phone1: y(n, "billtophonenumber")
}
},
Cart: []
};
if ("true" === n.shiptosameasbillto) {
var i = r.Consumer.BillingAddress;
r.Consumer.ShippingAddress.FullName = i.FullName, r.Consumer.ShippingAddress.Address1 = i.Address1, r.Consumer.ShippingAddress.Address2 = i.Address2, r.Consumer.ShippingAddress.City = i.City, r.Consumer.ShippingAddress.State = i.State, r.Consumer.ShippingAddress.PostalCode = i.PostalCode, r.Consumer.ShippingAddress.Phone1 = i.Phone1, r.Consumer.ShippingAddress.CountryCode = i.CountryCode
} else r.Consumer.ShippingAddress.FullName = y(n, "shiptoaddressee"), r.Consumer.ShippingAddress.Address1 = y(n, "shiptostreet1"), r.Consumer.ShippingAddress.Address2 = y(n, "shiptostreet2"), r.Consumer.ShippingAddress.City = y(n, "shiptocity"), r.Consumer.ShippingAddress.State = null === y(n, "shiptostate") ? null : y(n, "shiptostate").toUpperCase(), r.Consumer.ShippingAddress.PostalCode = y(n, "shiptozipcode"), r.Consumer.ShippingAddress.Phone1 = y(n, "shiptophonenumber"), r.Consumer.ShippingAddress.CountryCode = y(n, "shiptocountry");
if (n.cart)
for (var t = 0; t < n.cart.length; t++) r.Cart.push({
Name: y(n.cart[t], "name"),
Description: y(n.cart[t], "description"),
SKU: y(n.cart[t], "sku"),
Quantity: y(n.cart[t], "quantity"),
Price: y(n.cart[t], "unitprice")
});
return g("[MPI] Order object =", r), r
}
function R(e) {
Fbits.Carrinho.Loading(false);
var r = n("bpmpi_auth_suppresschallenge");
if (g("[MPI] Suppression enabled = " + r), "true" === r) return g("[MPI]", "Challenge supressed..."), void M("onChallengeSuppression", {
Xid: null,
Eci: null,
ReturnCode: "MPI601",
ReturnMessage: "Challenge suppressed",
ReferenceId: null
});
g("[MPI]", "Showing challenge...");
var i = {
AcsUrl: e.AcsUrl,
Payload: e.Pareq,
TransactionId: e.AuthenticationTransactionId
},
t = P(e.AuthenticationTransactionId);
g("[MPI] Continue object =", i), Cardinal.continue("cca", i, t)
}
function A(e) {
switch (g("[MPI]", "Authentication result =", e), e.Status) {
case "AUTHENTICATED":
document.getElementById("cavv").value = e.Cavv;
document.getElementById("xid").value = e.Xid;
document.getElementById("eci").value = e.Eci;
document.getElementById("version").value= e.Version[0];
document.getElementById("referenceId").value= e.DirectoryServerTransactionId;
M("onSuccess", {
Cavv: e.Cavv,
Xid: e.Xid,
Eci: e.Eci,
Version: e.Version[0],
ReferenceId: e.DirectoryServerTransactionId
});
break;
case "UNAVAILABLE":
var dataOnly = dict.bpmpi_auth_notifyonly === "true";
var eciValid = e.Eci !== null && e.Eci !== undefined && e.Eci !== "";
if (dataOnly && eciValid) {
document.getElementById("cavv").value = e.Cavv;
document.getElementById("xid").value = e.Xid;
document.getElementById("eci").value = e.Eci;
document.getElementById("version").value = e.Version[0];
document.getElementById("referenceId").value = e.DirectoryServerTransactionId;
M("onSuccess", {
Cavv: e.Cavv,
Xid: e.Xid,
Eci: e.Eci,
Version: e.Version[0],
ReferenceId: e.DirectoryServerTransactionId
});
break;
} else {
M("onUnenrolled", {
Cavv: e.Cavv,
Xid: e.Xid,
Eci: e.Eci,
Version: e.Version[0],
ReferenceId: e.DirectoryServerTransactionId
});
alert("Cartão não autenticável!");
location.replace(location.href);
break;
}
case "FAILED":
M("onFailure", {
Xid: e.Xid,
Eci: e.Eci || e.EciRaw,
Version: e.Version[0],
ReferenceId: e.DirectoryServerTransactionId
});
alert("Falha ao autenticar!");
location.replace(location.href);
break;
case "ERROR_OCCURRED":
M("onError", {
Xid: e.Xid,
Eci: e.Eci || e.EciRaw,
ReturnCode: e.ReturnCode,
ReturnMessage: e.ReturnMessage,
ReferenceId: e.DirectoryServerTransactionId
});
alert("Erro desconhecido ao autenticar!");
location.replace(location.href);
break;
default:
M("onError", {
Xid: e.Xid,
Eci: e.Eci || e.EciRaw,
ReturnCode: k.HasError() ? k.Number : e.ReturnCode,
ReturnMessage: k.HasError() ? k.Description : e.ReturnMessage,
ReferenceId: e.DirectoryServerTransactionId
});
alert("Erro desconhecido ao autenticar!");
location.replace(location.href);
}
}
function w(e) {
Fbits.Carrinho.Loading(true);
var n = p();
n.transactionId = e, g("[MPI]", "Validating..."), C("/v2/3ds/validate", n, function(e) {
A(e)
})
}
function S(e) {
return "function" == typeof D[e]
}
function M(e, n) {
g("[MPI]", "Notifying..."), g("[MPI]", "Event type =", e), g("[MPI]", "Event data =", n || "None"), S(e) && D[e](n)
if (e == "onError") {
alert("Erro desconhecido ao autenticar!");
location.replace(location.href);
}
if(e == "onSuccess"){
if (document.getElementById("nameSOP") != null) {
FecharPedidoCielo();
} else {
Fbits.Carrinho.Pedido.Fechar();
}
}
}
var D = c(),
N = ["bpmpi_transaction_mode", "bpmpi_merchant_url", "bpmpi_merchant_newcustomer", "bpmpi_ordernumber", "bpmpi_currency", "bpmpi_totalamount", "bpmpi_paymentmethod", "bpmpi_installments", "bpmpi_cardnumber", "bpmpi_cardexpirationmonth", "bpmpi_cardexpirationyear", "bpmpi_cardalias", "bpmpi_default_card", "bpmpi_cardaddeddate", "bpmpi_giftcard_amount", "bpmpi_giftcard_currency", "bpmpi_billto_customerid", "bpmpi_billto_contactname", "bpmpi_billto_email", "bpmpi_billto_street1", "bpmpi_billto_street2", "bpmpi_billto_city", "bpmpi_billto_state", "bpmpi_billto_zipcode", "bpmpi_billto_phonenumber", "bpmpi_billto_country", "bpmpi_shipto_sameasbillto", "bpmpi_shipto_addressee", "bpmpi_shipto_email", "bpmpi_shipto_street1", "bpmpi_shipto_street2", "bpmpi_shipto_city", "bpmpi_shipto_state", "bpmpi_shipto_zipcode", "bpmpi_shipto_shippingmethod", "bpmpi_shipto_phonenumber", "bpmpi_shipto_firstusagedate", "bpmpi_shipto_country", "bpmpi_device_ipaddress", "bpmpi_device_#_fingerprint", "bpmpi_device_#_provider", "bpmpi_device_channel", "bpmpi_cart_#_name", "bpmpi_cart_#_description", "bpmpi_cart_#_sku", "bpmpi_cart_#_quantity", "bpmpi_cart_#_unitprice", "bpmpi_order_recurrence", "bpmpi_order_productcode", "bpmpi_order_countlast24hours", "bpmpi_order_countlast6months", "bpmpi_order_countlast1year", "bpmpi_order_cardattemptslast24hours", "bpmpi_order_marketingoptin", "bpmpi_order_marketingsource", "bpmpi_useraccount_guest", "bpmpi_useraccount_createddate", "bpmpi_useraccount_changeddate", "bpmpi_useraccount_passwordchangeddate", "bpmpi_useraccount_authenticationmethod", "bpmpi_useraccount_authenticationprotocol", "bpmpi_useraccount_authenticationtimestamp", "bpmpi_airline_travelleg_#_carrier", "bpmpi_airline_travelleg_#_departuredate", "bpmpi_airline_travelleg_#_origin", "bpmpi_airline_travelleg_#_destination", "bpmpi_airline_passenger_#_name", "bpmpi_airline_passenger_#_ticketprice", "bpmpi_airline_numberofpassengers", "bpmpi_airline_billto_passportcountry", "bpmpi_airline_billto_passportnumber", "bpmpi_mdd1", "bpmpi_mdd2", "bpmpi_mdd3", "bpmpi_mdd4", "bpmpi_mdd5", "bpmpi_auth_notifyonly", "bpmpi_auth_suppresschallenge", "bpmpi_recurring_enddate", "bpmpi_recurring_frequency", "bpmpi_recurring_originalpurchasedate", "bpmpi_challenge_window_size"],
T = null,
X = null,
k = {
Number: null,
Description: null,
HasError: function() {
return null !== this.Number
}
},
O = !1;
return {
Mpi: {
load: function() {
v()
},
authenticate: function() {
I()
}
}
}
}();
function bpmpi_config() {
return {
onReady: function () {
bpmpi_authenticate();
},
Environment:"PRD",
Debug: true,
};
}
function MpiLoad() {
let numberText = document.getElementsByName("number");
let amount = document.getElementsByClassName("currency")[0].innerHTML.replace(',', '').replace('.', '');
let token = document.getElementById("tokenMpi").value;
token = token.replace('Bearer ', '');
if (document.getElementById("dataOnly") != null) {
dict.bpmpi_auth_notifyonly = document.getElementById("dataOnly").value;
}
var divs = document.body.getElementsByTagName("div");
for (const div of divs) {
if (div.hasAttribute("data-gateway-parcelas")) {
dict.bpmpi_installments = div.getAttribute("data-gateway-parcelas");
}
};
dict.bpmpi_accesstoken = token;
dict.bpmpi_ordernumber = Fbits.Carrinho.Id;
dict.bpmpi_cardnumber = numberText[0].value.split(" ").join("");
dict.bpmpi_totalamount = amount;
dict.bpmpi_cardexpirationmonth = document.getElementsByName("month")[0].value;
dict.bpmpi_cardexpirationyear = document.getElementsByName("year")[0].value;
dict.bpmpi_paymentmethod = document.getElementById("paymentType").value;
dict.bpmpi_billto_name = Fbits.Carrinho.Usuario.Nome;
dict.bpmpi_billto_email = Fbits.Carrinho.Usuario.Email;
dict.bpmpi_billto_street1 = Fbits.Carrinho.Usuario.Enderecos[0].Rua;
dict.bpmpi_billto_street2 = Fbits.Carrinho.Usuario.Enderecos[0].Complemento;
dict.bpmpi_billto_city = Fbits.Carrinho.Usuario.Enderecos[0].Cidade;
dict.bpmpi_billto_state = Fbits.Carrinho.Usuario.Enderecos[0].Estado;
dict.bpmpi_billto_zipcode = Fbits.Carrinho.Usuario.Enderecos[0].CEP;
dict.bpmpi_shipto_name = Fbits.Carrinho.Usuario.Nome;
dict.bpmpi_merchant_url = window.location.origin;
bpmpi_load();
}
</script>
Clique em Salvar > Publicar.
Updated about 1 hour ago