Dodo Payments
Dodo Payments는 AI, SaaS 및 디지털 비즈니스가 세금, 사기 또는 규정 준수를 다루지 않고 150개 이상의 국가에서 판매할 수 있도록 하는 글로벌 Merchant-of-Record 플랫폼입니다. 단일 개발자 친화적 API가 체크아웃, 청구 및 지불을 지원하므로 몇 분 안에 전 세계에 출시할 수 있습니다.
Dodo Payments의 Discord에서 지원 받기
이 플러그인은 Dodo Payments 팀이 유지 관리합니다.
질문이 있으신가요? 저희 팀이 Discord에서 언제든지 도와드립니다.
기능
- 가입 시 자동 고객 생성
- 제품 슬러그 매핑을 사용한 타입 안전 체크아웃 플로우
- 셀프 서비스 고객 포털
- 서명 검증을 통한 실시간 웹훅 이벤트 처리
Dodo Payments 시작하기
이 통합을 사용하려면 Dodo Payments 계정과 API 키가 필요합니다.
설치
프로젝트 루트에서 다음 명령을 실행합니다:
npm install @dodopayments/better-auth dodopayments better-auth zod.env 파일에 다음을 추가합니다:
DODO_PAYMENTS_API_KEY=your_api_key_here
DODO_PAYMENTS_WEBHOOK_SECRET=your_webhook_secret_heresrc/lib/auth.ts를 생성하거나 업데이트합니다:
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);
},
}),
],
}),
],
});프로덕션의 경우 environment를 live_mode로 설정합니다.
src/lib/auth-client.ts를 생성하거나 업데이트합니다:
import { dodopaymentsClient } from "@dodopayments/better-auth";
export const authClient = createAuthClient({
baseURL: process.env.BETTER_AUTH_URL || "http://localhost:3000",
plugins: [dodopaymentsClient()],
});사용법
체크아웃 세션 생성
const { data: checkout, error } = await authClient.dodopayments.checkout({
slug: "premium-plan",
customer: {
email: "customer@example.com",
name: "John Doe",
},
billing: {
city: "San Francisco",
country: "US",
state: "CA",
street: "123 Market St",
zipcode: "94103",
},
referenceId: "order_123",
});
if (checkout) {
window.location.href = checkout.url;
}고객 포털 액세스
const { data: customerPortal, error } = await authClient.dodopayments.customer.portal();
if (customerPortal && customerPortal.redirect) {
window.location.href = customerPortal.url;
}고객 데이터 나열
// 구독 가져오기
const { data: subscriptions, error } =
await authClient.dodopayments.customer.subscriptions.list({
query: {
limit: 10,
page: 1,
active: true,
},
});
// 결제 기록 가져오기
const { data: payments, error } = await authClient.dodopayments.customer.payments.list({
query: {
limit: 10,
page: 1,
status: "succeeded",
},
});웹훅
웹훅 플러그인은 Dodo Payments로부터 안전한 서명 검증과 함께 실시간 결제 이벤트를 처리합니다. 기본 엔드포인트는 /api/auth/dodopayments/webhooks입니다.
Dodo Payments 대시보드에서 엔드포인트 URL(예: https://your-domain.com/api/auth/dodopayments/webhooks)에 대한 웹훅 시크릿을 생성하고 .env 파일에 설정합니다:
DODO_PAYMENTS_WEBHOOK_SECRET=your_webhook_secret_here핸들러 예제:
webhooks({
webhookKey: process.env.DODO_PAYMENTS_WEBHOOK_SECRET!,
onPayload: async (payload) => {
console.log("Received webhook:", payload.event_type);
},
});구성 참조
플러그인 옵션
- client (필수): DodoPayments 클라이언트 인스턴스
- createCustomerOnSignUp (선택 사항): 사용자 가입 시 고객을 자동으로 생성
- use (필수): 활성화할 플러그인 배열 (checkout, portal, webhooks)
Checkout 플러그인 옵션
- products: 제품 배열 또는 제품을 반환하는 비동기 함수
- successUrl: 성공적인 결제 후 리디렉션할 URL
- authenticatedUsersOnly: 사용자 인증 필요 (기본값: false)
문제가 발생하면 문제 해결 단계는 Dodo Payments 문서를 참조하세요.