Search Unity

[Solved] Exception in Unity IAP on Google Play

Discussion in 'Unity IAP' started by WillemKokke, Oct 21, 2016.

Thread Status:
Not open for further replies.
  1. WillemKokke

    WillemKokke

    Joined:
    Sep 6, 2014
    Posts:
    31
    Unity 5.4.2
    Unity IAP 1.8.3

    I'm connected to the uk google play store, I have an app in beta, and everything is generally working fine.

    I'm at the stage where I'm translating the app in multiple languages, and testing that.

    When I change the handset (samsung galaxy S5 and S6 Edge both exhibit this) to french, and launch the app, I get the following error in the log, and the store never becomes available.

    10-21 04:12:16.122: I/Unity(4164): FormatException: Invalid character at position 1
    10-21 04:12:16.122: I/Unity(4164): at System.Decimal.ThrowAtPos (Int32 pos) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at System.Decimal.stripStyles (System.String s, NumberStyles style, System.Globalization.NumberFormatInfo nfi, System.Int32& decPos, System.Boolean& isNegative, System.Boolean& expFlag, System.Int32& exp, Boolean throwex) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at System.Decimal.PerformParse (System.String s, NumberStyles style, IFormatProvider provider, System.Decimal& res, Boolean throwex) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at System.Decimal.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at System.Decimal.Parse (System.String s) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at UnityEngine.Purchasing.JSONSerializer.DeserializeMetadata (System.Collections.Generic.Dictionary`2 data) [0x00000] in <filename unknown>:0
    10-21 04:12:16.122: I/Unity(4164): at UnityEngine.Purchasing.JSONSerializer.DeserializeProductDescriptions (System.String json) [0x00000] in <filename

    Changing the handset to Italian, German, Spanish and Italian, and then launching the app works fine though.

    Any Ideas?
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
  3. WillemKokke

    WillemKokke

    Joined:
    Sep 6, 2014
    Posts:
    31
    Haven't been able to get the workaround to work as of yet
     
  4. WillemKokke

    WillemKokke

    Joined:
    Sep 6, 2014
    Posts:
    31
    I have fixed this issue by replace the function UnityEngine.Purchasing.JSONSerializer.DeserializeMetadata in Stores.dll with the following function. I had to replace TryGetString with an inline implementation as ILSpy + Reflexil don't allow you call extension methods.

    Code (CSharp):
    1.     static UnityEngine.Purchasing.ProductMetadata DeserializeMetadata(System.Collections.Generic.Dictionary<string, object> data)
    2.     {
    3.         string localizedPriceString = null;
    4.         if (data.ContainsKey("localizedPriceString")) { localizedPriceString = data["localizedPriceString"].ToString();}
    5.  
    6.         string localizedTitle = null;
    7.         if (data.ContainsKey("localizedTitle")) { localizedTitle = data["localizedTitle"].ToString();}
    8.  
    9.         string localizedDescription = null;
    10.         if (data.ContainsKey("localizedDescription")) { localizedDescription = data["localizedDescription"].ToString();}
    11.  
    12.         string isoCurrencyCode = null;
    13.         if (data.ContainsKey("isoCurrencyCode")) { isoCurrencyCode = data["isoCurrencyCode"].ToString();}
    14.  
    15.         string localizedPriceAsString = data["localizedPrice"].ToString();
    16.         Debug.Log("LocalisedPrice: " + localizedPriceAsString);
    17.  
    18.         decimal localizedPriceAsDecimal;
    19.         if (!decimal.TryParse(localizedPriceAsString, out localizedPriceAsDecimal))
    20.         {
    21.             localizedPriceAsDecimal = decimal.Parse(localizedPriceAsString, System.Globalization.NumberStyles.Any, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"));
    22.         }
    23.  
    24.         return new ProductMetadata(localizedPriceString, localizedTitle, localizedDescription, isoCurrencyCode, localizedPriceAsDecimal);
    25.     }
     
    ap-unity and rayw24 like this.
  5. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @WillemKokke,

    I'm glad you got it working for you. We are going to have this fixed in the one of the next versions of the plugin.
     
Thread Status:
Not open for further replies.