はじめに
チームがすでにコラボレーションしている場所で情報を提供します。Discord統合は、支払い、サブスクリプション、紛争、その他の重要なイベントを、選択した任意のチャンネルに直接配信します—ポーリングやダッシュボードは不要です。
このガイドでは、Dodo Payments ダッシュボードの Integrations セクションにアクセスできることを前提としています。
始め方
Open the Webhook Section
Dodo Payments ダッシュボードで、Webhooks → + Add Endpoint を開き、ドロップダウンを展開して統合を表示します。 Select Discord
Discord カードを選択し、次に Connect your Discord workspace をクリックします。
Authorize the Bot
ボットが選択したチャンネルにメッセージを投稿できるよう、要求された権限を付与します。
Edit Transformation Code
ペイロード → 埋め込みのマッピングを必要に応じて調整するか、以下のテンプレートから始めてください。
Test & Create
サンプルペイロードを使用して埋め込みをプレビューし、Create をクリックします。
Done!
🎉 Discord チャンネルにリアルタイムの Dodo Payments アップデートが届くようになります。
変換コードの例
最小限の支払い埋め込み
function handler(webhook) {
if (webhook.eventType === "payment.succeeded") {
const p = webhook.payload.data;
webhook.payload = {
embeds: [{
title: "✅ Payment Successful",
description: `**Amount:** $${(p.total_amount / 100).toFixed(2)}\n**Customer:** ${p.customer.email}`,
color: 0x2ecc71 // green
}]
};
}
return webhook;
}
サブスクリプションイベント
function handler(webhook) {
const s = webhook.payload.data;
switch (webhook.eventType) {
case "subscription.active":
webhook.payload = {
embeds: [{
title: "📄 Subscription Activated",
fields: [
{ name: "Customer", value: s.customer.email, inline: true },
{ name: "Product", value: s.product_id, inline: true },
{ name: "Next Billing", value: new Date(s.next_billing_date).toLocaleDateString(), inline: true }
],
color: 0x2ecc71
}]
};
break;
case "subscription.cancelled":
webhook.payload = {
embeds: [{
title: "⚠️ Subscription Cancelled",
fields: [
{ name: "Customer", value: s.customer.email, inline: true },
{ name: "Product", value: s.product_id, inline: true }
],
color: 0xf1c40f
}]
};
break;
}
return webhook;
}
紛争アラート
function handler(webhook) {
if (webhook.eventType.startsWith("dispute.")) {
const d = webhook.payload.data;
webhook.payload = {
embeds: [{
title: d.dispute_status === "won" ? "🏆 Dispute Won" : d.dispute_status === "lost" ? "❌ Dispute Lost" : "🚨 Dispute Update",
fields: [
{ name: "Payment ID", value: d.payment_id, inline: true },
{ name: "Amount", value: `$${(d.amount / 100).toFixed(2)}`, inline: true },
{ name: "Status", value: d.dispute_status, inline: true }
],
color: d.dispute_status === "won" ? 0x2ecc71 : d.dispute_status === "lost" ? 0xe74c3c : 0xe67e22
}]
};
}
return webhook;
}
ヒント
- リッチフォーマットと色のために埋め込みを好む。
- タイトルは短く保ち、詳細はフィールドに記入する。
- 直感的な色を使用する:緑(成功)、赤(失敗)、オレンジ(警告)。
トラブルシューティング
- ボットがチャンネルにアクセスできることを確認します。
- 変換が
embeds を含む JSON オブジェクトを返すことを確認します。