Skip to content
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

onPurchasedProductsFetched is always called twice #46

Open
lioriluz opened this issue Oct 30, 2022 · 4 comments
Open

onPurchasedProductsFetched is always called twice #46

lioriluz opened this issue Oct 30, 2022 · 4 comments

Comments

@lioriluz
Copy link

onPurchasedProductsFetched is called twice on connect().
One time with purchases empty and once with purchases as expected (in case the user purchased).
The worst thing is that there's a race condition so you can't even write a logic based on skipping the first time as sometimes this is the correct data, followed by the false data.

It doesn't help to connect before setting the listener or after.

@rajagrawal1
Copy link

onPurchasedProductsFetched is called twice on connect(). One time with purchases empty and once with purchases as expected (in case the user purchased). The worst thing is that there's a race condition so you can't even write a logic based on skipping the first time as sometimes this is the correct data, followed by the false data.

It doesn't help to connect before setting the listener or after.

I had the same issue. If your device supports subscriptions, then the code sends first callback to onPurchasedProductsFetched(..) and second one containing the actual purchase history you are interested in. This is how the library is designed currently.

In my case, I am only interested in INAPP purchases so I skipped all redundant callbacks by checking productType == ProductType.INAPP.

@moisoni97
Copy link
Owner

I've never had any problems restoring purchases with my app, but I'm only using INAPP
What's the status of the issue? Checking the productType is a workaround or still having issues?

@lioriluz
Copy link
Author

It helps for sure. I still have some reports from users saying they "lose" their Pro purchase experience but I didn't check yet if it's a lib issue or my own implementation issue. I can say that it started happening since I switched to this lib and only when the user opens the app after it was in the background for a while (Don't keep activities doesn't reproduce the same conditions unfortunately).

@moisoni97
Copy link
Owner

moisoni97 commented Mar 16, 2023

The onPurchasedProductsFetched is MEANT to be called twice, once for each product type (IN-APP and SUBS).
Try to follow the logic from the RemoveAdsExampleActivity...

Also, it's good to know that Google Billing API returns purchases details for currently owned items without a network request using the Google Play Store cache... that's why Google recommends to handle purchases and security on your server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants