Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by wasicool7 · Dec 23, 2016 at 11:02 AM · not workingiap

Unity2D: IAP not working on mobile phone

I'm having problems with unity IAP services; I followed this tutorial on online to the tea and it works within Unity Editor however it doesn't work on my mobile. I checked through everything and even tested it out on a different mobile, but it still giving the same results. I recently upgraded unity 5.4 to 5.5 and even before I upgraded to 5.5, I was still having the same problem as before; I even tried out the new IAP system that unity 5.5 provide and still having the same problem. Heck, I think that the problem is, is that my IAP script (the one which was also provided my unity) isn't working on mobile, as before mention it does work within unity engine.One more thing to mention is that my IAP script was working before (on mobiles), before it stopped working on mobile phones, however I am not sure how or what triggered my script to not work now on mobile phones.

My Script:

 public static IAPManager Instance{set; get;}

 private static IStoreController m_StoreController; 
 private static IExtensionProvider m_StoreExtensionProvider;

 public static string PRODUCT_50_GOLD =    "gold50";   
 public static string PRODUCT_100_GOLD = "gold100";
 public static string PRODUCT_NO_ADS =  "noads"; 

 private void Awake()
 {
     Instance = this; 
 }
 private void Start()
 {
     if (m_StoreController == null)
     {
         InitializePurchasing();
     }
 }
 public void InitializePurchasing() 
 {
     if (IsInitialized())
     {
         return;
     }

     var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());

     builder.AddProduct(PRODUCT_50_GOLD, ProductType.Consumable);
     builder.AddProduct(PRODUCT_100_GOLD, ProductType.Consumable);
     builder.AddProduct(PRODUCT_NO_ADS, ProductType.NonConsumable);

         
     UnityPurchasing.Initialize(this, builder);
 }
 private bool IsInitialized()
 {
     return m_StoreController != null && m_StoreExtensionProvider != null;
 }

 public void Buy50Gold()
 {
     BuyProductID(PRODUCT_50_GOLD);
 }
 public void Buy100Gold()
 {
     BuyProductID(PRODUCT_100_GOLD);
 }
 public void BuyNoAds()
 {
     BuyProductID(PRODUCT_NO_ADS);
 }


 private void BuyProductID(string productId)
 {
     // If Purchasing has been initialized ...
     if (IsInitialized())
     {
         // ... look up the Product reference with the general product identifier and the Purchasing 
         // system's products collection.
         Product product = m_StoreController.products.WithID(productId);

         // If the look up found a product for this device's store and that product is ready to be sold ... 
         if (product != null && product.availableToPurchase)
         {
             Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
             // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed 
             // asynchronously.
             m_StoreController.InitiatePurchase(product);
         }
         // Otherwise ...
         else
         {
             // ... report the product look-up failure situation  
             Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
         }
     }
     // Otherwise ...
     else
     {
         // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or 
         // retrying initiailization.
         Debug.Log("BuyProductID FAIL. Not initialized.");
     }
 }
 public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
 {
     // Purchasing has succeeded initializing. Collect our Purchasing references.
     Debug.Log("OnInitialized: PASS");

     // Overall Purchasing system, configured with products for this application.
     m_StoreController = controller;
     // Store specific subsystem, for accessing device-specific store features.
     m_StoreExtensionProvider = extensions;
 }
 public void OnInitializeFailed(InitializationFailureReason error)
 {
     // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
     Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
 }


 public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args) 
 {
     if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_50_GOLD, StringComparison.Ordinal))
     {
         Debug.Log ("Purchase Successfull!");
         ScoreManager.Coin += 50;
     }
     else if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_100_GOLD, StringComparison.Ordinal))
     {
         Debug.Log ("Purchase Successfull!");
         ScoreManager.Coin += 100;
     }
     else if (String.Equals(args.purchasedProduct.definition.id, PRODUCT_NO_ADS, StringComparison.Ordinal))
     {
         Debug.Log ("Purchase Successfull!");
     }
     else 
     {
         Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
     }
     return PurchaseProcessingResult.Complete;
 }


 public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
 {
     // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing 
     // this reason with the user to guide their troubleshooting actions.
     Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
 }
 }

The below code is being referenced above:

 private void Start() {

 }

 public void Buy50Gold() {
     IAPManager.Instance.Buy50Gold ();
 }

 public void Buy100Gold() {
     IAPManager.Instance.Buy100Gold ();
 }
 public void BuyNoAds() {
     IAPManager.Instance.BuyNoAds ();
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

85 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Touch detecting not working with Google Cardboard. 2 Answers

My knockback script is not working 0 Answers

When Lights Go Bad? 0 Answers

Animation working in Unity and PC build, but not Android 1 Answer

Brick Breaker - When you die on a level and start over, if you complete the level it wont take you to the next level 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges