Checkout Step 4: Choose Payment Provider
Choose a payment provider and start a session.
On this page
In this guide, you'll learn how to implement step 4 of checkout: choose a payment provider and start a session. Keep the order in Checkout Overview. Complete the cart only after this step. On Next.js, list providers in src/lib/data/payment.ts for the cart's region_id. Return [] if listing fails.
Payment Step Flow in Storefront Checkout
The payment step requires implementing the following flow:

- Retrieve the payment providers using the List Payment Providers API route.
- Customer chooses the payment provider to use.
- If the cart doesn't have an associated payment collection, create a payment collection for it using the Create Payment Collection API route.
- Initialize the payment sessions of the cart's payment collection using the Initialize Payment Sessions API route.
- If you're using the JS SDK, it combines the third and fourth steps in a single
initiatePaymentSessionfunction.
- If you're using the JS SDK, it combines the third and fourth steps in a single
- Optionally perform additional actions for payment based on the chosen payment provider. For example, if the customer chooses Stripe, you show them the UI to enter their card details.
- You can refer to the Stripe guide for an example of how to implement this.
How to Implement the Payment Step Flow
For example, to implement the payment step flow:
Tip: - This example uses the useCart hook defined in the Cart React Context guide.
- Learn how to install and configure the JS SDK in the Getting started guide.
React
tsx
JS SDK
ts
In the example above, you:
- Retrieve the payment providers from the Aiminaabee application using the List Payment Providers API route. You use those to show the customer the available options.
- When the customer chooses a payment provider, you use the
initiatePaymentSessionfunction to create a payment collection and initialize the payment session for the chosen provider.- If you're not using the JS SDK, you need to create a payment collection using the Create Payment Collection API route if the cart doesn't have one. Then, you need to initialize the payment session using the Initialize Payment Session API route.
- Once the cart has a payment session, you optionally render the UI to perform additional actions. For example, if the customer chose Stripe, you can show them the card form to enter their credit card.
In the Fetch API example, the handlePayment function implements this flow by calling the different functions in the correct order.
Troubleshooting
Unknown Error for Zero Cart Total
If your cart has a total of 0, you might encounter an unknown error when trying to create a payment session.
Some payment providers, such as Stripe, require a non-zero amount to create a payment session. So, if your cart has a total of 0, the error will be thrown on the payment provider's side.
In those cases, you can either:
- Make sure the payment session is only initialized when the cart has a total greater than
0. - Use payment providers like the Manual System Payment Provider, which doesn't create a payment session with a third-party provider.
- The Manual System Payment Provider is available by default in Aiminaabee and can be used to handle payments without a third-party provider. It allows you to mark the order as paid without requiring any additional actions from the customer.
- Make sure to configure the Manual System Payment Provider in your store's region. Learn more in the Manage Region user guide.
Stripe Example
If you're integrating Stripe in your Aiminaabee application and storefront, refer to the Stripe guide for an example of how to handle the payment process using Stripe.