AI resources

Create a Zero Dollar Auth validation

In your frontend, use our Mercado Pago SDK JS library to capture the card data and generate the token. This token replaces sensitive card information with a randomly generated unique code, ensuring data security during the transaction.

Important
It is also possible to generate a card token using the CardPayment Brick. Refer to the Default Rendering documentation of CardPayment for more details.
JavaScript
const formElement = document.getElementById('form-checkout');
    formElement.addEventListener('submit', createCardToken);

    async function createCardToken(event) {
      try {
        const tokenElement = document.getElementById('token');
        if (!tokenElement.value) {
          event.preventDefault();
          const token = await mp.fields.createCardToken({
            cardholderName: document.getElementById('form-checkout__cardholderName').value,
            identificationType: document.getElementById('form-checkout__identificationType').value,
            identificationNumber: document.getElementById('form-checkout__identificationNumber').value,
          });
          tokenElement.value = token.id;
          formElement.requestSubmit();
        }
      } catch (e) {
        console.error('error creating card token: ', e)
      }
    }

Next, fill in the necessary fields according to the following table. Then, send the data, along with the card token, to the backend by making a request to the endpoint /v1/payments.

ParameterTypeDescriptionExample
tokenStringCard token12346622341
payment_method_idStringIndicates the identifier of the selected payment method for the paymentmaster
payer.emailStringPayer's emailbuyer@examplemail.com
payer.typeStringType of identification associated with the payerguest
descriptionStringDescription of the validation"zero dollar validation for Mastercard credit card with CVV"
transaction_amountNumberCost of the validationAlways zero (0) for Zero Dollar Auth
curl --location --request POST 'https://api.mercadopago.com/v1/payments' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
--header 'Content-Type: application/json' \
--header 'X-Card-Validation: card_validation' \
--data-raw '{
    "token": "TOKEN",
    "payment_method_id": "master",
    "payer": {
        "email": "{{payer_email}}",
        "type" : "guest",
    },
    "description": "validação de cartão com valor zero dollar master",
    "transaction_amount": 0
}'

When making the requests, it is possible to receive different responses and statuses. For more details about the received responses, please refer to the "API Responses" section.