Search Unity

Manually invoke Restore Purchases equivalent on Android?

Discussion in 'Unity IAP' started by skullthug, Jan 5, 2021.

  1. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Hello. I'm currently migrating a project out of Stan's Assets Android Native billing flow into the Unity IAP system, for a product that is already on iOS, Android, macOS, & Windows.

    I'm well aware of the Restoring Transactions (https://docs.unity3d.com/Manual/UnityIAPRestoringTransactions.html) flow, specifically
    Stan's Assets has the functionality that has allowed us to call the restore purchases on Android at will (via a Restore Purchases button), as well as it being called automatically on first launch after fresh install.

    My problem with the Unity IAP approach is I don't trust this one singular restore call only being called once right after a fresh install, and would prefer to maintain the ability to have the user hit a Restore Purchases button additionally as a backup plan. I've run into far too many customer support edge cases now where the user had no internet/poor internet, or was just blatantly cursed somehow, causing the fresh install call to fail somehow. And in those cases having the Restore Purchase button available to debug with saved both me and the customer a headache.

    So is there a way to maintain this flow on Android using the Unity restoration procedure? Thanks.
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You should be able to use:

    m_GoogleExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
    m_GoogleExtensions.RestoreTransactions(callBack);
     
    skullthug likes this.
  3. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Awesome, thanks!
     
  4. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    88
    IGooglePlayStoreExtensions
    doesn't contain a definition for
    RestoreTransactions
    , though... :(
     
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    It does with Unity IAP 2.2.5 and Package Manager In App Purchasing 2.2.1
     
  6. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    88
    ah! ok, yeah. Something had gone wrong with a previous attempt & it turns out I was working with an older version of the package. It's properly updated, now, and I see it.
     
    JeffDUnity3D likes this.
  7. javierfed

    javierfed

    Joined:
    Apr 10, 2015
    Posts:
    50
    I have In App Purchasing installed, 4.1.3, but running
    GooglePlayStoreExtension.RestoreTransactions(OnRestore)
    I am only seeing it get called, and execute the OnRestore delegate. but it is not run through restoring purchases. we have a game where we want users to be able to reset their data and also want to allow them to manually restore purchases like how Apple does it. is it true Google Play won't allow us to restore purchases any other time than on a reinstall?
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    You can only restore non-consumables or subscriptions. During restore, you can expect a ProcessPurchase call for each product of this type. Does restore work for you when you reinstall?
     
  9. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Hi @JeffDUnity3D

    When I call RestorePurchases I have this exception inside Purchasing module and can not actually restore purchase on Android. On game restart (on initialize purchaser) the same thing happens and transaction don't get restored.

    InAppPurchasing 4.5.1

    If I start buy this non consumable again I will result in Duplicate Transaction response as expected.

    2022/12/10 00:56:52.072 28071 28113 Warn Unity Unity IAP: Unable to process purchase with transaction id: plkdndkpmhiafijhlckmhbjo.AO-J1Ox9X6uMoM5GM-wlzrh5sFbESeUB5V8S5PdJe_Td67T-2kXEnE4I9HjxBvthgf1ClWzoqaQWCSmOuAtWojbxVdtyT40Jf2EmoTi6KyYH8oMw2Av-OrY because the product details associated with the purchased products were not found.
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Action`1:Invoke(T)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity UnityEngine.Purchasing.<IgnoreExceptions>d__1`2:MoveNext()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Linq.<SelectManyIterator>d__17`2:MoveNext()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Collections.Generic.List`1:.ctor(IEnumerable`1)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Linq.Enumerable:ToList(IEnumerable`1)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity UnityEngine.Purchasing.<QueryPurchases>d__3:MoveNext()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Threading.ContextCallback:Invoke(Object)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Threading.ExecutionContext:RunInternal(ExecutionContext, ContextCallback, Object, Boolean)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Runtime.CompilerServices.MoveNextRunner:Run()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Action:Invoke()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity System.Threading.SendOrPostCallback:Invoke(Object)
    2022/12/10 00:56:52.072 28071 28113 Warn Unity UnityEngine.WorkRequest:Invoke()
    2022/12/10 00:56:52.072 28071 28113 Warn Unity UnityEngine.UnitySynchronizationContext:Exec()
     
  10. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    226
    Hello Jes28,

    This is usually caused by a product being restored that doesn't match between the Google Play Store and your products (IAP catalog for codeless or ConfigurationBuilder for coded).

    If you can trigger this, you could first validate which product the Google Play Store is trying to restore by going in the Google Play Console under Order Management and matching the purchase token with the one found in the error message (this is incorrectly labelled "transaction id" in our error message).

    Once you've identified which order caused the error, you can then compare the product information with the one in your application to make sure it matches.


    For the Duplicate Transaction one, this is usually caused by a pending transaction that hasn't been acknowledged with
    ConfirmPendingPurchase. If you are on coded IAP, could you debug the ProcessPurchase to see if you receive anything during the restore transaction?

    There was also a recent thread about a similar issue, maybe you'll find additional information there:
    https://forum.unity.com/threads/unable-to-process-purchase-with-transaction-id.1366257/
     
    JesOb likes this.
  11. kumarji_unity

    kumarji_unity

    Joined:
    Oct 20, 2022
    Posts:
    1
    Hello, I have somewhat same issue , I'm migrating our product from native java code of android billing using v4.0.0 to Unity's IAP v4.9.3. Our product is already on Android and iOS platforms.

    The issue I'm facing is, after installing build containing Unity IAP build using account where purchases were made using our old store code (using native billing), owned purchases are not being restored. Even manual way mentioned above is not restoring.

    When using test account for debugging and printing all the products related data received from store after Initialization, I have noticed that owned products do not have any transaction related details. But the same owned products have transaction details when debugging and printing from native code.

    I thought restore flow should work because behind the scenes both are using Android billing. Is there anything I'm missing? Any help or feedback would be helpful. Thanks.
     
    Last edited: Jul 24, 2023