协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
testing-and-go-live【开发与工程】Dodo Payments test mode and production launch, covering test cards and payment methods, success and decline scenarios, renewal simulation, local webhook testing with the CLI, copying products from test to live, and a go-live checklist. Use when verifying payment flows, switching from test_mode to live_mode, or preparing to launch.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
This skill covers test mode, test payment methods, webhook testing, and the production launch checklist. Use it when building payment flows that need verification before going live, or when preparing to switch from test to production.
Test vs. live mode: Dodo Payments maintains two completely separate environments. Each has its own base URL, API keys, webhooks, products, customers, and transactions. Data does not carry over between them.
https://test.dodopayments.comhttps://live.dodopayments.comEach environment requires separate API keys issued from the dashboard. The SDK defaults to live_mode if you don't specify environment, which is a real footgun in development.
Test payment methods: Dodo documents specific card numbers, VPAs, and payment method scenarios for testing. These only work in test mode.
Webhook testing: The CLI provides commands to listen for webhooks locally and trigger test events without making real payments.
Always explicitly set environment: 'test_mode' during development. The default is live_mode.
import DodoPayments from 'dodopayments';
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
environment: 'test_mode', // REQUIRED — defaults to 'live_mode'
});
import os
from dodopayments import DodoPayments
client = DodoPayments(
bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),
environment="test_mode", # defaults to "live_mode"
)
client := dodopayments.NewClient(
option.WithBearerToken("dodo_test_..."),
option.WithEnvironmentTestMode(), // defaults to WithEnvironmentLiveMode()
)
Get your test API key from the Dodo dashboard. Test keys are prefixed dodo_test_.
Use these card numbers in test mode with expiry 06/32 (or 12/34) and CVV 123.
| Scenario | Card Number | Result |
|---|---|---|
| Success | 4242 4242 4242 4242 | Payment succeeds |
| Decline | 4000 0000 0000 0002 | Payment declined |
| Decline (insufficient funds) | 4000 0000 0000 9995 | Insufficient funds error |
Only use cards listed on the Testing Process page; other Stripe-style test numbers (for example "lost card" variants) are not documented for Dodo.
To test subscription renewal failures, use this card:
| Card Number | Expiry | CVV | Behavior |
|---|---|---|---|
4000 0000 0000 0341 | 12/34 | 123 | Declined at the subscription's next charge (renewal, upgrade, or downgrade) |
Create the subscription with a success card first, then switch its payment method to this card in the Customer Portal.
Test UPI success and failure with these VPAs. The billing country must be IN and the currency INR (non-Indian merchants also need Adaptive Currency enabled):
| VPA | Result |
|---|---|
success@upi | Payment succeeds |
failure@upi | Payment fails |
BNPL, Apple Pay, Google Pay, and European payment methods (Giropay, iDEAL, Bancontact) are available in test mode. Exact test scenarios vary by method. Refer to the Testing Process documentation for the current test matrix.
To force a subscription to renew on a specific date without waiting, update the next_billing_date:
await client.subscriptions.update('sub_123', {
next_billing_date: '2026-05-03T00:00:00Z',
});
client.subscriptions.update(
'sub_123',
next_billing_date='2026-05-03T00:00:00Z'
)
// NextBillingDate is param.Field[time.Time], not a string. Passing a string
// literal compiles to param.Field[string] and will not type-check.
client.Subscriptions.Update(ctx, "sub_123", dodopayments.SubscriptionUpdateParams{
NextBillingDate: dodopayments.F(time.Date(2026, time.May, 3, 0, 0, 0, 0, time.UTC)),
})
This immediately schedules the renewal. If you used the subscription-renewal-failure card, the failed charge emits payment.failed and the affected subscription enters on_hold, which emits subscription.on_hold.
The CLI ships separately from the SDKs:
npm install -g dodopayments-cli
dodo login
dodo login opens the API Keys page, accepts a pasted key, and asks whether it is Test Mode or Live Mode. One key of each can stay authenticated at the same time.
dodo wh listen http://localhost:3000/webhook
This forwards real test-mode events to your local URL over an outbound relay. It is not a tunnel: nothing listens publicly and no URL is printed for you to paste into the dashboard. If you need a registerable HTTPS URL, use ngrok instead — that flow is described in the webhook-integration skill.
Two constraints to know before running it:
dodo wh listen only works inside the interactive TUI as /wh listen, which opens a wizard.Events arriving this way carry valid signatures, so verify them normally with webhooks.unwrap().
dodo wh trigger payment.success http://localhost:3000/webhook
Sends a realistic mock payload for a chosen event. It runs offline and works even while logged out — which is the tell for the part that matters: these payloads are unsigned. unwrap() rejects them because there is no valid signature to verify.
Use unsafeUnwrap() for triggered events only, and never on an endpoint that also receives real traffic. Trigger names are <category>.<event>, for example payment.success, subscription.active, or dispute.opened.
Trigger names are not always the payload type. payment.success delivers type: "payment.succeeded", refund.success delivers refund.succeeded, and licence.created delivers license_key.created. Switch on the payload types in your handler; a case 'payment.success' never matches.
As with listen, both arguments are required in direct mode; /wh trigger inside the TUI opens a wizard instead.
Covered in the webhook-integration skill. Verify every webhook that arrives over the network, in test mode as well as live. The single exception is the unsigned payloads produced by dodo wh trigger above.
Products are environment-specific. You cannot reuse a test product ID in production. Instead, recreate the product in live mode or use the dashboard to export and reimport.
Manual approach:
Programmatic approach:
Fetch the product from test mode, extract its configuration, and create it in live mode. API keys are per mode — a test key does not authenticate against live mode and vice versa — so this needs two distinct keys:
// In test mode
const testClient = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_TEST_API_KEY,
environment: 'test_mode',
});
const testProduct = await testClient.products.retrieve('pdt_test_123');
// In live mode
const liveClient = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_LIVE_API_KEY,
environment: 'live_mode',
});
const liveProduct = await liveClient.products.create({
name: testProduct.name,
price: testProduct.price,
tax_category: testProduct.tax_category,
// ... other fields
});
Before switching to production, verify each item:
dodo_live_).environment: 'live_mode' (or omits it, since live is the default).client.webhooks.unwrap() or the standardwebhooks package.environment unsetThe SDK defaults to live_mode. If you forget to set environment: 'test_mode' during development, your test code will hit production and create real charges.
// WRONG — this hits live mode
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
});
// CORRECT
const client = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY,
environment: 'test_mode',
});
Test and live environments are completely separate. A product ID from test mode does not exist in live mode. Always create new products in live mode or use the dashboard to migrate them.
// WRONG — pdt_test_123 does not exist in live mode
const session = await liveClient.checkoutSessions.create({
product_cart: [{ product_id: 'pdt_test_123', quantity: 1 }],
});
// CORRECT — use a live product ID
const session = await liveClient.checkoutSessions.create({
product_cart: [{ product_id: 'pdt_live_456', quantity: 1 }],
});
Test and live modes have separate webhook endpoints and secrets. If you copy your test webhook configuration to production without updating the URL and secret, webhooks will fail or go to the wrong place.
DODO_PAYMENTS_WEBHOOK_KEY in production environment variables.Always verify webhook signatures using client.webhooks.unwrap() or the standardwebhooks package. Never trust a webhook without verification, even if it came from Dodo.
// WRONG — no verification
app.post('/webhook', (req, res) => {
const event = req.body;
handleEvent(event);
res.json({ received: true });
});
// CORRECT
app.post('/webhook', async (req, res) => {
try {
const unwrapped = client.webhooks.unwrap(req.body.toString(), {
headers: {
'webhook-id': req.headers['webhook-id'] as string,
'webhook-signature': req.headers['webhook-signature'] as string,
'webhook-timestamp': req.headers['webhook-timestamp'] as string,
},
});
handleEvent(unwrapped);
res.json({ received: true });
} catch (error) {
res.status(401).json({ error: 'Invalid signature' });
}
});
Test keys (prefixed dodo_test_) only work with https://test.dodopayments.com. Live keys are issued per mode from the dashboard. Using a test key with live mode will fail with an authentication error.