docs/api-reference/tutorials/quick-checkout-with-stripe.mdx
Assume that you have a cart made with line items in it already.
Quick checkout works by handling 3 different events:
How you should handle them depends on your platform/language:
For Web and JS, please review:
For iOS, please review:
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):
<AccordionGroup> <Accordion title="Update the checkout">```bash Update order [expandable]
curl -X PATCH <SHOP URL>/api/v2/storefront/checkout \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/json' \
-d '{
"order": {
"ship_address_attributes": {
"quick_checkout": true,
"firstname": <First name>,
"lastname": <Last name>,
"city": <City>,
"zipcode": <Zip>,
"country_iso": <Country>,
"state_name": <State>
},
"bill_address_id": "CLEAR"
}
}'
```
<ParamField body="quick_checkout" type="bool" required>
`true` indicating that the order is from quick checkout. It is required as the address details you will receive from Apple Pay or Google Pay are not complete and wouldn't be valid for the standard checkout.
</ParamField>
<ParamField body="firstname" type="string">
Customer's first name, e.g. John
</ParamField>
<ParamField body="lastname" type="string">
Customer's last name, e.g. Doe
</ParamField>
<ParamField body="city" type="string" required>
Customer's city, e.g. Mountain View
</ParamField>
<ParamField body="zipcode" type="string">
Customer's zip code, e.g. 94043
</ParamField>
<ParamField body="country_iso" type="string" required>
Customer's country ISO, e.g. US
</ParamField>
<ParamField body="state_name" type="string" required>
Customer's address state, e.g. CA (empty string is also accepted)
</ParamField>
<ParamField body="bill_address_id" type="string" required>
Set it to `CLEAR` to clear the existing billing address (this prevents the order from accidentally advancing to the `payment` step).
</ParamField>
[Full documentation](/api-reference/storefront/checkout/update-checkout)
curl -X PATCH '<SHOP URL>/api/v2/storefront/checkout/advance?state=delivery&include=shipments.shipping_rates' \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/json' \
-d '{
"quick_checkout": true,
"shipping_method_id": <Shipping Method ID>
}'
This will return you an order response, and you can update the payment element with a new total (you should use total_minus_store_credits for total) and shipping rates.
</Accordion>
Here we need to send the selected shipping method to the backend and update the total in the payment element
curl -X PATCH '<SHOP URL>/api/v2/storefront/checkout/select_shipping_method' \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/json' \
-d '{
"shipping_method_id": <Shipping Method ID>
}'
Subsequently, update the payment element with a new total taken from the response's total_minus_store_credits
Now you should make several more calls to the backend
<AccordionGroup> <Accordion title="Confirm that the order is ready for the payment"> ```bash Validate order for payment curl -X POST '<SHOP URL>/api/v2/storefront/checkout/validate_order_for_payment?skip_state=true' \ -H 'Authorization: Bearer <Token>' ``` <Info> `200` response code means that the order is ready for the payment. </Info>[Endpoint documentation](/api-reference/storefront/checkout/validate-order-payment)
You should have a lot more information about the customer (in previous events, Stripe probably will not provide you information such as customer address), so send them to the backend:
curl -X PATCH <SHOP URL>/api/v2/storefront/checkout \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/json' \
-d '{
"order": {
"email": <EMAIL>,
"ship_address_attributes": {
"quick_checkout": true,
"firstname": <First name>,
"lastname": <Last name>,
"address1": <Address>,
"address2": <Address 2>,
"city": <City>,
"zipcode": <Zip>,
"country_iso": <Country>,
"state_name": <State>,
"phone": <Phone>
}
},
"do_not_change_state": true
}'
Thereafter, you should confirm the payment intent using the Stripe library; this depends on your platform/language.
<Warning> `<PAYMENT INTENT ID>` should be Spree's internal payment intent ID, which you will receive when you create the payment intent. Do not confuse it with Stripe's payment intent ID. </Warning>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:
curl -X POST <SHOP URL>/api/v2/storefront/stripe/payment_intents/<PAYMENT INTENT ID>/confirm \
-H 'Authorization: Bearer <Token>'
This will also check if the payment intent is confirmed, and it will move the order to the complete state
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.
curl -X PATCH <SHOP URL>/api/v2/storefront/checkout \
-H 'Authorization: Bearer <Token>' \
-H 'Content-Type: application/json' \
-d '{
"order": {
"ship_address_id": "CLEAR",
"bill_address_id": "CLEAR"
}
}'