Skip to content

Commit f68f206

Browse files
authored
Add KMP VC docs (#1050)
1 parent faf3054 commit f68f206

File tree

2 files changed

+48
-12
lines changed

2 files changed

+48
-12
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Fetch virtual currencies
2+
// With coroutines
3+
try {
4+
val virtualCurrencies: VirtualCurrencies = Purchases.sharedInstance.awaitVirtualCurrencies()
5+
// TODO: Handle virtual currencies
6+
} catch(error: PurchasesException) {
7+
// TODO: Handle error
8+
}
9+
10+
// With callbacks
11+
Purchases.sharedInstance.getVirtualCurrencies(
12+
onError = { error: PurchasesError ->
13+
// TODO: Handle error
14+
},
15+
onSuccess = { virtualCurrencies: VirtualCurrencies ->
16+
// TODO: Handle virtual currencies
17+
},
18+
)
19+
20+
// Get the details of a specific virtual currency
21+
val virtualCurrency = virtualCurrencies.all[<your_virtual_currency_code>]
22+
val balance = virtualCurrency?.balance
23+
val name = virtualCurrency?.name
24+
val code = virtualCurrency?.code
25+
26+
// Keep in mind that serverDescription may be null if no description was provided
27+
// in the RevenueCat dashboard
28+
val description = virtualCurrency?.serverDescription
29+
30+
// Iterate through all virtual currencies
31+
for ((virtualCurrencyCode, virtualCurrency) in virtualCurrencies.all) {
32+
println("$virtualCurrencyCode: ${virtualCurrency.balance}")
33+
}

docs/offerings/virtual-currency.mdx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,19 @@ import fetchVCBalancesReactNative from "@site/code_blocks/virtual-currency/vc-ba
101101
import fetchVCBalancesFlutter from "@site/code_blocks/virtual-currency/vc-balance-sdk-flutter.dart?raw";
102102
import fetchVCBalancesCapacitor from "@site/code_blocks/virtual-currency/virtual-currency-balance-capacitor.ts?raw";
103103
import fetchVCBalancesUnity from "@site/code_blocks/virtual-currency/vc-balance-unity.cs?raw";
104+
import fetchVCBalancesKMP from "@site/code_blocks/virtual-currency/vc-balance-sdk-kmp.kt?raw";
104105

105106
Fetching virtual currency balances is supported in the following SDK versions:
106107

107-
| SDK | Supported Versions |
108-
| ---------------- | ------------------ |
109-
| iOS SDK | 5.32.0+ |
110-
| Android SDK | 9.1.0+ |
111-
| React Native SDK | 9.1.0+ |
112-
| Flutter SDK | 9.1.0+ |
113-
| Capacitor SDK | 11.1.0+ |
114-
| Unity SDK | 8.1.0+ |
108+
| SDK | Supported Versions |
109+
| ---------------- | -------------------------- |
110+
| iOS SDK | 5.32.0+ |
111+
| Android SDK | 9.1.0+ |
112+
| React Native SDK | 9.1.0+ |
113+
| Flutter SDK | 9.1.0+ |
114+
| Capacitor SDK | 11.1.0+ |
115+
| Unity SDK | 8.1.0+ |
116+
| KMP SDK | 2.1.0+16.2.0+ |
115117

116118
You can use the `virtualCurrencies()` function to retrieve a customer's balance. The function returns a `VirtualCurrencies` object, which includes the customer's balances along with each virtual currency's metadata.
117119

@@ -152,6 +154,11 @@ You can use the `virtualCurrencies()` function to retrieve a customer's balance.
152154
content: fetchVCBalancesUnity,
153155
name: "Unity"
154156
},
157+
{
158+
type: "kotlin",
159+
title: "Kotlin Multiplatform",
160+
content: fetchVCBalancesKMP,
161+
},
155162
]}
156163
/>
157164

@@ -175,10 +182,6 @@ import cachedVirtualCurrenciesSwift from "@site/code_blocks/virtual-currency/cac
175182
]}
176183
/>
177184

178-
##### Hybrid SDK Support
179-
180-
Virtual currency support in the hybrid SDKs is coming soon!
181-
182185
### Depositing or spending
183186

184187
You can deposit or spend currency by calling the [virtual currency transactions Developer API endpoint](https://www.revenuecat.com/docs/api-v2#tag/Customer/operation/create-virtual-currencies-transaction) from the backend of your app:

0 commit comments

Comments
 (0)