Skip to content

Commit 5a98107

Browse files
authored
add VC capacitor docs (#1017)
1 parent 06de14e commit 5a98107

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Fetch virtual currencies
2+
try {
3+
const { virtualCurrencies } = await Purchases.getVirtualCurrencies();
4+
// TODO: Handle virtual currencies
5+
} catch (error) {
6+
// TODO: Handle error
7+
}
8+
9+
// Get the details of a specific virtual currency
10+
const virtualCurrency = virtualCurrencies.all['<virtual_currency_code>'];
11+
const balance = virtualCurrency.balance;
12+
const name = virtualCurrency.name;
13+
const code = virtualCurrency.code;
14+
15+
// Keep in mind that serverDescription may be null if no description was provided
16+
// in the RevenueCat dashboard
17+
const serverDescription = virtualCurrency.serverDescription;
18+
19+
// Iterate through all virtual currencies
20+
for (const [virtualCurrencyCode, virtualCurrency] of Object.entries(virtualCurrencies.all)) {
21+
console.log(`${virtualCurrency.code}: ${virtualCurrency.balance}`);
22+
}

docs/offerings/virtual-currency.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ import fetchVCBalancesKotlin from "@site/code_blocks/virtual-currency/vc-balance
9999
import fetchVCBalancesJava from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.java?raw";
100100
import fetchVCBalancesReactNative from "@site/code_blocks/virtual-currency/vc-balance-sdk-react-native.ts?raw";
101101
import fetchVCBalancesFlutter from "@site/code_blocks/virtual-currency/vc-balance-sdk-flutter.dart?raw";
102+
import fetchVCBalancesCapacitor from "@site/code_blocks/virtual-currency/virtual-currency-balance-capacitor.ts?raw";
102103

103104
Fetching virtual currency balances is supported in the following SDK versions:
104105

@@ -108,6 +109,7 @@ Fetching virtual currency balances is supported in the following SDK versions:
108109
| Android SDK | 9.1.0+ |
109110
| React Native SDK | 9.1.0+ |
110111
| Flutter SDK | 9.1.0+ |
112+
| Capacitor SDK | 11.1.0+ |
111113

112114
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.
113115

@@ -138,6 +140,11 @@ You can use the `virtualCurrencies()` function to retrieve a customer's balance.
138140
title: "Flutter",
139141
content: fetchVCBalancesFlutter,
140142
},
143+
{
144+
type: "capacitor",
145+
title: "Capacitor",
146+
content: fetchVCBalancesCapacitor,
147+
},
141148
]}
142149
/>
143150

0 commit comments

Comments
 (0)