Search Unity

Questions about Codeless IAP with non-consumables

Discussion in 'Unity IAP' started by Tiollo, May 27, 2020.

  1. Tiollo

    Tiollo

    Joined:
    Mar 14, 2015
    Posts:
    23
    Hi!

    I'm using Codeless IAP with non-consumables on Unity 2018.4 and I'm having some troubles with understanding the best practices to handle IAP listeners, restore purchases and the player saved data.

    (I'm following this documentation and the example project, but I can't find the answers I need)

    So, that's what I'm doing:
    - I setup the IAP catalog
    - I create the IAP buttons
    - The function OnPurchaseComplete(Product product) will save on a local file that the player made a purchase (i.e. no_ads = true)
    - Every time that the game needs to show (or to not show) the ads, I simply check the value of no_ads on the local file
    - Everything works so far!

    But I'm having some doubts about how the "Restore purchases" exactly works with Codeless IAP, in case the player deletes his local data.

    I have two main questions:

    1) As far as I understand, for iOS I need to insert the "Restore Purchases" button. When this button is pressed, how will Unity IAP handle the outcome of the restored purchase? I mean: how can I store again on my local file that no_ads = true? Do I need to make something manually? Or is it handled automatically from the Restore purchases that calls again the OnPurchaseComplete() function for each IAP button of the scene?

    2) About Android and the Play Store, I understood that the "Restore Purchases" is automatically handled when the player installs again the app. So I have the same doubts: how can I save again on the local file that the player already made a purchase?
    As far as I understand, I need to use the IAP Listener. But then I didn't get what are the next steps. The IAP Listener is listening - I guess - so when the game starts it will download the purchase data from the Play Store and I can use it somehow to check the values and save on my local file. Is it correct or did I misunderstand something? In case, how do I access to the purchase data (if I have to)?

    3) By looking at the documentation about IAP Listeners I also have another doubt: do I need to add an event (in the events list of "OnPurchaseComplete") for every possible product/purchase?

    Thanks in advance and sorry for the stupid questions :)
     
    mindawlee likes this.
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    In your code, a Restore happens exactly as if the user just made a brand new purchase. It's like an invisible person is clicking the Buy button.There are two Sample IAP projects here, the first is Scripted IAP, the second is Codeless. I would recommend using the first https://forum.unity.com/threads/sample-iap-project.529555/ Regarding (3),note that it's passing you the Product object as a parameter, so code your method accordingly. You can save your purchase information in PlayerPrefs.
     
  3. Tiollo

    Tiollo

    Joined:
    Mar 14, 2015
    Posts:
    23
    Thanks for the fast reply!

    I downloaded both the example projects but I'm still a little bit confused, sorry about that.

    With the Codeless version of the sample project, I can see that the IAP Listener calls a function (myListenerSucceed) that just shows a log message, instead of calling a Restore function or saving some data (in PlayerPrefs or on a binary file).
    That's why I'm a little bit confused. On the documentation it calls an event from a specific GameObject but I don't know what's written inside. On the sample project it doesn't do anything, so I feel stuck.
    So, sorry if I ask the questions again:
    - Is the IAP Listener the right solution for gathering and saving data from the restored purchases on Android?
    - If it is, is it handled automatically (like the Restore Purchase on iOS, but on the app start) or do I need to do something manually (like dragging the events of every single possible completed purchase)?


    With the Scripted version of the sample project, I can't find the part regarding the saved data. I can see that in
    MyIAPManager there is a BuyNoAds() function that is called from the BuyButton, but I can't find where the data is saved (in PlayerPrefs or a binary file, if it's needed) or what should I do to check it. Does the MyIAPManager wrapper save locally the purchase? If yes, how can I check it? I can't find a "isPurchased(product_id) function or something similiar.


    Thanks and sorry again if I insist with the silly questions :)
     
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Don't worry about the listener for now. Are initial purchases working correctly? We don't save in PlayerPrefs or anything for you, that is something you need to do yourself. Yes, you would save the purchase in your BuyNoAds method if you want. But again, don't worry about that now. First thing, get an initial purchase working. Start with the Sample IAP project, don't make any changes, and create the same products on your Google Dashboard, publish and test. This may help https://docs.unity3d.com/Manual/UnityIAPGoogleConfiguration.html