Apple Pay payment
Apple Pay is Apple's digital payment solution that lets customers pay by credit card quickly, securely, and conveniently on compatible devices (iPhone, iPad, Apple Watch, and Mac).
Using tokenization and biometric authentication (Face ID or Touch ID), Apple Pay eliminates manually typing card details on every purchase, reducing checkout time and increasing conversion. In addition, Apple Pay transactions carry no fraud chargeback risk.
Compatibility
Apple Pay is only displayed in the Safari browser (macOS or iOS) and on Apple devices that support the method. In other browsers, the button doesn't appear.
Before you start: choose your integration model
This is the decision that raises the most questions. There are two Apple
Pay integration models with Appmax, and the difference is in who registers
the domain with Apple and who controls the merchantIdentifier.
In every model, you host the `.well-known` file
Regardless of the model below, it is always the merchant's responsibility
(or the integrator's, on the store's behalf) to publish the
.well-known/apple-developer-merchantid-domain-association file at the root of
each domain where Apple Pay will be used — including in the integrated model.
See the full step-by-step, with the file contents and the Content-Type
recipes per server, in
Domain configuration for Apple Pay.
| Aspect | Integrated model (integrated store / integrator via AppStore) | Direct flow |
|---|---|---|
| Who registers the domain with Apple | Appmax, via API, under Appmax's Apple account/merchant | The merchant themselves, in their own Apple account |
Who hosts the .well-known |
The merchant/integrator, in all cases | The merchant hosts the file at the domain root |
merchantIdentifier |
Managed by Appmax, shared across several of the integrator's domains | The merchant's own |
| Recommended for | Platforms/integrators that operate several stores (e.g., SaaS e-commerce) | A single merchant who manages their own Apple account |
How do I know which one applies to me?
If you are a platform/integrator and you install the Appmax app on behalf
of several stores (AppStore flow, with a client_id/external_id per store),
you are in the integrated model. If you are a merchant setting up
Apple Pay directly in your own Apple account, you are in the
direct flow. In both cases, you need to publish the
.well-known file (see the warning above).
The steps below indicate, where relevant, what changes between the two models.
Glossary
| Term | Description |
|---|---|
| Apple Pay | Apple's payment solution for secure purchases through Apple Wallet, with biometric authentication and end-to-end encryption. |
| Apple Token (Apple Pay Token) | Encrypted JSON object returned by the PaymentSheet after the user confirms the payment, containing paymentData, paymentMethod, and transactionIdentifier. It is the tokenized card and is used to complete the payment in the Appmax API. Generated per transaction. |
| PaymentSheet | Apple Pay's native interface that shows the amount and the available methods, and asks for authentication (Face ID, Touch ID, or passcode). |
| Merchant Session | JSON session signed by Apple, valid for one domain and merchantIdentifier. It validates the site before the PaymentSheet is shown. Obtained in real time on every transaction. |
.well-known/apple-developer-merchantid-domain-association |
Static Apple domain validation file, tied to the merchantIdentifier (not to the transaction). The merchant's responsibility in all integration models — see Domain configuration for Apple Pay. |
external_id |
UUID that identifies the pair (installed app + store). Generated at installation and used in CDN calls. See App installation. |
Prerequisites
- Compatible browser — Safari (macOS or iOS).
- Apple Wallet set up — at least one Visa or Mastercard card in Apple Wallet.
- App installation done with the
domain_nameparameter (step 1). .well-knownfile published and domain validated with Apple (step 2).- Appmax JS included and initialized with the callbacks (step 3).
Flow components:
- JS script:
https://scripts.appmax.com.br/appmax.min.js(production) — in sandbox, usehttps://scripts.sandboxappmax.com.br/appmax.min.js. - Domain validated with Apple.
- Payment request to the Appmax API with a valid
appleToken,order_id, andcustomer_id.
1. Authorize the app installation
Register the app with Appmax, providing the domain:
curl --location 'https://api.appmax.com.br/app/authorize' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer SEU_TOKEN' \
--data '{
"app_id": "APP_ID",
"external_key": "EXTERNAL_KEY",
"url_callback": "URL_CALLBACK",
"domain_name": "subdominio.dominio.com.br"
}'
INFO
The domain_name parameter must contain subdomain + domain (e.g.,
minhaloja.minhaintegracao.com.br). You can also send several
domains with domain_names (array). More details in
App installation.
2. Publish the .well-known file and validate the domain
2.1 Publish the .well-known file (required in all models)
In all integration models, each domain where the Apple Pay button will be shown must serve the validation file at the root of the site:
https://subdominio.dominio.com.br/.well-known/apple-developer-merchantid-domain-association
The file, the publishing step-by-step, and the command to check that it is accessible are in Domain configuration for Apple Pay.
INFO
The contents of the .well-known file are not the Apple Token. The Apple Token is the
tokenized card, generated per transaction. The .well-known is a static
domain validation file, tied to the merchantIdentifier — the
same file is used on all domains of your implementation.
2.2 Register the domain with Apple
WARNING
This step changes depending on the integration model.
Integrated model (integrated store / integrator): you don't need to
register the domain through the Apple portal. Registration is done via API,
by Appmax, under Appmax's merchantIdentifier. It's enough that the domain
was provided at installation (step 1) and that the .well-known file
(step 2.1) is already published — Apple checks the file when validating the
domain.
If the merchant's domain changes: the new domain is treated as a new domain and must be registered again. There is no need to create a new merchant.
Direct flow: you register the domain yourself, directly in
Apple's developer portal, in your own account. Apple validates the
.well-known file published in step 2.1 at registration time.
3. Front-end script configuration and initialization
TIP
This section summarizes the essentials. For the full step-by-step — button selectors, SPA load order, DOM contract, and troubleshooting — see Implementing the Apple Pay button with the Appmax JS.
WARNING
The externalId expected here is the same external_id you returned with
HTTP 200 in the App installation step.
appmax.min.js does three things:
- Styles the button with Apple's official design (optional).
- Initializes the button to open the PaymentSheet with the cart data.
- Fires the success, error, update, and authorization callbacks.
3.1 Initialize with onSuccess, onError, externalId, onUpdate, and onAuthorize
<script>
// Authorization callback: receives the Apple Token and completes the payment
const onAuthorize = async (appleToken) => {
await processPayment(appleToken);
};
// Error callback
const onError = (err) => {
console.error('Apple Pay error:', err);
};
// Customer IP callback (collection is mandatory and requires a
// form[data-appmax-customer] in the DOM before init)
const onIp = ({ ip }) => {
customer.value.ip = ip;
};
// Update callback: must return the current checkout data
const onUpdate = () => getCheckoutData();
onMounted(() => {
const script = document.createElement('script');
// Production: https://scripts.appmax.com.br/appmax.min.js
// Sandbox: https://scripts.sandboxappmax.com.br/appmax.min.js
script.src = 'https://scripts.appmax.com.br/appmax.min.js';
script.onload = () => {
if (window.AppmaxScripts) {
window.AppmaxScripts.init({ externalId, onIp, onError, onUpdate, onAuthorize });
} else {
console.error('AppmaxScripts not loaded.');
}
};
document.head.appendChild(script);
});
</script>
WARNING
Pay attention to the callback names: the one that receives the Apple Token is
onAuthorize (not onAutorize). The positional form
init(onSuccess, onError, externalId, onUpdate, onAuthorize) still
works, but requires this exact order — the options object doesn't have this
risk.
The normative reference for init (both forms, all callbacks, and the
onError contract) is in
Appmax JS. This page covers only what is
specific to Apple Pay.
Naming convention: externalId is the init() parameter in
JavaScript; external_id is the API and installation field. It is the same
value, written in each side's convention.
3.2 Keeping onUpdate up to date (plain JS)
onUpdate must return the current checkout data to feed the
PaymentSheet (amount, shipping, discount, installments, items):
function getCheckoutData() {
const products = Array.from(document.querySelectorAll('.product-item')).map(item => ({
name: item.querySelector('.product-name').textContent,
price: parseFloat(item.querySelector('.product-price').value),
quantity: parseInt(item.querySelector('.product-quantity').value, 10)
}));
const freight = parseFloat(document.getElementById('freight').value || 0);
const discount = parseFloat(document.getElementById('discount').value || 0);
const totalItems = products.reduce((sum, p) => sum + p.price * p.quantity, 0);
return {
total: totalItems + freight - discount,
freight: freight,
discount: discount,
installments: parseInt(document.getElementById('installments').value, 10) || 1,
products: products
};
}
INFO
About orderId in onUpdate: the field here is used to build the
PaymentSheet. The required order_id is the one in the payment request
(POST /v1/payments/apple-pay) — it doesn't necessarily need to be
set in onUpdate, but it must be the order_id of an Order that already
exists in Appmax (see step 4).
4. Process the payment
An Apple Pay payment requires three elements: customer_id, order_id, and the
appleToken. The order is: create customer → create order → complete the payment.
async function processPayment(appleToken) {
// 1. Create customer — POST /v1/customers (see /api-reference/customers/criar-atualizar)
// 2. Create order — POST /v1/orders (see /api-reference/orders/criar-pedido)
// 3. Complete payment — POST /v1/payments/apple-pay
const paymentPayload = {
order_id, // Order that already exists in Appmax
customer_id,
payment_data: {
apple_pay: {
installments: 3, // 1 to 12
holder_document_number: "22233344450", // required
soft_descriptor: "EXEMPLOLOJA", // optional, max. 13 characters
// From appleToken.paymentData:
payment_data: {
version: "EC_v1",
data: "exemplo",
signature: "signature",
header: {
ephemeralPublicKey: "MFk...==",
transactionId: "trx....wvu"
}
},
// From appleToken.paymentMethod:
payment_method: {
displayName: "Visa •••• 3714",
network: "Visa",
type: "credit"
},
// From appleToken.transactionIdentifier:
transaction_identifier: "trx....wvu"
}
}
};
const resp = await fetch('https://api.appmax.com.br/v1/payments/apple-pay', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer SEU_TOKEN` },
body: JSON.stringify(paymentPayload)
});
if (!resp.ok) throw new Error('Payment failed');
return resp.json();
}
Mapping from the Apple Token to the payload:
appleToken field |
Goes in |
|---|---|
paymentData |
payment_data.apple_pay.payment_data |
paymentMethod |
payment_data.apple_pay.payment_method |
transactionIdentifier |
payment_data.apple_pay.transaction_identifier |
INFO
Required fields: order_id, installments (1–12), and
holder_document_number. soft_descriptor is optional (max. 13 characters).
The Apple Pay installment cap is 12 — on cards it can be higher
Here the limit is fixed at 12. On the credit card endpoint, the cap is the one configured for the store, which by default is also 12, but can be higher when the store has extended installments enabled.
In practice: a store with extended installments accepts 18x on the card and declines 18x on Apple Pay. If you offer both payment methods on the same screen, limit the Apple Pay installment options to 12 — otherwise the buyer picks a value that will only be declined at the moment of payment.
Real-time validation (Merchant Session)
Domain validation with Apple is not a one-time thing — Apple revalidates the
domain/merchant on every transaction, when the PaymentSheet is
opened (the Merchant Session is obtained in real time). It is a fast process and
transparent to the user; Appmax JS handles this automatically. See
POST /v1/apple-pay/merchant-session.
Testing and Sandbox
WARNING
You can't test Apple Pay on localhost. Apple Pay requires a public
domain, with valid HTTPS and properly registered/configured. Apple
doesn't validate non-public domains.
In the sandbox, no card is charged
In the sandbox you pay with a real Wallet card, but the appleToken
is not decrypted: Appmax processes the order with its own test
card, which the test acquirer approves. Nothing is charged to the
Wallet card, and there is nothing to refund.
In practice:
- Use any real card added to the Wallet on your iPhone or Mac. You don't need a Sandbox Apple Account or Apple's test cards, which don't support Brazil.
- The payment is always approved. There is no way to simulate an Apple Pay decline in the sandbox.
- The brand and last digits recorded on the order are those of the test card, not those of the Wallet card.
- The test domain must publish the sandbox
.well-known, which is different from the production one. See Domain configuration for Apple Pay.
Apple has no sandbox merchant session
Apple always validates the domain and merchant on its own production infrastructure, even when you use the Appmax sandbox. That's why the test domain must be public, with valid HTTPS and registered. The sandbox script calls Appmax's sandbox endpoint, which talks to Apple's production using Appmax's sandbox identity.
Environments
| Sandbox | Production | |
|---|---|---|
| JS script | https://scripts.sandboxappmax.com.br/appmax.min.js |
https://scripts.appmax.com.br/appmax.min.js |
| API | https://api.sandboxappmax.com.br |
https://api.appmax.com.br |
Frequently asked questions (FAQ)
What is the appleToken used for?
It's the card tokenized by Apple. It must be sent to
POST /v1/payments/apple-pay (in the payment_data, payment_method,
and transaction_identifier fields). Without it, the payment isn't processed. It is single-use
per transaction.
Do I need to host the .well-known file on every domain?
Yes, in all integration models — this doesn't change between the integrated model and the direct flow. What changes between the models is only who registers the domain with Apple (Appmax, via API, in the integrated model; you, through the Apple portal, in the direct flow). See Domain configuration for Apple Pay.
Does the onUpdate order_id need to be from a real Appmax Order?
The required order_id is the one in the payment request, and it must be from an
existing Order (created via POST /v1/orders). It doesn't need to come from
onUpdate, but it must be in the payment payload.
If the merchant's domain changes, do I need a new merchant?
No. The new domain is registered again on the existing installation.
Is there one token/file per merchant, or a shared one?
The Apple Token is always per transaction. The contents of the domain
validation file are the same for all domains linked to the merchantIdentifier
managed by Appmax — it isn't generated per merchant. Even so, each domain
must host its own copy of that same file (see
Domain configuration for Apple Pay). What
is per merchant are the credentials (client_id/client_secret) and the
external_id.
Does domain validation take long?
Domain registration is fast (synchronous call). Merchant Session validation happens in real time, on every transaction — also fast.
Can I test through the Appmax sandbox?
Yes. You need a public, registered domain publishing the sandbox
.well-known. You pay with a real Wallet card and nothing
is charged (see Testing and Sandbox).
Conclusion — checklist
- Authorize the installation with
domain_name. - Publish the
.well-knownfile on each domain (required in all models) and register the domain with Apple — Appmax via API (integrated model) or yourself (direct flow). See Domain configuration for Apple Pay. - Include and initialize Appmax JS with
onSuccess,onError,externalId,onUpdate,onAuthorize. - Create customer → create order → process the
appleTokenviaPOST /v1/payments/apple-pay.
Authorizations
Bearer token of the merchant obtained via POST /oauth2/token using the
merchant's credentials (not the app's). See
Authentication.
Request Body
Responses
Apple Pay payment approved.