docs/content/docs/plugins/dodopayments.mdx
Dodo Payments is a global Merchant-of-Record platform that lets AI, SaaS and digital businesses sell in 150+ countries without touching tax, fraud, or compliance. A single, developer-friendly API powers checkout, billing, and payouts so you can launch worldwide in minutes.
<Callout> This plugin is maintained by the Dodo Payments team. For bugs, issues or feature requests, please visit the [Dodo Payments GitHub repo](https://github.com/dodopayments/dodo-adapters). </Callout> <Card href="https://discord.gg/bYqAp4ayYh" title="Get support on Dodo Payments' Discord"> Have questions? Our team is available on Discord to assist you anytime. </Card>```bash
npm install @dodopayments/better-auth dodopayments better-auth zod
```
```txt
DODO_PAYMENTS_API_KEY=your_api_key_here
DODO_PAYMENTS_WEBHOOK_SECRET=your_webhook_secret_here
```
```typescript
import { betterAuth } from "better-auth";
import {
dodopayments,
checkout,
portal,
webhooks,
} from "@dodopayments/better-auth";
import DodoPayments from "dodopayments";
export const dodoPayments = new DodoPayments({
bearerToken: process.env.DODO_PAYMENTS_API_KEY!,
environment: "test_mode"
});
export const auth = betterAuth({
plugins: [
dodopayments({
client: dodoPayments,
createCustomerOnSignUp: true,
use: [
checkout({
products: [
{
productId: "pdt_xxxxxxxxxxxxxxxxxxxxx",
slug: "premium-plan",
},
],
successUrl: "/dashboard/success",
authenticatedUsersOnly: true,
}),
portal(),
webhooks({
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!,
onPayload: async (payload) => {
console.log("Received webhook:", payload.event_type);
},
}),
],
}),
],
});
```
<Card>
Set `environment` to `live_mode` for production.
</Card>
```typescript
import { createAuthClient } from "better-auth/react";
import { dodopaymentsClient } from "@dodopayments/better-auth";
export const authClient = createAuthClient({
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3000",
plugins: [dodopaymentsClient()],
});
```
const { data: checkoutSession, error } =
await authClient.dodopayments.checkoutSession({
slug: "premium-plan",
});
if (checkoutSession) {
window.location.href = checkoutSession.url;
}
const { data: customerPortal, error } = await authClient.dodopayments.customer.portal();
if (customerPortal && customerPortal.redirect) {
window.location.href = customerPortal.url;
}
// Get subscriptions
const { data: subscriptions, error } =
await authClient.dodopayments.customer.subscriptions.list({
query: {
limit: 10,
page: 1,
active: true,
},
});
// Get payment history
const { data: payments, error } = await authClient.dodopayments.customer.payments.list({
query: {
limit: 10,
page: 1,
status: "succeeded",
},
});
```txt
DODO_PAYMENTS_WEBHOOK_SECRET=your_webhook_secret_here
```
```typescript
webhooks({
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!,
onPayload: async (payload) => {
console.log("Received webhook:", payload.event_type);
},
});
```
If you encounter any issues, please refer to the Dodo Payments documentation for troubleshooting steps.