locked
Xamarin.InAppBilling: Price_Amount_Micros is always null RRS feed

  • Question

  • User48232 posted

    I've just started using Xamarin.InAppBilling v2.2 and it looks pretty good but I can't figure out why PriceAmountMicros is always null. Any ideas?

    Thursday, July 30, 2015 1:13 PM

All replies

  • User31231 posted

    Hi @songtv,

    There might have been a change to the Google Play Services API since the latest version was released. I'll need to take a look and ensure that the component and the API are still in sync.

    Thanks for pointing this out,

    Kevin

    Thursday, July 30, 2015 1:30 PM
  • User128102 posted

    Hello @KMullins,

    Any idea when this will be fixed?

    Robin

    Tuesday, August 25, 2015 10:59 AM
  • User58730 posted

    Hi @KMullins,

    do you have any updates?

    Wednesday, August 26, 2015 11:45 AM
  • User14407 posted

    Hello,

    Any updates on this?

    Wednesday, August 26, 2015 11:48 AM
  • User2086 posted

    I just ran into this. A quick look via reflection seems to be a problem when deserializing from Google's response.

    It seems Price_Amount_Micros is defined as a string in the Product class, yet Google actually returns it as an integer in the JSON. Google's own documentation seems to suggest it is a string (i.e. a quoted number) in the JSON, but in reality, it doesn't appear to be (number is unquoted).

    Does the JSON deserializer try to make it a string from an integer and just sets it to null (or leaves it unset)?

    Wednesday, January 6, 2016 4:02 PM
  • User2086 posted

    Well, just as a work around, you can do something like...

    micros = (int)(double.Parse(gItem.Price.Substring(1)) * 1000000.0);
    

    ... to get the same result. Depends if your IAPs are set up in a default currency that has a single symbol at the start (in my case a £).

    Wednesday, January 6, 2016 5:12 PM
  • User135921 posted

    @KMullins any progress in this bug? I can confirm what cleardemon said, JSON contains "priceamountmicros":49000000. I'd like to use the component and PriceAmountMicros is crucial for my app. If you don't fix it, we can still use connection.Service.GetSkuDetails(...), just some more work to do for us.. Thanks :)

    EDIT: long? micros = product["price_amount_micros"] as long?; does the trick

    Wednesday, March 30, 2016 10:50 PM
  • User250249 posted

    As this issue continues, workaround is like this for those who are searching for a solution.

        public async Task<string> GetProduct(string productId) {
            IList<string> productIds = new List<string>();
            productIds.Add(productId);
            Android.OS.Bundle bundle = new Android.OS.Bundle();
            bundle.PutStringArrayList("ITEM_ID_LIST", productIds);
            var skuDetails = serviceConnection.Service.GetSkuDetails(3, "<package_name>", ItemType.Product, bundle);
            int response = skuDetails.GetInt("RESPONSE_CODE");
    
            if (response == 0) {
                IList<string> responseList = skuDetails.GetStringArrayList("DETAILS_LIST");
    
                JSONObject obj = new JSONObject(responseList[0]);
                float price = obj.GetInt("price_amount_micros") / 1000000f;
                string currency = obj.GetString("price_currency_code");
    
                return (currency + price);
            } else {
                return null;
            }
        }
    
    Sunday, September 11, 2016 7:44 AM
  • User77653 posted

    Koray Agdemir thanks for the workaround on this. Not sure how this is still an issue in 2017, but I essentially used your code and built the Product class objects out of it. Essentially rewriting QueryInventoryAsync.

    Thursday, May 11, 2017 6:34 PM
  • User236688 posted

    Is there any chance you @KMullins will be converting this to a nuget package now that Components are deprecated? @KorayAgdemir Thank you for the code. That helped! I am a little confused why you made the function async.

    Wednesday, March 21, 2018 11:30 PM
  • User250249 posted

    @"AndyMartin.6838" No problem! It has been so long, not sure why I made it async, i think i had it wrapped with Task.Run, might have removed it for this example.

    Thursday, March 22, 2018 12:00 AM