Mercado Pago integration for websites
This model lets you offer Apple Pay on your website without managing payment certificates or decrypting tokens on your server. Mercado Pago handles validation with Apple and returns a token ready to create the payment.
You can integrate in two ways: using the Mercado Pago JavaScript SDK (JS SDK) to display the button in the frontend (Via SDK), or implementing the flow directly with the APIs in your backend (Via API). In both cases, the payment is created in your backend with the Orders API.
This integration method uses our JS SDK in the frontend to display the Apple Pay button. Mercado Pago validates the session with Apple and returns a token ready to create the payment in your backend. Follow the steps to integrate.
sequenceDiagram
participant C as Buyer
participant V as Website (frontend)
participant B as Your backend
participant MP as Mercado Pago
participant A as Apple
V->>MP: Initialize Apple Pay
MP->>A: Validate merchant and domain
A-->>V: Apple Pay button available
C->>V: Click the Apple Pay button
V->>A: Payment request (Touch ID/Face ID)
A-->>V: Encrypted payment data
V->>MP: Tokenize the payment (SDK)
MP-->>V: Mercado Pago token (callback)
V->>B: Send the token
B->>MP: Create the order (token + data)
MP-->>B: Order response
B-->>V: Payment result
Before you start, configure the Apple Developer certificates and gather the following data:
- Public KeyPublic key linked to an application, used in the frontend to initialize the SDK.: used to initialize the JS SDK in the frontend.
- Access TokenPrivate key linked to an application, used in the backend to authenticate operations. of a test user to generate the certificates and process payments in the backend.
- Merchant ID: identifier of your business in Apple Pay.
- Domain Name: domain of your business, previously verified in the Apple Developer Portal.
- Site ID: identifier of the site in Mercado Pago.
Include the JS SDK in your frontend. You can add the code in a <script> tag or in a separate JavaScript file.
<script src="https://sdk.mercadopago.com/js/v2"></script>
Then, initialize the SDK and Apple Pay as soon as the page loads, so the button is quickly displayed to the buyer.
const mp = new MercadoPago("YOUR_PUBLIC_KEY");
const quickCheckoutBuilder = mp.quickCheckout();
With the information obtained in the previous step, configure the payment and the Apple Pay session using the parameters in the table below.
| Parameter | Type | Description | Required | Example |
checkoutTypes | Array | Payment methods displayed by the JS SDK. For Apple Pay, use applePay. | Required | ['applePay'] |
applePay.paymentRequest.countryCode | String | Country code of the transaction. | Required | COUNTRY_CODE |
applePay.paymentRequest.currencyCode | String | Currency code of the transaction. | Required | CURRENCY_CODE |
applePay.paymentRequest.merchantCapabilities | Array | Accepted payment types. The supports3DS value is mandatory. | Required | ['supports3DS'] |
applePay.paymentRequest.supportedNetworks | Array | Supported card brands. For now, only visa and masterCard. | Required | ['visa', 'masterCard'] |
applePay.paymentRequest.total.label | String | Description of the total amount shown on the Apple Pay sheet. | Required | T-shirt |
applePay.paymentRequest.total.amount | String | Total payment amount. | Required | 5.00 |
applePay.sessionRequest.id | String | Public hash value provided by Mercado Pago after configuring the certificates. | Required | CERTIFICATE_PUBLIC_HASH |
applePay.sessionRequest.merchantIdentifier | String | Merchant identifier created in the Apple Developer Portal. | Required | merchant.your-identifier |
applePay.sessionRequest.domainName | String | Domain verified in the Apple Developer Portal. | Required | your-domain.com |
applePay.sessionRequest.displayName | String | Store name shown to the buyer during payment. | Required | My store |
applePay.sessionRequest.initiative | String | Fixed value web. | Required | web |
applePay.sessionRequest.initiativeContext | String | Must match the value of domainName. | Required | your-domain.com |
applePay.customization.locale | String | Language and region of the button. If not sent, the button uses the language and region identified from the browser. | Optional | en-US |
applePay.callbacks.onTokenGenerated | Function | Runs when the token is successfully generated. It receives token (identifier of the generated token), bin (first 6 digits of the card), and paymentMethodId (card brand: visa or master). Send this data to your backend to process the payment. | Required | — |
applePay.callbacks.onReady | Function | Runs when the Apple Pay session starts. | Optional | — |
applePay.callbacks.onCancel | Function | Runs when the buyer cancels the payment. | Optional | — |
applePay.callbacks.onError | Function | Runs when tokenization fails. | Optional | — |
Once the parameters are defined, create and render the button by running the command:
const renderApplePayBrick = async (quickCheckoutBuilder) => {
const settings = {
checkoutTypes: ['applePay'],
applePay: {
// Payment settings
paymentRequest: {
countryCode: 'COUNTRY_CODE',
currencyCode: 'CURRENCY_CODE',
merchantCapabilities: ['supports3DS'],
supportedNetworks: ['visa', 'masterCard'],
total: {
label: 'T-shirt',
amount: '5.00'
}
},
// Apple Pay session settings
sessionRequest: {
id: 'CERTIFICATE_PUBLIC_HASH',
merchantIdentifier: 'merchant.your-identifier',
domainName: 'your-domain.com',
displayName: 'My store',
initiative: 'web',
initiativeContext: 'your-domain.com'
},
callbacks: {
onReady: async () => {
// Optional: runs when the Apple Pay session starts
console.log('Apple Pay started');
},
onTokenGenerated: async (token, bin, paymentMethodId) => {
// Runs when the token is successfully generated.
// token: identifier of the token generated by Mercado Pago
// bin: first 6 digits of the card
// paymentMethodId: card brand ('visa' or 'master')
// Send this data to your backend, which will create the payment with POST /v1/orders (step 3).
const response = await fetch('/your-endpoint/create-order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token, bin, paymentMethodId })
});
const result = await response.json();
// Show the result to the buyer based on your backend's response
},
onCancel: async () => {
// Optional: runs when the buyer cancels the payment
console.log('Payment canceled by the buyer');
},
onError: async (error) => {
// Optional: runs when tokenization fails
console.error('Apple Pay error:', error);
}
}
}
};
window.applePayBrickController = await quickCheckoutBuilder.create(
'payment-container',
settings
);
};
renderApplePayBrick(quickCheckoutBuilder);
For Argentina, use countryCode: 'AR' and currencyCode: 'ARS'.
Then, add the container where the button will be rendered.
<div id="payment-container" class="payment-container"></div>
If you want, customize the color, text, and language of the button with the available options.
const settings = {
// ...
applePay: {
// ...
customization: {
buttonStyle: 'black', // 'black' (default) | 'white' | 'white-outline'
buttonType: 'pay', // 'add-money' | 'book' | 'buy' | 'check-out' | 'continue' | 'contribute' | 'donate' | 'order' | 'pay' | 'plain' | 'reload' | 'rent' | 'set-up' | 'subscribe' | 'support' | 'tip' | 'top-up'
locale: 'en-US' // The default value is the browser's current language and region. 'ar-AB' | 'ca-ES' | 'cs-CZ' | 'da-DK' | 'de-DE' | 'el-GR' | 'en-AU' | 'en-GB' | 'en-US' | 'es-ES' | 'es-MX' | 'fi-FI' | 'fr-CA' | 'fr-FR' | 'he-IL' | 'hi-IN' | 'hr-HR' | 'hu-HU' | 'id-ID' | 'it-IT' | 'ja-JP' | 'ko-KR' | 'ms-MY' | 'nb-NO' | 'nl-NL' | 'pl-PL' | 'pt-BR' | 'pt-PT' | 'ro-RO' | 'ru-RU' | 'sk-SK' | 'sv-SE' | 'th-TH' | 'tr-TR' | 'uk-UA' | 'vi-VN' | 'zh-CN' | 'zh-HK' | 'zh-TW'
}
}
};
When the buyer authorizes the payment, the onTokenGenerated callback delivers the token, the bin, and the card brand. Send this data to your backend and, from there, create the order by sending a POST 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 and must never be exposed in the frontend. to the endpoint /v1/ordersPOST.
curl --location 'https://api.mercadopago.com/v1/orders' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{YOUR_ACCESS_TOKEN}}' \
--header 'X-Idempotency-Key: SOME_UNIQUE_VALUE' \
--data '{
"type": "online",
"processing_mode": "automatic",
"total_amount": "100.00",
"currency_id": "ARS",
"external_reference": "ext_ref_1234",
"payer": {
"email": "buyer@email.com",
"identification": {
"type": "DNI",
"number": "12345678"
}
},
"transactions": {
"payments": [
{
"amount": "100.00",
"payment_method": {
"id": "visa",
"type": "credit_card",
"token": "TOKEN_RETURNED_BY_CALLBACK",
"installments": 1
}
}
]
}
}'
| Parameter | Type | Description | Required |
Authorization | Header | Header with your test Access TokenPrivate key linked to an application, used in the backend to authenticate operations in the test environment. It cannot process real payments and must never be exposed in the frontend.. | Required |
X-Idempotency-Key | Header | Unique value per request (UUID v4) to avoid duplicate payments. | Required |
type | String | Order type. Fixed value online. | Required |
processing_mode | String | Processing mode of the order. The possible values are automatic, to create and process the order in automatic mode, and manual, to create the order and process it later. For more information, visit the section Integration model. | Required |
total_amount | String | Total amount for the transaction. | Required |
external_reference | String | Reference to sync the order with your system. | Optional |
payer.email | String | Buyer's email address. | Required |
payer.identification.type | String | Buyer's identification document type. You can check the available values by sending a request to the Get identification types endpoint. | Required |
payer.identification.number | String | Buyer's identification document number. | Required |
transactions.payments[].amount | String | Transaction amount. | Required |
transactions.payments[].payment_method.id | String | Payment method identifier. In this case, it is the card brand, delivered in paymentMethodId by the onTokenGenerated callback. You can check the complete list of available identifiers by sending a request to the Get payment methods endpoint. | Required |
transactions.payments[].payment_method.type | String | Payment method type. For credit card payments, it should be credit_card, and for debit card payments, it should be debit_card. | Required |
transactions.payments[].payment_method.token | String | Card token delivered in token by the onTokenGenerated callback. | Required |
transactions.payments[].payment_method.installments | Integer | Number of installments the payment will be split into. | Required |
To simulate different payment scenarios during development, use the testStatus property in the Apple Pay configuration. It works only in the test environment, when the Public Key starts with TEST-.
testStatus property is optional and must be used only for testing. You do not need to include this configuration when going to production.const settings = {
checkoutTypes: ['applePay'],
applePay: {
// ... other settings ...
testStatus: 'APRO', // Optional: for testing only
// ... callbacks ...
}
};
The possible values for testStatus are the same as the payment scenarios of the test cards.
| Payment scenario | testStatus value |
| Approved payment | APRO |
| Declined for general error | OTHE |
| Pending payment | CONT |
| Declined with validation to authorize | CALL |
| Declined for insufficient amount | FUND |
| Declined for invalid security code | SECU |
| Declined due to due date issue | EXPI |
| Declined due to form error | FORM |
Rejected for missing card_number | CARD |
| Rejected for invalid installments | INST |
| Rejected for duplicate payment | DUPL |
| Rejected for disabled card | LOCK |
| Rejected for non-permitted card type | CTNA |
| Rejected due to exceeded PIN attempts | ATTE |
| Rejected for being on the blacklist | BLAC |
| Not supported | UNSU |
| Used to apply amount rules | TEST |