dodo-best-practices
Comprehensive guide for integrating Dodo Payments - the all-in-one payment and billing platform for SaaS and AI products.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Comprehensive guide for integrating Dodo Payments - the all-in-one payment and billing platform for SaaS and AI products.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Guide for creating checkout sessions and payment flows with Dodo Payments - one-time, subscriptions, and overlay checkout.
Guide for implementing credit-based billing with Dodo Payments - credit entitlements, balances, ledger management, rollover, overage, and meter-based deduction.
Guide for implementing subscription billing with Dodo Payments - trials, upgrades, downgrades, and on-demand billing.
Guide for implementing usage-based billing with Dodo Payments - meters, events, pricing per unit, and metered subscriptions.
Complete guide for setting up and handling Dodo Payments webhooks for real-time payment event notifications.
| name | dodo-best-practices |
| description | Comprehensive guide for integrating Dodo Payments - the all-in-one payment and billing platform for SaaS and AI products. |
Always consult docs.dodopayments.com for the latest API reference and code examples.
Dodo Payments is the all-in-one engine to launch, scale, and monetize worldwide. Designed for SaaS and AI products, it handles payments, billing, subscriptions, and distribution without extra engineering.
DODO_PAYMENTS_API_KEY - Your API key from the dashboardDODO_PAYMENTS_WEBHOOK_SECRET - Webhook signing secret for verificationhttps://api.dodopayments.com (default)https://api.dodopayments.com with environment: 'test_mode'npm install dodopayments
# or
yarn add dodopayments
# or
pnpm add dodopayments
import DodoPayments from "dodopayments";
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
environment: "live_mode", // or 'test_mode'
});
pip install dodopayments
from dodopayments import DodoPayments
client = DodoPayments(bearer_token=os.environ["DODO_PAYMENTS_API_KEY"])
go get github.com/dodopayments/dodopayments-go
import "github.com/dodopayments/dodopayments-go"
client := dodopayments.NewClient(
option.WithBearerToken(os.Getenv("DODO_PAYMENTS_API_KEY")),
)
composer require dodopayments/client
use Dodopayments\Client;
$client = new Client(bearerToken: getenv('DODO_PAYMENTS_API_KEY'));
Products are the items you sell. Create them in the dashboard or via API:
Credits are virtual balances (API calls, tokens, compute hours) attached to products. Create them in Dashboard → Products → Credits:
The primary way to collect payments. Create a checkout session and redirect customers:
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: "prod_xxxxx", quantity: 1 }],
customer: {
email: "customer@example.com",
name: "John Doe",
},
return_url: "https://yoursite.com/success",
});
// Redirect customer to: session.checkout_url
Listen to events for real-time updates:
payment.succeeded - Payment completedpayment.failed - Payment failedsubscription.active - Subscription activatedsubscription.cancelled - Subscription cancelledrefund.succeeded - Refund processeddispute.opened - Dispute receivedlicense_key.created - License key generatedcredit.added - Credits granted to customercredit.deducted - Credits consumedcredit.balance_low - Credit balance below thresholdpayment.succeeded webhook// Create checkout for one-time payment
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: "prod_one_time_product", quantity: 1 }],
customer: { email: "customer@example.com" },
return_url: "https://yoursite.com/success",
});
subscription.active webhook to grant accesssubscription.cancelled to revoke access// Create checkout for subscription
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: "prod_monthly_subscription", quantity: 1 }],
subscription_data: { trial_period_days: 14 }, // Optional trial
customer: { email: "customer@example.com" },
return_url: "https://yoursite.com/success",
});
Always verify webhook signatures:
import crypto from "crypto";
function verifyWebhook(
payload: string,
signature: string,
secret: string
): boolean {
const expectedSignature = crypto
.createHmac("sha256", secret)
.update(payload)
.digest("hex");
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(expectedSignature)
);
}
Allow customers to manage their subscriptions:
const portal = await client.customers.createPortalSession({
customer_id: "cust_xxxxx",
return_url: "https://yoursite.com/account",
});
// Redirect to: portal.url
Handle API errors gracefully:
try {
const session = await client.checkoutSessions.create({...});
} catch (error) {
if (error.status === 400) {
// Invalid request - check parameters
} else if (error.status === 401) {
// Invalid API key
} else if (error.status === 429) {
// Rate limited - implement backoff
}
}
sk_test_)4242 4242 4242 4242 - Success4000 0000 0000 0002 - DeclineUse ngrok or similar for webhook testing:
ngrok http 3000
Then configure the ngrok URL as your webhook endpoint in the dashboard.
Use API routes for server-side operations:
// app/api/checkout/route.ts
import { NextResponse } from "next/server";
import DodoPayments from "dodopayments";
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
});
export async function POST(req: Request) {
const { productId, email } = await req.json();
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: productId, quantity: 1 }],
customer: { email },
return_url: `${process.env.NEXT_PUBLIC_URL}/success`,
});
return NextResponse.json({ url: session.checkout_url });
}
import express from "express";
import DodoPayments from "dodopayments";
const app = express();
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
});
app.post("/create-checkout", async (req, res) => {
const session = await client.checkoutSessions.create({
product_cart: [{ product_id: req.body.productId, quantity: 1 }],
customer: { email: req.body.email },
return_url: "https://yoursite.com/success",
});
res.json({ url: session.checkout_url });
});