Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Unity IAP - UWP not initialized.

Discussion in 'Unity IAP' started by elliotjb, Mar 18, 2019.

  1. elliotjb

    elliotjb

    Joined:
    Nov 15, 2015
    Posts:
    3
    We are developing an application with Unity (v2018.2.2f1) and we are integrating In-App Purchases through the Unity Plugin (v2.0.6).
    We have adapted the "Purchaser" script found in the Unity tutorial (link: https://unity3d.com/en/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game)
    Through the Microsoft Partner Center, we have published a trial version of the application and we have created the add-ons to be purchased within the app.
    Within this we have added the products with their respective id to link them correctly with the store.
    To test transactions, we have activated the "MockBillingSystem".
    We use IL2CPP as "Scripting Backend".

    Within the Unity environment, the store works well, as it connects to the Unity Fake Store. The problem comes when we build a build and we want to connect directly with the Microsoft Store: the store module is not initialized. OnInitialized or OnInitializeFailed are not called.
    We have researched and found cases similar to ours, when working specifically with UWP, since it does work for us when we want to establish a connection with the Google Play Store.

    Is there any specific configuration, within the Unity project or in the generated solution (.sln) that must be implemented in order to connect correctly with the Microsoft Store?

    Thanks and sorry for the inconvenience
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    We have heard of similar reports of this behavior with the Windows Store, but unfortunately we do not have a resolution at this time. We suspect that something may have changed on the Windows side, but not confirmed. Due to resource constraints, we have been focusing on iOS and Android issues.
     
  3. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    39
    I seem to be facing the same issue. The IAP code is from the Sample IAP Project. I added some Debug statements to it so this Debug info can be seen in the attached logs.
    The IStoreController and IExtensionProvider are both null as per these logs.

    Android :
    Consumables
    Published : Yes, Internal Test Track
    IAP Result : Real Purchase (Credit Card ) worked
    UWP :
    Consumables : Developer Managed
    Published : Yes, available only to test users
    IAP Result : Not Initialised

    This is what i read in the Microsoft docs :
    https://docs.microsoft.com/en-us/windows/uwp/monetize/in-app-purchases-and-trials#api_intro
    " This section provides an overview of important tasks and concepts for the Windows.Services.Store namespace. This namespace is available only to apps that target Windows 10 Anniversary Edition (10.0; Build 14393) or a later release in Visual Studio (this corresponds to Windows 10, version 1607). We recommend that apps use the Windows.Services.Store namespace instead of the Windows.ApplicationModel.Store namespace if possible. "

    I thought it's something to do with this so I set the min Platform Version as 10.0.14393.0 but it's not working

    Can you please tell me which of the two namespaces does Unity IAP use i.e
    Windows.Services.Store Or Windows.ApplicationModel.Store ?



    Version Info :
    Unity 2018.3.9f1
    Unity IAP 1.20.1

    Windows Build Settings :
    Architecture : x64
    Build Type : D3D
    Target SDK : Latest Installed
    Min Platform Version : 10.0.14393.0

    Configuration:
    Scripting Runtime Version .NET 4.x Equivalent
    Scripting Backend IL2CPP
    API Compatibility Level .NET Standard 2.0

    Code (CSharp):
    1.  
    2.  
    3. public class Purchaser : MonoBehaviour, IStoreListener
    4. {
    5.     public Text debugText;
    6.     public Text receiptText;
    7.     public UnityEvent processEventAndroid;
    8.     public UnityEvent processEventIos;
    9.     public UnityEvent processEventUwp;
    10.     private static IStoreController m_StoreController;          // The Unity Purchasing system.
    11.     private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
    12.  
    13.  
    14.  
    15.     public static Product test_product = null;
    16.     public static string kProductIDConsumable = "gold1000";  
    17.  
    18.  
    19.     void Start()
    20.     {
    21.  
    22.  
    23.         // If we haven't set up the Unity Purchasing reference
    24.         if (m_StoreController == null)
    25.         {
    26.             // Begin to configure our connection to Purchasing
    27.             MyDebug("Begin to configure our connection to Purchasing");
    28.             InitializePurchasing();
    29.         }
    30.         else
    31.         {
    32.             MyDebug("m_store Controller is not null");
    33.         }
    34.     }
    35.  
    36.     public void InitializePurchasing()
    37.     {
    38.         // If we have already connected to Purchasing ...
    39.         if (IsInitialized())
    40.         {
    41.             // ... we are done here.
    42.             MyDebug("Already connected to Purchasing");
    43.             return;
    44.         }
    45.  
    46.         // Create a builder, first passing in a suite of Unity provided stores.
    47.         var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    48.  
    49.         // Add a product to sell / restore by way of its identifier, associating the general identifier
    50.         // with its store-specific identifiers.
    51.      
    52.         builder.AddProduct(kProductIDConsumable, ProductType.Consumable);
    53.    
    54.         // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration
    55.         // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed.
    56.         MyDebug("Products added , proceed to init");
    57.         UnityPurchasing.Initialize(this, builder);
    58.     }
    59.  
    60.  
    61.     private bool IsInitialized()
    62.     {
    63.         // Only say we are initialized if both the Purchasing references are set.
    64.         if(m_StoreController==null)
    65.         {
    66.             MyDebug("m_StoreController is null ");
    67.  
    68.         }
    69.  
    70.         if (m_StoreExtensionProvider == null)
    71.         {
    72.             MyDebug("m_StoreExtensionProvider is null");
    73.         }
    74.  
    75.         return m_StoreController != null && m_StoreExtensionProvider != null;
    76.     }
    77.  
    78.  
    79.     public void BuyConsumable()
    80.     {
    81.         // Buy the consumable product using its general identifier. Expect a response either
    82.         // through ProcessPurchase or OnPurchaseFailed asynchronously.
    83.         BuyProductID(kProductIDConsumable);
    84.     }
    85.  
    86.  
    87.  
    88.     void BuyProductID(string productId)
    89.     {
    90.         // If Purchasing has been initialized ...
    91.         if (IsInitialized())
    92.         {
    93.             // ... look up the Product reference with the general product identifier and the Purchasing
    94.             // system's products collection.
    95.             Product product = m_StoreController.products.WithID(productId);
    96.  
    97.             // If the look up found a product for this device's store and that product is ready to be sold ...
    98.             if (product != null && product.availableToPurchase)
    99.             {
    100.                 MyDebug(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    101.                 // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
    102.                 // asynchronously.
    103.                 m_StoreController.InitiatePurchase(product);
    104.             }
    105.             // Otherwise ...
    106.             else
    107.             {
    108.                 // ... report the product look-up failure situation
    109.                 MyDebug("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    110.             }
    111.         }
    112.         // Otherwise ...
    113.         else
    114.         {
    115.             // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
    116.             // retrying initiailization.
    117.            MyDebug("BuyProductID FAIL. Not initialized.");
    118.         }
    119.     }
    120.  
    121.     public void CompletePurchase()
    122.     {
    123.         if (test_product == null)
    124.             MyDebug("Cannot complete purchase, product not initialized.");
    125.         else
    126.         {
    127.             m_StoreController.ConfirmPendingPurchase(test_product);
    128.             MyDebug("Completed purchase with " + test_product.transactionID.ToString());
    129.         }
    130.  
    131.     }
    132.  
    133.     private void MyDebug(string debug)
    134.     {
    135.        
    136.         debugText.text = debug;
    137.         Debug.Log(debug);
    138.  
    139.     }
    140.  
    141.     //
    142.     // --- IStoreListener Interface Implementation:
    143.     //
    144.  
    145.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    146.         {
    147.             // Purchasing has succeeded initializing. Collect our Purchasing references.
    148.            MyDebug("OnInitialized: PASS");
    149.  
    150.             // Overall Purchasing system, configured with products for this application.
    151.             m_StoreController = controller;
    152.             // Store specific subsystem, for accessing device-specific store features.
    153.             m_StoreExtensionProvider = extensions;
    154.         }
    155.  
    156.  
    157.     public void OnInitializeFailed(InitializationFailureReason error)
    158.     {
    159.         // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
    160.        MyDebug("OnInitializeFailed InitializationFailureReason:" + error);
    161.     }
    162.  
    163.  
    164.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    165.     {
    166.         test_product = args.purchasedProduct;
    167.  
    168.         // A consumable product has been purchased by this user.
    169.         if (String.Equals(args.purchasedProduct.definition.id, kProductIDConsumable, StringComparison.Ordinal))
    170.         {
    171.             MyDebug(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id + " - " + test_product.transactionID.ToString()));
    172.             MyDebug(args.purchasedProduct.receipt);
    173.             receiptText.text = args.purchasedProduct.receipt;
    174.  
    175.  
    176.             switch(Application.platform)
    177.             {
    178.                 case RuntimePlatform.Android:
    179.                     MyDebug("Platform is Android");
    180.                     processEventAndroid.Invoke();
    181.                     return PurchaseProcessingResult.Complete;
    182.  
    183.                 case RuntimePlatform.WindowsPlayer:
    184.                     MyDebug("Platform is Windows");
    185.                     processEventUwp.Invoke();
    186.                     return PurchaseProcessingResult.Pending;
    187.  
    188.                 case RuntimePlatform.IPhonePlayer:
    189.                     MyDebug("Platform is IPhone");
    190.                     processEventIos.Invoke();
    191.                     return PurchaseProcessingResult.Pending;
    192.  
    193.  
    194.                 default:
    195.                     MyDebug("UnSuppported Platform");
    196.                     return PurchaseProcessingResult.Complete;
    197.            
    198.             }
    199.    
    200.  
    201.  
    202.         }
    203.    
    204.         // Or ... an unknown product has been purchased by this user. Fill in additional products here....
    205.         else
    206.         {
    207.             MyDebug(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id + " - " + test_product.transactionID.ToString()));
    208.             return PurchaseProcessingResult.Complete;
    209.         }
    210.  
    211.         // Return a flag indicating whether this product has completely been received, or if the application needs
    212.         // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
    213.         // saving purchased products to the cloud, and when that save is delayed.
    214.  
    215.     }
    216.  
    217.  
    218.     public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    219.     {
    220.         // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
    221.         // this reason with the user to guide their troubleshooting actions.
    222.         MyDebug(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    223.     }
    224. }
    225.  
     

    Attached Files:

    Last edited: Mar 24, 2019
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    @rushk1 We use Windows.ApplicationModel.Store
     
    rushk1 likes this.
  5. big_3

    big_3

    Joined:
    Apr 20, 2016
    Posts:
    45
    When is this fixed? We have the same problem. If IAP for UWP apps is not supported, please update your documentation.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    We are still working on this, I'm hoping to test this week.
     
  7. webjeff

    webjeff

    Joined:
    Mar 11, 2015
    Posts:
    36
    @JeffDUnity3D Any updates? I am experiencing the same issue. I submitted a bug report through Unity a few days ago (no email confirmation or anything yet).

    Here's what I posted:
    1. What happened
    When trying to build a UWP version of our game, IAP's are not working. More specifically, the call to 'UnityPurchasing.Initialize' does not ever call 'OnInitialized' nor 'OnInitializeFailed'. This call works fine for iOS and Android. After some debugging time (using a simple scene), I noticed the output window would show an exception:

    Exception thrown at 0x00007FFE24609129 in Air Combat Pilot.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x000000F6023FF1C8.

    This happens both with useMockBillingSystem set to true and false (when posted in Microsoft dev console).

    I will say, while most of the time I get those exceptions and no callbacks, although once in a while it does seem to work with no change to the code/project. Just re-running it multiple times.

    Any idea?

    Unity 2018.4.1f1
    IAP 1.22.0
     
  8. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    This is a known issue, no ETA for a potential fix at this time.
     
  9. eVPublishing

    eVPublishing

    Joined:
    Oct 25, 2016
    Posts:
    14
    Hi @JeffDUnity3D :

    Hate to press on this issue, but do you happen to know what other developers are doing for UWP IAPs? Writing their own native wrapper?

    It seems there are a good number of apps on the Windows store, probably Unity-based, that are using IAPs.

    I just don't want to spend a lot of time and $ going down the wrong path.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    Sorry I do not. If you think the UWP market is worth the effort, that might be something to consider.
     
  11. TechOmegaZeta

    TechOmegaZeta

    Joined:
    Jul 27, 2017
    Posts:
    2
    Greetings,
    We're facing the same issue and would be great to know if there's been some advancements on the matter.
    Thanks for the hard work!!
     
  12. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    I don't expect any updates any time soon.
     
  13. big_3

    big_3

    Joined:
    Apr 20, 2016
    Posts:
    45
  14. alexds9

    alexds9

    Joined:
    Feb 9, 2019
    Posts:
    5
    Hi @JeffDUnity3D,

    I have a problem with codeless IAP in UWP. I have an app in Microsoft store with addons ready for IAP. I use the "Automatic initialize UnityPurchasing", that is working fine with Google Play store. In Visual Studio I've associate my app with the store and uploaded the app, it is working fine when downloaded from the Microsoft store, but I don't see the store part in the code ever initializing, so IAP does not work.
    Do you think that it's the same problem that people having here, and if so, any updates regarding fix or workarounds?
     
  15. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    No updates at this time.
     
  16. anand-qneuro

    anand-qneuro

    Joined:
    Mar 12, 2016
    Posts:
    1
    Hi, I am facing the same issue with UnityIAP for uwp app. I tried creating my own uwp store plugin which uses Windows.Services.Store namespace, yet the store fails to initialize. Screenshot_1.png

    This is the log when i call the initialize store function


    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\Windows.ApplicationModel.Store.dll'.
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\webservices.dll'.
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\cryptsp.dll'.
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\cabinet.dll'.
    info:Windows::Services::Store::StoreContextFactory::GetDefault() invoked. (CV:gMauU90EB0SmRkYz.2) [Windows::Services::Store::StoreContextFactory::GetDefault]
    The thread 0x4410 has exited with code 0 (0x0).
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\CryptoWinRT.dll'.
    info:Windows::Services::Store::StoreContext::get_User() invoked. (CV:gMauU90EB0SmRkYz.2.3) [Windows::Services::Store::StoreContext::get_User]
    Exception thrown at 0x00007FFBC81DA388 in UnityIAP.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x0000000BAC2FE170.
    ERROR FindDefaultInterface:CM_Get_Device_Interface_List_Size failed:0x00000000, InterfaceListSize = 1
    ERROR SensorOpenByType:Failed to open sensor error:0x0000007E
    ERROR FindDefaultInterface:CM_Get_Device_Interface_List_Size failed:0x00000000, InterfaceListSize = 1
    ERROR SensorOpenByType:Failed to open sensor error:0x00000490
    ERROR FindDefaultInterface:CM_Get_Device_Interface_List_Size failed:0x00000000, InterfaceListSize = 1
    ERROR SensorOpenByType:Failed to open sensor error:0x00000490
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Globalization.dll'.
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\BCP47mrm.dll'.
    'UnityIAP.exe' (Win32): Loaded 'C:\Windows\System32\BCP47Langs.dll'.
    Uploading Crash Report
    NullReferenceException: Object reference not set to an instance of an object.
    at UWPstore.InAppPurchaser.InitializeStoreForUser (UWPstore.InAppPurchaser+InAppType type) [0x00000] in <00000000000000000000000000000000>:0
    at UWP_InAppPurchaseManager.Start () [0x00000] in <00000000000000000000000000000000>:0


    I noticed that Windows.ApplicationModel.Store is being loaded instead of Windows.Services.Store. Is this normal?
     
  17. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    7,424
    So you're not able to get it to work using a native implementation? Is the NRE in your code?
     
unityunity