The Dodo Payments Checkout SDK provides a seamless way to integrate our payment overlay into your web application. Built with TypeScript and modern web standards, it offers a robust solution for handling payments with real-time event handling and customizable themes.
Install the Dodo Payments Checkout SDK using your preferred package manager:
Copy
npm install dodopayments-checkout
2
Initialize the SDK
Initialize the SDK in your application, typically in your main component or app entry point:
Copy
import { DodoPayments } from "dodopayments-checkout";DodoPayments.Initialize({ mode: "test", // Change to 'live' for production displayType: "overlay", // Optional: defaults to 'overlay' for overlay checkout onEvent: (event) => { console.log("Checkout event:", event); // Handle different events switch (event.event_type) { case "checkout.opened": // Checkout overlay has been opened break; case "checkout.closed": // Checkout has been closed break; case "checkout.error": // Handle errors console.error("Checkout error:", event.data?.message); break; } },});
Always initialize the SDK before attempting to open the checkout. Initialization should happen once when your application loads.
3
Create a Checkout Button Component
Create a component that opens the checkout overlay:
Show or hide the checkout timer. Defaults to true. When disabled, you will receive the checkout.link_expired event when the session expires.
options.showSecurityBadge
boolean
No
Show or hide the security badge. Defaults to true.
options.manualRedirect
boolean
No
When enabled, the checkout will not automatically redirect after completion. Instead, you will receive checkout.status and checkout.redirect_requested events to handle the redirect yourself.
DodoPayments.Initialize({ onEvent: (event: CheckoutEvent) => { switch (event.event_type) { case "checkout.opened": // Checkout overlay has been opened break; case "checkout.form_ready": // Checkout form is ready for user input break; case "checkout.payment_page_opened": // Payment page has been displayed break; case "checkout.customer_details_submitted": // Customer and billing details submitted break; case "checkout.closed": // Checkout has been closed break; case "checkout.redirect": // Checkout will perform a redirect break; case "checkout.error": // An error occurred console.error("Error:", event.data?.message); break; case "checkout.link_expired": // Checkout session has expired (only when showTimer is false) break; case "checkout.status": // Checkout status update (only when manualRedirect is enabled) const status = event.data?.message?.status; break; case "checkout.redirect_requested": // Redirect requested (only when manualRedirect is enabled) const redirectUrl = event.data?.message?.redirect_to; break; } }});
Event Type
Description
checkout.opened
Checkout overlay has been opened
checkout.form_ready
Checkout form is ready to receive user input. Useful for hiding loading states.
checkout.payment_page_opened
Payment page has been displayed
checkout.customer_details_submitted
Customer and billing details have been submitted
checkout.closed
Checkout overlay has been closed
checkout.redirect
Checkout will perform a redirect
checkout.error
An error occurred during checkout
checkout.link_expired
Fired when the checkout session expires. Only received when showTimer is set to false.
checkout.status
Fired when manualRedirect is enabled. Contains the checkout status (succeeded, failed, or processing).
checkout.redirect_requested
Fired when manualRedirect is enabled. Contains the URL to redirect the customer to.
You can customize the checkout appearance by passing a themeConfig object in the options parameter when opening checkout. The theme configuration supports both light and dark modes, allowing you to customize colors, borders, text, buttons, and border radius.
The SDK provides detailed error information through the event system. Always implement proper error handling in your onEvent callback:
Copy
DodoPayments.Initialize({ mode: "test", displayType: "overlay", onEvent: (event: CheckoutEvent) => { if (event.event_type === "checkout.error") { console.error("Checkout error:", event.data?.message); // Handle error appropriately // You may want to show a user-friendly error message // or retry the checkout process } if (event.event_type === "checkout.link_expired") { // Handle expired checkout session console.warn("Checkout session has expired"); } }});
Always handle the checkout.error event to provide a good user experience when errors occur.
Use overlay checkout for faster integration with minimal changes to your existing pages. Use inline checkout when you want maximum control over the checkout experience and seamless branding.