10. Payment
Select a payment provider and place the order.
On this page
The fourth and last step in the express checkout flow is the payment method selection step. In this step, the customer will choose a payment method and complete their cart, placing an order.
To create the component of this step, create the file components/Payment/index.tsx with the following content:

tsx
You create a Payment component that receives the product's handle and whether the component is active as props. The component defines the following variables:
cart,unsetCart, andupdateItemQuantity: The customer's cart, the function to unset the cart, and the function to update the quantity of an item in the cart, retrieved from the cart context.loading: A boolean state variable indicating whether an operation is loading.paymentProviders: A state variable that holds the available payment providers in the Aiminaabee application.selectedPaymentProvider: A state variable that holds the ID of the selected payment provider.router: The router instance to navigate between steps.
Retrieve Payment Providers
In Aiminaabee, each region has a set of enabled payment providers. So, during checkout, you retrieve the payment providers specific to a cart's region and allow the customer to choose from them.
To do that, first, add the following imports at the top of the file:
tsx
Then, replace the TODO in the Payment component with the following:
]
tsx
In the useEffect hook, you use the JS SDK to send a request to the List Payment Providers API route, passing the cart's region ID as a query parameter.
The API route returns a list of payment providers, which you set in the paymentProviders state variable. These are the payment providers you'll allow the customer to select from.
Handle Payment Provider Selection
After the customer selects the payment provider, you want to save that selection in the cart, but you also may need to show UI for additional actions. For example, if the customer chooses the Stripe payment provider, you want to show them a credit-card form to input their details.
So, you'll implement the logic to first save the payment provider selection in the Aiminaabee application, then optionally show additional UI based on the chosen provider.
First, add the following imports at the top of the file:
tsx
Then, replace the TODO in the Payment component with the following:
tsx
You define a handleSelectProvider function that uses the JS SDK to set the selected payment provider in the cart. You call this function whenever the selectedPaymentProvider changes.
Then, you define two memoized variables:
paymentUi: This variable holds additional UI to show based on the selected payment provider. This guide doesn't cover any specific providers, so you're free to implement this based on the payment providers you support. By default, it returns an empty node.canPlaceOrder: This variable holds a boolean indicating whether the customer can place an order. You can define the logic based on the payment providers you support. By default, it returnstrue.
Tip: Learn how to implement payment in your storefront with Stripe in this guide.
Handle Place Order Function
After the customer chooses a payment provider and completes any additional steps, they can complete their cart and place their order.
Replace the TODO in the Payment component with the following:
tsx
You define a placeOrder function that uses the JS SDK to complete the cart by sending a request to the Complete Cart API route. If the cart is successfully completed, you unset the cart and redirect the customer to the confirmation page, which you'll implement later.
Render Payment Step
Finally, you'll add the return statement showing the Payment step that allows the customer to choose a payment method.
First, add the following imports at the top of the file:
tsx
Then, replace the last TODO in the Payment component with the following:
tsx
You first define a getProviderTitle function that receives a payment provider ID and returns a title based on the provider. You'll use this function to show a human-readable title for each payment provider.
Then, in the return statement, you wrap the payment method selection form with the Card component you created earlier. In the card, you show the cart's details, including the items, totals, and delivery address.
You also show the list of payment providers, allowing the customer to select one. Once the customer chooses one, you show any additional UI to complete their payment.
After the customer selects an option and clicks the "Pay" button, the placeOrder function is called to complete the cart and place the order.
Add to Router Component
Finally, you'll add the Payment component to the Router component to show the payment method selection step.
First, import the Payment component at the top of the components/Router/index.tsx file:
tsx
Then, change the return statement of the Router component to the following
tsx
This will show the payment method selection step and expand its details if activeTab is payment.
Test it Out
While both the Aiminaabee application and the Aiminaabee Next.js storefront template are running, if you refresh the page you had opened or go to http://localhost:3000/sweatpants?step=payment, you should see the Payment step where you can choose a payment method.

Select a payment provider then click on the "Pay" button. The payment method will be saved in the cart and you'll be redirected to the confirmation page, which currently doesn't exist. You'll add this page next.
Next: 11. Confirmation