Add completion callback to syncPurchases API#1002
Conversation
There was a problem hiding this comment.
I'm usually not a big fan of local functions, but I thought it was useful here. Lmk if you have any concerns or suggestions though!
There was a problem hiding this comment.
I added this new warning to the documentation so developers consider whether they need to wait for this to continue when using this function.
Codecov Report
@@ Coverage Diff @@
## main #1002 +/- ##
==========================================
+ Coverage 85.39% 85.52% +0.12%
==========================================
Files 169 169
Lines 6006 6036 +30
Branches 841 840 -1
==========================================
+ Hits 5129 5162 +33
+ Misses 545 543 -2
+ Partials 332 331 -1
|
There was a problem hiding this comment.
Note that this is slightly different than in iOS. In iOS, we would use the response from the post receipt request directly since we only do a single post receipt. In android, since we may be doing multiple requests is a bit more complex... we could use the result from the last post receipt, but there could be edge cases so I decided to just grab it from cache directly after all requests are done.
I also thought about initiating a fetch when there is no cached value to try to avoid failing when we don't have a cached customer info cached yet and there are no purchases... The window for that to happen is small though I think and the use cases for the sync purchases method would make that window even smaller. Also, we don't do that in iOS. So I thought we can go with cache only for now.
There was a problem hiding this comment.
That window could exist if calling syncPurchases right after configure? If there are no purchases and no cached info has been retrieved. What's the problem with doing a CacheFetchPolicy CACHED_OR_FETCHED to prevent that from happening.
There was a problem hiding this comment.
Hmm rethinking about it, I don't think it would be an issue... It might result in extra fetches when developers use syncPurchases, but it shouldn't be a big issue. Will change that
There was a problem hiding this comment.
Could this appInBackground = false be problematic if someone is calling syncPurchases from the background?
There was a problem hiding this comment.
This is used to detect whether the cached customer info is stale or not. If it's in the background, it won't be considered stale until it's 25h old. So potentially, this being hardcoded to false can cause an increase in requests to the get customer info endpoint.
So I thought that considering the use cases for syncPurchases, users shouldn't really call it with the app in the background... But I think it's better to be safe than sorry, so I can pass that as a parameter to avoid an increase too big.
74dc4f2 to
014d7e0
Compare
…s much as possible
014d7e0 to
518043d
Compare
**This is an automatic release.** ### New Features * Support DEFERRED mode (#985) via swehner (@swehner) * Add completion callback to syncPurchases API (#1002) via Toni Rico (@tonidero) ### Bugfixes * Workaround bug in android 4 for JSON objects with List<String> (#942) via Andy Boedo (@aboedo) ### Dependency Updates * Bump fastlane-plugin-revenuecat_internal from `fe45299` to `13773d2` (#1015) via dependabot[bot] (@dependabot[bot]) ### Other Changes * Bump dokka to 1.8.10 to support Gradle 8 (#1009) via Toni Rico (@tonidero) * Disable offline entitlements temporarily (#1023) via Toni Rico (@tonidero) * Fix integration tests in CI (#1019) via Toni Rico (@tonidero) * Add offline entitlements integration tests (#1006) via Toni Rico (@tonidero) * Disable offline entitlements in observer mode (#1014) via Toni Rico (@tonidero) * Extracts setup and teardown to BasePurchasesTest (#1011) via Cesar de la Vega (@vegaro) * Support forcing server errors for tests (#1008) via Toni Rico (@tonidero) --------- Co-authored-by: revenuecat-ops <ops@revenuecat.com> Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Description
This PR adds a new optional parameter to the
syncPurchasesfunction containing a success and error callbacks for that operation. Also added a new Kotlin-only versionsyncPurchasesWithto provide an easier Kotlin API.Additionally, while doing this, I decided to move the logic from
syncPurchasesto a newSyncPurchasesHelper, so it can be better tested in isolation.