stripe-paymentsapplepayjs

Stripe get Apple Pay token to create a customer - web


Is there a way to get the apple pay payment method id without charging the user? Right now I've been trying to do some variation of step 5: https://stripe.com/docs/stripe-js/elements/payment-request-button, but I seem to only be able to get the payment method id after i have confirmed a payment.


Solution

  • You listen to the PaymentRequest's paymentmethod event on your page, like shown here: https://stripe.com/docs/stripe-js/elements/payment-request-button#html-js-complete-payment

    The example uses the ev.paymentMethod.id to confirm a PaymentIntent but you can choose to not do that and instead post the PaymentMethod token to your server and use it some other way (e.g. to attach to a Customer and use in a Subscription).

    Make sure to call ev.complete() with success/fail as appropriate so that the payment sheet closes with the correct message to the customer.