IAP codeless for Android Google play

Sorry for silly question…
I am not good at code. I use IAP codeless and have some simple purchaser code:

public class Purchaser : MonoBehaviour
{
    public GameObject iapButton;

    private void Awake()
    {
        iapButton.SetActive(true);
    }

    public void OnPurchaseComplete(Product product)
    {
#if UNITY_EDITOR || UNITY_ANDROID
        StartCoroutine(DisableTapButton());
#endif
    }

    public void OnPurchaseFailure(Product product, PurchaseFailureReason reason)
    {
        Debug.Log("Purchase of product " + product.definition.id + " failed due to " + reason);
    }

All works as right, but what i shoud do to restore purchases locally? I have some ideas, but I don’t understand where to start. Ideal for me would be: save purchaser data in the Google cloud. What specific steps do I need to take for reach the goal using this code?

  • I tried to create a save/load system using the data manager. Not successfully.
  • What i can do with json file of IAP Catalog in “Resources” folder?
  • I also read about receipt validation. It completely confused me.

Thanks for help!

You would not want to be writing script for Codeless, as the name implies. You are mixing Codeless and Scripted which will not work. Please start with the Sample IAP project here Sample IAP Project

Yes, I saw your video. I just noticed that I accidentally copied not all the code. This is what I’m need for.

    private IEnumerator DisableTapButton()
    {
        yield return new WaitForEndOfFrame();
        iapButton.SetActive(false);
    }
}

Can this be implemented using IAP codeless?

Not to my knowledge. You are writing code for codeless :slight_smile:

Interesting, but it works for me) My question is a little different. After restart the app, purchases are reset, I want to save purchaser data in the cloud or server. I dont know. The question may be not addressed special for you. Maybe someone on the forum knows how to do this. And what to do.

Ahh sory for my accent:eyes:I hope you understand. Non consumable purchases need to save.

I understand now. You can use PlayerPrefs to store purchase history on the device, but it’s not entirely secure. Also, ChilliConnect offers a cloud solution https://www.chilliconnect.com/live-ops-features/ https://docs.unity3d.com/ScriptReference/PlayerPrefs.html . I might suggest however that you consider refactoring your code and start with the Sample IAP project, you are combining Codeless with Scripting that could likely lead to issues. At least you should consider renaming your OnPurchaseComplete and OnPurchaseFailure methods, they are the same names as in the library.

Ok, Jeff I made as you said. I disabled library of purchasing in script and renamed methods. Thanks for your remark. I don’t even consider PlayerPrefs. Very unsafe. Json file seems more attractible.

To store data in the cloud, first need to create an internal storage system or what?
Can I send Json IAP catalog to the cloud? If send local save will work?

That will be up to you, but I would get local storage working first using the easiest approach (PlayerPrefs). A JSON file would be even easier for a user to hack, you would need to do a binary save for better security. Your IAP catalog only defines products, it does not track transactions.

After my last test, I found that on the Google server, purchases are not saved. Does this mean that I need to add IAP Listener?

My Unity console looks like, when i use IAP listener :
IAPButton.ProcessPurchase(PurchaseEventArgs UnityEngine.Purchaser.PurchaseEventArgs - MyProduct)
UnityEngine.EventSystems.EventSystem:Update()
IAPListener.ProcessPurchase(PurchaseEventArgs UnityEngine.Purchaser.PurchaseEventArgs - MyProduct)
UnityEngine.EventSystems.EventSystem:Update()

But then I do not understand the meaning of this checkbox.
6089166--661200--22.PNG

What do you mean, purchases are not saved? Please show a screenshot

After reinstalling the app.

Sorry I don’t quite follow, what are you expecting to happen after you reinstall your game that isn’t happening? Where are you expecting the purchases to be saved, please show a screenshot. If you are using PlayerPrefs as previously suggested to store purchases, please note that PlayerPrefs can be deleted during app reinstall.