Quick Checkout with Stripe and Storefront API
This tutorial will show you how to add quick checkout to your headless/composable storefront using Stripe and Spree APIs.
This guide is aimed at advanced users who have some experience with Spree API and Stripe. You also need to install Spree Stripe extension before.
If youāre using the standard Spree Storefront, then you can skip this tutorial as quick checkout is already built in.
Prerequisites
Assume that you have a cart made with line items in it already.
Quick checkout works by handling 3 different events:
- Address change
- Shipping Method/Rate change
- Confirmation
How you should handle them depends on your platform/language:
-
For Web and JS, please review:
- Express Checkout Element
- We also recommend reviewing the spree_stripe implementation in Stimulus.js
-
For iOS, please review:
Checkout Flow
Address change
Here we need to send some basic information about the customerās shipping address, and we should move the order to the delivery step (donāt forget to replace the placeholders with the customerās data):
Shipping Method/Rate change
Here we need to send the selected shipping method to the backend and update the total in the payment element
Shipping method ID of the selected shipping rate
Subsequently, update the payment element with a new total taken from the responseās total_minus_store_credits
Confirming the payment
Now you should make several more calls to the backend
Thereafter, you should confirm the payment intent using the Stripe library; this depends on your platform/language.
If you like to redirect the user to Spreeās order summary page, then set the return_url
when confirming the payment intent to <SHOP URL>/stripe/payment_intents/<PAYMENT INTENT ID>
. This will check if the payment intent is confirmed, move the order to the complete state, and redirect the user to the order summary.
If you like to make the order summary page by yourself, then after confirming the payment intent in Stripe, make this request:
This will also check if the payment intent is confirmed, and it will move the order to the complete state
User cancels the payment
If at any point, the user cancels the payment (closes the quick checkout sheet/modal), you will need to handle this event and clear the shipping and billing address from the order as these addresses will not be valid and if someones decides to use standard checkout it could lead to errors.
All Done!
Congrats! Now, your users should be able to pay for orders with quick checkout! Need support or want to give some feedback? You can join our community or drop us an email at [email protected].