Overlay Checkout (Beta)
A modern TypeScript library for embedding Dodo Payments overlay checkout and listening to checkout events in real-time.
Overview
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.
- Live Demo: https://atlas.dodopayments.com
- Github code for demo: https://github.com/dodopayments/dodo-checkout-demo
Installation
Quick Start
Configuration
Initialize Options
Option | Type | Required | Description |
---|---|---|---|
mode | string | Yes | Environment mode: ‘test’ or ‘live’ |
onEvent | function | Yes | Callback function for handling checkout events |
theme | string | No | UI theme: ‘light’ or ‘dark’ |
linkType | string | No | Payment link type: ‘static’ or ‘dynamic’ |
displayType | string | Yes | Display type, must be ‘overlay’ |
Checkout Options
Option | Type | Required | Description |
---|---|---|---|
products | array | Yes* | Array of products to purchase |
paymentLink | string | Yes* | payment link for dynamic payment link |
redirectUrl | string | No | URL to redirect after payment |
queryParams | object | No | Additional query parameters |
*Either products
or paymentLink
must be provided
Event Handling
The SDK provides real-time events that you can listen to:
Methods
Open Checkout
Close Checkout
Check Status
Browser Support
- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Edge (latest)
- IE11+
Note: Apple Pay is not currently supported in the overlay checkout experience. We plan to add support for Apple Pay in a future release.
TypeScript Support
The SDK is written in TypeScript and includes comprehensive type definitions. All public APIs are fully typed for better developer experience.
Error Handling
The SDK provides detailed error information through the event system. Always implement proper error handling in your onEvent
callback:
Best Practices
- Always initialize the SDK before attempting to open the checkout
- Implement proper error handling in your event callback
- Use the test mode during development
- Handle all relevant events for a complete user experience
- Provide a redirect URL for better user flow
- Use TypeScript for better type safety and developer experience
Step-by-Step Guide
1. Project Setup
First, ensure you have a modern JavaScript/TypeScript project. We recommend using Next.js, React, or Vue.js.
2. Install the SDK
Install the Dodo Payments Checkout SDK using your preferred package manager:
3. Basic Implementation
Create a new component for your checkout button:
4. Add to Your Page
Use the checkout button in your page:
5. Handle Success and Failure
Create success and failure pages:
6. Testing Your Integration
- Start your development server:
- Test the checkout flow:
- Click the checkout button
- Verify the overlay appears
- Test the payment flow using test credentials
- Confirm redirects work correctly
7. Going Live
When you’re ready to go live:
- Change the mode to ‘live’:
- Update your product IDs to use live products
- Test the complete flow in production
- Monitor events and errors
Common Issues and Solutions
-
Checkout not opening
- Verify SDK initialization
- Check for console errors
- Ensure product IDs are correct
-
Events not firing
- Confirm event handler is properly set up
- Check for JavaScript errors
- Verify network connectivity
-
Styling issues
- Ensure no CSS conflicts
- Check theme settings
- Verify responsive design
For more help, visit our Discord or contact our developer support team.