Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ProcessPurchase method is not called when reentering game

Discussion in 'Unity IAP' started by better_walk_away, Jun 13, 2019.

  1. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Hi,

    I am using Unity Codeless IAP, my game has only one IAP Button that is used for purchasing a non-consumable product, but I don't know how to restore the non-consumable product that customer had previously bought when reentering the game.

    When the customer reenters the game, I want to be able to set one of the booleans in the my scripts to true if the customer had already purchased the non-consumable product previously.

    When the game starts, I can see that that Unity IAP is being initialized because there are these messages in the Console:
    Initializing UnityPurchasing via Codeless IAP
    UnityEngine.Purchasing.IAPButton:OnEnable()

    UnityIAP Version: 1.22.0
    UnityEngine.Purchasing.IAPButton:OnEnable()


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

    It says when Unity IAP is initialized, Unity IAP's backend process will call the ProcessPurchase method via the IStoreListener on each item being restored. But actually the ProcessPurchase methods in Both IAPButton.cs and CodelessIAPStoreListener.cs are not being called at all. I didn't modify any code, I only add a random Debug.Log("hi") message to test if the method is actually being called, but it's not. It only output a message in the Console "Already recorded transaction GPA.xxxx-xxxx-xxxx-xxxxx".

    By the way, my IAP button is placed in the startup scene, so Unity IAP gets initialized right after I open the game.
    I am testing on an Android device.
    I am using Unity 2018.4.2f1.

    What should I do?
    It would be nice if somebody can help me..
     
    Last edited: Jun 13, 2019
  2. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I found that ProcessPurchase was called after reinstalling the game and opening the game for the first time. But when I restarted the game, ProcessPurchase wasn't being called. What should I do?
     
  3. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I found that by clearing the game's data through setting on the Android device, the ProcessPurchase will get called after entering the game, but again, when I reenter the game, ProcessPurchase doesn't get called. It only output a message in the Console "Already recorded transaction GPA.xxxx-xxxx-xxxx-xxxxx".
     
  4. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    Hi, I finally fixed this issue, it was very ridiculous...

    My product is non-consumable, I should uncheck the "Consume Purchase" in my IAP Button.
    I thought "Consume Purchase" meant to consume this purchase so that customer can use the paid features immediately after the purchase. No, it actually means to consume this purchase right away and use it, it is for consumable products only, the product won't be restored when restarting game, thus, ProcessPurchase won't be called.

    I think Unity should disable this option automatically if the product is non-consumable, it makes no sense to show this option when the product is actually non-consumable...
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    No, that is not the correct approach. This will leave the product in Pending state. Instead, you will want to implement inventory management to track purchases. You don't want to use ProcessPurchase be your inventory management method.
     
    better_walk_away likes this.
  6. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I have read this several times:
    https://docs.unity3d.com/Manual/UnityIAPValidatingReceipts.html

    If I store the receipt of a non-consumable product on the device in a txt file, when the game starts, I read the receipt using CrossPlatformValidator, if it's valid, then unlock the paid content.
    But this seems to be not secure. I copied the receipt from the device, then I pasted the receipt to another device. The copied receipt also passed the validation. So if a player shares his receipt to his friends, his friends will be able to pass the validation without purchasing as well. Is this an expected behavior when it comes to local receipt validation?

    I am thinking a safe way to store the transaction record. When a player wants to purchase a non-consumable product, I will request the player to login with his Facebook or Google account before he can purchase it. When the purchase succeeds, I then store the transaction record on the cloud server. When player restarts the game, player has to login his account, then I read the transaction record from the cloud server, if there is a record, then player will be allowed to use the paid features. If the player doesn't login his account, then I can't read the record on the cloud server, the player can't use the paid features just like a free-to-play player.
     
  7. better_walk_away

    better_walk_away

    Joined:
    Jul 12, 2016
    Posts:
    291
    I still have a question,
    Why is there a "Already recorded transaction GPA.xxxx-xxxx-xxxx-xxxxx" message every time the player starts the game? Is it Unity checking the transaction record? If so, then why can't we unlock the paid feature as well when Unity is checking the transaction record?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Please keep in mind to fully implement IAP, you also need to implement inventory management to track user purchases. Some developers use PlayerPrefs, but it's not completely secure. Other studios save user purchases to their cloud server.
     
    better_walk_away likes this.