Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin.InAppBilling (2.2.0) Android BuyProduct() invoked but callbacks sometimes not invoked - How to diagnose/fix root cause?

The last couple of weeks we have been experiencing a number of failed In-App Purchase failures on Android (iOS has been fine).

We use the Xamarin.InAppBilling component (version 2.2.0) which has been absolutely fine for many months, but recently we can see that we are invoking line (A) but the usual IAP callbacks are not being invoked, which implies...

  • Google doesn't receive the purchase request - we can rule this out, they are being charged.

  • Google doesn't reply - Our most likely scenario

  • A bug in the Xamarin.InAppBilling - unlikely since it has been working to date.

  • We haven't registered a callback properly - unlikely because we have logging on the first line of each callback...

        _serviceConnection.BillingHandler.OnUserCanceled += BillingHandler_OnProductCanceled;
        _serviceConnection.BillingHandler.OnProductPurchased += BillingHandler_OnProductPurchased;
        _serviceConnection.BillingHandler.OnGetProductsError += BillingHandler_OnGetProductsError;
        _serviceConnection.BillingHandler.OnPurchaseConsumed += BillingHandler_OnPurchaseConsumed;
        _serviceConnection.BillingHandler.OnPurchaseConsumedError += BillingHandler_OnPurchaseConsumedError;
        _serviceConnection.BillingHandler.OnProductPurchasedError += BillingHandler_OnProductPurchasedError;
        _serviceConnection.BillingHandler.OnPurchaseFailedValidation += BillingHandler_OnPurchaseFailedValidation;
        _serviceConnection.BillingHandler.OnInvalidOwnedItemsBundleReturned += BillingHandler_OnInvalidOwnedItemsBundleReturned;
    

Here's an excerpt of the code that invokes the purchase...

        Device.BeginInvokeOnMainThread (async () => {

            var products = await _serviceConnection.BillingHandler.QueryInventoryAsync (new List<String> { consumableSku }, ItemType.Product);

            if (products != null && products.Count == 1) {

                var product = products [0];

                logger.Log ("FeatureService purchaseConsumableFromGooglePlay product:"+product.ToString()+ " payload:" + this.developerPayload);

                // (A)
                _serviceConnection.BillingHandler.BuyProduct (product, this.developerPayload);

            } else {
                this.iapConsumableEvent.Purchased = false;
                this.Publish<IapConsumableEvent> (this.iapConsumableEvent);
            }
        });

        logger.Log ("FeatureService purchaseConsumableFromGooglePlay completed");

Most of the time the BillingHandler callbacks are invoked, but when it doesn't work it seems that those callbacks are not invoked.

We have seen this on Android 7 and 8 (so it's an Android 8 issue).

We are not sure where to go from here, any suggestions on debugging this further is appreciated.

like image 338
Devology Ltd Avatar asked Sep 16 '17 20:09

Devology Ltd


1 Answers

Okay,

As it turned out it was an issue at Google

Thanks for your reply to Google Play Developer Support!

Our team have recently made some changes that should fix this issue (which is what you have confirmed).

On the other hand, we do encourage developers to use our new Play Billing library (https://developer.android.com/google/play/billing/billing_library.html), which gracefully handles most of use cases, and a good example of integrating with it is our open-sourced sample: https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive_v2 I appreciate your patience on this fix, I hope this helps! If you have any further questions, please let me know. I'm happy to help.

like image 128
Devology Ltd Avatar answered Sep 27 '22 16:09

Devology Ltd