메인 콘텐츠로 건너뛰기

고객 지갑이란?

고객 지갑을 사용자가 사용할 수 있는 디지털 저금통으로 생각하세요. 고객 계정을 생성할 때마다 자동으로 하나씩 제공됩니다. 이러한 지갑을 사용하여 다음을 수행할 수 있습니다:
  • USD 및 INR에서 크레딧 잔액 추적
  • OpenAI 또는 Claude와 같은 API 크레딧 시스템 구축
  • 고객이 사전 결제하는 청구 생성
  • 현금 대신 지갑 크레딧으로 환불 처리
  • 상세한 거래 내역으로 복잡한 청구 관리
고객 계정을 생성할 때마다 자동으로 지갑이 제공됩니다. 지갑은 USD 및 INR 통화를 지원하며 각 통화에 대해 별도의 잔액을 가집니다.
고객 지갑

작동 방식

고객 지갑은 간단합니다: 고객이 서비스에 사용할 수 있는 돈(크레딧)을 보유합니다. 고객이 구매를 할 때, 먼저 지갑 잔액이 확인되고, 사용 가능한 크레딧이 결제 수단으로 청구되기 전에 사용됩니다.

자동 설정

새 고객을 생성하면 Dodo Payments가 자동으로 잔액이 0인 지갑을 생성합니다. API를 통해 즉시 사용할 수 있습니다.

다중 통화 지원

각 지갑은 서로 다른 통화의 잔액을 보유할 수 있습니다:
USD Balance
integer
미국 달러의 잔액(센트로 저장됨)
INR Balance
integer
인도 루피의 잔액(파이세로 저장됨)
현재 USDINR 잔액만 사용할 수 있습니다. 더 많은 통화가 곧 추가될 예정입니다.

지갑 작업하기

고객 잔액 확인

고객이 모든 통화에서 얼마나 많은 크레딧을 보유하고 있는지 확인하세요. 구매를 처리하기 전에 충분한 자금이 있는지 확인하는 데 적합합니다.

고객 지갑 잔액 가져오기

지원되는 모든 통화에서 고객의 지갑 크레딧 잔액을 확인하세요.

크레딧 추가 또는 제거

고객에게 크레딧(예: 환영 보너스)을 제공하거나 크레딧을 차감(예: 사용 요금)하세요. 각 거래에 대한 이유를 추가하여 발생한 일을 추적할 수 있습니다.

고객 지갑 원장 항목 생성

고객의 지갑에서 크레딧을 추가하거나 제거하세요.

거래 내역 보기

고객의 모든 크레딧 및 차감 거래를 확인하세요. 청구 문제를 디버깅하거나 고객에게 지출 내역을 보여주는 데 유용합니다.

고객 지갑 원장 항목 목록

고객의 모든 크레딧 및 차감 거래를 확인하세요.

실제 사례

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');
    }
  }
}

선불 청구 시스템

고객이 사전 결제하여 크레딧을 구매하고 시간이 지남에 따라 사용할 수 있도록 하세요:
1

신규 고객 환영

신규 고객에게 시작할 수 있도록 무료 크레딧을 제공하세요.
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}`
});
2

크레딧 구매 처리

고객이 크레딧을 구매할 때, 이를 지갑에 추가하세요.
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}`
});
3

사용 요금 청구

고객이 서비스를 사용할 때 크레딧을 차감하세요.
await client.customers.wallets.ledgerEntries.create(customerId, {
  amount: usageCost,
  currency: 'USD', 
  entry_type: 'debit',
  reason: `Service usage - ${usageCost} credits`,
  idempotency_key: `usage_${usageId}`
});
4

잔액 모니터링

고객의 크레딧이 부족한지 확인하세요.
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;
}

다음에 올 것들

이 기능들은 향후 릴리스에 계획되어 있습니다:
  • 크레딧 만료: 특정 시간 후에 크레딧이 만료되도록 설정
  • 더 나은 분석: 상세한 지출 보고서 및 사용 통찰력
  • 더 많은 웹훅: 잔액 변경 및 낮은 크레딧에 대한 실시간 알림
기본 크레딧/차감 작업으로 간단하게 시작한 후, 비즈니스가 성장함에 따라 더 복잡한 기능을 추가하세요.