Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity BuyProductID Fail. Not initialized

Discussion in 'Unity Ads & User Acquisition' started by fiatwiriya, Nov 30, 2018.

  1. fiatwiriya

    fiatwiriya

    Joined:
    Jun 27, 2018
    Posts:
    12
    Hi. Everything seems to work fine in unity editor. When I click on button and buying menu pop up but once it runs on android emulator when I click on the button. It says "Unity BuyProductID Fail. Not initialized"
    I have done some research but still can't pinpoint. Here is some useful information incase I did something wrong.

    - I don't have android phone only runs on android studio emulator.
    - I uploaded it to google play and IAP is active.
    - I haven't set up bank or tax yet.

    Any helps would be greatly appreciate. Thanks
    this is code from unity.

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Purchasing;
    5.  
    6.  
    7.     public class IAPManager : MonoBehaviour, IStoreListener
    8.     {
    9.         private static IStoreController m_StoreController;          // The Unity Purchasing system.
    10.         private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
    11.        
    12.         public static string PRODUCT_NO_ADS = "removedads";  
    13.    
    14.    // public static IAPManager Instance { set; get; }
    15.  
    16. //    private void Awake()
    17.     //{
    18. //       Instance = this;
    19.     //}
    20.  
    21.  
    22.     void Start()
    23.         {
    24.             // If we haven't set up the Unity Purchasing reference
    25.             if (m_StoreController == null)
    26.             {
    27.                 // Begin to configure our connection to Purchasing
    28.                 InitializePurchasing();
    29.             }
    30.         }
    31.        
    32.         public void InitializePurchasing()
    33.         {
    34.             // If we have already connected to Purchasing ...
    35.             if (IsInitialized())
    36.             {
    37.                 // ... we are done here.
    38.                 return;
    39.             }
    40.            
    41.             // Create a builder, first passing in a suite of Unity provided stores.
    42.             var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    43.            
    44.          builder.AddProduct(PRODUCT_NO_ADS, ProductType.NonConsumable);
    45.          
    46.             UnityPurchasing.Initialize(this, builder);
    47.         }
    48.        
    49.        
    50.         private bool IsInitialized()
    51.         {
    52.             // Only say we are initialized if both the Purchasing references are set.
    53.             return m_StoreController != null && m_StoreExtensionProvider != null;
    54.         }
    55.        
    56.         public void BuyNoAds()
    57.         {
    58.            
    59.         BuyProductID(PRODUCT_NO_ADS);
    60.         }
    61.        
    62.        
    63.         void BuyProductID(string productId)
    64.         {
    65.             // If Purchasing has been initialized ...
    66.             if (IsInitialized())
    67.             {
    68.                 // ... look up the Product reference with the general product identifier and the Purchasing
    69.                 // system's products collection.
    70.                 Product product = m_StoreController.products.WithID(productId);
    71.                
    72.                 // If the look up found a product for this device's store and that product is ready to be sold ...
    73.                 if (product != null && product.availableToPurchase)
    74.                 {
    75.                     Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    76.                     // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
    77.                     // asynchronously.
    78.                     m_StoreController.InitiatePurchase(product);
    79.                 }
    80.                 // Otherwise ...
    81.                 else
    82.                 {
    83.                     // ... report the product look-up failure situation
    84.                     Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    85.                 }
    86.             }
    87.             // Otherwise ...
    88.             else
    89.             {
    90.                 // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
    91.                 // retrying initiailization.
    92.                 Debug.Log("BuyProductID FAIL. Not initialized.");
    93.             }
    94.         }
    95.        
    96.        
    97.  
    98.         public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    99.         {
    100.             // Purchasing has succeeded initializing. Collect our Purchasing references.
    101.             Debug.Log("OnInitialized: PASS");
    102.            
    103.             // Overall Purchasing system, configured with products for this application.
    104.             m_StoreController = controller;
    105.             // Store specific subsystem, for accessing device-specific store features.
    106.             m_StoreExtensionProvider = extensions;
    107.         }
    108.        
    109.        
    110.         public void OnInitializeFailed(InitializationFailureReason error)
    111.         {
    112.             // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
    113.             Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    114.         }
    115.        
    116.        
    117.         public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    118.         {
    119.             // A consumable product has been purchased by this user.
    120.             if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_NO_ADS, StringComparison.Ordinal))
    121.             {
    122.  
    123.             //CanasScript.Instance.removeAds();
    124.        
    125.  
    126.             Debug.Log("No Ads has removed");
    127.             }
    128.        
    129.             else
    130.             {
    131.                 Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    132.             }
    133.  
    134.  
    135.             return PurchaseProcessingResult.Complete;
    136.         }
    137.        
    138.        
    139.         public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    140.         {
    141.             // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
    142.             // this reason with the user to guide their troubleshooting actions.
    143.             Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    144.         }
    145.  
    146.  
    147.     //public void checkIfPlayerHaspurchased()
    148.     //{
    149.     //    Product product = m_StoreController.products.WithID("removedads");
    150.  
    151.     //    if(product != null && product.hasReceipt)
    152.     //    {
    153.     //        CanasScript.Instance.adsHasPurchased = true;
    154.     //    }
    155.  
    156.     //}
    157.     }
    158.  
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    fiatwiriya likes this.