Pix
With Mercado Pago's Checkout Transparente, it's also possible to offer instant payments with Pix through a QR code or a payment link.
If you already set up your environment and want to offer payments with Pix, follow the steps below.
processing_mode parameter. For more information, visit the section Integration model.To be able to receive payments, you need to add a form in the frontend that securely captures the payer's information.
If you already have a development that includes your own payment form, make sure to include Pix among the payment options you want to offer, as indicated below, and continue to the next step.
If you do not have a payment form, add the form below to your project, including the identifier for boleto bancário among the payment methods to be offered.
| Payment method | payment_method_id |
| Pix | pix |
html<form id="form-checkout" action="/process_payment" method="post"> <div> <div> <label for="payerFirstName">Nome</label> <input id="form-checkout__payerFirstName" name="payerFirstName" type="text"> </div> <div> <label for="payerLastName">Sobrenome</label> <input id="form-checkout__payerLastName" name="payerLastName" type="text"> </div> <div> <label for="email">E-mail</label> <input id="form-checkout__email" name="email" type="text"> </div> <div> <label for="identificationType">Tipo de documento</label> <select id="form-checkout__identificationType" name="identificationType" type="text"></select> </div> <div> <label for="identificationNumber">Número do documento</label> <input id="form-checkout__identificationNumber" name="identificationNumber" type="text"> </div> </div> <div> <div> <input type="hidden" name="transactionAmount" id="transactionAmount" value="100"> <input type="hidden" name="description" id="description" value="Nome do Produto"> <br> <button type="submit">Pagar</button> </div> </div> </form>
To facilitate the correct entry of data in the payment form, it is necessary to obtain the possible document types to be accepted.
The function below will allow you to automatically populate the available options, thanks to the inclusion of the select element with the id: form-checkout__identificationType found in the form used as an example in the previous step.
If you already have a development that includes the retrieval of document types, as indicated below, proceed to Submit payment.
If you do not have this function, add the following to your project.
javascript(async function getIdentificationTypes() { try { const identificationTypes = await mp.getIdentificationTypes(); const identificationTypeElement = document.getElementById('form-checkout__identificationType'); createSelectOptions(identificationTypeElement, identificationTypes); } catch (e) { return console.error('Error getting identificationTypes: ', e); } })(); function createSelectOptions(elem, options, labelsAndKeys = { label: "name", value: "id" }) { const { label, value } = labelsAndKeys; elem.options.length = 0; const tempOptions = document.createDocumentFragment(); options.forEach(option => { const optValue = option[value]; const optLabel = option[label]; const opt = document.createElement('option'); opt.value = optValue; opt.textContent = optLabel; tempOptions.appendChild(opt); }); elem.appendChild(tempOptions); }
The payment submission must be made by creating an order that contains associated payment transactions.
To do this, send a request with your test Access TokenPrivate key linked to an application, used in the backend to authenticate operations in the test environment. You can find it in the application's Credentials section, within the test environment. It cannot process real payments, must never be exposed in the frontend, and starts with the `APP_USR` prefix. and the required parameters listed below to the endpoint /v1/ordersPOST.
processing_mode=manual) can have an expiration period defined in the expiration_time field. If the field is not sent, the default period is P1D (one day). When the period expires before the order reaches a final status, it is automatically closed, the associated pending payments are canceled, and the integrator is notified.curlcurl -X POST \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer {{YOUR_ACCESS_TOKEN}}' \ -H 'X-Idempotency-Key: {{SOME_UNIQUE_VALUE}}' \ 'https://api.mercadopago.com/v1/orders' \ -d '{ "type": "online", "total_amount": "50.00", "external_reference": "ext_ref_1234", "processing_mode": "automatic", "config": { "location": { "state_id": "BR-SP" } }, "transactions": { "payments": [ { "amount": "50.00", "payment_method": { "id": "pix", "type": "bank_transfer" }, "expiration_time": "P3Y6M4DT12H30M5S" } ] }, "payer": { "email": "test_payer@example.com" } }'
429 Too Many Requests error, wait the time indicated in the Retry-After response header before retrying. See Possible errors for more details.See the table below for descriptions of the parameters that are mandatory in the request and those that, although optional, have some important particularity that should be highlighted.
| Parameter | Type | Description | Requirement |
Authorization | Header | Refers to your private key, the test Access TokenPrivate key linked to an application, used in the backend to authenticate operations in the test environment. You can find it in the application's Credentials section, within the test environment. It cannot process real payments, must never be exposed in the frontend, and starts with the `APP_USR` prefix.. | Required |
X-Idempotency-Key | Header | Idempotency key. It is used to ensure that each request is processed only once, avoiding duplications. Use a unique value in the header of your request, such as a UUID V4 or random strings. | Required |
total_amount | Body. String | Total amount for the transaction. | Required |
external_reference | Body. String | External reference of the order, which can be, for example, a hashcode from the Central Bank, serving as the transaction's source identifier. | Required |
processing_mode | Body. String | Processing mode of the order. The possible values are: - automatic: to create and process the order in automatic mode. - manual: to create the order and process it later. For more information, visit the section Integration model. | Required |
expiration_time | Body. String | When an order is created in manual mode (processing_mode=manual), this parameter lets you define its expiration time using the ISO 8601 duration format. The period starts at created_date and the maximum limit is 2920 hours. If not sent, the default value will be P1D (one day). This parameter must not be sent when creating an order in automatic mode (processing_mode=automatic). | Optional |
config.location | Body. Object | Information about the payer's location. | Optional |
config.location.state_id | Body. String | Code of the payer's state, province, or administrative region, formed by the two-letter country code, followed by a hyphen and the location code. See the accepted values.Acre (BR-AC); Alagoas (BR-AL); Amapá (BR-AP); Amazonas (BR-AM); Bahia (BR-BA); Ceará (BR-CE); Distrito Federal (BR-DF); Espírito Santo (BR-ES); Goiás (BR-GO); Maranhão (BR-MA); Mato Grosso (BR-MT); Mato Grosso do Sul (BR-MS); Minas Gerais (BR-MG); Pará (BR-PA); Paraíba (BR-PB); Paraná (BR-PR); Pernambuco (BR-PE); Piauí (BR-PI); Rio de Janeiro (BR-RJ); Rio Grande do Norte (BR-RN); Rio Grande do Sul (BR-RS); Rondônia (BR-RO); Roraima (BR-RR); Santa Catarina (BR-SC); São Paulo (BR-SP); Sergipe (BR-SE); Tocantins (BR-TO). | Optional |
transaction.payments.payment_method.id | Body. String | Identifier of the payment method. In this case, the value should be pix. | Required |
transaction.payments.payment_method.type | Body. String | Type of the payment method. In the case of payments with a slip, the value should be bank_transfer. | Required |
transaction.payment.expiration_time | Body. String | Allows you to set the due date using the ISO 8601 duration format. By default, the due date of a Pix payment is 24 hours, but it can be changed through this parameter. It must be set to a minimum of 30 minutes from the creation of the payment, and a maximum of 30 days. | Optional |
payer.email | Body. String | Buyer’s e-mail. | Required |
The response will return the parameters ticket_url, qr_code and qr_code_base64, containing, respectively, the URL with instructions for the buyer to complete the payment, an alphanumeric code to be used in the configuration to display the option that will allow copying and pasting the payment code, and the QR code that can be rendered directly on the payment screen. You must make one or all of these options available following the guidelines in the Make the payment available step. Additionally, it will also display the status action_required with status_detail=waiting_transfer until the payment is made.
json{ "id": "ORD01HRYFWNYRE1MR1E60MW3X0T2P", "type": "online", "total_amount": "50.00", "external_reference": "ext_ref_1234", "country_code": "BRA", "status": "action_required", "status_detail": "waiting_transfer", "capture_mode": "automatic", "transactions": { "payments": [ { "id": "PAY01HRYFXQ53Q3JPEC48MYWMR0TE", "reference_id": "123456789", "status": "action_required", "status_detail": "waiting_transfer", "amount": "50.00", "payment_method": { "id": "pix", "type": "bank_transfer", "ticket_url": "https://www.mercadopago.com.br/sandbox/payments/00000000000/ticket?caller_id=77777777777&hash=34cb0d7c-81d9-478c-92a5-767d0kakjja", "qr_code": "00020126580014br.gov.bcb.pix0136b76aa9c2-2ec4-4110-954e-ebfe34f05b61520400005303986540510.005802BR5912TESTPVBWOSBE6009Sao Paulo62240520mpqrinter715936942186304C3C0", "qr_code_base64": "iVBORw0KGgoAAAANSUhEUgAABWQAAAVkAQAAAAB79i" } } ] }, "processing_mode": "automatic", "marketplace": "NONE" }
Among the returned parameters, we have those indicated in the table below.
| Parameter | Type | Description |
transaction.payments.status | String | Returns the status of the transaction. In this case, it will return action_required to indicate the need for action to complete processing, that is, until the payment of the Pix is made. |
transaction.payments.status_detail | String | In this case, the obtained status_detail is waiting (waiting_payment) for the user to complete the payment process of the Pix with their bank. |
transaction.payments.payment_method.ticket_url | String | URL for the rendered Pix with QR code, Pix Copia e Cola, and payment instructions. See more information in Make the payment available. |
transaction.payments.payment_method.qr_code | String | Presents an alphanumeric code to be used in the configuration to display the option that will allow copying and pasting the payment code for Pix payment. See more information in Make the payment available. |
transaction.payments.payment_method.qr_code_base64 | String | Base64 representation of the QR code image to be scanned to complete the payment. Provides the value to be used in the request to display the QR code for Pix payment. See more information in Make the payment available. |
expiration_time | String | Expiration period (in ISO 8601 format) returned for an order created in manual mode (processing_mode=manual), counted from created_date. When omitted from the request, the returned default will be P1D (one day). This parameter will not be returned for an order created in automatic mode (processing_mode=automatic). |
After creating the payment request with Pix, choose how the user will be able to make the payment on the frontend, either through a payment link or button or a rendered QR code.
Select the option that best fits your business model and follow the steps described below.
Add link or bottom
When choosing to add a link or button for payment with Pix, the buyer will be directed to a new window containing all the information to complete the payment, such as QR code or Pix Copia e Cola, along with the respective payment instructions.
To offer this option, use the ticket_url attribute returned in the response of the request, as shown below:
html<a href="https://www.mercadopago.com.br/payments/123456789/ticket?caller_id=123456&hash=123e4567-e89b-12d3-a456-426655440000" target="_blank">Pagar com Pix</a>
Render QR code
It is possible to render the current QR code returned in the response of the request, which should be used only once, on the payment screen itself. Additionally, you can also add an option to copy and paste the payment code, allowing the transaction to be carried out via Internet Banking.
To do this, follow the steps below.
- Add the
qr_code_base64, returned in the response of the request, to display the QR code.
html<img src={`data:image/jpeg;base64,${qr_code_base64}`}/>
- Next, add the
qr_code, returned in the response of the request, to present the option that allows copying and pasting the code.
html<label for="copiar">Copiar Hash:</label> <input type="text" id="copiar" value={qr_code} readonly/>
Once these steps are completed, the buyer will see the rendered QR code along with the option to copy and paste their payment code at the time of payment.
If you wish, you can cancel a payment created, as long as it is pending or in process; that is, with status=action_required.
Additionally, we recommend canceling payments that were not made by the established due date to avoid billing and reconciliation issues.
For more information, please consult the Refunds and cancellations section.