Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fechamento de compra com iFrame
function handleEvents(event) {
switch(event) {
// ...
case 'sendPayments.vtex':
let checkoutPayments =[0];
let transactionResponse =[1];
let deviceFingerprint =[2];
sendPayments(checkoutPayments, transactionResponse, deviceFingerprint);
function sendPayments(checkoutPayments, transactionResponse, deviceFingerprint) {
// Recupero os dados do pagamento que estao dentro do iFrame
let iFramePayments = PaymentStore.get('payments');
let payments = map(checkoutPayments, (checkoutPayment) => {
if (checkoutPayment.originalPaymentIndex == null) {
return checkoutPayment;
let payment = iFramePayments.get(checkoutPayment.originalPaymentIndex);
let fields = payment.get('fields');
// Adiciono fingePrint caso o pagamento precise
if (deviceFingerprint) {
fields.deviceFingerprint = deviceFingerprint;
// Preencho o array de pagamentos com os dados sensiveis
// Todos dentro do objeto "fieds"
return {
groupName: paymentGroup,
fields: fields
// Monto a URL que o VTEX PCI receberá os pagamentos
let orderId = transactionResponse.gatewayCallbackTemplatePath.split('/')[3];
let tid =;
const transactionUrl = `https://${accountName}${tid}/payments?orderId=${orderId}`;
url: transactionUrl,
method: 'post',
data: payments
}).then(() => {
// Mando um evento do iFrame para o Checkout com a resposta
Checkout.paymentSuccess(transactionResponse.gatewayCallbackTemplatePath.replace('{messageCode}', 'Success'));
}).catch(() => {
Checkout.paymentFail(transactionResponse.gatewayCallbackTemplatePath.replace('{messageCode}', 'SystemInconsistency'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.