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_typesincludescard. 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
Check which wallets the browser supports
checkout.canMakePayments()returns a boolean for each wallet. Render a wallet's button only when its value istrue.const wallets = await checkout.canMakePayments() // { applepay: true, googlepay: false } - 2
Pay when the customer taps a button
Call
checkout.headless()withapplepayorgooglepay. 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 callsonSuccess, oronPendingfor a pending result. If the payment fails, it callsonFailureand rejects, so wrap the call intry/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-buttonin 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
- Universal checkout: Let Universal checkout show the wallet buttons for you.
- Express checkout: Show the wallet buttons on product and cart pages.
checkout.headless()andcheckout.canMakePayments(): Their options and results in the Pay.com.js reference.