Back to Developers

Guide

Wallet Integration Guide

Integrate digital wallets into your application. Manage balances, process transfers, handle credits, and track transactions.

Implementation

Wallet Setup

Create and configure wallets for your users. Each wallet supports multiple currencies and credit types.

TypeScript SDK typescript
// Create a wallet for a user
const wallet = await nexbic.wallets.create({
  userId: "usr_...",
  currency: "USD",
  metadata: {
    tier: "premium"
  }
});

console.log(wallet.id); // "wlt_..."
console.log(wallet.balance); // 0
curl bash
curl -X POST https://api.nexbic.dev/v1/wallets \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer nxb_sk_..." \
  -d '{
    "user_id": "usr_...",
    "currency": "USD"
  }'

Implementation

Credit Management

Add, deduct, and check credits for any wallet. All operations are atomic and idempotent.

TypeScript SDK typescript
// Add credits to a wallet
await nexbic.wallets.credits.add({
  walletId: "wlt_...",
  amount: 1000,
  description: "Premium plan purchase",
  idempotencyKey: "unique_key_123"
});

// Deduct credits
await nexbic.wallets.credits.deduct({
  walletId: "wlt_...",
  amount: 250,
  description: "API call usage"
});

// Check balance
const balance = await nexbic.wallets.getBalance("wlt_...");
console.log(balance.credits); // 750
curl bash
curl -X POST https://api.nexbic.dev/v1/wallets/wlt_.../credits \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer nxb_sk_..." \
  -d '{
    "amount": 1000,
    "description": "Premium plan purchase",
    "idempotency_key": "unique_key_123"
  }'

Implementation

Transfers

Transfer credits between wallets with built-in validation and audit logging.

TypeScript SDK typescript
// Transfer credits between users
const transfer = await nexbic.wallets.transfer({
  fromWalletId: "wlt_sender_...",
  toWalletId: "wlt_receiver_...",
  amount: 500,
  description: "Payment for services"
});

console.log(transfer.id); // "txn_..."
console.log(transfer.status); // "completed"
curl bash
curl -X POST https://api.nexbic.dev/v1/wallets/transfer \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer nxb_sk_..." \
  -d '{
    "from_wallet_id": "wlt_sender_...",
    "to_wallet_id": "wlt_receiver_...",
    "amount": 500,
    "description": "Payment for services"
  }'

Implementation

Webhook Events

Listen for wallet events in real time via webhooks. Each event is delivered with an idempotency key and signature.

Webhook Events typescript
// Webhook event types for wallets
// wallet.credit.added    - Credits were added
// wallet.credit.deducted - Credits were deducted
// wallet.transfer.sent   - Transfer was initiated
// wallet.transfer.received - Transfer was received
// wallet.balance.low     - Balance dropped below threshold

// Example webhook payload
{
  "type": "wallet.credit.added",
  "id": "evt_...",
  "data": {
    "wallet_id": "wlt_...",
    "amount": 1000,
    "balance": 5000
  },
  "idempotency_key": "unique_key_123"
}

Wallet integration complete

Now set up webhooks and explore the full API reference.