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 Noxide7 · Oct 29, 2019 at 03:36 AM · iosin app purchase

Restoring Transactions ios, what do I add when the restoration process succeeded?

I've been trying to get my non consumables to restore on my ios device but I'm getting no results with my restore button. I want to know if there is anything else I'm supposed to add in this code?

 // Inside class inheriting from Unity IAP IStoreListener interface
 public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
 {
     extensions.GetExtension
  
    ().RestoreTransactions (result => {
         if (result) {
             // This does not mean anything was restored,
             // merely that the restoration process succeeded.
         } else {
             // Restoration failed.
         }
     });
 }

I can't find any examples on what needs to go in, if anything at all. If someone could provide a bit of clarity or even an example code that has a working restore function then I would be really grateful.

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
1

Answer by Getsumi3 · Oct 29, 2019 at 12:42 PM

Hi
I'm bad at explanation but I'll try to help.

The restore method is almost the same as yours.
In my game I have a bool variable that is called on Awake/Start that tells to the game that item is unlocked.

Ok. So basicly if "result" returns true than CallYourMethodThatWillUnlockItems()

Here is the BuyLevels() and RestorePurchases() code that worked for my game.

     private void Awake()
         {
             isUnlocked = PlayerPrefs.HasKey("isUnlocked") ? (isUnlocked = (PlayerPrefs.GetString("isUnlocked") == "true") ? true : false) : false;
             PlayerPrefs.SetString("isUnlocked", (isUnlocked ? "true": "false"));
         }
 
 public void BuyLevels()
     {
         // 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(kProductIDLevels);
 
             // 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)
             {
                 Console.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);
                 isUnlocked = true;
                 PlayerPrefs.SetString("isUnlocked", (isUnlocked ? "true" : "false"));
             }
             // Otherwise ...
             else
             {
                 // ... report the product look-up failure situation  
                 Console.LogWarning("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
                 isUnlocked = false;
                 PlayerPrefs.SetString("isUnlocked", (isUnlocked ? "true" : "false"));
             }
         }
         // Otherwise ...
         else
         {
             // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or 
             // retrying initiailization.
             Console.LogError("BuyProductID FAIL. Not initialized.");
             isUnlocked = false;
             PlayerPrefs.SetString("isUnlocked", (isUnlocked ? "true" : "false"));
 
         }
     }
 
         // Restore purchases previously made by this customer. Some platforms automatically restore purchases, like Google. 
         // Apple currently requires explicit purchase restoration for IAP, conditionally displaying a password prompt.
         public void RestorePurchases()
         {
             // If Purchasing has not yet been set up ...
             if (!IsInitialized())
             {
                 // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
                 Console.LogError("RestorePurchases FAIL. Not initialized.");
                 return;
             }
         // If we are running on an Apple device ... 
             if (Application.platform == RuntimePlatform.IPhonePlayer ||
                     Application.platform == RuntimePlatform.OSXPlayer)
             {
                     // ... begin restoring purchases
                     Console.Log("RestorePurchases started ...");
         
                     // Fetch the Apple store-specific subsystem.
                     var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
                     // Begin the asynchronous process of restoring purchases. Expect a confirmation response in 
                     // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
                     apple.RestoreTransactions((result) =>
                     {
                         // The first phase of restoration. If no more responses are received on ProcessPurchase then 
                         // no purchases are available to be restored.
                         Console.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
         
                         if (result == true)
                         {
                             Console.Log("Purchase restored");
                             //purchase restored. Unlock all bought items
                             isUnlocked = true;
                             PlayerPrefs.SetString("isUnlocked", (isUnlocked ? "true": "false"));
                         }
                         else
                         {
                             Console.LogWarning("No purchases available to restore");
                         }
                     });
             }
             // Otherwise ...
             else
             {
                     // We are not running on an Apple device. No work is necessary to restore purchases.
                     Console.LogError("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
             }
     }




Comment
Add comment · Show 1 · 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
avatar image Noxide7 · Oct 29, 2019 at 01:26 PM 0
Share

I'll try this out with my code tonight after work but just so I understand, the code used to unlock the levels in your BuyLevels() method just needs to be copy pasted into the "result == true" if statement that's within the RestorePurchases() method correct?

Edit: O$$anonymous$$ so I think I'm missing something. I get that now I'm supposed to put in some kind of code to unlock the passed levels purchased but how do I do that if I can only use the results bool? I have multiple levels that are sorted by numbered string variables, how to I restore them if in the PurchaseProcessingResult() I did it like this.

 if (String.Equals(args.purchasedProduct.definition.id, "puzzle_pack_" + packNumber.ToString(), StringComparison.Ordinal))
         {
             Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
             Data$$anonymous$$anager.Instance.UnlockPuzzle("puzzle_pack_" + packNumber.ToString());
         }

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

149 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 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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

any SINGLE plugin for both ios and android In App Purchase?? 4 Answers

iOS Native Plugin: Cannot get product information 0 Answers

IOS alert box Confirmation 0 Answers

IAP not working in iOS builds? 1 Answer


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