Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

[AmazonAppStore] Problem of UnityPurchasing.Initialize

Discussion in 'Unity IAP' started by mhshim, Feb 6, 2020.

  1. mhshim

    mhshim

    Joined:
    Dec 21, 2016
    Posts:
    6
    Hi there!
    I couldn't get an IStoreListener callback from UnityPurchasing.Initialize() to either OnInitialized() or OnInitializeFailed()

    Build with Unity2018.4.11f1, UnityIAP1.23
    Test with Fire HD8

    Can anyone point to anything that may help me trouble shoot this?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Did you target Amazon? Does it work on Android? Please show your code, and the output of your run time debugging flow. Debug.Log will show in the device logs

    Like:

    Debug.Log("I'm just before Initialize");
    Debug.Log("I'm in OnInitialized");
    Debug.Log("I'm in OnInitializedFailed");

    etc...
     

    Attached Files:

  3. mhshim

    mhshim

    Joined:
    Dec 21, 2016
    Posts:
    6
    Yes, targeted Amazon. and works on Android well.

    here is my code below :
    Code (CSharp):
    1. public void InitUnityIAP(Action<string> callback) {
    2.             if (_isInitialized) {
    3.                 Debugger.Log("IAPHelper.InitUnityIAP - IAPHelper was initialized");
    4.                 Platform.SafeCallback(callback, RESULT.success.ToString());
    5.                 return;
    6.             }
    7.             if(_initRequested) {
    8.                 Debugger.Log("IAPHelper.InitUnityIAP - IAPHelper is initializing");
    9.                 Platform.SafeCallback(callback, RESULT.AlreadyOnProccess.ToString());
    10.                 return;
    11.             }
    12.  
    13.             _initRequested = true;
    14.             Debugger.Log("IAPHelper.InitUnityIAP");
    15.             Debug.Log(">>> IAPHelper.InitUnityIAP");
    16.             string storeName = GooglePlay.Name; //Default
    17.             if (StoreType == PlatformContext.StoreType.AppleStore) {
    18.                 storeName = AppleAppStore.Name;
    19.             } else if (StoreType == PlatformContext.StoreType.AmazonStore) {
    20.                 storeName = AmazonApps.Name;
    21.             }
    22.  
    23.             ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    24. #if UNITY_IOS
    25.             builder.Configure<IAppleConfiguration>().SetApplePromotionalPurchaseInterceptorCallback(OnPromotionalPurchase);
    26. #endif
    27.             foreach (ShopItem shopItem in Context.UncleBill.shopItems) {
    28.                 builder.AddProduct(shopItem.id, shopItem.productType, new IDs() {
    29.                     { shopItem.GetPriceID(), storeName }
    30.                 });
    31.                 Debug.Log("IAPHelper.InitUnityIAP.AddProduct : " + shopItem.name);
    32.             }
    33.             _initUnityIAPCallback = callback;
    34.             UnityPurchasing.Initialize(this, builder);
    35.             Debug.Log("<<< IAPHelper.InitUnityIAP");
    36.         }
    37.  
    38.         public void OnInitialized(IStoreController controller, IExtensionProvider extension) {
    39.             Debugger.Log("IAPHelper.OnInitialized");
    40.             Debug.Log(">>> IAPHelper.OnInitialized");
    41.             if (controller == null) {
    42.                 Debugger.Assert(false, "IAPHelper.OnInitialized - controller is null");
    43.             }
    44.  
    45.             if (extension == null) {
    46.                 Debugger.Assert(false, "IAPHelper.OnInitialized - extension is null");
    47.             }
    48.  
    49.             storeController = controller;
    50.             storeExtension = extension;
    51.             appleExt = storeExtension.GetExtension<IAppleExtensions>();
    52.             appleExt.RegisterPurchaseDeferredListener(OnDeferred);
    53.             googleExt = storeExtension.GetExtension<IGooglePlayStoreExtensions>();
    54.  
    55.             if (StoreType == PlatformContext.StoreType.AppleStore) {
    56.                 intro_dict = appleExt.GetIntroductoryPriceDictionary();
    57.             } else if (StoreType == PlatformContext.StoreType.GoogleStore) {
    58.                 intro_dict = googleExt.GetProductJSONDictionary();
    59.             }
    60.  
    61.             _initRequested = false;
    62.             _isInitialized = true;
    63. #if USE_Firebase
    64.             FirebaseAnalyticsHelper.logEvent("IAPHelper.Initialized", "success");
    65. #endif
    66.             Platform.SafeCallback(_initUnityIAPCallback, RESULT.success.ToString());
    67.             _initUnityIAPCallback = null;
    68.             if (StoreType == PlatformContext.StoreType.GoogleStore) {
    69.                 UncleBill.RestoreAllPurchases(null);
    70.             }
    71.         }
    72.  
    73.         public void OnInitializeFailed(InitializationFailureReason error) {
    74.             Debugger.Log($"IAPHelper.OnInitializeFailed - error : {error.ToString()}");
    75.             Debug.Log($">>> IAPHelper.OnInitializeFailed - error : {error.ToString()}");
    76.             _initRequested = false;
    77.             Platform.SafeCallback(_initUnityIAPCallback, error.ToString());
    78.             _initUnityIAPCallback = null;
    79.         }


    The result is as follows :
    Code (CSharp):
    1. No instance of BM.Store.IAPHelper, a temporary one is created.
    2. >>> IAPHelper.InitUnityIAP
    3. UnityIAP Version: 1.23.0
    4. IAPHelper.InitUnityIAP.AddProduct : 150 Coins
    5. IAPHelper.InitUnityIAP.AddProduct : 500 Coins
    6. IAPHelper.InitUnityIAP.AddProduct : 900 Coins
    7. IAPHelper.InitUnityIAP.AddProduct : 2000 Coins
    8. IAPHelper.InitUnityIAP.AddProduct : 4500 Coins
    9. IAPHelper.InitUnityIAP.AddProduct : Remove Ads
    10. IAPHelper.InitUnityIAP.AddProduct : Special Offer
    11. IAPHelper.InitUnityIAP.AddProduct : Holiday Pack
    12. IAPHelper.InitUnityIAP.AddProduct : Holiday Pack
    13. IAPHelper.InitUnityIAP.AddProduct : Weekend Sale
    14. IAPHelper.InitUnityIAP.AddProduct : 10200 Coins
    15. IAPHelper.InitUnityIAP.AddProduct : Holiday Pack
    16. IAPHelper.InitUnityIAP.AddProduct : Rookie Pack
    17. IAPHelper.InitUnityIAP.AddProduct : Expert Pack
    18. IAPHelper.InitUnityIAP.AddProduct : Master Pack
    19. <<< IAPHelper.InitUnityIAP
    20. Using configuration builder objects
     
    Last edited: Feb 11, 2020
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please try with 1.23.1. Also, can you correlate your Debug.Log statements to those in the logs?
     
  5. mhshim

    mhshim

    Joined:
    Dec 21, 2016
    Posts:
    6
    OK, I'll try with 1.23.1!

    (And, incidentally, it works with Amazon App Tester in sandbox mode.
    but, it doesn't works in Live App Testing.)
     
  6. mhshim

    mhshim

    Joined:
    Dec 21, 2016
    Posts:
    6
    I tried with 1.23.1. but the result was same as before..
    I couldn't get callback either OnInitialized() or OnInitializeFailed()

    here is my code below :
    Code (CSharp):
    1.         public void InitUnityIAP(Action<string> callback) {
    2.             if (_isInitialized) {
    3.                 Debugger.Log("IAPHelper.InitUnityIAP - IAPHelper was initialized");
    4.                 Platform.SafeCallback(callback, RESULT.success.ToString());
    5.                 return;
    6.             }
    7.  
    8.             if (_initRequested) {
    9.                 Debugger.Log("IAPHelper.InitUnityIAP - IAPHelper is initializing");
    10.                 Platform.SafeCallback(callback, RESULT.AlreadyOnProccess.ToString());
    11.                 return;
    12.             }
    13.  
    14.             _initRequested = true;
    15.             ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    16.             foreach (ShopItem shopItem in Context.UncleBill.shopItems) {
    17.                 builder.AddProduct(
    18.                     shopItem.id, shopItem.productType,
    19.                     new IDs() { { shopItem.GetPriceID(), AmazonApps.Name } }
    20.                 );
    21.             }
    22.  
    23.             _initUnityIAPCallback = callback;
    24.             Debug.Log("I'm just before Initialize");
    25.             UnityPurchasing.Initialize(this, builder);
    26.             Debug.Log("I'm Initializing!");
    27.         }
    28.  
    29.         public void OnInitialized(IStoreController controller, IExtensionProvider extension) {
    30.             Debug.Log("I'm in OnInitialized");
    31.             _initRequested = false;
    32.             _isInitialized = true;
    33.             Platform.SafeCallback(_initUnityIAPCallback, RESULT.success.ToString());
    34.             _initUnityIAPCallback = null;
    35.         }
    36.  
    37.         public void OnInitializeFailed(InitializationFailureReason error) {
    38.             Debug.Log("I'm in OnInitializedFailed. Fail reason is " + error.ToString());
    39.             _initRequested = false;
    40.             Platform.SafeCallback(_initUnityIAPCallback, error.ToString());
    41.             _initUnityIAPCallback = null;
    42.         }
    The result is as follows :
    Code (CSharp):
    1. UnityIAP Version: 1.23.1
    2. I'm just before Initialize
    3. I'm Initializing!
    4. Using configuration builder objects
    5. UncleBill.AskForBuy fail : Uninitialized
     
    Last edited: Feb 11, 2020
  7. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Is this your first attempt at IAP? I might recommend not customizing the code like you have, instead get the basics working first would be my advice. You have added your own callbacks, I would not advise that. Start with the Sample IAP project here: https://forum.unity.com/threads/sample-iap-project.529555/ Get it working first, THEN add any custom code and test. https://docs.unity3d.com/Manual/UnityIAPAmazonConfiguration.html You mention it works in Sandbox mode but not Release, generally that may imply a store issue, you may also want to contact Amazon. But first try the basic project. What Amazon device are you testing on, a recent Kindle?
     
  8. TocaSimon

    TocaSimon

    Joined:
    Jan 30, 2018
    Posts:
    4
    Did you ever solve this? I have a very similar problem myself at the moment.
     
  9. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446