GitHub Repository
Minimal Go + Dodo Payments boilerplate
Overview
The Go boilerplate provides a production-ready starting point for integrating Dodo Payments with your Go backend. This template includes checkout session handling, webhook verification, customer portal integration, and follows Go best practices to help you start accepting payments quickly.This boilerplate uses Go 1.21+ with clean architecture patterns (
cmd, internal, templates), HTML templates, and the dodopayments-go SDK for seamless API integration.Features
- Quick Setup - Get started in under 5 minutes
- Payment Integration - Pre-configured checkout flow using
dodopayments-goSDK - Modern UI - Clean, dark-themed pricing page with HTML templates
- Webhook Handling - Securely verify and process payment events
- Customer Portal - Self-serve subscription management
- Go Best Practices - Clean architecture with
cmd,internal, andtemplates - Pre-filled Checkout - Demonstrates passing customer data to improve UX
Prerequisites
Before you begin, make sure you have:- Go 1.21+
- Dodo Payments account (to access API and Webhook Keys from dashboard)
Quick Start
1
Clone the Repository
2
Install Dependencies
3
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
4
Configure Environment Variables
Create a Update the values with your Dodo Payments credentials:
.env file in the root directory:.env
5
Add Your Products
Update
internal/lib/products.go with your actual product IDs from Dodo Payments:6
Run the Development Server
You should see a dark-themed pricing page with your products ready to purchase.
Project Structure
API Endpoints
The boilerplate includes the following pre-configured endpoints:| Endpoint | Method | Description |
|---|---|---|
/ | GET | Pricing page with product listing |
/api/checkout | POST | Create a new checkout session |
/api/webhook | POST | Handle Dodo Payments webhooks |
/api/customer-portal | POST | Generate customer portal URL |
Customization
Update Product Information
Editinternal/lib/products.go to modify:
- Product IDs (from your Dodo dashboard)
- Pricing
- Features
- Descriptions
Pre-fill Customer Data
Intemplates/index.html, replace the hardcoded customer data with your actual user data:
Webhook Events
The boilerplate demonstrates handling webhook events ininternal/api/webhook.go. Supported events include:
| Event | Description |
|---|---|
subscription.active | Triggered when a subscription becomes active |
payment.succeeded | Triggered when a payment is successful |
- 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
Build for Production
Deploy to Vercel
Docker
Create aDockerfile:
Production Considerations
Troubleshooting
Build errors or missing dependencies
Build errors or missing dependencies
Ensure Go modules are properly downloaded:
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 server 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.Templates not loading
Templates not loading
Ensure you’re running the server from the project root directory, or that the templates path is correctly configured in your code.
Learn More
Go SDK
Complete Go SDK documentation
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