Apple Pay via direct API
This guide covers how to integrate Apple Pay directly with DEUNA's API. Direct integration gives you full control over the payment flow, making it ideal for merchants who need custom implementations or have existing payment systems. This integration supports one-time payments.
Apple Pay with DEUNA
The following is the standard process for an Apple Pay purchase with DEUNA:
1. Get the payment methods
With Order Token
curl --location 'https://api.{env}.deuna.io/merchants/orders/{order-token}/payments-methods' \
--header 'x-api-key: {merchant private api key}'Without Order Token
curl --location 'https://api.{env}.deuna.io/merchants/stores/payments-methods' \
--header 'x-api-key: {merchant private api key}' \
--header 'x-store-code: {store id}' \
--data ''Response
{
"data": [
....
{
"allow_installments_plan": true,
"credentials": {
"external_merchant_id": "merchant.test.io.deuna.pay" // apple pay merchant id: used by apple pay web sdk
},
"enabled": true,
"extra_params": {
"allowed_auth_methods": [ // used by apple pay web sdk
"supports3DS"
],
"allowed_card_networks": [ // used by apple pay web sdk
"visa",
"masterCard",
"amex"
],
"merchant_name": "Test DEUNA" // used by apple pay web sdk
},
"id": "ef2319fe-f88d-4d8d-b4d1-e4fa08f18651", // credential id used for get apple pay payment session
"method_type": "card_wallet",
"payment_provider": "apple_pay",
"processor_name": "apple_pay", //
"team": "apple_pay"
}
...
]
}2. Initialize the Apple Pay Web SDK
Doc: https://developer.apple.com/documentation/applepayontheweb
Import the JS SDK de Apple Pay
<script src="https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js" crossorigin=""></script>
<script>
// 1a. Check ApplePaySession
if (!window.ApplePaySession) {
setStatus('ApplePaySession not available (not Safari?)', 'err');
return;
}
// 1c. canMakePayments
if (!ApplePaySession.canMakePayments()) {
setStatus('canMakePayments() = false', 'err');
return;
}
</script>Initialize the Apple Pay SDK when the user clicks Pay with Apple Pay.
<script>
const request = {
countryCode: 'MX',
currencyCode: 'MXN',
supportedNetworks: ['visa', 'masterCard', 'amex', 'discover'],
merchantCapabilities: ['supports3DS'],
total: { label: 'DEUNA Test', amount: '1.00', type: 'final' },
};
// Create session (sync — MUST be in user gesture)
const session = new ApplePaySession(negotiatedVersion, request);
</script>In the onvalidatemerchant event, add the following call to obtain the Apple session:
curl --location --globoff 'https://api.{env}.deuna.io/wallet/credentials/{credential-id}/payment-session' \
--header 'X-Merchant-Id: {deuna merchant id}' \
--header 'X-Store-Code: {deuna store code}' \
--header 'Content-Type: application/json' \
--data '{
"validation_url": "{{validation url from sdk event}}", // event.validationURL
"domain": "{{web domain}}" // your current domain
}'Get the Validation URL
<script>
session.onvalidatemerchant = async (event) => {
let validationURL = event.validationURL
// add request here
let merchantSession = response.data(); // API response
session.completeMerchantValidation(merchantSession);
}
</script>2. Purchase with Apple Pay
Once the user authorizes the payment on their Apple device, the onpaymentauthorized event will be fired by the Apple Pay SDK. The event data contains the encrypted card token. This token must be sent as-is, without any modification, in the DEUNA create card or purchase request. The token is received in the event.payment property of the SDK.
<script>
session.onpaymentauthorized = (event) => {
let applePayToken = event.payment // sent in create card or purchase request
// add request here
session.completePayment(ApplePaySession.{Payment Status});
};
</script> 1.1 Create Card (Docs)
curl --location 'https://api.{env}.deuna.io/users/{user-id}/cards' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer {user token}' \
--data '[
{
"apple_pay": {
"paymentData": {
"token": {
"transactionIdentifier": "7a94479858348...",
"paymentMethod": {
"type": "debit",
"displayName": "Visa 7553",
"network": "Visa"
},
"paymentData": {
"data": "EOeLQTsv8X7f...",
"header": {
"publicKeyHash": "MpXcCgm...",
"ephemeralPublicKey": "MFkwEwYH...",
"transactionId": "7a94479858348..."
},
"version": "EC_v1"
}
}
}
},
"credential_source": "apple_pay"
}
]'1.2 Purchase with Card ID (DOCS)
It should be a standard purchase using a card ID, just like any other card payment.
curl --location 'http://api.{env}.deuna.io/v2/merchants/orders/purchase' \
--header 'Content-Type: application/json' \
--header 'X-Merchant-Id: {merchant id}' \
--header 'X-Store-Code: {store code}' \
--header 'x-api-key: {private key}' \
--header 'Authorization: Bearer {user token}' \
--data-raw '{
"order_token":"{order token}",
"order_type": "DEUNA_CHECKOUT",
"payer_info": {
"email": "[email protected]",
"card_holder_dni": "12345678"
},
"payment_source": {
"method_type": "credit_card",
"card_info": {
"card_id": "{deuna card id}"
}
}
}'2 Direct Purchase (Without card id)
curl --location 'http://api.{env}.deuna.io/v2/merchants/orders/purchase' \
--header 'Content-Type: application/json' \
--header 'X-Merchant-Id: {merchant id}' \
--header 'X-Store-Code: {store code}' \
--header 'x-api-key: {private key}' \
--header 'Authorization: Bearer {user token}' \
--data-raw '{
"order_token": "56fb285e-66f0-4c4f-a36b-d2887d3583a1",
"order_type": "DEUNA_CHECKOUT",
"payer_info": {
"email": "[email protected]",
"card_holder_dni": "12345678"
},
"payment_source": {
"method_type": "credit_card"
},
"specific_fields": {
"apple_pay": {
"paymentData": {
"token": {
"transactionIdentifier": "7a94479858348...",
"paymentMethod": {
"type": "debit",
"displayName": "Visa 7553",
"network": "Visa"
},
"paymentData": {
"data": "EOeLQTsv8X7f...",
"header": {
"publicKeyHash": "MpXcCgm...",
"ephemeralPublicKey": "MFkwEwYH...",
"transactionId": "7a94479858348..."
},
"version": "EC_v1"
}
}
}
}
}
}'Initiate a purchase with Apple Pay
Once the customer authorizes the payment on their Apple device, the SDK delivers the payment token. Send it to DEUNA's purchase endpoint.
curl --location '{{apigw_url}}/v2/merchants/orders/purchase' \
--header 'Content-Type: application/json' \
--header 'X-Session-Id: {{session_id}}' \
--header 'x-api-key: {{merchant_private_api_key}}' \
--header 'x-device-id: {{device_fingerprint}}' \
--header 'Authorization: Bearer {{user_token}}' \
--data-raw '{
"order_token": "{{order_token}}",
"order_type": "DEUNA_CHECKOUT",
"payer_info": {
"email": "[email protected]"
},
"payment_source": {
"method_type": "credit_card",
"apple_pay": {
"token": {
"paymentData": {
"version": "EC_v1",
"data": "3+f4oOTwPa6f1UZ6tG...CE=",
"signature": "MIAGCSqGSIb3DQ...AAAA==",
"header": {
"ephemeralPublicKey": "MFkwEK...Md==",
"publicKeyHash": "l0CnXdMv...D1I=",
"transactionId": "32b...4f3"
}
},
"paymentMethod": {
"displayName": "Visa 1234",
"network": "Visa",
"type": "debit"
},
"transactionIdentifier": "32b...4f3"
}
}
},
"anti_fraud_info": {
"device": {
"id": "{{device_fingerprint}}"
}
}
}'Response
{
"order_type": "DEUNA_CHECKOUT",
"order_token": "4598f493-de86-4fe0-b9fd-c4c6c9847e39",
"order": {
"order_id": "DEUNA_CHECKOUT_b6a5c0b6-3df9-4b3b-b778-7086c190062b",
"currency": "MXN",
"total_amount": 10000,
"display_total_amount": "MXN 100,00",
"status": "succedeed",
"payment": {
"data": {
"status": "processed"
}
}
}
}Updated about 5 hours ago