| Time | Status | User Agent | |
|---|---|---|---|
Retrieving recent requests… | |||
Unlike Hosted Checkout, where DigetPay handles Apple Pay on its payment page, Apple Pay S2S requires your website or application to obtain an Apple Pay payment token and submit it securely from your backend.
Important: Apple Pay S2S uses the standard S2S Sale endpoint but requires a dedicated
applePayTokenobject and a different request hash formula.
1. Prerequisites
Before integrating Apple Pay S2S, ensure that:
- Apple Pay S2S is enabled for your DigetPay merchant account.
- You have a valid Test or Live API Key.
- Your website or application can obtain an authorized Apple Pay payment token.
- The required Apple Pay merchant configuration and certificates are set up for your integration.
- Your merchant backend supports HTTPS and secure API communication.
- You have a mechanism to verify payment status and handle webhooks.
For Apple Pay on the Web, merchant validation must be completed through your backend.
2. How Apple Pay S2S Works
- The customer selects Apple Pay on the merchant's checkout page.
- The merchant's Apple Pay integration presents the payment sheet.
- The customer authorizes the payment using Face ID, Touch ID, or another supported authentication method.
- Apple Pay returns an encrypted payment token.
- The merchant securely sends the token to their backend.
- The backend generates the Apple Pay-specific hash.
- The backend submits the payment to the DigetPay S2S Sale API.
- The merchant verifies the final payment status before completing the order.
Payment flow
sequenceDiagram
autonumber
participant Customer
participant Website as Merchant Website
participant Apple as Apple Pay
participant Backend as Merchant Backend
participant API as DigetPay API
Customer->>Website: Select Apple Pay
Website->>Apple: Open Apple Pay sheet
Customer->>Apple: Authorize payment
Apple-->>Website: Encrypted payment token
Website->>Backend: Send payment token
Backend->>Backend: Generate Apple Pay hash
Backend->>API: POST /payment/s2s/sale
API-->>Backend: Payment result
Backend->>API: Verify transaction status
API-->>Backend: Final payment status
Backend->>Backend: Update order
3. API Endpoint
| Property | Value |
|---|---|
| Method | POST |
| Endpoint | /payment/s2s/sale |
| Base URL | https://api.digetpay.com/v1 |
| Authentication | x-api-key |
| Content-Type | application/json |
| Payment Method | applepay |
Both Test and Live environments use the same API base URL. The API key determines the environment.
4. Create an Apple Pay Payment
Example Request
curl --location 'https://api.digetpay.com/v1/payment/s2s/sale' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"orderId": "ORDER-APPLE-001",
"amount": 1,
"currency": "SAR",
"paymentMethod": "applepay",
"auth": "N",
"applePayToken": {
"paymentData": {
"version": "EC_v1",
"data": "BASE64_ENCODED_ENCRYPTED_PAYMENT_DATA_EXAMPLE",
"signature": "BASE64_ENCODED_APPLE_PAY_SIGNATURE_EXAMPLE",
"header": {
"ephemeralPublicKey": "BASE64_ENCODED_EPHEMERAL_PUBLIC_KEY_EXAMPLE",
"publicKeyHash": "BASE64_ENCODED_PUBLIC_KEY_HASH_EXAMPLE",
"transactionId": "TRANSACTION_ID_HEX_EXAMPLE"
}
},
"transactionIdentifier": "ABC123TXN"
},
"customer": {
"name": "Test Customer",
"email": "[email protected]",
"phone": "966512345678"
},
"successUrl": "https://merchant.example/success",
"failureUrl": "https://merchant.example/failure",
"hash": "GENERATED_UPPERCASE_MD5_HASH"
}'Important: The Apple Pay token in this request is illustrative. Replace the example token fields with the actual encrypted token generated by Apple Pay for the customer's payment.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
orderId | string | Yes | Unique merchant order reference. |
amount | number | Yes | Payment amount. |
currency | string | Yes | Payment currency, such as SAR. |
paymentMethod | string | Yes | Set to applepay. |
auth | string | Yes | Set to N for the sale request shown here. |
applePayToken | object | Yes | Apple Pay encrypted payment token. |
customer.name | string | Yes | Customer name. |
customer.email | string | Yes | Customer email used in hash generation. |
customer.phone | string | Yes | Customer phone number. |
successUrl | string | Yes | Merchant success URL. |
failureUrl | string | Yes | Merchant failure URL. |
hash | string | Yes | Apple Pay-specific uppercase MD5 hash. |
Apple Pay Token Fields
| Field | Description |
|---|---|
paymentData.version | Apple Pay token encryption version. |
paymentData.data | Encrypted payment information. |
paymentData.signature | Cryptographic signature for the token. |
paymentData.header.ephemeralPublicKey | Ephemeral public key included in the illustrated EC token. |
paymentData.header.publicKeyHash | Public key hash. |
paymentData.header.transactionId | Identifier inside the payment-data header. |
transactionIdentifier | Apple Pay payment token identifier used to generate the DigetPay request hash. |
Critical:
applePayToken.transactionIdentifierandapplePayToken.paymentData.header.transactionIdare different fields. Always useapplePayToken.transactionIdentifierfor the hash.
5. Apple Pay S2S Hash Generation
Apple Pay S2S uses a different hash formula from standard Card S2S and Tamara S2S payments.
Hash Formula
HASH = UPPERCASE_MD5_HEX(
UPPERCASE(
REVERSE(customer.email)
+ API_KEY
+ REVERSE(applePayToken.transactionIdentifier)
)
)Trim the email and transaction identifier before reversing them.
Hash Generation Steps
- Reverse the customer's email address.
- Append the merchant API key.
- Reverse
applePayToken.transactionIdentifier. - Concatenate all three values without separators.
- Convert the combined string to uppercase.
- Generate the MD5 hash.
- Convert the resulting hexadecimal hash to uppercase.
JavaScript Function
function s2sApplePayTokenHash(email, apiKey, transactionId) {
const rev = (s) => s.split("").reverse().join("");
const combined = (
rev(email.trim()) +
apiKey +
rev(String(transactionId).trim())
).toUpperCase();
return CryptoJS.MD5(combined)
.toString(CryptoJS.enc.Hex)
.toUpperCase();
}Hash Comparison
| Payment Method | Hash Identifier |
|---|---|
| Card S2S | Card number portion specified by the Card S2S hash |
| Tamara S2S | orderId |
| Apple Pay S2S | applePayToken.transactionIdentifier |
Apple Pay also requires an uppercase MD5 hexadecimal result.
6. Postman Pre-request Script
Create an environment variable named digetpay_api_key containing your API key.
Configure the request header:
x-api-key: {{digetpay_api_key}}Then add the following Pre-request Script:
function s2sApplePayTokenHash(email, apiKey, transactionId) {
const rev = (s) => s.split("").reverse().join("");
const combined = (
rev(email.trim()) +
apiKey +
rev(String(transactionId).trim())
).toUpperCase();
return CryptoJS.MD5(combined)
.toString(CryptoJS.enc.Hex)
.toUpperCase();
}
const API_KEY = pm.environment.get("digetpay_api_key");
if (!API_KEY) {
throw new Error("Missing digetpay_api_key");
}
const body = JSON.parse(pm.request.body.raw);
const email = body.customer?.email;
const transactionId = body.applePayToken?.transactionIdentifier;
if (!email || !transactionId) {
throw new Error(
"customer.email and applePayToken.transactionIdentifier are required"
);
}
const hash = s2sApplePayTokenHash(
email,
API_KEY,
transactionId
);
body.hash = hash;
pm.request.body.raw = JSON.stringify(body, null, 2);The script calculates the hash and inserts it into the request body before submission.
Security: Generate the hash on your backend in production. Never expose merchant API keys in frontend JavaScript, application logs, or public repositories.
7. API Response Handling
After submitting the request, DigetPay returns the S2S payment result.
Inspect the fields actually returned by the API, including the transaction status and any identifiers needed for payment verification.
| Field | Description |
|---|---|
code | API response code. |
data.result | Payment processing result or required action, when returned. |
data.status | Current transaction status, when returned. |
data.transactionId | DigetPay gateway transaction UUID, when returned. |
data.paymentId | Payment processor identifier, when returned. |
data.order_id | Merchant order reference, when returned. |
data.redirect_url | Customer redirect URL if DigetPay explicitly returns a redirect flow. |
data.decline_reason | Decline reason, when available. |
A successful API response does not automatically mean the payment has been approved.
The merchant must verify the final transaction status before updating the order.
Response example: The exact Apple Pay S2S Sale response has not yet been supplied, so a JSON response example should be added after validating a real Apple Pay transaction. Do not assume the response matches Card or Tamara in every field.
8. Transaction Status Verification
Use the Embedded Transaction Status API to retrieve the latest payment status.
Endpoint
GET https://api.digetpay.com/v1/payment/s2s/transaction/{transactionId}Example Request
curl --location \
'https://api.digetpay.com/v1/payment/s2s/transaction/YOUR_PAYMENT_ID' \
--header 'x-api-key: YOUR_API_KEY'Although the endpoint path parameter is named transactionId, the existing DigetPay S2S status documentation specifies using the paymentId returned by Direct Sale.
Always store the available payment identifiers with your merchant order.
Payment Confirmation
- Verify the transaction has reached a successful or approved status.
- Match the merchant order reference.
- Verify the payment amount and currency.
- Update the order only after successful verification.
- Use idempotent processing to prevent duplicate fulfillment.
Do not rely solely on a success redirect or webhook notification.
9. Troubleshooting
| Issue | Recommended Check |
|---|---|
| Invalid Request Hash | Check email reversal, API key, transaction identifier reversal, uppercase conversion, and MD5 output. |
| Invalid Apple Pay Token | Use a genuine token generated for the current payment, not sample token values. |
| Transaction Identifier Mismatch | Use applePayToken.transactionIdentifier, not paymentData.header.transactionId. |
| Apple Pay Not Available | Check the customer's device, browser, wallet configuration, and merchant integration. |
| Merchant Validation Error | Check the Apple Pay merchant identity, certificate, verified domain, and server-side validation setup. |
| Unauthorized Request | Verify the API key and ensure the same key is used for request authentication and hash generation. |
| Payment Pending | Query the S2S Transaction Status API before updating the order. |
| Order Not Updated | Check payment status verification, webhook processing, and order reference mapping. |
10. Important Notes
- Use
paymentMethod: "applepay". - Include the encrypted
applePayTokenobject. - Do not send raw card details.
- Generate the hash using
customer.email, the API key, andapplePayToken.transactionIdentifier. - Convert both the combined hash input and resulting MD5 hexadecimal digest to uppercase.
- Obtain a valid Apple Pay payment token before submitting the Sale request.
- Process the request securely from your backend.
- Verify the final payment status before fulfilling the order.
- Test and Live environments share the same API base URL.
Related Documentation
200
