Skip to main content
Below we highlight common use cases that come up with checkout sessions and how to handle them. If there is a scenario that is not addressed, reach out to miguel@withflex.com

Shipping options

If you need to ship a good, Flex can collect shipping details for you. Set the shipping_address_collection parameter to true as part of the payload. If you additionally want to charge a shipping rate then you can do so by either:

Creating a fixed shipping rate

Then specifying the returned shipping_rate_id as part of the payload when creating a checkout session.

Creating a dynamic shipping rate

If your shipping varies based on the cart items, pass the shipping data in the checkout session payload. Flex creates the shipping rate from it.

Setting a tax amount

If you need to pass along a tax amount to charge a customer you can do so by setting a tax_rate. It’s important to note that Flex does not currently calculate tax. This is an amount that you have previously calculated.

Add a discount

To add a discount when charging a customer, create a coupon. Then set the discounts parameter as part of the payload.

Creating a coupon

Then using the returned coupon_id as part of the checkout session payload

Iframe embedding

The checkout may be embedded on a page or within a modal by placing the checkout within an iframe:
A MessageEvent will be emitted to the window before the customer is redirected. You can listen to this event like this:
The data property mimics the checkout.session.completed Webhook Event. However, unlike webhooks, the event from the client is not guaranteed to fire. Therefore it’s recommended to listen to the webhooks to ensure that the message is received. The message could be customized by creating a redirect to your own site and having that page post a message to the parent:

React example

This is an example of how you could embed the checkout in a React application: