カスタマーウォレットとは?
カスタマーウォレットは、ユーザーのためのデジタル貯金箱のようなものです。顧客アカウントを作成すると、自動的に1つが付与されます。これらのウォレットを使用して、以下のことができます:
- USDおよびINRでのクレジット残高を追跡
- OpenAIやClaudeのようなAPIクレジットシステムを構築
- 顧客が前払いでクレジットを購入するプリペイド請求を作成
- 現金の代わりにウォレットクレジットとして返金を処理
- 詳細な取引履歴を持つ複雑な請求を管理
顧客アカウントを作成すると、すべての顧客に自動的にウォレットが付与されます。ウォレットはUSDおよびINR通貨をサポートし、それぞれの残高が分かれています。
仕組み
カスタマーウォレットはシンプルです:顧客がサービスに使えるお金(クレジット)を保持します。顧客が購入を行うと、まずウォレット残高が確認され、利用可能なクレジットがあればそれが使用され、次に支払い方法が請求されます。
自動セットアップ
新しい顧客を作成すると、Dodo Paymentsは自動的に残高ゼロのウォレットを作成します。すぐにAPIを通じて使用可能です。
マルチ通貨サポート
各ウォレットは異なる通貨での残高を保持できます:
現在、USDおよびINRの残高のみが利用可能です。今後、他の通貨も追加予定です。
ウォレットの操作
顧客残高の確認
顧客がすべての通貨でどれだけのクレジットを持っているかを確認します。購入処理の前に十分な資金があるかを確認するのに最適です。
顧客ウォレット残高を取得
サポートされているすべての通貨で顧客のウォレットクレジット残高を確認します。
クレジットの追加または削除
顧客にクレジット(ウェルカムボーナスのようなもの)を付与したり、クレジットを差し引いたりします(使用料のようなもの)。各取引に理由を追加して、何が起こったかを追跡できます。
顧客ウォレット元帳エントリを作成
顧客のウォレットからクレジットを追加または削除します。
取引履歴の表示
顧客のすべてのクレジットおよびデビット取引を確認します。請求の問題をデバッグしたり、顧客に支出履歴を示したりするのに最適です。
顧客ウォレット元帳エントリの一覧
顧客のすべてのクレジットおよびデビット取引を表示します。
実世界の例
APIクレジットシステム(OpenAIのような)
顧客がクレジットを購入し、APIコールに使うシステムを構築します:
// Give new customers welcome credits
async function giveWelcomeCredits(customerId) {
await client.customers.wallets.ledgerEntries.create(customerId, {
amount: 10000, // $100 in cents
currency: 'USD',
entry_type: 'credit',
reason: 'Welcome bonus - 100 API credits',
idempotency_key: `welcome_${customerId}_${Date.now()}`
});
}
// Charge customers for API usage
async function chargeForApiUsage(customerId, usageCost) {
try {
await client.customers.wallets.ledgerEntries.create(customerId, {
amount: usageCost, // Cost in cents
currency: 'USD',
entry_type: 'debit',
reason: `API usage - ${usageCost} credits consumed`,
idempotency_key: `usage_${customerId}_${Date.now()}`
});
} catch (error) {
if (error.status === 400) {
console.log('Customer needs to buy more credits');
}
}
}
プリペイド請求システム
顧客が前払いでクレジットを購入し、時間をかけて使うことを許可します:
新しい顧客を歓迎
新しい顧客に無料のクレジットを提供してスタートさせます。await client.customers.wallets.ledgerEntries.create(customerId, {
amount: 5000, // $50 welcome bonus
currency: 'USD',
entry_type: 'credit',
reason: 'Welcome bonus for new customer',
idempotency_key: `welcome_${customerId}`
});
クレジット購入の処理
顧客がクレジットを購入したとき、それをウォレットに追加します。await client.customers.wallets.ledgerEntries.create(customerId, {
amount: purchaseAmount, // Amount paid in cents
currency: 'USD',
entry_type: 'credit',
reason: `Credit purchase - ${purchaseAmount} credits`,
idempotency_key: `purchase_${paymentId}`
});
使用料の請求
顧客がサービスを使用したときにクレジットを差し引きます。await client.customers.wallets.ledgerEntries.create(customerId, {
amount: usageCost,
currency: 'USD',
entry_type: 'debit',
reason: `Service usage - ${usageCost} credits`,
idempotency_key: `usage_${usageId}`
});
残高の監視
顧客のクレジットが不足していないか確認します。const wallets = await client.customers.wallets.list(customerId);
const usdWallet = wallets.items.find(w => w.currency === 'USD');
const balance = usdWallet.balance;
if (balance < 1000) { // Less than $10
// Send low balance notification
await sendLowBalanceNotification(customerId, balance);
}
マルチ通貨サポート
異なる国の顧客を扱います:
米国の顧客にUSDクレジットを提供します。await client.customers.wallets.ledgerEntries.create(customerId, {
amount: 20000, // $200 in cents
currency: 'USD',
entry_type: 'credit',
reason: 'USD credit purchase',
idempotency_key: `usd_purchase_${paymentId}`
});
インドの顧客にINRクレジットを提供します。await client.customers.wallets.ledgerEntries.create(customerId, {
amount: 1500000, // ₹15,000 in paise
currency: 'INR',
entry_type: 'credit',
reason: 'INR credit purchase',
idempotency_key: `inr_purchase_${paymentId}`
});
ベストプラクティス
重複取引を防ぐ
冪等性キーを使用して、同じことに対して顧客に二重請求しないようにします:
async function addCreditsSafely(customerId, amount, reason) {
const idempotencyKey = `${reason}_${customerId}_${Date.now()}`;
try {
const result = await client.customers.wallets.ledgerEntries.create(customerId, {
amount: amount,
currency: 'USD',
entry_type: 'credit',
reason: reason,
idempotency_key: idempotencyKey
});
return { success: true, wallet: result };
} catch (error) {
if (error.status === 400 && error.message.includes('Insufficient balance')) {
return { success: false, error: 'INSUFFICIENT_BALANCE' };
}
if (error.status === 409) {
// Transaction already processed
return { success: true, wallet: null, duplicate: true };
}
throw error;
}
}
請求の前に残高を確認
高額な操作を処理する前に、顧客に十分なクレジットがあるかを常に確認します:
async function checkBalanceBeforeOperation(customerId, requiredAmount) {
const wallets = await client.customers.wallets.list(customerId);
const usdWallet = wallets.items.find(w => w.currency === 'USD');
if (!usdWallet || usdWallet.balance < requiredAmount) {
throw new Error('Not enough credits for this operation');
}
return usdWallet.balance;
}
今後の予定
- クレジットの有効期限:一定の時間後にクレジットが失効するように設定
- より良い分析:詳細な支出レポートと使用状況の洞察
- より多くのWebhook:残高の変化やクレジット不足のリアルタイム通知
基本的なクレジット/デビット操作から始め、ビジネスが成長するにつれてより複雑な機能を追加してください。