Xamarin.InAppBilling (2.2.0) Android BuyProduct () is called, but callbacks sometimes do not call - How to diagnose / fix the root?

Over the past couple of weeks, we have encountered a number of unsuccessful crashes when purchasing applications on Android (iOS was fine).

We use the Xamarin.InAppBilling component (version 2.2.0), which has been absolutely perfect for many months, but recently we see that we call line (A), but normal IAP calls are not called, which implies ...

  • Google does not receive a purchase request - we can exclude this, they are charging.

  • Google doesn't answer - our most likely scenario

  • The error in Xamarin.InAppBilling is unlikely, as it works to date.

  • We did not register the callback correctly - it is unlikely because we have an entry in 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 is an excerpt of the code that causes 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"); 

In most cases, the BillingHandler callback is called, but when it does not work, it seems that these callbacks are not being called.

We saw this on Android 7 and 8 (so this is a problem with Android 8).

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

+8
android google-play-services xamarin xamarin.android in-app-purchase
source share
2 answers

Good,

As it turned out, this was a problem on Google

Thanks for your response in support of Google Play developers!

Our team recently made some changes that should solve this problem (this is what you confirmed).

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

+4
source share

As indicated by Google's answer (as part of your answer), Xamarin uses the β€œold” Google Play billing library, suggesting rev 5 if your Android SDK is updated.

A newer library from Google was finally released ( 1.0 ), which replaces the old methods and provides a new API. This new library ( .aar ) is accessible through maven and is not installed locally in the Android SDK.

  • com.android.billingclient:billing:1.0

Google Play Billing Library 1.0 / September 19, 2017 Released

I use it through the binding library, and it’s much better to work with the old one in terms of APIs, server responses and error handling; -)

+1
source share

All Articles