Skip to content

Commit ba034a0

Browse files
authored
update vc docs for android release (#996)
1 parent 31053c8 commit ba034a0

File tree

3 files changed

+71
-37
lines changed

3 files changed

+71
-37
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Fetch virtual currencies
2+
Purchases.sharedInstance.getVirtualCurrencies(
3+
new GetVirtualCurrenciesCallback() {
4+
@Override
5+
public void onReceived(@NonNull VirtualCurrencies virtualCurrencies) {
6+
// TODO: Handle virtual currencies
7+
}
8+
9+
@Override
10+
public void onError(@NonNull PurchasesError error) {
11+
// TODO: Handle error
12+
}
13+
}
14+
);
15+
16+
// Get the details of a specific virtual currency
17+
VirtualCurrency virtualCurrency = virtualCurrencies.getAll().get("");
18+
int balance = virtualCurrency.getBalance();
19+
String name = virtualCurrency.getName();
20+
String code = virtualCurrency.getCode();
21+
22+
// Keep in mind that serverDescription may be null if no description was provided
23+
// in the RevenueCat dashboard
24+
String serverDescription = virtualCurrency.getServerDescription();
25+
26+
// Iterate through all virtual currency balances
27+
virtualCurrencies.getAll().forEach((key, virtualCurrency) -> {
28+
System.out.println(virtualCurrency.getCode() + ": " + virtualCurrency.getBalance());
29+
});
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
1-
// Don't forget to opt in to experimental RevenueCat APIs with
2-
// @OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)
1+
// Fetch virtual currencies
2+
// With coroutines
3+
try {
4+
val getVirtualCurrenciesResult: VirtualCurrencies = Purchases.sharedInstance.awaitGetVirtualCurrencies()
5+
// TODO: Handle virtual currencies
6+
} catch(error: PurchasesException) {
7+
// TODO: Handle error
8+
}
39

4-
// Get the balance of a specific virtual currency
5-
val balance = customerInfo.virtualCurrencies[<your_virtual_currency_code>]?.balance
10+
// With callbacks
11+
Purchases.sharedInstance.getVirtualCurrenciesWith(
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+
val description = virtualCurrency?.serverDescription
626

727
// Iterate through all virtual currency balances
8-
for((virtualCurrencyCode, virtualCurrencyInfo) in customerInfo.virtualCurrencies) {
9-
println("$virtualCurrencyCode: ${virtualCurrencyInfo.balance}")
28+
for ((virtualCurrencyCode, virtualCurrency) in virtualCurrencies.all) {
29+
println("$virtualCurrencyCode: ${virtualCurrency.balance}")
1030
}

docs/offerings/virtual-currency.mdx

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,7 @@ Virtual currency functionality is available in the native iOS SDK in versions 5.
5050

5151
### Android
5252

53-
When adding the purchases-android SDK to your app, use the most recent `vc-beta` version when adding `purchases-android` to your `build.gradle`:
54-
55-
[![Latest Virtual Currency Android Beta Release](https://img.shields.io/github/release/RevenueCat/purchases-android.svg?filter=*vc-beta*&style=flat)](https://github.com/RevenueCat/purchases-android/releases)
56-
57-
```kotlin
58-
// build.gradle
59-
60-
implementation 'com.revenuecat.purchases:purchases:8.14.2-vc-beta.1'
61-
```
62-
63-
When you use the beta virtual currency features, you’ll need to annotate your function/class with the `@OptIn(ExperimentalPreviewRevenueCatPurchasesAPI::class)` annotation:
64-
65-
import androidExperimentalAPIAnnotationExample from "@site/code_blocks/virtual-currency/vc-android-experimental-api-annotation-example.kt?raw";
66-
67-
<RCCodeBlock
68-
tabs={[
69-
{
70-
type: "kotlin",
71-
content: androidExperimentalAPIAnnotationExample,
72-
},
73-
]}
74-
/>
53+
Virtual currency functionality is available in the native Android SDK in versions 9.1.0 and above.
7554

7655
### React Native
7756

@@ -152,9 +131,11 @@ import content5 from "@site/code_blocks/virtual-currency/balance-response.json?r
152131

153132
#### From the SDK
154133

155-
##### iOS
134+
##### iOS and Android
156135

157136
import fetchVCBalancesSwift from "@site/code_blocks/virtual-currency/vc-balance-sdk-ios.swift?raw";
137+
import fetchVCBalancesKotlin from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.kt?raw";
138+
import fetchVCBalancesJava from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.java?raw";
158139

159140
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.
160141

@@ -165,6 +146,16 @@ You can use the `virtualCurrencies()` function to retrieve a customer's balance.
165146
content: fetchVCBalancesSwift,
166147
name: "Swift",
167148
},
149+
{
150+
type: "kotlin",
151+
content: fetchVCBalancesKotlin,
152+
name: "Kotlin",
153+
},
154+
{
155+
type: "java",
156+
content: fetchVCBalancesJava,
157+
name: "Java",
158+
},
168159
]}
169160
/>
170161

@@ -186,21 +177,15 @@ import cachedVirtualCurrenciesSwift from "@site/code_blocks/virtual-currency/cac
186177
]}
187178
/>
188179

189-
##### Android, React Native, and Flutter
180+
##### React Native and Flutter
190181

191-
If you're using the virtual currency SDK betas for Android, React Native, and Flutter, you can fetch the virtual currency balances from the [CustomerInfo](https://www.revenuecat.com/docs/customers/customer-info) object in the SDK:
182+
If you're using the virtual currency SDK betas for React Native or Flutter, you can fetch the virtual currency balances from the [CustomerInfo](https://www.revenuecat.com/docs/customers/customer-info) object in the SDK:
192183

193-
import fetchVCBalancesKotlin from "@site/code_blocks/virtual-currency/vc-balance-sdk-android.kt?raw";
194184
import fetchVCBalancesReactNative from "@site/code_blocks/virtual-currency/vc-balance-sdk-react-native.ts.txt?raw";
195185
import fetchVCBalancesFlutter from "@site/code_blocks/virtual-currency/vc-balance-sdk-flutter.dart?raw";
196186

197187
<RCCodeBlock
198188
tabs={[
199-
{
200-
type: "kotlin",
201-
content: fetchVCBalancesKotlin,
202-
name: "Kotlin",
203-
},
204189
{
205190
type: "rn",
206191
content: fetchVCBalancesReactNative,

0 commit comments

Comments
 (0)