チェックアウトハンドラー
Dodo PaymentsのチェックアウトをAstroアプリに統合します。
顧客ポータル
顧客がサブスクリプションや詳細を管理できるようにします。
Webhook
Dodo PaymentsのWebhookイベントを受信して処理します。
インストール
1
パッケージをインストール
プロジェクトのルートで次のコマンドを実行します:
コピー
npm install @dodopayments/astro
2
環境変数を設定
プロジェクトのルートに
.envファイルを作成します:コピー
DODO_PAYMENTS_API_KEY=your-api-key
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
DODO_PAYMENTS_RETURN_URL=https://yourdomain.com/checkout/success
.envファイルやシークレットをバージョン管理にコミットしないでください。ルートハンドラーの例
すべての例は、Astro App Routerを使用していることを前提としています。
- チェックアウトハンドラー
- 顧客ポータルハンドラー
- Webhookハンドラー
このハンドラーを使用して、Dodo PaymentsのチェックアウトをAstroアプリに統合します。静的(GET)、動的(POST)、およびセッション(POST)支払いフローをサポートします。
コピー
// src/pages/api/checkout.ts
import { Checkout } from "@dodopayments/astro";
export const prerender = false;
export const GET = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "static", // optional, defaults to 'static'
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "dynamic", // for dynamic checkout
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "session", // for checkout sessions
});
コピー
curl --request GET \
--url 'https://example.com/api/checkout?productId=pdt_fqJhl7pxKWiLhwQR042rh' \
--header 'User-Agent: insomnia/11.2.0' \
--cookie mode=test
コピー
curl --request POST \
--url https://example.com/api/checkout \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/11.2.0' \
--cookie mode=test \
--data '{
"billing": {
"city": "Texas",
"country": "US",
"state": "Texas",
"street": "56, hhh",
"zipcode": "560000"
},
"customer": {
"email": "[email protected]",
"name": "test"
},
"metadata": {},
"payment_link": true,
"product_id": "pdt_QMDuvLkbVzCRWRQjLNcs",
"quantity": 1,
"billing_currency": "USD",
"discount_code": "IKHZ23M9GQ",
"return_url": "https://example.com",
"trial_period_days": 10
}'
コピー
curl --request POST \
--url https://example.com/api/checkout \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/11.2.0' \
--cookie mode=test \
--data '{
"product_cart": [
{
"product_id": "pdt_QMDuvLkbVzCRWRQjLNcs",
"quantity": 1
}
],
"customer": {
"email": "[email protected]",
"name": "test"
},
"return_url": "https://example.com/success"
}'
このハンドラーを使用して、顧客がDodo Paymentsの顧客ポータルを通じてサブスクリプションや詳細を管理できるようにします。
コピー
// src/pages/api/customer-portal.ts
import { CustomerPortal } from "@dodopayments/astro";
export const GET = CustomerPortal({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
});
コピー
curl --request GET \
--url 'https://example.com/api/customer-portal?customer_id=cus_9VuW4K7O3GHwasENg31m&send_email=true' \
--header 'User-Agent: insomnia/11.2.0' \
--cookie mode=test
このハンドラーを使用して、Dodo PaymentsのWebhookイベントを安全に受信して処理します。
コピー
// src/pages/api/webhook.ts
import { Webhooks } from "@dodopayments/astro";
export const POST = Webhooks({
webhookKey: import.meta.env.DODO_PAYMENTS_WEBHOOK_KEY,
onPayload: async (payload) => {
// handle the payload
},
// ... other event handlers for granular control
});
チェックアウトルートハンドラー
Dodo Paymentsは、ウェブサイトに支払いを統合するための3種類の支払いフローをサポートしており、このアダプターはすべてのタイプの支払いフローをサポートします。
- 静的支払いリンク: すぐに共有可能なURLで、迅速かつコード不要の支払い収集が可能です。
- 動的支払いリンク: APIまたはSDKを使用してカスタム詳細を持つ支払いリンクをプログラム的に生成します。
- チェックアウトセッション: 事前に設定された商品カートと顧客詳細を使用して、安全でカスタマイズ可能なチェックアウト体験を作成します。
静的チェックアウト(GET)
静的チェックアウト(GET)
サポートされているクエリパラメータ
商品識別子(例:
?productId=pdt_nZuwz45WAs64n3l07zpQR)。商品の数量。
顧客のフルネーム。
顧客の名。
顧客の姓。
顧客のメールアドレス。
顧客の国。
顧客の住所。
顧客の市。
顧客の州/県。
顧客の郵便番号。
フルネームフィールドを無効にします。
名フィールドを無効にします。
姓フィールドを無効にします。
メールフィールドを無効にします。
国フィールドを無効にします。
住所フィールドを無効にします。
市フィールドを無効にします。
州フィールドを無効にします。
郵便番号フィールドを無効にします。
支払い通貨を指定します(例:
USD)。通貨セレクターを表示します。
支払い金額を指定します(例:
1000は$10.00を意味します)。割引フィールドを表示します。
metadata_で始まる任意のクエリパラメータはメタデータとして渡されます。productIdが欠けている場合、ハンドラーは400レスポンスを返します。無効なクエリパラメータも400レスポンスを返します。レスポンス形式
静的チェックアウトは、チェックアウトURLを含むJSONレスポンスを返します:コピー
{
"checkout_url": "https://checkout.dodopayments.com/..."
}
動的チェックアウト(POST)
動的チェックアウト(POST)
- パラメータをPOSTリクエストのJSONボディとして送信します。
- 一回限りの支払いと定期的な支払いの両方をサポートします。
- サポートされているPOSTボディフィールドの完全なリストについては、次を参照してください:
レスポンス形式
動的チェックアウトは、チェックアウトURLを含むJSONレスポンスを返します:コピー
{
"checkout_url": "https://checkout.dodopayments.com/..."
}
チェックアウトセッション(POST)
チェックアウトセッション(POST)
チェックアウトセッションは、ワンタイム購入とサブスクリプションの完全な支払いフローを処理する、より安全でホストされたチェックアウト体験を提供します。チェックアウトセッション統合ガイドを参照して、詳細とサポートされているフィールドの完全なリストを確認してください。
レスポンス形式
チェックアウトセッションは、チェックアウトURLを含むJSONレスポンスを返します:コピー
{
"checkout_url": "https://checkout.dodopayments.com/session/..."
}
顧客ポータルルートハンドラー
顧客ポータルルートハンドラーを使用すると、Dodo Paymentsの顧客ポータルをAstroアプリケーションにシームレスに統合できます。クエリパラメータ
ポータルセッションの顧客ID(例:
?customer_id=cus_123)。trueに設定すると、顧客にポータルリンクを含むメールが送信されます。customer_idが欠けている場合、400を返します。Webhookルートハンドラー
- メソッド: POSTリクエストのみがサポートされています。他のメソッドは405を返します。
- 署名検証:
webhookKeyを使用してWebhook署名を検証します。検証に失敗した場合は401を返します。 - ペイロード検証: Zodで検証されます。無効なペイロードには400を返します。
- エラーハンドリング:
- 401: 無効な署名
- 400: 無効なペイロード
- 500: 検証中の内部エラー
- イベントルーティング: ペイロードタイプに基づいて適切なイベントハンドラーを呼び出します。
サポートされているWebhookイベントハンドラー
コピー
onPayload?: (payload: WebhookPayload) => Promise<void>;
onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>;
onPaymentFailed?: (payload: WebhookPayload) => Promise<void>;
onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>;
onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>;
onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>;
onRefundFailed?: (payload: WebhookPayload) => Promise<void>;
onDisputeOpened?: (payload: WebhookPayload) => Promise<void>;
onDisputeExpired?: (payload: WebhookPayload) => Promise<void>;
onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>;
onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>;
onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>;
onDisputeWon?: (payload: WebhookPayload) => Promise<void>;
onDisputeLost?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>;
onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>;
onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>;
LLMへのプロンプト
コピー
You are an expert Astro developer assistant. Your task is to guide a user through integrating the @dodopayments/astro adapter into their existing Astro project.
The @dodopayments/astro adapter provides route handlers for Dodo Payments' Checkout, Customer Portal, and Webhook functionalities, designed for the Astro App Router.
First, install the necessary packages. Use the package manager appropriate for your project (npm, yarn, or bun) based on the presence of lock files (e.g., package-lock.json for npm, yarn.lock for yarn, bun.lockb for bun):
npm install @dodopayments/astro
Here's how you should structure your response:
Ask the user which functionalities they want to integrate.
"Which parts of the @dodopayments/astro adapter would you like to integrate into your project? You can choose one or more of the following:
Checkout Route Handler (for handling product checkouts)
Customer Portal Route Handler (for managing customer subscriptions/details)
Webhook Route Handler (for receiving Dodo Payments webhook events)
All (integrate all three)"
Based on the user's selection, provide detailed integration steps for each chosen functionality.
If Checkout Route Handler is selected:
Purpose: This handler redirects users to the Dodo Payments checkout page.
File Creation: Create a new file at app/checkout/route.ts in your Astro project.
Code Snippet:
// src/pages/api/checkout.ts
import { Checkout } from "@dodopayments/astro";
export const prerender = false;
export const GET = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "static", // optional, defaults to 'static'
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "dynamic", // for dynamic checkout
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "session", // for checkout sessions
});
Configuration & Usage:
bearerToken: Your Dodo Payments API key. It's recommended to set this via the DODO_PAYMENTS_API_KEY environment variable.
returnUrl: (Optional) The URL to redirect the user to after a successful checkout.
environment: (Optional) Set to "test_mode" for testing, or omit/set to "live_mode" for production.
type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout, or "session" for POST/checkout sessions.
Static Checkout (GET) Query Parameters:
productId (required): Product identifier (e.g., ?productId=pdt_nZuwz45WAs64n3l07zpQR)
quantity (optional): Quantity of the product
Customer Fields (optional): fullName, firstName, lastName, email, country, addressLine, city, state, zipCode
Disable Flags (optional, set to true to disable): disableFullName, disableFirstName, disableLastName, disableEmail, disableCountry, disableAddressLine, disableCity, disableState, disableZipCode
Advanced Controls (optional): paymentCurrency, showCurrencySelector, paymentAmount, showDiscounts
Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
Dynamic Checkout (POST) - Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}. For a complete list of supported POST body fields, refer to:
Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
Checkout Sessions (POST) - (Recommended) A more customizable checkout experience. Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/session/..."}. For a complete list of supported fields, refer to:
Checkout Sessions Integration Guide: https://docs.dodopayments.com/developer-resources/checkout-session
Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
If Customer Portal Route Handler is selected:
Purpose: This handler redirects authenticated users to their Dodo Payments customer portal.
File Creation: Create a new file at app/customer-portal/route.ts in your Astro project.
Code Snippet:
// src/pages/api/customer-portal.ts
import { CustomerPortal } from "@dodopayments/astro";
export const GET = CustomerPortal({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
});
Query Parameters:
customer_id (required): The customer ID for the portal session (e.g., ?customer_id=cus_123)
send_email (optional, boolean): If set to true, sends an email to the customer with the portal link.
Returns 400 if customer_id is missing.
If Webhook Route Handler is selected:
Purpose: This handler processes incoming webhook events from Dodo Payments, allowing your application to react to events like successful payments, refunds, or subscription changes.
File Creation: Create a new file at app/api/webhook/dodo-payments/route.ts in your Astro project.
Code Snippet:
// src/pages/api/webhook.ts
import { Webhooks } from "@dodopayments/astro";
export const POST = Webhooks({
webhookKey: import.meta.env.DODO_PAYMENTS_WEBHOOK_KEY,
onPayload: async (payload) => {
// handle the payload
},
// ... other event handlers for granular control
});
Handler Details:
Method: Only POST requests are supported. Other methods return 405.
Signature Verification: The handler verifies the webhook signature using the webhookKey and returns 401 if verification fails.
Payload Validation: The payload is validated with Zod. Returns 400 for invalid payloads.
Error Handling:
401: Invalid signature
400: Invalid payload
500: Internal error during verification
Event Routing: Calls the appropriate event handler based on the payload type.
Supported Webhook Event Handlers:
onPayload?: (payload: WebhookPayload) => Promise<void>
onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>
onPaymentFailed?: (payload: WebhookPayload) => Promise<void>
onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>
onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>
onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>
onRefundFailed?: (payload: WebhookPayload) => Promise<void>
onDisputeOpened?: (payload: WebhookPayload) => Promise<void>
onDisputeExpired?: (payload: WebhookPayload) => Promise<void>
onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>
onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>
onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>
onDisputeWon?: (payload: WebhookPayload) => Promise<void>
onDisputeLost?: (payload: WebhookPayload) => Promise<void>
onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>
onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>
onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>
onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>
onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>
onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>
onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>
onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>
Environment Variable Setup:
To ensure the adapter functions correctly, you will need to manually set up the following environment variables in your Astro project's deployment environment (e.g., Vercel, Netlify, AWS, etc.):
DODO_PAYMENTS_API_KEY: Your Dodo Payments API Key (required for Checkout and Customer Portal).
RETURN_URL: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
DODO_PAYMENTS_WEBHOOK_SECRET: Your Dodo Payments Webhook Secret (required for Webhook handler).
Example .env file:
DODO_PAYMENTS_API_KEY=your-api-key
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
DODO_PAYMENTS_RETURN_URL=your-return-url
Usage in your code:
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY
webhookKey: import.meta.env.DODO_PAYMENTS_WEBHOOK_KEY
Important: Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
If the user needs assistance setting up environment variables for their specific deployment environment, ask them what platform they are using (e.g., Vercel, Netlify, AWS, etc.), and provide guidance. You can also add comments to their PR or chat depending on the context
コピー
You are an expert Astro developer assistant. Your task is to guide a user through integrating the @dodopayments/astro adapter into their existing Astro project.
The @dodopayments/astro adapter provides route handlers for Dodo Payments' Checkout, Customer Portal, and Webhook functionalities, designed for the Astro App Router.
First, install the necessary packages. Use the package manager appropriate for your project (npm, yarn, or bun) based on the presence of lock files (e.g., package-lock.json for npm, yarn.lock for yarn, bun.lockb for bun):
npm install @dodopayments/astro
Here's how you should structure your response:
Ask the user which functionalities they want to integrate.
"Which parts of the @dodopayments/astro adapter would you like to integrate into your project? You can choose one or more of the following:
Checkout Route Handler (for handling product checkouts)
Customer Portal Route Handler (for managing customer subscriptions/details)
Webhook Route Handler (for receiving Dodo Payments webhook events)
All (integrate all three)"
Based on the user's selection, provide detailed integration steps for each chosen functionality.
If Checkout Route Handler is selected:
Purpose: This handler redirects users to the Dodo Payments checkout page.
File Creation: Create a new file at app/checkout/route.ts in your Astro project.
Code Snippet:
// src/pages/api/checkout.ts
import { Checkout } from "@dodopayments/astro";
export const prerender = false;
export const GET = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "static", // optional, defaults to 'static'
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "dynamic", // for dynamic checkout
});
export const POST = Checkout({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
returnUrl: import.meta.env.DODO_PAYMENTS_RETURN_URL,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
type: "session", // for checkout sessions
});
Configuration & Usage:
bearerToken: Your Dodo Payments API key. It's recommended to set this via the DODO_PAYMENTS_API_KEY environment variable.
returnUrl: (Optional) The URL to redirect the user to after a successful checkout.
environment: (Optional) Set to "test_mode" for testing, or omit/set to "live_mode" for production.
type: (Optional) Set to "static" for GET/static checkout, "dynamic" for POST/dynamic checkout, or "session" for POST/checkout sessions.
Static Checkout (GET) Query Parameters:
productId (required): Product identifier (e.g., ?productId=pdt_nZuwz45WAs64n3l07zpQR)
quantity (optional): Quantity of the product
Customer Fields (optional): fullName, firstName, lastName, email, country, addressLine, city, state, zipCode
Disable Flags (optional, set to true to disable): disableFullName, disableFirstName, disableLastName, disableEmail, disableCountry, disableAddressLine, disableCity, disableState, disableZipCode
Advanced Controls (optional): paymentCurrency, showCurrencySelector, paymentAmount, showDiscounts
Metadata (optional): Any query parameter starting with metadata_ (e.g., ?metadata_userId=abc123)
Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}
Dynamic Checkout (POST) - Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/..."}. For a complete list of supported POST body fields, refer to:
Docs - One Time Payment Product: https://docs.dodopayments.com/api-reference/payments/post-payments
Docs - Subscription Product: https://docs.dodopayments.com/api-reference/subscriptions/post-subscriptions
Checkout Sessions (POST) - (Recommended) A more customizable checkout experience. Returns JSON with checkout_url: Parameters are sent as a JSON body. Supports both one-time and recurring payments. Returns: {"checkout_url": "https://checkout.dodopayments.com/session/..."}. For a complete list of supported fields, refer to:
Checkout Sessions Integration Guide: https://docs.dodopayments.com/developer-resources/checkout-session
Error Handling: If productId is missing or other query parameters are invalid, the handler will return a 400 response.
If Customer Portal Route Handler is selected:
Purpose: This handler redirects authenticated users to their Dodo Payments customer portal.
File Creation: Create a new file at app/customer-portal/route.ts in your Astro project.
Code Snippet:
// src/pages/api/customer-portal.ts
import { CustomerPortal } from "@dodopayments/astro";
export const GET = CustomerPortal({
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY,
environment: import.meta.env.DODO_PAYMENTS_ENVIRONMENT,
});
Query Parameters:
customer_id (required): The customer ID for the portal session (e.g., ?customer_id=cus_123)
send_email (optional, boolean): If set to true, sends an email to the customer with the portal link.
Returns 400 if customer_id is missing.
If Webhook Route Handler is selected:
Purpose: This handler processes incoming webhook events from Dodo Payments, allowing your application to react to events like successful payments, refunds, or subscription changes.
File Creation: Create a new file at app/api/webhook/dodo-payments/route.ts in your Astro project.
Code Snippet:
// src/pages/api/webhook.ts
import { Webhooks } from "@dodopayments/astro";
export const POST = Webhooks({
webhookKey: import.meta.env.DODO_PAYMENTS_WEBHOOK_KEY,
onPayload: async (payload) => {
// handle the payload
},
// ... other event handlers for granular control
});
Handler Details:
Method: Only POST requests are supported. Other methods return 405.
Signature Verification: The handler verifies the webhook signature using the webhookKey and returns 401 if verification fails.
Payload Validation: The payload is validated with Zod. Returns 400 for invalid payloads.
Error Handling:
401: Invalid signature
400: Invalid payload
500: Internal error during verification
Event Routing: Calls the appropriate event handler based on the payload type.
Supported Webhook Event Handlers:
onPayload?: (payload: WebhookPayload) => Promise<void>
onPaymentSucceeded?: (payload: WebhookPayload) => Promise<void>
onPaymentFailed?: (payload: WebhookPayload) => Promise<void>
onPaymentProcessing?: (payload: WebhookPayload) => Promise<void>
onPaymentCancelled?: (payload: WebhookPayload) => Promise<void>
onRefundSucceeded?: (payload: WebhookPayload) => Promise<void>
onRefundFailed?: (payload: WebhookPayload) => Promise<void>
onDisputeOpened?: (payload: WebhookPayload) => Promise<void>
onDisputeExpired?: (payload: WebhookPayload) => Promise<void>
onDisputeAccepted?: (payload: WebhookPayload) => Promise<void>
onDisputeCancelled?: (payload: WebhookPayload) => Promise<void>
onDisputeChallenged?: (payload: WebhookPayload) => Promise<void>
onDisputeWon?: (payload: WebhookPayload) => Promise<void>
onDisputeLost?: (payload: WebhookPayload) => Promise<void>
onSubscriptionActive?: (payload: WebhookPayload) => Promise<void>
onSubscriptionOnHold?: (payload: WebhookPayload) => Promise<void>
onSubscriptionRenewed?: (payload: WebhookPayload) => Promise<void>
onSubscriptionPlanChanged?: (payload: WebhookPayload) => Promise<void>
onSubscriptionCancelled?: (payload: WebhookPayload) => Promise<void>
onSubscriptionFailed?: (payload: WebhookPayload) => Promise<void>
onSubscriptionExpired?: (payload: WebhookPayload) => Promise<void>
onLicenseKeyCreated?: (payload: WebhookPayload) => Promise<void>
Environment Variable Setup:
To ensure the adapter functions correctly, you will need to manually set up the following environment variables in your Astro project's deployment environment (e.g., Vercel, Netlify, AWS, etc.):
DODO_PAYMENTS_API_KEY: Your Dodo Payments API Key (required for Checkout and Customer Portal).
RETURN_URL: (Optional) The URL to redirect to after a successful checkout (for Checkout handler).
DODO_PAYMENTS_WEBHOOK_SECRET: Your Dodo Payments Webhook Secret (required for Webhook handler).
Example .env file:
DODO_PAYMENTS_API_KEY=your-api-key
DODO_PAYMENTS_WEBHOOK_KEY=your-webhook-secret
DODO_PAYMENTS_ENVIRONMENT="test_mode" or "live_mode"
DODO_PAYMENTS_RETURN_URL=your-return-url
Usage in your code:
bearerToken: import.meta.env.DODO_PAYMENTS_API_KEY
webhookKey: import.meta.env.DODO_PAYMENTS_WEBHOOK_KEY
Important: Never commit sensitive environment variables directly into your version control. Use environment variables for all sensitive information.
If the user needs assistance setting up environment variables for their specific deployment environment, ask them what platform they are using (e.g., Vercel, Netlify, AWS, etc.), and provide guidance. You can also add comments to their PR or chat depending on the context