Skip to Content
Docs

Apple Pay and Google Pay in Headless checkout

Render your own Apple Pay and Google Pay buttons, check that the browser supports each wallet, and pay with checkout.headless().

With Headless checkout, you render the Apple Pay and Google Pay buttons yourself. Pay.com.js tells you which wallets the customer's browser supports, shows the wallet's payment sheet, and creates the charge.

Requirements

Set up these before you add wallet buttons.

  • A Headless checkout instance, created from a payment session whose payment_method_types includes card. See Headless checkout.
  • Apple Pay and Google Pay are turned on in the Pay.com dashboard. See Turn on payment methods.
  • Every domain that shows your Apple Pay button is registered for Apple Pay. See Apple Pay.

Add the wallet buttons

Check which wallets the browser supports, then pay with the wallet the customer taps.

  1. 1

    Check which wallets the browser supports

    checkout.canMakePayments() returns a boolean for each wallet. Render a wallet's button only when its value is true.

    const wallets = await checkout.canMakePayments()
    // { applepay: true, googlepay: false }
  2. 2

    Pay when the customer taps a button

    Call checkout.headless() with applepay or googlepay. Pay.com.js shows the wallet's payment sheet and creates the charge with the card the customer authorizes.

    async function payWith(wallet) {
      try {
        await checkout.headless(wallet) // 'applepay' or 'googlepay'
      } catch (error) {
        console.log('Payment failed:', error.message)
      }
    }

    checkout.headless() resolves with the payment result and calls onSuccess, or onPending for a pending result. If the payment fails, it calls onFailure and rejects, so wrap the call in try/catch. Confirm the charge on your server with webhooks before you fulfill the order.

Follow each wallet's button rules

Apple and Google each set rules for how their button looks.

  • Apple Pay: use the official button, with -webkit-appearance: -apple-pay-button in your CSS or Apple's button guidelines. Don't style a generic button to look like Apple Pay.
  • Google Pay: follow Google's brand guidelines for the button's label and colors.

Next steps

Was this page helpful?