jamesmontemagno / InAppBillingPlugin

Cross-platform In App Billing Plugin for .NET
MIT License
667 stars 153 forks source link

[Android] Migrated app to MAUI - GetPurchasesAsync returns no results #612

Open garnelsoftware opened 4 months ago

garnelsoftware commented 4 months ago

Firstly, thank you so much for this plugin - it has been vital for me since first installing it 3 years ago. However, since MAUI migration it's failing to work as expected.

My MAUI app, migrated from Xamarin, cannot restore purchases - GetPurchasesAsync is returning no results. If instead you choose to Purchase, it finds that the item is already owned.

Version Number of Plugin: 7.1.0 Device Tested On: Android (Samsung S21) Simulator Tested On: N/A Version of Rider: 2023.3

Start the app, press the button to restore purchases.

The existing purchase should be found BUT instead the app reports that there are no purchases found and thus will fail to restore (no results are returned from the GetPurchasesAsync call).

If you choose to make a purchase the app reports that the item is already owned and then the app recognises that the purchase has been made and effectively restores it.

sheharyarshahid commented 4 months ago

For me GetPurchasesAsync doesn't works for iOS. It returns nothings not even throw any exception and keeps on running.

electro-logic commented 3 months ago

Hello James, I have the same issue with MAUI 8.0.71 and InAppBillingPlugin 8.0.2 beta , GetPurchasesAsync is not returning on iOS

sheharyarshahid commented 3 months ago

My workaround was instead of calling GetPurchasesAsync function, I directly call PurchaseAsync (iOS only) and it would work fine. If user is already subscribed, it will return purchase token of that specific purchase. Otherwise it will start new purchase

electro-logic commented 3 months ago

Ok guys, I found the issue and I have a fix for the .net 8 branch.

In InAppBilling.ios.cs in the RestoreAsync() method (line 247) there is

return tcsTransaction.Task

change it with

var result = await tcsTransaction.Task;
return result;

to avoid issue with the finally statement that unsubscribe the handler. From my preliminary testing, with this patch everything works fine on the iPhone.

https://github.com/jamesmontemagno/InAppBillingPlugin/pull/621/files

This fix is related to many issues, not only #612

jamesmontemagno commented 3 months ago

I am not sure how that would fix anything as it would be doing the same thing....

jamesmontemagno commented 3 months ago

@electro-logic will push out 8.0.3, but that isn't related to this at all as they are saying it is android

electro-logic commented 3 months ago

Hello James, yes my reply was to sheharyarshahid that was mentioning iOS as not working.