Check if user bought a non consumable

Hi,
I’m adding Unity IAP to my game I will use it to allow the user to unlock the full game.
The idea is to have a single splash screen that check if the user bought the non consumable:

  • If the user bought it just move to the main menu
  • If the user haven’t bought it I move to aa “Try/Unlock Full Game” scene

I know that on Android there’s no need to restore a purchase but I still need to check if the product has been bought or not.

I actually thought about using this code

            if (product != null && product.hasReceipt)
            {
                // Move to full main menu
            }
            else if(product != null && !product.hasReceipt)
            {
                // Move to unlock game menu
            }

Do you think this can fit my needs?

After investingating it looks like that the best way to handle this issue is to save that in the PlayerPrefs when ProcessPurchase.
From what I understood ProcessPurchase is called when a purchase is done for the first time and when the game is installed again/for the first time, is that right?
This mean that unity will automatically call this function and that there’s no need to manually call it?
I just need an object with the IAP handler script assigned.

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
        {
            PlayerPrefs.SetInt("keyGameUnlocked", 1);
        }
        return PurchaseProcessingResult.Complete;
    }

That is one solution. Keep in mind that PlayerPrefs can be deleted during reinstall. We are working on an improved restore option for Android, hopefully it will be included in the next release.

Thank you for your answer can you confirm that ProcessPurchase will be called by Unity and there’s no need for me to manually call it right?

During a reinstall, yes. You should never call ProcessPurchase directly.