Skip to Content
Docs

Accept Apple Pay and Google Pay with the API

Accept Apple Pay and Google Pay with the API by passing the wallet's payment token to Pay.com from your server.

To accept Apple Pay or Google Pay through the Pay.com API, you render the wallet's button on your frontend and receive a payment token from the wallet when the customer authorizes the payment. Your server then passes the token to Pay.com to create the charge, either decrypted (as a network token) or encrypted (exactly as the wallet returned it).

How it works

When the customer authenticates on their device, the wallet's payment token contains the card's DPAN (Device Primary Account Number), a one-time cryptogram, and an ECI (Electronic Commerce Indicator) value that proves the cardholder authenticated on-device.

When a customer authorizes a payment with Face ID, Touch ID, or passcode, Apple Pay returns an encrypted paymentData object that contains the DPAN, the cryptogram, and the ECI value.

Apple Pay always uses Cryptogram 3DS authentication. The device-level biometric verification satisfies 3DS requirements, so no additional bank challenge is triggered.

There are two ways to send the token to Pay.com:

PathHow it worksWhen to use
You decryptYour server decrypts the token and sends the DPAN, cryptogram, and ECI to Pay.com as a network_token. For Apple Pay, you decrypt the paymentData blob using your Apple Pay payment processing certificate.You need full control over the payload, or you want to inspect the token data before submitting.
Pay.com decryptsYour server passes the encrypted token to Pay.com as the wallet returns it, and Pay.com decrypts it. Send Apple Pay's paymentData with source_data.type: "applepay", or Google Pay's signature, intermediateSigningKey, protocolVersion, and signedMessage with source_data.type: "googlepay". For Apple Pay, your backend also validates the merchant through POST /v1/sessions/applepay. Step 1 shows the requests. Pay.com.js (checkout.headless('applepay'), checkout.headless('googlepay'), or Universal checkout) does this for you.You want a simpler integration. Requires a real device session and cannot be tested server-side.

Requirements

Before processing wallet payments via the API:

  • Apple Pay is turned on in the Pay.com dashboard. See Turn on payment methods.
  • Register every domain that shows the Apple Pay button with Pay.com, which registers it with Apple for you. See Apple Pay. If you decrypt the token yourself, you use your own Apple merchant ID and validate the merchant with Apple instead (see step 1).

Create a wallet charge

Send the wallet's token to Pay.com from your server, then track the charge's outcome.

  1. 1

    Send the charge request

    Once the customer authorizes the payment, call POST /v1/charges from your server. amount is in minor units (the smallest currency unit), so 10000 in the examples is $100.00 (or €100.00 in eur).

    Use the Apple Pay JS SDK on your frontend to prompt the customer for payment. Once the customer authorizes with Face ID, Touch ID, or passcode, Apple returns a PKPayment object. How you validate the merchant and send the charge depends on who decrypts the token.

    On either path, map the billing address from the onpaymentauthorized event into source_data.billing_details:

    Apple Pay fieldPay.com parameter
    payment.billingContact.addressLines[0]line1
    payment.billingContact.addressLines[1]line2
    payment.billingContact.localitycity
    payment.billingContact.postalCodepostal_code
    payment.billingContact.administrativeAreastate
    payment.billingContact.countryCodecountry

    Apple Pay opens the payment sheet only after your page completes merchant validation. In your ApplePaySession onvalidatemerchant handler, call your backend. Your backend calls POST /v1/sessions/applepay with the domain that shows the Apple Pay button:

    {
      "domain": "checkout.example.com"
    }

    The response is Apple's merchant session object. Return it to the browser unchanged and pass it to session.completeMerchantValidation(). The domain must be registered with Pay.com first (see Apple Pay).

    When the customer authorizes the payment, send the token from the onpaymentauthorized event to your backend. Set source_data.type to "applepay" and pass the fields of the token's paymentData object in source_data.applepay as Apple returns them: version, data, signature, and header (with ephemeralPublicKey, publicKeyHash, and transactionId). You can also pass the token's paymentMethod object (displayName, network, type). Pay.com decrypts the token and processes the payment as an Apple Pay card payment.

    Pay.com accepts an Apple Pay token for 5 minutes after Apple creates it. Create the charge within this window, or it fails.

    POST https://api.sandbox.pay.com/v1/charges

    {
      "amount": 10000,
      "currency": "usd",
      "source_data": {
        "type": "applepay",
        "applepay": {
          "version": "EC_v1",
          "data": "<paymentData.data>",
          "signature": "<paymentData.signature>",
          "header": {
            "ephemeralPublicKey": "<paymentData.header.ephemeralPublicKey>",
            "publicKeyHash": "<paymentData.header.publicKeyHash>",
            "transactionId": "<paymentData.header.transactionId>"
          },
          "paymentMethod": {
            "displayName": "Visa 4242",
            "network": "Visa",
            "type": "debit"
          }
        },
        "billing_details": {
          "name": "John Smith",
          "email": "john.smith@example.com",
          "address": {
            "line1": "123 Main Street",
            "city": "San Francisco",
            "state": "CA",
            "postal_code": "94102",
            "country": "US"
          }
        }
      },
      "customer_reference_id": "cust-john-smith-001",
      "description": "Apple Pay payment for Order #12348",
      "reference": "order-12348"
    }

    The response has the same shape as the one under You decrypt.

    Testing in the sandbox: The example network token values (token 4242424242424242, cryptogram, and ECI) work as test data in the sandbox. You don't need a real Apple Pay or Google Pay device session to test the merchant-decrypted path (Apple Pay, or Google Pay with CRYPTOGRAM_3DS) server-side.

  2. 2

    Listen for webhooks

    Subscribe to these events to track the outcome of each charge, and verify every signature before acting on them:

    • charge.succeeded: The funds were captured successfully.
    • charge.failed: The charge was declined by the issuer or wallet provider.

Next steps

Was this page helpful?