jamesmontemagno / InAppBillingPlugin

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

billing.PurchaseAsync never returns after completing the purchase #614

Closed RicovanBuren closed 4 months ago

RicovanBuren commented 4 months ago

Bug Information

Version Number of Plugin: 7.1 Device Tested On: OnePlus 6 (Android 12), Oppo Find X3 Pro (Android 14) Simulator Tested On: none Version of VS: Visual Studio Professional 2022 (17.10.3) Version of Xamarin: 5.00.2337 Versions of other things you are using: -

Steps to reproduce the Behavior

Connect using await billing.ConnectAsync(); and check if we are connected. Purchase the subscription: var purchase = await billing.PurchaseAsync(productId, Plugin.InAppBilling.ItemType.Subscription);

Expected Behavior

billing.PurchaseAsync returns the purchase after buying the subscription through Google Play

Actual Behavior

billing.PurchaseAsync never returns after buying the subscription through Google Play. After closing and reopening the page in the app a Task Was Canceled Exception is thrown

  at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productSku, System.String itemType, System.String obfuscatedAccountId, System.String obfuscatedProfileId, System.String subOfferToken) [0x00215] in D:\a\1\s\src\Plugin.InAppBilling\InAppBilling.android.cs:394 
  at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productId, Plugin.InAppBilling.ItemType itemType, System.String obfuscatedAccountId, System.String obfuscatedProfileId, System.String subOfferToken) [0x0015e] in D:\a\1\s\src\Plugin.InAppBilling\InAppBilling.android.cs:342 
  at AddressReadApp2.Pages.ContractPage2.purchase (System.Boolean yearly) [0x002c4] in ...\Pages\ContractPage2.xaml.cs:868 

However the payment is accepted and is created in Google Play. Checking for the purchased items does return the subscription and it can be activated by calling await billing.ConsumePurchaseAsync(purchase.ProductId, purchase.TransactionIdentifier);

Code snippet

        var connected = await billing.ConnectAsync();
        if (!connected)
        {
            //we are offline or can't connect, don't try to purchase
            return false;
        }

        //check purchases
        var purchase = await billing.PurchaseAsync(productId, ItemType.Subscription);