Create an Apple Pay Session
Overview
Create an Apple Pay Session using the validation URL provided by Apple to receive the merchantSession object for payment processing on the web. This endpoint is required to enable Apple Pay on your website.
Resource Access
- User Permissions: All users can access this endpoint
- Endpoint:
POST /apple_pay_sessions
Arguments
| Parameter | Type | Required | Description |
|---|---|---|---|
| display_name | string | No | The merchant name displayed in the Apple Pay sheet (e.g., "Ahrvo Network Test Merchant") |
| domain | string | Yes | Your registered domain (e.g., "www.yourmerchant.com") |
| merchant_identity | string | Yes | The Merchant Identity ID |
| validation_url | string | Yes | The validation URL provided by Apple during the payment flow |
Example Request
curl -X POST \
'https://api.ahrvo.network/payments/na/apple_pay_sessions' \
-u username:password \
-H 'Content-Type: application/json' \
-d '{
"display_name": "Acme Retail Store",
"domain": "www.acmeretail.com",
"merchant_identity": "IDmerchantExample123",
"validation_url": "https://apple-pay-gateway-cert.apple.com/paymentservices/startSession"
}'
Example Response
{
"id": "APSapplePaySession789",
"session_details": "{\"epochTimestamp\":1623847200000,\"expiresAt\":1623850800000,\"merchantSessionIdentifier\":\"SSH123456789\",\"nonce\":\"abc123def456\",\"merchantIdentifier\":\"merchant.com.acmeretail\",\"domainName\":\"www.acmeretail.com\",\"displayName\":\"Acme Retail Store\",\"signature\":\"MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQ...\"}",
"_links": {
"self": {
"href": "https://api.ahrvo.network/payments/na/apple_pay_sessions/APSapplePaySession789"
}
}
}
Implementation Flow
- Register Your Domain: Register your domain with Apple through your Apple Developer account
- Apple Pay Button Click: User clicks the Apple Pay button on your website
- Request Validation URL: Apple provides a validation URL through the Apple Pay JS API
- Call This Endpoint: Send the validation URL to this endpoint to create a session
- Receive merchantSession: Get the
session_detailsfrom the response - Parse and Use: Parse the JSON string in
session_detailsand pass it to Apple Pay JS to complete the session - Process Payment: After the user authorizes, you'll receive a payment token to create a Payment Instrument
Example JavaScript Implementation
// Step 1: User clicks Apple Pay button
const paymentRequest = {
countryCode: 'US',
currencyCode: 'USD',
total: {
label: 'Your Merchant Name',
amount: '10.00'
}
};
const session = new ApplePaySession(3, paymentRequest);
// Step 2: Handle validation
session.onvalidatemerchant = async (event) => {
// Step 3: Call Ahrvo Network API to create session
const response = await fetch('https://api.ahrvo.network/payments/na/apple_pay_sessions', {
method: 'POST',
headers: {
'Authorization': 'Basic ' + btoa('username:password'),
'Content-Type': 'application/json'
},
body: JSON.stringify({
display_name: 'Acme Retail Store',
domain: 'www.acmeretail.com',
merchant_identity: 'IDmerchantExample123',
validation_url: event.validationURL
})
});
const data = await response.json();
// Step 4: Parse session details and complete validation
const merchantSession = JSON.parse(data.session_details);
session.completeMerchantValidation(merchantSession);
};
// Step 5: Handle payment authorization
session.onpaymentauthorized = async (event) => {
// Create Payment Instrument with the token
const paymentToken = event.payment.token;
// ... process payment with token
};
session.begin();
Additional Information
- Domain Registration: Before using this endpoint, you must register and verify your domain with Apple in your Apple Developer account
- Session Expiration: Apple Pay sessions are time-limited (typically 5 minutes). Create a new session for each payment attempt
- Validation URL: The validation URL is provided by Apple during the payment flow and changes for each session
- Session Details Format: The
session_detailsfield contains a JSON string (not a JSON object) that must be parsed before use - merchantSession Object: Contains:
merchantSessionIdentifier: Unique identifier for this sessionnonce: Security token for this sessionmerchantIdentifier: Your Apple Merchant IDdomainName: Your registered domaindisplayName: Name shown to the usersignature: Cryptographic signature from AppleepochTimestampandexpiresAt: Session validity period
- Security: The session validation ensures that:
- Your domain is registered with Apple
- The request is legitimate and not spoofed
- The merchant is authorized to process Apple Pay payments
- Testing: Use Apple's sandbox environment for testing before going live
- Supported Browsers: Apple Pay on the web is supported in Safari on macOS and iOS
- Certificate Management: Ahrvo Network manages the merchant certificates required for Apple Pay validation