Skip to main content

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-go SDK
  • 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, and templates
  • 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

git clone https://github.com/dodopayments/go-boilerplate.git
cd go-boilerplate
2

Install Dependencies

make install
Or manually:
go mod download
3

Get API Credentials

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

Configure Environment Variables

Create a .env file in the root directory:
cp .env.example .env
Update the values with your Dodo Payments credentials:
.env
DODO_PAYMENTS_API_KEY=your_api_key_here
DODO_PAYMENTS_WEBHOOK_KEY=your_webhook_signing_key_here
DODO_PAYMENTS_RETURN_URL=http://localhost:8000
DODO_PAYMENTS_ENVIRONMENT=test_mode
Never commit your .env file to version control. It’s already included in .gitignore.
5

Add Your Products

Update internal/lib/products.go with your actual product IDs from Dodo Payments:
var Products = []Product{
    {
        ProductID:   "pdt_001", // Replace with your product ID
        Name:        "Basic Plan",
        Description: "Get access to basic features and support",
        Price:       9999, // in cents
        Features: []string{
            "Access to basic features",
            "Email support",
            "1 Team member",
            "Basic analytics",
        },
    },
    // ... add more products
}
6

Run the Development Server

make run
Or manually:
go run cmd/server/main.go
Open http://localhost:8000 to see your pricing page!
You should see a dark-themed pricing page with your products ready to purchase.

Project Structure

go-boilerplate/
├── cmd/
│   └── server/             # Application entry point
├── internal/
│   ├── api/                # API handlers (Checkout, Portal, Webhook)
│   ├── core/               # Configuration and system core
│   └── lib/                # Shared logic (Products, Customer utils)
├── templates/              # HTML templates
├── Makefile                # Build and run commands
├── go.mod                  # Go module definition
├── go.sum                  # Dependency checksums
├── .env.example            # Environment template
└── README.md

API Endpoints

The boilerplate includes the following pre-configured endpoints:
EndpointMethodDescription
/GETPricing page with product listing
/api/checkoutPOSTCreate a new checkout session
/api/webhookPOSTHandle Dodo Payments webhooks
/api/customer-portalPOSTGenerate customer portal URL

Customization

Update Product Information

Edit internal/lib/products.go to modify:
  • Product IDs (from your Dodo dashboard)
  • Pricing
  • Features
  • Descriptions
var Products = []Product{
    {
        ProductID:   "pdt_001", // Replace with your product ID
        Name:        "Basic Plan",
        Description: "Get access to basic features and support",
        Price:       9999,
        Features: []string{
            "Access to basic features",
            "Email support",
            "1 Team member",
            "Basic analytics",
        },
    },
}

Pre-fill Customer Data

In templates/index.html, replace the hardcoded customer data with your actual user data:
const customerData = {
    name: "John Doe",       // Replace with actual logged-in user's name
    email: "[email protected]"  // Replace with actual logged-in user's email
};
In a production app, you would dynamically inject these values from your authentication system.

Webhook Events

The boilerplate demonstrates handling webhook events in internal/api/webhook.go. Supported events include:
EventDescription
subscription.activeTriggered when a subscription becomes active
payment.succeededTriggered when a payment is successful
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:
ngrok http 8000
Update the webhook URL in your Dodo Payments Dashboard:
https://your-ngrok-url.ngrok.io/api/webhook

Deployment

Build for Production

make build
Or manually:
go build -o bin/server cmd/server/main.go
./bin/server

Deploy to Vercel

Deploy with Vercel

Docker

Create a Dockerfile:
FROM golang:1.21-alpine AS builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download

COPY . .
RUN go build -o bin/server cmd/server/main.go

FROM alpine:latest
WORKDIR /app
COPY --from=builder /app/bin/server .
COPY --from=builder /app/templates ./templates

EXPOSE 8000
CMD ["./server"]
Build and run:
docker build -t go-dodo .
docker run -p 8000:8000 --env-file .env go-dodo

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 Go modules are properly downloaded:
go mod tidy
go mod download
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
For local testing, use ngrok to expose your server:
ngrok http 8000
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 you’re running the server from the project root directory, or that the templates path is correctly configured in your code.

Learn More

Support

Need help with the boilerplate?