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

iOS purchase restore button

Discussion in 'Game Foundation' started by metiscoda, Aug 30, 2020.

  1. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    How do I implement a "Restore Purchase" button for IAP transactions? Since I don't explicitly create IAPButtons in GF, not sure how to inform GF when the Restore is successful and a new product has been added to the inventory.
     
    erika_d likes this.
  2. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    One way of doing this would be to create an IAPListener and have it generate the right inventory item when a restore is done. But having an IAPListener in the scene seems to mess with GF initialization (since it probably initializes UnityPurchasing itself)? Is there a way around this?
     
  3. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    We will check into this. Apple requires a Restore button, for example.
     
  4. Digitalpen

    Digitalpen

    Joined:
    Jun 18, 2019
    Posts:
    2
    does it require restore button or not ? I checked some other games, they do have restore button
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, Apple requires a Restore button. It's on our roadmap to include this prefab. You'll notice that Codeless IAP already has a Restore button type.
     
  6. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    Apple requires it, but I've noticed that if you do not have it, and you have reinstalled the app, the non-consumable will appear for purchase again, and when you purchase it, it will tell you that you already purchased it and you will get it for free.

    I tried the IAPButton and IAPListener route for the "Restore" button, but as soon as I introduce either one, GF fails initialization (probably because of the other issue I pointed out - https://forum.unity.com/threads/interaction-with-unity-iap.959880/#post-6266718).

    In addition, I have not gotten my non-consumables to work on GF for iOS at all. E.g. I have set it up properly and tested in the Editor, but when I build to iOS, it does not seem to trigger the inventory item reward for the purchase. This is for the original purchase (not even for Restore).

    I got the chance to try it on Google Play last night and it seems to behave the same way - non-consumable rewards do not seem to be granted.
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You would not want to use the IAP Listener or IAPButtons with Game Foundation, only the PreFabs. Please provide the device logs. Android is a bit easier https://forum.unity.com/threads/how-to-capturing-device-logs-on-android.528680/ and https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/ As mentioned, you can't test IAP in the Editor, it doesn't connect to any store. You need to configure each store first https://docs.unity3d.com/Manual/UnityIAPAppleConfiguration.html and https://docs.unity3d.com/Manual/UnityIAPGoogleConfiguration.html
     
  8. metiscoda

    metiscoda

    Joined:
    Nov 18, 2013
    Posts:
    41
    Got the non-consumables working - the above problem was user error - I had not specified the reward in the db properly.
     
    erika_d and mingz-unity like this.
  9. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    @metiscoda @JeffDUnity3D , Hi, how do we access the Restore callback in Game Foundation? How would i know if the restore was successful or not? And award the user whatever was restored? I have called
    GameFoundationSdk.transactions.RestoreIAPPurchases() on Restore button.
     
  10. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    40
    After calling GameFoundationSdk.transactions.RestoreIAPPurchases() (in iOS), you can listen to the GameFoundation.transactions.purchaseSucceededInIAPSDK event to know when each purchase has been restored. Game Foundation automatically fulfills restored purchases.

    Normally if you want to handle processing those purchases yourself, you can uncheck "Process Background Purchases" in Game Foundation Settings, and then process them yourself with additional logic. However, there are problems in the release that currently prevent this working properly. Also, Game Foundation currently does not yet expose the callback that happens when iOS finishes restoring purchases. We'll continue to work on these issues/improvements.
     
    erika_d likes this.
  11. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Thanks and is there anything i can use for when the user cancels the purchase?
     
  12. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Hi @Raghavendra,

    When a user cancels the purchase it should trigger an OnTransactionFailed callback, which you can subscribe to in the Inspector window if you're using one of the Game Foundation Prefabs (Store, TransactionItem, PurchaseButton, etc) or via code `GameFoundationSdk.transactions.transactionFailed += YourListenerMethodHere;`

    Does that help address your use case?
     
    Raghavendra likes this.
  13. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Thanks. This worked for cancelled purchases.

    But unfortunately, GameFoundation.transactions.purchaseSucceededInIAPSDK didn't work for getting Restore purchase events.
     
  14. erika_d

    erika_d

    Joined:
    Jan 20, 2016
    Posts:
    413
    Glad that worked for cancelled purchases. Sorry the purchaseSucceededInIAPSDK isn't working for Restore purchases. Is the event just not getting triggered at all? Are you testing on Android or iOS so we can look into it for you?
     
  15. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    40
    Hi @Raghavendra,

    I can confirm that we've found a regression that has caused restored purchases to stop working. We'll work on getting this fixed in the next release.
     
    saskenergy likes this.
  16. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    I haven't updated to 0.8.0 yet. I am still on 0.7.0.
     
  17. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    40
    It looks like I misspoke about a regression with Restore Purchases. It is working for me in the latest release (0.8.0), but it does look like there's a problem with that purchaseSucceededInIAPSDK event not firing so we don't know when restore purchases is finished. I'll follow up here when I know more.
     
    Raghavendra likes this.
  18. richj_unity

    richj_unity

    Unity Technologies

    Joined:
    Sep 23, 2019
    Posts:
    40
    Hi again, sorry for the extended delay in following up on this, but I tested and found that the purchaseSucceededInIAPSDK event is firing as expected in the 0.8.0 release. But please let us know if you do have any issues with it.
     
  19. itierney

    itierney

    Joined:
    Jan 28, 2019
    Posts:
    27
    This issue is stopping my app getting into the app store!

    When you add an IAP Restore button, the preferences to set a function disappear.
    Also when I look at the IAP rockets example the restore button isn't even a IAP button!

    So just to clarify:
    1. When I use an IAP_restore button do I have to write additional code to trigger a restore (Many tutorials say you don't) or just set the button type to "restore" ?
    2. If so, where do I put this code and how do I link it to the IAP button (all options disappear when you set the button type to restore!)
    3. At the moment I am just creating an IAP button and setting it to restore (no additional code). When I look at the console while running on an iPhone it prints the following but nothing happens...so iOS sign in..nothing!

    2022-11-05 19:31:46.901607+0000 PocketBuddha[67035:5564595] UnityIAP: RestorePurchase

    2022-11-05 19:31:47.922061+0000 PocketBuddha[67035:5564595] UnityIAP: PaymentQueueRestoreCompletedTransactionsFinished"