Skip to content

Fix billing connection error when querying purchases early in the process lifetime#1032

Merged
tonidero merged 2 commits into
mainfrom
fix-play-billing-connection-error
May 30, 2023
Merged

Fix billing connection error when querying purchases early in the process lifetime#1032
tonidero merged 2 commits into
mainfrom
fix-play-billing-connection-error

Conversation

@tonidero

@tonidero tonidero commented May 30, 2023

Copy link
Copy Markdown
Contributor

Description

With the addition of offline entitlements, we query active purchases early in the process lifetime. This sometimes resulted in the billing client connection not being established at that point in time and not calculating offline entitlements (returning an error).

This PR fixes those errors by making the queryPurchases method execute AFTER the billing client connection has been established. We already do this in all other methods that interact with the billing client except this one, so it seemed like a bug.

@tonidero tonidero added the pr:fix A bug fix label May 30, 2023
@tonidero tonidero requested a review from a team May 30, 2023 10:25
val mapOfActiveSubscriptions =
activeSubsPurchases.toMapOfGooglePurchaseWrapper(BillingClient.ProductType.SUBS)
executeRequestOnUIThread {
withConnectedClient {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only change here is wrapping the existing code inside the executeRequestOnUIThread method, which already has the logic to execute the block AFTER the billing client connection has been established. We already do this in all methods that interact with the billing client, except this one.

@tonidero tonidero marked this pull request as ready for review May 30, 2023 10:28
@codecov

codecov Bot commented May 30, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1032 (94b865d) into main (faf63e5) will increase coverage by 0.00%.
The diff coverage is 60.00%.

@@           Coverage Diff           @@
##             main    #1032   +/-   ##
=======================================
  Coverage   85.54%   85.54%           
=======================================
  Files         175      175           
  Lines        6122     6123    +1     
  Branches      857      857           
=======================================
+ Hits         5237     5238    +1     
  Misses        550      550           
  Partials      335      335           
Impacted Files Coverage Δ
.../com/revenuecat/purchases/google/BillingWrapper.kt 80.78% <60.00%> (+0.04%) ⬆️

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense

}

@Test
fun `defers query purchases if client not connected`() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@tonidero tonidero merged commit e5d9ac8 into main May 30, 2023
@tonidero tonidero deleted the fix-play-billing-connection-error branch May 30, 2023 13:55
tonidero added a commit that referenced this pull request Jun 1, 2023
**This is an automatic release.**

### New Features
* Offline entitlements support (#1030) via Toni Rico (@tonidero)
### Bugfixes
* Fix billing connection error when querying purchases early in the
process lifetime (#1032) via Toni Rico (@tonidero)
### Performance Improvements
* Perform product entitlement mapping request after more critical
requests (#1017) via Toni Rico (@tonidero)
### Dependency Updates
* Bump fastlane from 2.212.2 to 2.213.0 (#1024) via dependabot[bot]
(@dependabot[bot])
### Other Changes
* Get offerings response from disk cache if available (#1029) via Toni
Rico (@tonidero)
* Improve offline entitlements logs to mention limitations of this mode
(#1039) via Toni Rico (@tonidero)
* Improve error message when backend returns internal error code (#1038)
via Toni Rico (@tonidero)
* PurchaseTester: Add new UI to configure internal proxy behavior
(#1016) via Toni Rico (@tonidero)
* Updated readme to include links to migration guides (#1021) via Marcos
Castany (@mcastany)
* Store offerings response in SharedPreferences (#1028) via Toni Rico
(@tonidero)
* Refactor offerings code out of Purchases (#1027) via Toni Rico
(@tonidero)

---------

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
Co-authored-by: Toni Rico <antonio.rico.diez@revenuecat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants