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

Question Returns FakeGooglePlayStoreExtensions after initializing UnityPurchasing for the second time

Discussion in 'Unity IAP' started by yuki_goto, Oct 7, 2022.

  1. yuki_goto

    yuki_goto

    Joined:
    May 8, 2020
    Posts:
    4
    Hi,
    Now I'm testing Google deferred purchase using Unity IAP 4.4.1 on Unity 2020.3.40f1.

    I found "googlePlayStoreExtensions.IsPurchasedProductDeferred(product)" returns false, so I logged "googlePlayStoreExtensions" variable, it was "UnityEngine.Purchasing.FakeGooglePlayStoreExtensions".
    It is no probrem after call "UnityPurchasing.Initialize(listener, builder)" for the first time, but "extensions.GetExtension<IGooglePlayStoreExtensions>()" returns Fake class after calling initialize for the second time. I'd like to call initialize several time during running app because products may change.

    Do you have any solutions?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please share the code that you are using, we will take a look. Are you testing on an Android device or in the Editor?
     
  3. yuki_goto

    yuki_goto

    Joined:
    May 8, 2020
    Posts:
    4
    I'm testing on Android device.

    Our code is like the following.

    After the first time initializing, I see "UnityEngine.Purchasing.MetricizedGooglePlayStoreExtensions" in the log, but second time "UnityEngine.Purchasing.FakeGooglePlayStoreExtensions".

    Code (CSharp):
    1. private static readonly IStoreListener listener = new StoreListener();
    2.  
    3. public static void Init()
    4. {
    5.     ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    6.     builder.Configure<IGooglePlayConfiguration>().SetDeferredPurchaseListener(OnGoogleDefferredPurchase);
    7.  
    8.     foreach (var productId in productIds)
    9.     {
    10.         builder.AddProduct(productId, ProductType.Consumable);
    11.     }
    12.     UnityPurchasing.Initialize(listener, builder);
    13. }
    14.  
    15. private class StoreListener : IStoreListener
    16. {
    17.     private IGooglePlayStoreExtensions goooglePlayStoreExtension;
    18.  
    19.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    20.     {
    21.         goooglePlayStoreExtension = extensions.GetExtension<IGooglePlayStoreExtensions>();
    22.         Debug.Log(goooglePlayStoreExtension);
    23.     }
    24.  
    25.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    26.  
    27.         Debug.Log("IsDeferred : " + googlePlayStoreExtensions.IsPurchasedProductDeferred(args.purchasedProduct));
    28.     }
    29.     ....
    30. }
    Thanks.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    What happens when you try to make a purchase? I will check also. Also please test with IAP 4.5.0. Was this working in a previous version for you?
     
  5. yuki_goto

    yuki_goto

    Joined:
    May 8, 2020
    Posts:
    4
    We have no problem on making a purchase. I'm testing like the following on an Android device.

    1. Login (Initialize)
    2. Make a purchase by the "Slow test card" of Google Play.
    3. Logout and login again (Initialize again)
    4. Callback "ProcessPurchase" and "IsPurchasedProductDeferred" returns false though the purchase is not completed.

    I'll try IAP 4.5.0 latar.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    So you do have a problem making a purchase, I just wanted to confirm. We will take a look.
     
  7. yuki_goto

    yuki_goto

    Joined:
    May 8, 2020
    Posts:
    4
    I updated IAP to 4.5.0 and tested again. But it seems it has the same problem.
     
    JeffDUnity3D likes this.
  8. NiallSoe

    NiallSoe

    Joined:
    Jan 30, 2018
    Posts:
    17
    Just ran into this same issue.

    Digging into the source code it appears to be because the storeInstance is only ever created once:

    upload_2023-10-16_17-49-22.png

    InstantiateStore normally ends up calling BindGoogleExtension() which would then overwrite the fake store.

    It appears it's simply not safe to reinitialise UnityIAP, even though I have read otherwise here: https://forum.unity.com/threads/how...device-on-a-running-game.587206/#post-3929020

    @John_Corbett - Can the reinitialisation flow be fixed, please?
     
    Last edited: Oct 16, 2023