Embaded Apple Pay

Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…

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 applePayToken object 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

  1. The customer selects Apple Pay on the merchant's checkout page.
  2. The merchant's Apple Pay integration presents the payment sheet.
  3. The customer authorizes the payment using Face ID, Touch ID, or another supported authentication method.
  4. Apple Pay returns an encrypted payment token.
  5. The merchant securely sends the token to their backend.
  6. The backend generates the Apple Pay-specific hash.
  7. The backend submits the payment to the DigetPay S2S Sale API.
  8. 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

PropertyValue
MethodPOST
Endpoint/payment/s2s/sale
Base URLhttps://api.digetpay.com/v1
Authenticationx-api-key
Content-Typeapplication/json
Payment Methodapplepay

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

ParameterTypeRequiredDescription
orderIdstringYesUnique merchant order reference.
amountnumberYesPayment amount.
currencystringYesPayment currency, such as SAR.
paymentMethodstringYesSet to applepay.
authstringYesSet to N for the sale request shown here.
applePayTokenobjectYesApple Pay encrypted payment token.
customer.namestringYesCustomer name.
customer.emailstringYesCustomer email used in hash generation.
customer.phonestringYesCustomer phone number.
successUrlstringYesMerchant success URL.
failureUrlstringYesMerchant failure URL.
hashstringYesApple Pay-specific uppercase MD5 hash.

Apple Pay Token Fields

FieldDescription
paymentData.versionApple Pay token encryption version.
paymentData.dataEncrypted payment information.
paymentData.signatureCryptographic signature for the token.
paymentData.header.ephemeralPublicKeyEphemeral public key included in the illustrated EC token.
paymentData.header.publicKeyHashPublic key hash.
paymentData.header.transactionIdIdentifier inside the payment-data header.
transactionIdentifierApple Pay payment token identifier used to generate the DigetPay request hash.

Critical: applePayToken.transactionIdentifier and applePayToken.paymentData.header.transactionId are different fields. Always use applePayToken.transactionIdentifier for 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

  1. Reverse the customer's email address.
  2. Append the merchant API key.
  3. Reverse applePayToken.transactionIdentifier.
  4. Concatenate all three values without separators.
  5. Convert the combined string to uppercase.
  6. Generate the MD5 hash.
  7. 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 MethodHash Identifier
Card S2SCard number portion specified by the Card S2S hash
Tamara S2SorderId
Apple Pay S2SapplePayToken.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.

FieldDescription
codeAPI response code.
data.resultPayment processing result or required action, when returned.
data.statusCurrent transaction status, when returned.
data.transactionIdDigetPay gateway transaction UUID, when returned.
data.paymentIdPayment processor identifier, when returned.
data.order_idMerchant order reference, when returned.
data.redirect_urlCustomer redirect URL if DigetPay explicitly returns a redirect flow.
data.decline_reasonDecline 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

IssueRecommended Check
Invalid Request HashCheck email reversal, API key, transaction identifier reversal, uppercase conversion, and MD5 output.
Invalid Apple Pay TokenUse a genuine token generated for the current payment, not sample token values.
Transaction Identifier MismatchUse applePayToken.transactionIdentifier, not paymentData.header.transactionId.
Apple Pay Not AvailableCheck the customer's device, browser, wallet configuration, and merchant integration.
Merchant Validation ErrorCheck the Apple Pay merchant identity, certificate, verified domain, and server-side validation setup.
Unauthorized RequestVerify the API key and ensure the same key is used for request authentication and hash generation.
Payment PendingQuery the S2S Transaction Status API before updating the order.
Order Not UpdatedCheck payment status verification, webhook processing, and order reference mapping.

10. Important Notes

  • Use paymentMethod: "applepay".
  • Include the encrypted applePayToken object.
  • Do not send raw card details.
  • Generate the hash using customer.email, the API key, and applePayToken.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

Response
200
Language
Credentials
Header
LoadingLoading…
Response
Click Try It! to start a request and see the response here!