GitHub Repository
Complete FastAPI + Dodo Payments boilerplate
Overview
The FastAPI boilerplate provides a production-ready starting point for integrating Dodo Payments with your Python backend. This template includes checkout session handling, webhook verification, customer portal integration, and async API patterns to help you start accepting payments quickly.This boilerplate uses FastAPI with async/await patterns, Pydantic for validation, and the
dodopayments Python SDK for seamless API integration.Features
- Quick Setup - Get started in under 5 minutes
- Async Support - Built with FastAPI’s native async/await patterns
- Checkout Sessions - Pre-configured checkout flow using the Python SDK
- Webhook Handling - Secure webhook endpoint with signature verification
- Customer Portal - Easy customer portal session creation
- Type Safety - Full Pydantic validation and type hints
- Environment Configuration - Ready-to-use environment variable setup
Prerequisites
Before you begin, make sure you have:- Python 3.9+ (recommended: Python 3.11+)
- pip or uv for package management
- Dodo Payments account (to access API and Webhook Keys from dashboard)
Quick Start
1
Clone the Repository
2
Create Virtual Environment
Set up an isolated Python environment:Or using uv for faster dependency management:
3
Install Dependencies
4
Get API Credentials
Sign up at Dodo Payments and get your credentials from the dashboard:
- API Key: Dashboard → Developer → API Keys
- Webhook Key: Dashboard → Developer → Webhooks
5
Configure Environment Variables
Create a Update the values with your Dodo Payments credentials:
.env file in the root directory:.env
6
Run the Development Server
You should see FastAPI’s Swagger UI with all available endpoints ready to test.
Project Structure
API Endpoints
The boilerplate includes the following pre-configured endpoints:| Endpoint | Method | Description |
|---|---|---|
/checkout | POST | Create a new checkout session |
/webhook | POST | Handle Dodo Payments webhooks |
/customer-portal | POST | Generate customer portal URL |
Code Examples
Creating a Checkout Session
Handling Webhooks
Customer Portal Integration
Webhook Events
The boilerplate demonstrates handling common webhook events:| Event | Description |
|---|---|
payment.succeeded | Payment completed successfully |
payment.failed | Payment attempt failed |
subscription.active | Subscription is now active |
subscription.cancelled | Subscription was cancelled |
refund.succeeded | Refund processed successfully |
- Update user permissions in your database
- Send confirmation emails
- Provision access to digital products
- Track analytics and metrics
Testing Webhooks Locally
For local development, use tools like ngrok to expose your local server:Deployment
Docker
Production Considerations
Troubleshooting
Import errors or missing modules
Import errors or missing modules
Ensure your virtual environment is activated and dependencies are installed:
Checkout session creation fails
Checkout session creation fails
Common causes:
- Invalid product ID - verify it exists in your Dodo dashboard
- Wrong API key or environment setting in
.env - Check the FastAPI logs for detailed error messages
Webhooks not receiving events
Webhooks not receiving events
For local testing, use ngrok to expose your server:Update the webhook URL in your Dodo dashboard to the ngrok URL. Make sure to update your
.env file with the correct webhook verification key.Webhook signature verification fails
Webhook signature verification fails
- Ensure
DODO_PAYMENTS_WEBHOOK_KEYis correctly set in your.env - Verify you’re using the raw request body for signature verification
- Check that you’re reading the
webhook-signatureheader correctly
Learn More
Python SDK
Complete Python SDK documentation with async support
Webhooks Documentation
Learn about all webhook events and best practices
Checkout Sessions
Deep dive into checkout session configuration
API Reference
Complete Dodo Payments API documentation
Support
Need help with the boilerplate?- Join our Discord community for questions and discussions
- Check the GitHub repository for issues and updates
- Contact our support team for assistance