To create a single checkout link for multiple products using Dodo Payments, you can utilize the "Checkout Sessions" feature. This allows you to bundle multiple products into one checkout session. Here's how you can achieve that:
-
Create a Checkout Session: Use the Dodo Payments API to create a checkout session that includes all the products and their quantities in a single request.
-
Define the Product Cart: Structure your request to include a
product_cartarray, which will list all the products you want to include in the checkout session, each with its respectiveproduct_idandquantity. -
Add Metadata and Redirect URL: You can include metadata and a
return_urlto redirect users after a successful checkout. Metadata can be useful for tracking purposes. -
API Request Example:
const session = await client.checkoutSessions.create({ product_cart: [ { product_id: 'prod_1', quantity: 5 }, { product_id: 'prod_2', quantity: 3 } ], customer: { email: '[email protected]' }, return_url: 'https://site.com', metadata: { message: 'HappyBday' } }); -
Receive Checkout URL: The response from the API will include a
checkout_urlthat you can use to redirect your customers to complete their purchase.
This method allows you to handle multiple products in a single transaction seamlessly. It's important to ensure that the products are compatible (e.g., all one-time purchase products) as the API may not support mixing product types like subscriptions and one-time purchases in a single session.
For detailed API documentation and more examples, you can refer to the Dodo Payments developer resources and API reference.
Helpful Links: