Search Unity

Naive Question: Codeless IAP and Remembering Past Purchases

Discussion in 'Unity IAP' started by HiddenDoorChris, Jul 4, 2021.

  1. HiddenDoorChris

    HiddenDoorChris

    Joined:
    Jan 26, 2021
    Posts:
    4
    Hi -

    I can't tell if I'm overthinking or underthinking things, but I'm confused about how to properly use Codeless IAP works with (in my case) nonconsumable purchases. One single nonconsumable purchase, fwiw.

    I was able to set things up with Codeless IAP to make a nonconsumable purchase, and change my game state during the game session based on its successful purchase.

    What's unclear is how a codeless IAP purchase persists across game sessions. So far I'm testing in Editor and when I restart play mode, there's no evidence that the purchase has been remembered.

    I can't tell which (if any) of these is the case:

    1. I'm supposed to save and restore the purchase record in PlayerPrefs myself (which seems too insecure to be the right answer).

    2. In cases when the IAP buttons are present in the game starting scene, Codeless IAP will automatically send "Purchase completed" events in some useful way on restart, triggering the same code path through the same buttons, enabling the purchase to be reconstructed each time. (If this is the case, I assume it doesn't work in Editor mode; in which case, what's the proper way to test this?)

    3. Code needs to be written to review the state of purchase records on game start... which would arguably defeat the purpose of this being "codeless."

    My hope is that the answer is 2. or something like it, but the documentation just sort of elides over how this is supposed to work, and tutorials either ignore this or are confusing.

    Can someone help me understand? Feel free to point to whatever docs I've missed or misunderstood; I was unable to find an "easy answer" on the forum via search.

    Thanks - Chris

    P.S. Full disclosure: this is for a personal project unrelated to Hidden Door; I posted with the wrong Unity account and haven't found a way to delete and repost.
     
    Last edited: Jul 4, 2021
    nicholasr likes this.
  2. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    208
    As far as I know, Google Play verifies and restores purchases stored in user's GP account only on start of a newly installed (or deleted and re-installed) app, not on every start of the same app. So you can't rely on that functionality to maintain IAP status between game sessions.

    Correct approach is using option #1. After completing purchase, store the data locally on device, and then check it on each start of your game. Personally, I use a simple text file saved in Application.persistentDataPath, with content of that file encrypted using AES.
     
  3. HiddenDoorChris

    HiddenDoorChris

    Joined:
    Jan 26, 2021
    Posts:
    4
    Thanks Ukounu.

    I'd seen some articles that showed (not entirely clearly) how to validate receipts to get info on past purchases, implying that this was a way to be more secure in recognizing past purchases.

    When is that approach applied? Is it a "belt and suspenders" way to be less hackable, or more appropriate to other circumstances? Maybe that's an alternative for Restoring Purchases when not using Codeless IAP?
     
  4. Ukounu

    Ukounu

    Joined:
    Nov 2, 2019
    Posts:
    208
    Validating purchase receipts is an extra step you can take after getting a response about completed purchase and before actually unlocking your game content, to make sure that this response was indeed issued by Google Play, and not spoofed by a hacking software. It doesn't replace the need to implement some functionality to store information about unlocked IAPs between game sessions.
     
    nicholasr and HiddenDoorChris like this.
  5. HiddenDoorChris

    HiddenDoorChris

    Joined:
    Jan 26, 2021
    Posts:
    4
    Thanks. This is extremely helpful context!