Guide
Integrate digital wallets into your application. Manage balances, process transfers, handle credits, and track transactions.
Implementation
Create and configure wallets for your users. Each wallet supports multiple currencies and credit types.
// 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); // 0curl -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
Add, deduct, and check credits for any wallet. All operations are atomic and idempotent.
// 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); // 750curl -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
Transfer credits between wallets with built-in validation and audit logging.
// 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 -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
Listen for wallet events in real time via webhooks. Each event is delivered with an idempotency key and signature.
// 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"
}