はじめに
ビジネスチームをリアルタイムの支払い通知でつなげましょう。統合により、支払いイベントがリッチなAdaptive Cardsとして配信されます。これは、Teamsが主要なコラボレーションツールである企業環境に最適です。
このガイドでは、Microsoft Teams ワークスペースで webhook を作成するための管理者アクセス権があることを前提としています。
始め方
Open the Webhook Section
Dodo Payments ダッシュボードで、Webhooks → + Add Endpoint に移動し、統合のドロップダウンを展開します。 Select Microsoft Teams
Microsoft Teams 統合カードを選択します。
Create Teams Webhook
Teams でチャネルに移動し、⋯ → Connectors → Incoming Webhook → Configure を開きます。Webhook URL をコピーします。
Paste Webhook URL
Teams の webhook URL をエンドポイント構成に貼り付けます。
Customize Transformation
変換コードを編集して、メッセージを Teams の Adaptive Card としてフォーマットします。
Test & Create
サンプルペイロードでテストし、Create をクリックして有効化します。
Done!
🎉 これで Teams チャネルに Dodo Payments の更新が Adaptive Card として届くようになります。
変換コードの例
基本的な支払いカード
function handler(webhook) {
if (webhook.eventType === "payment.succeeded") {
const p = webhook.payload.data;
webhook.payload = {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
type: "TextBlock",
text: "✅ Payment Successful",
weight: "Bolder",
size: "Medium"
},
{
type: "FactSet",
facts: [
{ title: "Amount", value: `$${(p.total_amount / 100).toFixed(2)}` },
{ title: "Customer", value: p.customer.email },
{ title: "Payment ID", value: p.payment_id }
]
}
]
}
}]
};
}
return webhook;
}
サブスクリプション管理
function handler(webhook) {
const s = webhook.payload.data;
switch (webhook.eventType) {
case "subscription.active":
webhook.payload = {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
type: "TextBlock",
text: "📄 Subscription Activated",
weight: "Bolder",
color: "Good"
},
{
type: "FactSet",
facts: [
{ title: "Customer", value: s.customer.email },
{ title: "Product", value: s.product_id },
{ title: "Amount", value: `$${(s.recurring_pre_tax_amount / 100).toFixed(2)}/${s.payment_frequency_interval}` },
{ title: "Next Billing", value: new Date(s.next_billing_date).toLocaleDateString() }
]
}
]
}
}]
};
break;
case "subscription.cancelled":
webhook.payload = {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
type: "TextBlock",
text: "⚠️ Subscription Cancelled",
weight: "Bolder",
color: "Warning"
},
{
type: "FactSet",
facts: [
{ title: "Customer", value: s.customer.email },
{ title: "Product", value: s.product_id },
{ title: "Cancelled At", value: new Date(s.cancelled_at).toLocaleDateString() }
]
}
]
}
}]
};
break;
}
return webhook;
}
争議アラート
function handler(webhook) {
if (webhook.eventType.startsWith("dispute.")) {
const d = webhook.payload.data;
const color = d.dispute_status === "won" ? "Good" : d.dispute_status === "lost" ? "Attention" : "Warning";
const title = d.dispute_status === "won" ? "🏆 Dispute Won" : d.dispute_status === "lost" ? "❌ Dispute Lost" : "🚨 Dispute Update";
webhook.payload = {
type: "message",
attachments: [{
contentType: "application/vnd.microsoft.card.adaptive",
content: {
type: "AdaptiveCard",
body: [
{
type: "TextBlock",
text: title,
weight: "Bolder",
color: color
},
{
type: "FactSet",
facts: [
{ title: "Payment ID", value: d.payment_id },
{ title: "Amount", value: `$${(d.amount / 100).toFixed(2)}` },
{ title: "Status", value: d.dispute_status },
{ title: "Stage", value: d.dispute_stage }
]
}
]
}
}]
};
}
return webhook;
}
ヒント
- リッチでインタラクティブなフォーマットのためにAdaptive Cardsを使用する
- 適切な色を選択する: 良好(緑)、警告(黄)、注意(赤)
- ファクトセットを簡潔で読みやすく保つ
- デプロイ前にTeamsのWebhookテスターでテストする
トラブルシューティング
- Webhook URL が正しくアクティブであることを確認してください
- 変換が有効な Adaptive Card JSON を返すことを確認してください
- Webhook にチャネルへの投稿権限があることを確認してください