|
| 1 | +--- |
| 2 | +title: Virtual Currency Events |
| 3 | +sidebar_label: Events |
| 4 | +slug: events |
| 5 | +hidden: false |
| 6 | +--- |
| 7 | + |
| 8 | +# Virtual Currency Events |
| 9 | + |
| 10 | +RevenueCat provides event tracking for virtual currency transactions, allowing you to monitor and respond to balance changes in real-time through webhooks. |
| 11 | + |
| 12 | +:::info Adjustments via API are view-only |
| 13 | +Virtual currency adjustments made through the [API](/offerings/virtual-currency#depositing-or-spending) will appear in the customer timeline, but cannot be clicked for additional details. These adjustments are displayed for reference only and do not generate webhook events. |
| 14 | +::: |
| 15 | + |
| 16 | +## Timeline Events |
| 17 | + |
| 18 | +Virtual currency transactions appear in the [Customer History](/dashboard-and-metrics/customer-history) timeline, providing visibility into when currency was granted or spent from a customer's balance. These events help with debugging, customer support, and understanding customer behavior. |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +### Event Types |
| 23 | + |
| 24 | +The following virtual currency events can appear in the customer timeline: |
| 25 | + |
| 26 | +| Event Name | Description | Webhook Event | |
| 27 | +| ---------------------- | ------------------------------------------------ | ------------------------------ | |
| 28 | +| Granted ... [Currency] | Currency was added to the customer's balance | `VIRTUAL_CURRENCY_TRANSACTION` | |
| 29 | +| Spent ... [Currency] | Currency was removed from the customer's balance | `VIRTUAL_CURRENCY_TRANSACTION` | |
| 30 | + |
| 31 | +### Event Details |
| 32 | + |
| 33 | +When you click on a virtual currency event in the Customer History, you can view additional details including: |
| 34 | + |
| 35 | +- The amount of currency granted or spent |
| 36 | +- The currency type and metadata |
| 37 | +- The product that triggered the transaction |
| 38 | +- The [source](/offerings/virtual-currency/events#source-values) of the transaction (`in_app_purchase`, `admin_api`) |
| 39 | + |
| 40 | +## Webhook Events |
| 41 | + |
| 42 | +RevenueCat sends `VIRTUAL_CURRENCY_TRANSACTION` webhook events whenever a virtual currency transaction occurs. These events provide detailed information about the transaction, including the amount, currency type, and source of the transaction. |
| 43 | + |
| 44 | +### When Events Are Sent |
| 45 | + |
| 46 | +Virtual currency webhook events are triggered in the following scenarios: |
| 47 | + |
| 48 | +- **In-app purchases**: When a customer purchases a product associated with virtual currency |
| 49 | +- **Subscription lifecycle**: For subscriptions that grant virtual currency, events are sent for the entire subscription lifecycle (initial purchase, renewals, refunds, etc.) whenever there is an adjustment to be made to the currency balance |
| 50 | +- **Manual adjustments via dashboard**: When virtual currency is manually adjusted through the dashboard |
| 51 | + |
| 52 | +### Event Structure |
| 53 | + |
| 54 | +Virtual currency webhook events include standard webhook fields plus virtual currency-specific fields. Here's an example of a virtual currency transaction event: |
| 55 | + |
| 56 | +import virtualCurrencyEvent from "@site/code_blocks/integrations/webhooks/sample-events_15.json?raw"; |
| 57 | + |
| 58 | +<RCCodeBlock |
| 59 | + tabs={[ |
| 60 | + { |
| 61 | + type: "json", |
| 62 | + content: virtualCurrencyEvent, |
| 63 | + }, |
| 64 | + ]} |
| 65 | +/> |
| 66 | + |
| 67 | +### Virtual Currency Specific Fields |
| 68 | + |
| 69 | +| Field | Type | Description | Possible Values | |
| 70 | +| ------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------- | ------------------------------ | |
| 71 | +| `adjustments` | Array | Array of virtual currency adjustments made in this transaction. Each adjustment contains the amount and currency details. | | |
| 72 | +| `adjustments[].amount` | Integer | The amount of virtual currency added (positive) or removed (negative) from the customer's balance. | | |
| 73 | +| `adjustments[].currency` | Object | Details about the virtual currency involved in the transaction. | | |
| 74 | +| `adjustments[].currency.code` | String | The unique identifier for the virtual currency. | | |
| 75 | +| `adjustments[].currency.name` | String | The display name of the virtual currency. | | |
| 76 | +| `adjustments[].currency.description` | String | The description of the virtual currency. | | |
| 77 | +| `product_display_name` | String | The display name of the product that triggered the virtual currency transaction. | | |
| 78 | +| `purchase_environment` | String | The environment where the product purchase was made. | `SANDBOX`, `PRODUCTION`. | |
| 79 | +| `source` | String | The source of the virtual currency transaction. | `in_app_purchase`, `admin_api` | |
| 80 | +| `virtual_currency_transaction_id` | String | Unique identifier for this virtual currency transaction. | | |
| 81 | + |
| 82 | +### Source Values |
| 83 | + |
| 84 | +The `source` field indicates what triggered the virtual currency balance adjustment: |
| 85 | + |
| 86 | +- `in_app_purchase`: Currency granted from a one-time or subscription purchase. This also includes the subscription lifecycle (initial purchase, renewals, refunds, etc.) whenever there is an adjustment to be made to the currency balance |
| 87 | +- `admin_api`: Currency was manually adjusted through the dashboard |
| 88 | + |
| 89 | +### Multiple Currency Adjustments |
| 90 | + |
| 91 | +A single webhook event can include adjustments for multiple virtual currency types. This is useful for scenarios like currency conversion or when a single purchase grants multiple types of currency. |
| 92 | + |
| 93 | +Example of a multi-currency transaction: |
| 94 | + |
| 95 | +```json |
| 96 | +{ |
| 97 | + "adjustments": [ |
| 98 | + { |
| 99 | + "amount": 1000, |
| 100 | + "currency": { |
| 101 | + "code": "GLD", |
| 102 | + "name": "Gold", |
| 103 | + "description": "Premium currency" |
| 104 | + } |
| 105 | + }, |
| 106 | + { |
| 107 | + "amount": 50, |
| 108 | + "currency": { |
| 109 | + "code": "SLV", |
| 110 | + "name": "Silver", |
| 111 | + "description": "Standard currency" |
| 112 | + } |
| 113 | + } |
| 114 | + ] |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +## Best Practices |
| 119 | + |
| 120 | +### Monitoring |
| 121 | + |
| 122 | +- **Balance Reconciliation**: Use webhook events to reconcile virtual currency balances with your internal systems |
| 123 | +- **Fraud Detection**: Monitor for unusual patterns in virtual currency transactions |
| 124 | +- **Customer Support**: Use timeline events to help customers understand their transaction history |
| 125 | + |
| 126 | +## Next Steps |
| 127 | + |
| 128 | +- [Webhook Event Types and Fields](/integrations/webhooks/event-types-and-fields#virtual-currency-transaction-fields) |
| 129 | +- [Customer History](/dashboard-and-metrics/customer-history) |
| 130 | +- [Virtual Currency Subscriptions](/offerings/virtual-currency/subscriptions) |
| 131 | +- [Virtual Currency Refunds](/offerings/virtual-currency/refunds) |
0 commit comments