Who this is for. Developers adding Apple Pay or Google Pay buttons to a cart or checkout page on a site that takes payment with Stripe. After this page you can mount the buttons, turn a wallet payment into an ordinary purchase call, and know what to set up before launch.
Where Apple Pay and Google Pay come from
Apple Pay and Google Pay are delivered by Stripe's Express Checkout Element, not by a payment method of their own. There is no wallet setting on the site: a site with an active Stripe method already has what the element needs, because the payment-methods list returns that method's publishableKey and accountId (Listing the methods a shopper can choose).
The payment itself is a Stripe payment like any other. The element leads to a Stripe confirmation token, and your script sends it to the same purchase call, with the Stripe method's id as _paymentMethodId. The invoice, the currency, the answers and the webhook that makes the order are the same as for a card, so everything on Payment methods and how a payment runs applies unchanged, the currency and the amount in minor units included (The currency a payment is taken in).
How it differs from a card payment
| Card payment | Express payment | |
|---|---|---|
| Where the shopper pays | Stripe's card fields on the checkout page | The wallet's own sheet, opened from the Express Checkout Element |
| Email and addresses | Typed into your form and written to the checkout before paying | Taken from the billing and shipping details the wallet sheet returns, then written to the checkout |
| Where the token comes from | The card fields | The wallet, through the Express Checkout Element |
| The purchase call | _paymentMethodId and confirmationToken | The same |
| Answers, order and webhook | The same for both | |
The flow
- Load Stripe with the Stripe method's
publishableKeyandaccountId, and create an elements group in payment mode with the checkout's amount and currency, with confirmation tokens created by your script (paymentMethodCreation: 'manual'). Stripe's script loads only once its hosts are in the site's policy (Content Security Policy). - Create the Express Checkout Element with Apple Pay and Google Pay, and mount it in its own container.
- When the shopper confirms in the wallet sheet, the element fires its
confirmevent with the billing and shipping details. Use the current checkout, or create one from the cart if there is none yet, and write the email and addresses to it. - Create shipping and select a rate, as on Addresses and shipping at checkout, so that the checkout is ready for payment.
- Call
elements.submit(), thenstripe.createConfirmationToken({ elements }). - Call purchase with the method's id and the token, and act on the answer exactly as for a card.
The billing and shipping details from the wallet become the checkout's addresses, the same address records described on Addresses and the address book. Ask the wallet for the email and addresses the checkout needs through the element's own options, which Stripe's documentation for the Express Checkout Element lists.