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 /
avatar image
0
Question by Hiten2012 · Jun 21, 2016 at 07:40 PM · unity 5iapinapp purchasesoomla

in app purchase sooma restore option

Hi all, by following https://www.youtube.com/watch?v=zsWVcAajMjY tutorial i developed demo, I have done same as this video tutorial... using Unity 5.2.2 and upto date version of soomla.. I have tested this demo live (google play). Everything works perfect, but after uninstalling aap, when i install it second time, It doesn't needs to press "Restore" button. and box becomes Green.... Is its Okay?? or i am missing something.... ??

//ExampleWindowScript.cs //Alexander Young //February 5, 2015 //Description - Creates the functionality to allow for in-app purchasing, specifically with reguards the GUI and using purchases to make changes to the game

using System; using UnityEngine; using System.Collections; using System.Collections.Generic;

namespace Soomla.Store.Example { //Allows for access to Soomla API
public class ExampleWindow : MonoBehaviour {
public Transform cube; // Stores the scene cube as a variable //secTime/floatTime are used to check for IAP changes every 2 seconds (ideally, you should only check for updates when you absoultely need to. This just shows a way check for the IAP changes) public float secTime = 2.0f; public float totTime = 0.0f; public bool greenCubeIAPOwned = false; public static bool isNoAdActvated = false;

     //Load the Scene with the cube/ setup the soomla intergration
     void Start () 
     {
         //PlayerPrefs.DeleteAll ();
         Application.LoadLevel ("test");                                                                //Load actual scene
         DontDestroyOnLoad(transform.gameObject);                                                    //Allows this gameObject to remain during level loads, solving restart crashes
         StoreEvents.OnSoomlaStoreInitialized += onSoomlaStoreIntitialized;                            //Handle the initialization of store events (calls function below - unneeded in this case)
         SoomlaStore.Initialize (new ExampleAssets());                                                //Intialize the store
     }

     //this is likely unnecessary, but may be required depending on how you plan on doing IAPS
     public void onSoomlaStoreIntitialized()
     {
         Debug.Log ("SOOMLA STORE started");
     }

     //ASSIGN CUBE TO BE COLORED
     void OnLevelWasLoaded(int level)
     {                                                                                                 //Assigns the cube if the level is loaded to correct level{                                            
         if (level == 1) {                                                                             //the second level in the build list (0 == first level, 1 == second level)
             cube = GameObject.Find ("testCube").transform;                                            //Assign cube by finding it the the hierarchy in the scene ( via its name)
         }
     }

     //UPDATE CUBE COLOR
     //Assign cube color based on it (using playerprefs) (see CheckIAP_PurchaseStatus() function below to understand)
     void Update () 
     {
         if (Time.timeSinceLevelLoad > totTime) 
         {
             CheckIAP_PurchaseStatus ();                                                                //Check status of in app purchase (true/false if player has purchased it)
             totTime = Time.timeSinceLevelLoad + secTime;
         }
         if(cube != null)
         {
             if(!greenCubeIAPOwned) 
             {
                 cube.transform.GetComponent<Renderer>().material.color = Color.blue;                                    // if player has purchased item, turn the cube green
             }

             if(greenCubeIAPOwned) 
             {
                 cube.transform.GetComponent<Renderer>().material.color = Color.green;                                // if player has not purchased item (or hasnt restored previous purchases) turn the cube red 
             }
         }
     }

     //CHECK IAP STATUS (0 = not owned, 1 = owned for GetItemBalance())
     //Check the Status of the In App Purchase (true/false if player has bought it)
     void CheckIAP_PurchaseStatus(){
         Debug.Log ("Restored .... turn_green_item_id 's balance is = " + StoreInventory.GetItemBalance("turn_green_item_id"));                            // Print the current status of the IAP
         if (StoreInventory.GetItemBalance("turn_green_item_id") >= 1) 
         {
             greenCubeIAPOwned = true;        // check if the non-consumable in app purchase has been bought or not
             isNoAdActvated = true;
             Admob_scripts.canEnableAds = false;
             Debug.Log("CUBE WOULD BE GREATE..!!!!!!");                            // Print the current status of the IAP
         }
     }
 
     void OnGUI() {
         //Button To PURCHASE ITEM
         if (GUI.Button (new Rect (Screen.width * 0.2f, Screen.height * 0.05f, 200, 200), "Show ads..")) {
             if(!isNoAdActvated)
             {
                 GameObject.Find ("Admob_DnD").GetComponent<Admob_scripts> ().ShowInterstitial ();
             }
             else
             {
                 Debug.Log("Succceess.... !isNoads Activated");
             }
         }

         if (GUI.Button(new Rect(Screen.width * 0.2f, Screen.height * 0.4f, 150,150),"Make green?")) 
         {
             try 
             {
                 Debug.Log("attempt to purchase ");
                 StoreInventory.BuyItem ("turn_green_item_id");                                        // if the purchases can be completed sucessfully
                 Debug.Log("After attempt to purchase ");
             } 
             catch (Exception e) 
             {                                                                                        // if the purchase cannot be completed trigger an error message connectivity issue, IAP doesnt exist on ItunesConnect, etc...)
                 Debug.Log ("SOOMLA/UNITY SucessFully Purchasedddd " + e.Message);                            
             }
         }
         //Button to RESTORE PURCHASES
         if (GUI.Button(new Rect(Screen.width * 0.2f, Screen.height * 0.8f, 150,150),"Restore\nPurchases")) {
             try 
             {
                 SoomlaStore.RestoreTransactions();                                                    // restore purchases if possible
             } 
             catch (Exception e) 
             {
                 Debug.Log ("SOOMLA/UNITY" + e.Message);                                                // if restoring purchases fails (connectivity issue, IAP doesnt exist on ItunesConnect, etc...)
             }
         }

         //Button to RESTART LEVEL (ensure it doesnt crash)
         if (GUI.Button(new Rect(Screen.width * 0.5f, Screen.height * 0.8f, 150,150),"Restart"))  
         {
             Application.LoadLevel (Application.loadedLevel);
         }
     }

 }

}

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 tkamruzzaman · Dec 06, 2016 at 07:54 AM

In IOS store items must be restored upon clicking restore purchase button. If you don't tap the button manually it should not restore automatically. However in Google Play and other stores it's different. IAP should restore Automatically after reinstalling the app. So you are doing it right just no need for restore purchase button in android. Cheers :)

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.

Follow this Question

Answers Answers and Comments

77 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

Related Questions

Fail to operate Soomla/Unity and do not understand the error 2 Answers

How to resolve Soomla_IAP Unity_iOS plugin InvalidCastException? 0 Answers

Authentication error when testing Unity IAP on an Android device 1 Answer

Problem with IAP (In App Purchase) unity 1 Answer

Payment Gateway for unity3d 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