jamesmontemagno / InAppBillingPlugin

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

PurchaseAsync threw exception of InAppBillingPurchaseException: Unable to process purchase #284

Closed hs79hs closed 2 years ago

hs79hs commented 4 years ago

Hi, I followed instructions of this plugin and created test product id on play store to try, ios works, but on Android, PurchaseAsync always threw an exception of InAppBillingPurchaseException: Unable to process purchase, like this,

{Plugin.InAppBilling.Abstractions.InAppBillingPurchaseException: Unable to process purchase. 
    at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productSku, System.String itemType, System.String payload,  Plugin.InAppBilling.Abstractions.IInAppBillingVerifyPurchase verifyPurchase) [0x00188] in C:\projects\inappbillingplugin\src\Plugin.InAppBilling.Android\InAppBillingImplementation.cs:337 
    at Plugin.InAppBilling.InAppBillingImplementation.PurchaseAsync (System.String productId, Plugin.InAppBilling.Abstractions.ItemType itemType, System.String payload, Plugin.InAppBilling.Abstractions.IInAppBillingVerifyPurchase verifyPurchase) [0x00108] in C:\projects\inappbillingplugin\src\Plugin.InAppBilling.Android\InAppBillingImplementation.cs:267 

I tried on several Android phones and got the same exception. And I tried to do those steps again, no luck. Could someone hit me a clue? Thanks.

My code likes

               var billing = CrossInAppBilling.Current;

        try
        {
            var connected = await billing.ConnectAsync(ItemType.Subscription);
            if (!connected)
            {
                return false;
            }

            // for test
            productId = "test_product_id";
            var purchase = await billing.PurchaseAsync(productId, ItemType.Subscription, payload);

            //possibility that a null came through.
            if (purchase == null)
            {
                //did not purchase
            }
            else
            {
                //purchased!
            }
        }
        catch (InAppBillingPurchaseException purchaseEx)
        {
            //Billing Exception handle this based on the type
            // this is where Android threw exception of InAppBillingPurchaseException: Unable to process purchase
            Console.WriteLine("Error: " + purchaseEx);
            return false;
        }
        catch (Exception ex)
        {
            Console.WriteLine("Issue connecting: " + ex);
            return false;
        }
        finally
        {
            await billing.DisconnectAsync();
        }

        return true;
jamesmontemagno commented 2 years ago

Try latest packages and make sure things are configured via documentation