Authorize the payment with authentication

Function esitefDoPayment#

After the customer fills in all the fields on the store's screen, they should click a button to complete the payment. In the onclick event, a JavaScript function should be called, filling the request with nit, payToken, merchantId, authenticate, onSuccess callback function, onProcessing, onFailure, onInvalid, and subsequently invoking the esitefDoPayment function, passing the request as a parameter. The esitefDoPayment function performs 3DS authentication, which may display a challenge involving security code checks, token validation, approvals on the buyer's mobile device, or other verifications. Following authentication, payment authorization takes place with the acquirer. It is important to clarify that, according to the parameterization provided during the transaction creation (authenticate field), the transaction authorization behavior may change:

  • If the transaction is submitted with authenticate = 1, then the transaction will only be authorized if the authentication is approved.
  • If the transaction is submitted with authenticate = 2, then the transaction will only be authorized if the authentication is approved, but for card networks not supported by 3DS, the authentication step will be skipped.
  • If the transaction is submitted with authenticate = 3, then the transaction will go through the authentication flow, but if there is a negative result, the flow proceeds to authorization.

Calling the Carat script#

When the buyer fills in the card details and clicks 'pay,' the merchant's page should call the JavaScript function esitefDoPayment, passing as an argument a request with the following fields:

ParameterDescriptionFormatMandatory
nitTransaction identifier in Carat. Field nit received during the transaction creation step.= 64 ANYES
payTokenField pay_token received during the transaction creation step. This token can only be used once.= 66 ANYES
merchantIdMerchant code in Carat. Production and certification codes will be different.< 15 NYES
onSuccessCallback function that will be called after a successful payment in Carat. This function takes the payment response as an argument, as described in - Response from success and failure callbacks.FYES
onProcessingCallback function that will be called after a challenge requested by the issuer in the 3DS authentication flow or late confirmation.FYES
onFailureCallback function that will be called after an unsuccessful payment in Carat. This function takes the payment response as an argument, as described in - Response from success and failure callbacks.FYES
onInvalidCallback function that will be called after a JavaScript validation error. This function takes the list of errors as an argument, as described in - Response from validation error callback.FYES
authenticateBoolean field to indicate that the JavaScript payment includes 3DS authentication, pass 'true' if the payment is with 3DS.= 4 ANYES
challengeWindowSizeField that represents the size for the presentation of the challenge: 01 - 250 x 400, 02 - 390 x 400, 03 - 500 x 600. If not passed, JavaScript will determine a value to be used.= 2 ANNO

Response from success and failure callbacks.#

The callback functions onSuccess and onFailure receive an object as an argument containing information related to the payment. Below are the descriptions of these fields:

ParameterDescriptionFormat
codeCarat response code. Any code other than 0 (zero) indicates failure. For more information, refer to the Response Codes.< 4 N
messageCarat response message.< 500 AN
payment
authorizer_codeAuthorization response code.< 10 AN
authorizer_messageAuthorization response message.< 500 AN
statusPayment transaction status in Carat.= 3 AN
nitIdentification number of the payment transaction in Carat.= 64 AN
order_idOrder code sent by the store during the creation of the transaction.< 40 AN
customer_receiptCoupon (via customer).< 4000 AN
authorizer_idCode of the acquirer used in the transaction.< 4 N

Validation error callback response.#

The onInvalid callback function receives, as an argument, a list of objects representing validation errors, containing the following fields:

ParameterDescriptionFormat
fieldName of the field with an error.< 30 AN
causeError message.<100 AN

Example#

Below is an example of a JavaScript function calling esitefDoPayment:

function myPay() {
var request = {
onSuccess: function(response) {
var responseValue = JSON.stringify(response);
localStorage.setItem('resultSuccess', responseValue);
if (response.payment.status == 'PPC') {
window.location = 'loja-pag-pendente-3ds-mpi.html?nit='+ findGetParameter('nit');
} else {
window.location = 'loja-sucesso-3ds-mpi.html';
}
},
onProcessing: function() {
window.location = 'loja-pag-pendente-3ds-mpi.html?nit='+ findGetParameter('nit');
},
onFailure: function(response) {
var responseValue = JSON.stringify(response);
localStorage.setItem('resultFailure', responseValue);
window.location = 'loja-fracasso-js.html';
},
onInvalid: function(response) {
var message = response[0].field + ' ' + response[0].cause;
for (var i = 1; i < response.length; i++) {
message += ', ' + response[i].field + ' ' + response[i].cause;
}
document.getElementById('resultInvalid').innerHTML = message;
},
nit: findGetParameter('nit'),
payToken: findGetParameter('payToken'),
merchantId: findGetParameter('merchantId'),
authenticate: 'true'
};
esitefDoPayment(request);
}
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}