Hoppa till huvudinnehåll

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

Or with uv:
4

Get API Credentials

Sign up at Dodo Payments and get your credentials from the dashboard:
Make sure you’re in Test Mode while developing!
5

Configure Environment Variables

Create a .env file in the root directory:
Update the values with your Dodo Payments credentials:
.env
Never commit your .env file to version control. It’s already included in .gitignore.
6

Run the Development Server

Open http://localhost:8000/docs to see the interactive API documentation!
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:

Code Examples

Creating a Checkout Session

Handling Webhooks

Customer Portal Integration

Webhook Events

The boilerplate demonstrates handling common webhook events: Add your business logic inside the webhook handler to:
  • 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:
Update the webhook URL in your Dodo Payments Dashboard:

Deployment

Docker

Build and run:

Production Considerations

Before deploying to production:
  • Switch DODO_PAYMENTS_ENVIRONMENT to live_mode
  • Use production API keys from the dashboard
  • Update the webhook URL to your production domain
  • Enable HTTPS for all endpoints

Troubleshooting

Ensure your virtual environment is activated and dependencies are installed:
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
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.
  • Ensure DODO_PAYMENTS_WEBHOOK_KEY is correctly set in your .env
  • Verify you’re using the raw request body for signature verification
  • Check that you’re reading the webhook-signature header 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?
Senast ändrad 28 maj 2026