Virtual Currencies Guide
Virtual Currencies Overview
Virtual Currencies allow you to create in-app economies where customers earn and spend currency units. Perfect for gaming apps, loyalty programs, and subscription perks.
Automatic Granting
Currencies are automatically granted on purchases, trials, and renewals
Transaction History
Complete audit trail of all grants, deductions, and spending
Real-time Balances
Fetch current balances instantly via SDK or API
Key Concepts
Virtual Currency
A virtual currency represents a unit of value in your app (e.g., Gems, Coins, Credits). Each currency has a code (like "GEMS"), name, description, and optional icon emoji.
Code: GEMS | Name: Gems | Icon: 💎Currency Balance
Each customer has a balance for every currency. Balances start at 0 and increase with grants, decrease with deductions. Balances are tracked per customer per currency.
Currency Products
Link currencies to your subscription products to automatically grant units on purchase, trial start, or subscription renewal. Configure units per event type.
Transactions
Every currency change creates a transaction record with type (grant/deduct), amount, balance before/after, source, and notes. Perfect for auditing and analytics.
Setting Up Virtual Currencies
Step 1: Create a Virtual Currency
Navigate to Dashboard → Virtual Currencies → Create Currency:
- Code: Unique identifier (e.g., "GEMS", "COINS")
- Name: Display name (e.g., "Premium Gems")
- Description: What this currency is used for
- Icon: Optional emoji (e.g., 💎, 🪙, ⭐)
Step 2: Link to Products
Configure automatic currency grants on purchases:
- Units on Purchase: Grant when customer buys the product
- Units on Trial Start: Grant when free trial begins
- Auto-expire on billing cycle end: For subscriptions, the units a billing period granted expire when that period ends (or sooner, if Expiration Days is shorter)
Step 3: Test Automatic Granting
When a customer purchases a linked product, currencies are automatically granted via webhook.
SDK Integration
Web / TypeScript
Web • typescript • editable snippet
iOS / Swift
iOS • swift • editable snippet
Android / Kotlin
Android • kotlin • editable snippet
React Native
React Native • typescript • editable snippet
Whose balance is this? An app reads only its own customer’s wallet: the customer its session proves (with BillDog Auth) or, for a guest, the one its device key proves. A customer_id it sends may only name that customer, and a public key alone, with no session or device proof, is refused with 403 PROOF_REQUIRED. Only your server’s secret key can name any customer of the project, by customer_id or app_user_id; it never creates one, so an unknown customer is a 404. Changing a balance needs the secret key. An organization’s balance lives on the organization’s own customer record, not on each member’s.
API Reference
Get Currency Balances
GET https://api.billdog.io/v1/virtual-currency/balances
Query parameters (or the same fields in a POST body, as the SDKs send them):
customer_idorapp_user_id- whose balance; secret key only (an app's session or device proof decides it)currency_id(optional) - one currency, by ID or code; without it, every currency
Response:
{
"balances": [
{
"currency": {
"id": "uuid",
"code": "GEMS",
"name": "Premium Gems",
"description": "...",
"icon": "💎"
},
"balance": 150
}
]
}Get Currency Transactions
GET https://api.billdog.io/v1/virtual-currency/transactions/history
Query parameters (or the same fields in a POST body, as the SDKs send them):
customer_idorapp_user_id- whose history; secret key only (an app's session or device proof decides it)currency_id(optional) - one currency, by ID or codelimit(optional, default: 50) - Number of transactions
Response:
{
"transactions": [
{
"id": "uuid",
"virtual_currency_id": "uuid",
"transaction_type": "grant",
"amount": 100,
"balance_after": 150,
"notes": "Auto-granted on purchase",
"metadata": {},
"created_at": "2024-11-08T12:00:00Z",
"virtual_currencies": {
"code": "GEMS",
"name": "Premium Gems"
}
}
]
}Manual Currency Management
As an admin, you can manually grant or deduct currencies from the Customer Detail page:
- Navigate to Dashboard → Customers
- Click on a customer to view details
- Go to the "Virtual Currencies" tab
- Click "Grant" or "Deduct" buttons
- Select currency, enter amount, and add optional notes
All manual operations create transaction records with source set to "manual" for auditing.
Currency Expiration
Virtual currencies can be configured to automatically expire after a set period, perfect for time-limited promotions, trial bonuses, or seasonal rewards. The system handles expiration processing and notifications automatically.
Configuring Expiration
When creating or editing a virtual currency product, you can set:
- Expiration Days: Number of days until granted currency expires (e.g., 30 days)
- Notify Before Expiration: Days before expiration to notify customers (e.g., 7 days)
How Expiration Works
- When currency is granted, an
expires_attimestamp is set based on expiration days - Daily automated job checks for currencies nearing expiration and sends notifications
- Daily automated job processes expired currencies and deducts them from balances
- All expirations are logged in transaction history with source set to "expiration"
Setting Up Automated Processing
To enable automated expiration processing, you need to set up cron jobs in Supabase. This requires enabling the pg_cron and pg_net extensions.
📋 Setup Guide
View the complete setup instructions including SQL commands for scheduling cron jobs, monitoring execution, and troubleshooting common issues.
View Virtual Currencies Setup Guide →Expiration Notifications
Customers are notified when their currency is about to expire (based on notification window configuration). Notifications include:
- Currency name and amount expiring
- Days until expiration
- Expiration date
Note: The notification system currently logs notification events. To send actual emails or push notifications, integrate your notification service in the notify-currency-expiration edge function.
Analytics & Reporting
Track currency performance with comprehensive analytics available in Dashboard → Virtual Currencies → Analytics:
Overview Metrics
- Total circulation across all currencies
- Total granted and deducted amounts
- Active customers with positive balances
- Transaction volume trends
Activity Trends
- Daily grant and deduct patterns
- Net currency change over time
- Transaction volume by day
- Customizable date ranges
Currency Breakdown
- Distribution pie charts
- Transaction volume by currency
- Balance totals per currency type
- Comparative statistics
Customer Insights
- Top customers by balance
- Most active users by transactions
- Customer engagement patterns
- Balance distribution analysis
Use Cases
Gaming Apps
- Grant gems on subscription purchase
- Reward daily login streaks
- Deduct for in-game purchases
- Special bonus currency for trials
Loyalty Programs
- Points for subscription renewals
- Bonus points on annual plans
- Redemption tracking
- Tier-based multipliers
Content Platforms
- Credits for premium content access
- Rollover unused credits
- Family sharing of credits
- Credit packs as IAP
SaaS Products
- API call credits per plan
- Usage-based credit consumption
- Credit top-ups for overages
- Enterprise credit pools
Best Practices
Next Steps
Was this page helpful?
Or rate this page: