Xtopay Docs
Credit Wallets

Transactions

Debit wallets and view full transaction history.

Debit a wallet

Deduct funds from a customer's wallet when they consume your product:

const debit = await xtopay.wallets.debit({
  wallet_id: "wal_a1b2c3",
  amount: 500,             // GHS 5.00
  description: "10 SMS messages sent",
  reference: "sms_batch_xyz",   // your internal reference — must be unique
});

The debit is atomic — if the wallet has insufficient balance, it fails immediately with 402 insufficient_wallet_balance. The balance is never partially deducted.

Idempotent debits

Pass a unique reference to make debits idempotent. If you retry with the same reference, Xtopay returns the original debit without double-charging:

const debit = await xtopay.wallets.debit({
  wallet_id: "wal_a1b2c3",
  amount: 500,
  description: "API call batch #8821",
  reference: "api_batch_8821",   // retry-safe
});

Check balance before debit

const wallet = await xtopay.wallets.retrieve("wal_a1b2c3");

if (wallet.balance < requiredAmount) {
  return { error: "insufficient_balance", balance: wallet.balance };
}

await xtopay.wallets.debit({
  wallet_id: wallet.id,
  amount: requiredAmount,
  reference: operationId,
});

Transaction object

{
  "id": "txn_a1b2c3",
  "wallet_id": "wal_abc",
  "type": "debit",
  "amount": 500,
  "currency": "GHS",
  "balance_before": 15000,
  "balance_after": 14500,
  "description": "10 SMS messages sent",
  "reference": "sms_batch_xyz",
  "created_at": "2026-05-24T10:05:00Z"
}

Transaction types

TypeTriggered by
topupCustomer completes a top-up payment
debitYour app calls /wallets/:id/debit
creditAdmin credit or promotional grant
refundTop-up refunded to customer's payment method
expiryCredits expired per expiry policy
transfer_inBalance moved from another wallet
transfer_outBalance moved to another wallet

List transactions

const transactions = await xtopay.wallets.listTransactions({
  wallet_id: "wal_a1b2c3",
  limit: 20,
  type: "debit",
});

Webhook events

EventFired when
wallet.topup_succeededTop-up payment completes
wallet.topup_failedTop-up payment fails
wallet.debitedDebit recorded
wallet.creditedAdmin credit applied
wallet.credit_expiredExpiring credits removed
wallet.balance_lowBalance drops below a threshold you configure
wallet.frozenWallet frozen
wallet.closedWallet closed

Configure the wallet.balance_low threshold in Dashboard → Settings → Wallet Alerts to prompt customers to top up before they run out.

On this page