Refactor syncing pending transactions logic out of Purchases#1058
Conversation
tonidero
left a comment
There was a problem hiding this comment.
The diff actually increases a lot, but most of it are tests... As I refactor this, I see some opportunities to test more things and it ends up growing...
There was a problem hiding this comment.
This has been moved to PostTransactionWithProductDetailsHelper
There was a problem hiding this comment.
This has been moved to SyncPendingTransactionsHelper
There was a problem hiding this comment.
The callback didn't exist before. Right now it's unused, but my plan is to use it once we want to sync purchases before fetching customer info.
There was a problem hiding this comment.
Note how I'm calling the error callback if any of the requests in the sync fails.
There was a problem hiding this comment.
Almost to 3k lines 😓. Hopefully we can get this thinner with these refactors.
Codecov Report
@@ Coverage Diff @@
## main #1058 +/- ##
==========================================
+ Coverage 85.76% 85.84% +0.08%
==========================================
Files 176 179 +3
Lines 6265 6336 +71
Branches 864 876 +12
==========================================
+ Hits 5373 5439 +66
+ Misses 557 556 -1
- Partials 335 341 +6
|
2a4f9b1 to
a3172f6
Compare
89fd8ba to
f46db41
Compare
There was a problem hiding this comment.
Sync might be confusingly mistaken with sync purchases. Maybe PostPendingTransactionsHelper would be better?
53de5f0 to
7a6f2a5
Compare
f46db41 to
d3cdbcc
Compare
There was a problem hiding this comment.
This test name should specify that autosync is false. So something like "If autosync is disabled, and sync is called, success callback with null value is called`
d3cdbcc to
4a44b45
Compare
### Description Followup to #1052 and #1058 This changes the behavior of fetching customer info. Now, when fetching customer info, we will first try to sync any pending purchases if any. If there are pending purchases, we will return the customer info from the last request sent. If there aren't, we will then hit the current customer info endpoint to get the latest customer info.
**This is an automatic release.** ### Bugfixes * Default customer info schema version to latest known by SDK (#1080) via Toni Rico (@tonidero) * Handle other diagnostics-related exceptions (#1076) via Toni Rico (@tonidero) * Return error in queryPurchases if error connecting to billing client (#1072) via Toni Rico (@tonidero) ### Other Changes * Fix offline entitlements integration tests (#1085) via Toni Rico (@tonidero) * Add defaultsRelease variant tests run configuration (#1074) via Toni Rico (@tonidero) * Compose sample app: move to gradle catalog (#1081) via Toni Rico (@tonidero) * Compose sample app: automate builds (#1082) via Toni Rico (@tonidero) * Compose sample app (#1056) via Toni Rico (@tonidero) * Migrate to Gradle version catalog (#1059) via Cesar de la Vega (@vegaro) * Trusted entitlements: Add logs with verification mode (#1067) via Toni Rico (@tonidero) * Sync pending purchases before getting customer info (#1073) via Toni Rico (@tonidero) * Refactor syncing pending transactions logic out of `Purchases` (#1058) via Toni Rico (@tonidero) * Refactor CustomerInfo listener and cache logic into CustomerInfoUpdater (#1052) via Toni Rico (@tonidero) * Trusted entitlements: Add integration tests (#1071) via Toni Rico (@tonidero) * Trusted entitlements: Add internal mechanism to force signing errors for tests (#1070) via Toni Rico (@tonidero) Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Description
SDK-3155
This is another refactor in the process of posting unsynced purchases before doing customer info requests, to make sure the information received from the backend is up to date.
In this PR, we are extracting the logic that syncs purchases on app foreground out of
Purchasesand added a callback to that process. The idea is to reuse the same logic when trying to fetch customer info first, and if that returns an empty customer info (that is, no unsynced purchases), then we actually fetch customer info from the backend.