-
Notifications
You must be signed in to change notification settings - Fork 82
Virtual Currency Support #2519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual Currency Support #2519
Conversation
This PR includes the following PRs with no other changes: - #2466 - #2496 - #2505 It is the collection of all of the work required to update the VC APIs and fetch the virtual currencies from the new v1 endpoint. To keep the PR sizes manageable, the work was broken up into smaller PRs, which have been individually approved and aggregated into this branch. Forgoing a review on this PR since all changes have already been reviewed, and we'll do a final review when we merge `virtual-currency-dev` into `main`
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2519 +/- ##
==========================================
+ Coverage 78.10% 78.23% +0.13%
==========================================
Files 286 291 +5
Lines 10573 10772 +199
Branches 1485 1504 +19
==========================================
+ Hits 8258 8428 +170
- Misses 1668 1692 +24
- Partials 647 652 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
return Date(preferences.getLong(virtualCurrenciesLastUpdatedCacheKey(appUserID), 0)) | ||
} | ||
|
||
private fun SharedPreferences.Editor.clearVirtualCurrenciesCacheTimestamp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since clearVirtualCurrenciesCache
and clearVirtualCurrenciesCacheTimestamp
are always called together, consider merging them into a single function like:
fun SharedPreferences.Editor.clearVirtualCurrenciesCacheAndTimestamp(appUserID: String): SharedPreferences.Editor
This would reduce call-site verbosity, clarify intent, and prevent potential future inconsistencies where one might be called without the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be good to keep as a separate private method to avoid bloating the clearVirtualCurrenciesCache
method but I do agree we should probably only use clearVirtualCurrenciesCache
generally.
There may be cases where we want to clear the timestamp and not the data, for example, if we want to force a stale cache. However, we're not doing that right now, so I do think this makes sense (we can always modify in the future if needed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Just some small comments but nothing blocking!
purchases/src/main/kotlin/com/revenuecat/purchases/virtualcurrencies/VirtualCurrencies.kt
Show resolved
Hide resolved
purchases/src/main/kotlin/com/revenuecat/purchases/virtualcurrencies/VirtualCurrencyManager.kt
Outdated
Show resolved
Hide resolved
purchases/src/main/kotlin/com/revenuecat/purchases/common/caching/DeviceCache.kt
Show resolved
Hide resolved
return Date(preferences.getLong(virtualCurrenciesLastUpdatedCacheKey(appUserID), 0)) | ||
} | ||
|
||
private fun SharedPreferences.Editor.clearVirtualCurrenciesCacheTimestamp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be good to keep as a separate private method to avoid bloating the clearVirtualCurrenciesCache
method but I do agree we should probably only use clearVirtualCurrenciesCache
generally.
There may be cases where we want to clear the timestamp and not the data, for example, if we want to force a stale cache. However, we're not doing that right now, so I do think this makes sense (we can always modify in the future if needed).
…purchases-android into virtual-currency-dev
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚢
📸 Snapshot Test648 unchanged
🛸 Powered by Emerge Tools |
…purchases-android into virtual-currency-dev
…purchases-android into virtual-currency-dev
**This is an automatic release.** ## RevenueCat SDK ### Virtual Currency #### ✨ New Features * Virtual Currency Support (#2519) via Will Taylor (@fire-at-will) ## RevenueCatUI SDK ### Paywallv2 #### ✨ New Features * PaywallActivityLauncher: Add `edgeToEdge` parameter to display paywall in full screen (#2530) via Toni Rico (@tonidero) #### 🐞 Bugfixes * Remove logic to avoid repurchasing already subscribed products (#2492) via Toni Rico (@tonidero) ### 🔄 Other Changes * Dont run VC tests on load shedder integration tests (#2538) via Will Taylor (@fire-at-will) * Introduces `CompatComposeView` to handle scenarios where the view tree is not set up (#2527) via JayShortway (@JayShortway) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Android counterpart to RevenueCat/purchases-ios#5108. This PR introduces virtual currencies to the Android SDK. It's a large PR, but all parts of it have been reviewed individually before here: - #2466 - #2496 - #2505 It includes the following: These functions allow you to fetch the virtual currencies for the current subscriber. The `invalidateVirtualCurrenciesCache` function allows developers to clear the cached virtual currencies, which will then force the refreshing of the virtual currencies from the backend the next time `getVirtualCurrencies()` is called. ```kotlin class Purchases { fun getVirtualCurrencies( callback: GetVirtualCurrenciesCallback, ) fun invalidateVirtualCurrenciesCache() val cachedVirtualCurrencies: VirtualCurrencies? } ``` ```kotlin class VirtualCurrencies internal constructor( val all: Map<String, VirtualCurrency>, ) : Parcelable { operator fun get(code: String): VirtualCurrency? = all[code] } class VirtualCurrency internal constructor( val balance: Int, val name: String, val code: String, val serverDescription: String? = null, ) ``` Kotlin: ```swift Purchases.sharedInstance.invalidateVirtualCurrenciesCache() Purchases.sharedInstance.getVirtualCurrencies( object: GetVirtualCurrenciesCallback { override fun onReceived(virtualCurrencies: VirtualCurrencies) {} override fun onError(error: PurchasesError) {} } ) Purchases.sharedInstance.getVirtualCurrenciesWith( onError = { _: PurchasesError -> }, onSuccess = { _: VirtualCurrencies -> }, ) val getVirtualCurrenciesResult: VirtualCurrencies = Purchases.sharedInstance.awaitGetVirtualCurrencies() val cachedVirtualCurrencies = Purchases.sharedInstance.cachedVirtualCurrencies ```
Description
Android counterpart to RevenueCat/purchases-ios#5108.
This PR introduces virtual currencies to the Android SDK. It's a large PR, but all parts of it have been reviewed individually before here:
It includes the following:
New APIs for Fetching Virtual Currency Balances + Metadata
New Top-Level Functions
These functions allow you to fetch the virtual currencies for the current subscriber. The
invalidateVirtualCurrenciesCache
function allows developers to clear the cached virtual currencies, which will then force the refreshing of the virtual currencies from the backend the next timegetVirtualCurrencies()
is called.New Objects
Example Usage
Kotlin: