• 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 /
avatar image
0
Question by Zima1 · Apr 07, 2016 at 05:43 PM · androidscenepluginloadlevelpurchase

OpenIAB - billing plugin. It works only once! need HELP!

My application consists of three levels. Billing plugin is in one of the levels. levels are repeated one after the other. (Android) - The problem is that purchase - operates correctly only when the application is loaded for the first time! How to make that work every time ? When level is loaded...?

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine.UI;
 using OnePF;
 
 public class DemoBilling : MonoBehaviour {
 
     public const string SKU_MIDDLE = "middle_stick";
     public const string SKU_BIG = "big_stick";
 
     public GameObject Play2;
     public GameObject buy2;
     public GameObject Play3;
     public GameObject buy3;
 
     private void OnEnable()
     {
     
         OpenIABEventManager.billingSupportedEvent += OnBillingSupported;
         OpenIABEventManager.billingNotSupportedEvent += OnBillingNotSupported;
         OpenIABEventManager.queryInventorySucceededEvent += OnQueryInventorySucceeded;
         OpenIABEventManager.queryInventoryFailedEvent += OnQueryInventoryFailed;
         OpenIABEventManager.purchaseSucceededEvent += OnPurchaseSucceded;
         OpenIABEventManager.purchaseFailedEvent += OnPurchaseFailed;
         OpenIABEventManager.consumePurchaseSucceededEvent += OnConsumePurchaseSucceeded;
         OpenIABEventManager.consumePurchaseFailedEvent += OnConsumePurchaseFailed;
         OpenIABEventManager.transactionRestoredEvent += OnTransactionRestored;
         OpenIABEventManager.restoreSucceededEvent += OnRestoreSucceeded;
         OpenIABEventManager.restoreFailedEvent += OnRestoreFailed;
     }
 
 
     void Start() {
         
         OpenIAB.mapSku(SKU_MIDDLE, OpenIAB_Android.STORE_GOOGLE, "middle_stick");
         OpenIAB.mapSku(SKU_BIG, OpenIAB_Android.STORE_GOOGLE, "big_stick");
         
         
         var options = new OnePF.Options();
         options.checkInventory = false;
         options.verifyMode = OptionsVerifyMode.VERIFY_EVERYTHING;
         options.storeKeys.Add(OpenIAB_Android.STORE_GOOGLE, "KEY");
         OpenIAB.init(options);
     }
 
     private void OnDisable()
     {
         OpenIABEventManager.billingSupportedEvent -= OnBillingSupported;
         OpenIABEventManager.billingNotSupportedEvent -= OnBillingNotSupported;
         OpenIABEventManager.queryInventorySucceededEvent -= OnQueryInventorySucceeded;
         OpenIABEventManager.queryInventoryFailedEvent -= OnQueryInventoryFailed;
         OpenIABEventManager.purchaseSucceededEvent -= OnPurchaseSucceded;
         OpenIABEventManager.purchaseFailedEvent -= OnPurchaseFailed;
         OpenIABEventManager.consumePurchaseSucceededEvent -= OnConsumePurchaseSucceeded;
         OpenIABEventManager.consumePurchaseFailedEvent -= OnConsumePurchaseFailed;
         OpenIABEventManager.transactionRestoredEvent -= OnTransactionRestored;
         OpenIABEventManager.restoreSucceededEvent -= OnRestoreSucceeded;
         OpenIABEventManager.restoreFailedEvent -= OnRestoreFailed;
     }
 
 
 
     void OnGUI() {
 
         if (Play2.activeSelf == true)
         {
             GUI.Box(new Rect (1, 1, 1, 1), "");
         }
         else if (GUI.Button (new Rect (Screen.width/2 - 50, Screen.height/2 + 5, 100, 50), "Buy blue!"))
         {
             OpenIAB.purchaseProduct(SKU_MIDDLE);
         }
 
 
         if (Play3.activeSelf == true)
         {
             GUI.Box(new Rect (1, 1, 1, 1), "");
         }
         else if (GUI.Button (new Rect (Screen.width/2 - 50, Screen.height/2 + 105, 100, 50), "Buy green!"))
         {
             OpenIAB.purchaseProduct(SKU_BIG);
         }
 
     }
 
     bool VerifyDeveloperPayload(string developerPayload)
     {
         /*
          * TODO: Need
          */
         return true;
     }
 
     private void OnBillingSupported()
     {
         Debug.Log("Billing is supported");
         OpenIAB.queryInventory(new string[] { SKU_MIDDLE, SKU_BIG });
     }
     
     private void OnBillingNotSupported(string error)
     {
         Debug.Log("Billing not supported: " + error);
     }
     
     private void OnQueryInventorySucceeded(Inventory inventory) {
         Debug.Log("Query inventory succeeded: " + inventory);
 
         if (!Play2.activeSelf){
 
                 Play2.SetActive(true);
                 buy2.SetActive(false);
         };
 
         if (!Play3.activeSelf){
             
             Play3.SetActive(true);
             buy3.SetActive(false);
         };
         }
 
     private void OnQueryInventoryFailed(string error)
     {
         Debug.Log("Query inventory failed: " + error);
     }
     
     private void OnPurchaseSucceded(Purchase purchase)
     {
         Debug.Log("Purchase succeded: " + purchase.Sku + "; Payload: " + purchase.DeveloperPayload);
         if (!VerifyDeveloperPayload(purchase.DeveloperPayload))
             return;
 
         switch (purchase.Sku)
         {
         case SKU_MIDDLE:
             if (!Play2.activeSelf){
                 Play2.SetActive (true);
                 buy2.SetActive(false);
                                     }
 
             break;
         case SKU_BIG:
             if (!Play3.activeSelf){
                 Play3.SetActive(true);
                 buy3.SetActive(false);
             }
 
             break;
         
         default:
             Debug.LogWarning("Unknown SKU: " + purchase.Sku);
             break;
         }    
     }
     
     private void OnPurchaseFailed(int errorCode, string error)
     {
     
         Debug.Log("Purchase failed: " + error);
     }
 
     private void OnConsumePurchaseSucceeded(Purchase purchase)
     {
         Debug.Log("Consume purchase succeded: " + purchase.ToString());
             }
     
     private void OnConsumePurchaseFailed(string error)
     {
         Debug.Log("Consume purchase failed: " + error);
     
     }
     
     private void OnTransactionRestored(string sku)
     {
         Debug.Log("Transaction restored: " + sku);
     }
     
     private void OnRestoreSucceeded()
     {
         Debug.Log("Transactions restored successfully");
     }
     
     private void OnRestoreFailed(string error)
     {
         Debug.Log("Transaction restore failed: " + error);
     }
 }
 
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by unity_UuAZkmyxo8I1TQ · May 08, 2019 at 06:11 AM

Try to seek advice from the developers https://www.timesolv.com/ they have been dealing with billing software for a long time, I think they understand perfectly how to help you in this case. Most likely you made a small error somewhere in the code that does not start the program cycle

Comment
Add comment · Share
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to load a level after 30 seconds? 3 Answers

Application.Loadlevel("Level Name"); not working on android 2 Answers

Game freeze while I click Gui texture loadlevel to change scene 0 Answers

Android: Scene change (Application.LoadLevel) has no effect 3 Answers

Application.LoadLevel Strange Problem 2 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