Search Unity

[Closed] Restore Purchase using Unity IAP

Discussion in 'Unity IAP' started by siddharth3322, Feb 15, 2018.

Thread Status:
Not open for further replies.
  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    I have game that contains 5 Non-Consumable in app purchase products. So these 5 can be later on restored by game player.
    I have gone through this whole document but details regarding restore purchase not mentioned.
    https://unity3d.com/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game

    At present I have this code for doing restore transaction:
    Code (CSharp):
    1. public void RestorePurchases ()
    2.     {
    3.         if (!IsInitialized ()) {
    4.             Debug.Log ("RestorePurchases FAIL. Not initialized.");
    5.             return;
    6.         }
    7.  
    8.         if (Application.platform == RuntimePlatform.IPhonePlayer ||
    9.             Application.platform == RuntimePlatform.OSXPlayer) {
    10.             Debug.Log ("RestorePurchases started ...");
    11.  
    12.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions> ();
    13.             apple.RestoreTransactions ((result) => {
    14.  
    15.  
    16.                 Debug.Log ("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    17.             });
    18.         } else {
    19.             Debug.Log ("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    20.         }
    21.     }
    I want to restore transaction for both Android and iOS games. So I require help for both platforms.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Is this code working for you in your testing in TestFlight? I will follow up with a Google Play implementation.
     
  3. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    I am asking for the code through which I can unlock the locked items - for ex. my game has 6 unique levels and each level get unlocked through purchase.
    So at restore purchase what code I require to write to unlock this item!!
    How to detect which which product previously purchased? so I can restore it.

    For both platforms, I am asking for this kind of code.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You should be receiving a ProcessPurchase callback for each of your restored items, so you would use the same logic as the original purchase in general.
     
    siddharth3322 likes this.
  5. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    As per this document and my understanding - For Android, ProcessPurchase method get called automatically, even I don't require to put Restore Purchase button in Android version of game.

    https://support.unity3d.com/hc/en-u...does-Unity-IAP-handle-restoring-transactions-

    But For iOS, I require to place Restore Purchase button and write code that restore purchased product, so I am asking for this code!! Through that purchased game product become unlocked.
    Or its same as like Android in, iOS too ProcessPurchase method get called automatically!!
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    As I mentioned and described in the link you provided, during restore, ProcessPurchase is called. The code that you originally posted is all you need. Please confirm with actual store and product testing. From this post, it appears you've had this question since 2016. I trust that you have tested in the respective store testing environments since then! https://answers.unity.com/questions/1133947/unity-iap-restore-google-play-store.html
     
    Last edited: Feb 16, 2018
    siddharth3322 likes this.
  7. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    Upto now I didn't done in app purchase for non-consumable things, either its renewable subscription purchase or its renewable products. For subscription, I require to detect in each app launch that where subscription running today or not.

    Like this way I have question, arise that what to do when any person restore transaction. But this time I am working with non-consumable products so I can check above points practically.
    At 2016, I can't able to understand actual point of implementation because I was new with Unity IAP structure :)
    But now I become experience with all phases.
     
Thread Status:
Not open for further replies.