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

Resolved [Solved]iOS Restore ProcessPurchase Fail

Discussion in 'Unity IAP' started by alexp96, Apr 15, 2019.

Thread Status:
Not open for further replies.
  1. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
    Hello,

    I'm having an issue with the restore purchase, buying new products works fine, it initializes and the purchase is made successfully, however after removing and installing the application again, when I tap the restore button i get the error: ProcessPurchase: FAIL. Unrecognized product: "productID"

    Promo interface is available for the correct number of items.

    I'm using the code provided by Unity and I cannot understand why this is happening, please help.

    Code (CSharp):
    1. public void RestorePurchases()
    2.     {
    3.         // If Purchasing has not yet been set up ...
    4.         if (!IsInitialized())
    5.         {
    6.             // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
    7.             Debug.Log("RestorePurchases FAIL. Not initialized.");
    8.             return;
    9.         }
    10.  
    11.         // If we are running on an Apple device ...
    12.         if (Application.platform == RuntimePlatform.IPhonePlayer ||
    13.             Application.platform == RuntimePlatform.OSXPlayer)
    14.         {
    15.             // ... begin restoring purchases
    16.             Debug.Log("RestorePurchases started ...");
    17.  
    18.             // Fetch the Apple store-specific subsystem.
    19.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    20.             // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
    21.             // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    22.             apple.RestoreTransactions((result) => {
    23.                 // The first phase of restoration. If no more responses are received on ProcessPurchase then
    24.                 // no purchases are available to be restored.
    25.                 Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    26.             });
    27.         }
    28.         // Otherwise ...
    29.         else
    30.         {
    31.             // We are not running on an Apple device. No work is necessary to restore purchases.
    32.             Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    33.         }
    34.     }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    The error is in ProcessPurchase not in your RestorePurchases method. ProcessPurchase is called during a restore for each product. Of what you can, please show your ProcessPurchase code, the code where you add your products, a screenshot of your products as configured on iTunes, and the device logs. https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/
     
  3. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
    Adding products:
    Code (CSharp):
    1. for (int i = 0; i < charachterList.Length; i++)
    2.                     Purchaser.Instance.builder.AddProduct("com.PopAlexandru.CrossyLands." + charachterList[i].name, ProductType.NonConsumable);
    3.                 Purchaser.Instance.InitializePurchasing();
    Builder:
    Code (CSharp):
    1. public void InitializePurchasing()
    2.     {
    3.         // If we have already connected to Purchasing ...
    4.         Debug.Log("PRIMA " + IsInitialized());
    5.         if (IsInitialized())
    6.         {
    7.             // ... we are done here.
    8.             return;
    9.         }
    10.  
    11.         UnityPurchasing.Initialize(this, builder);
    I'm adding the products outside the Purchaser class because I have a very big list of characters (don't know if its right but it has been working fur purchasing (first time using )).

    ProcessPurchase:
    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2.     {
    3.         if (String.Equals(args.purchasedProduct.definition.id, productName, StringComparison.Ordinal))
    4.         {
    5.             Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
    6.             // TODO: The non-consumable item has been successfully purchased, grant this item to the player.
    7.             CharacherSelection.instance.ChangeSprite(CharacherSelection.instance.index2);
    8.         }
    9.         else
    10.         {
    11.             Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    12.         }
    13.  
    14.         // Return a flag indicating whether this product has completely been received, or if the application needs
    15.         // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
    16.         // saving purchased products to the cloud, and when that save is delayed.
    17.         return PurchaseProcessingResult.Complete;
    18.     }
    19.  



    Log:
     
    Last edited: Apr 16, 2019
  4. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    As another user, are you able to purchase those products? Are you testing In an Alpha/Beta release as a tester separate from your developer account? Your testers need to first download the Alpha/Beta release from Google Play after they receive the test invite, then subsequently you can side load the app directly. But the first time, it must be downloaded (as a tester) from Google Play.
     
  5. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
    I've tested only on iOS, sandbox testing without uploading to TestFlight, only adding a sandbox test user and no success, I also tried TestFlight and the result was the same. Restoring the purchase didn't work, but buying new products works every time. Also, when trying to buy the same character after reinstalling the application the "You have already purchased this ... , would you like to get it for free?" pops up
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Got it, I will check here
     
  7. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Notice the error in your logs, Unrecognized Product: com.PopAlexandru.CrossyLands.Character_BusinessWoman2 . Have you submitted a new build along with adding new products, as their Dashboard message states?
     
  9. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
    Every product was added and available on the iTunesConnect dashboard. The problem was that the restore method was not passing the correct product name.

    I solved this problem by writing my own restore purchase method.
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    What name was it passing? Do you mean in Apple's code?
    Code (CSharp):
    1.  
    2.            var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    3.             // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
    4.             // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    5.             apple.RestoreTransactions((result)...
     
  11. alexp96

    alexp96

    Joined:
    Aug 30, 2018
    Posts:
    7
    Yes, the Apple code returned a null product name. Initially thought it was my fault but buying worked, after spending some days debugging I was able to find the problem.
     
    OneGame-Studio likes this.
  12. OneGame-Studio

    OneGame-Studio

    Joined:
    Dec 5, 2016
    Posts:
    13
    Hi Alex! I'm in the same situation. How do u fix it ? Thanks
     
  13. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you elaborate where the product name is null in the Apple code?
     
  14. jasilkm

    jasilkm

    Joined:
    Apr 26, 2017
    Posts:
    6
    I am also faced same error and I fixed easy way.

    This issue in process purchase code. Please see my comment

    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2. {
      // This condition never satisfy because when we trigger restore purchase 'productName' always be null, that's why we getting log ' Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", 'product name'));'

      if (String.Equals(args.purchasedProduct.definition.id, productName, StringComparison.Ordinal))
    3. {
    4. Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
    5. // TODO: The non-consumable item has been successfully purchased, grant this item to the player.
    6. CharacherSelection.instance.ChangeSprite(CharacherSelection.instance.index2);
    7. }
    8. else
    9. {
    10. Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    11. }

    12. }
     
  15. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Where are you setting the value for productName?It's not declared nor set in your code. Is it a public variable?
     
  16. jasilkm

    jasilkm

    Joined:
    Apr 26, 2017
    Posts:
    6
    'productName' set as public only but it will use only for product purchase right?. Here am talking about restore purchase . When we call restore purchase 'productName' will be empty, so String.Equals() will not satisfy.

    i made code like this

    Code (CSharp):
    1. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    2.         {
    3.         // A consumable product has been purchased by this user.
    4.  
    5.  
    6.  
    7.         if (_isRestorePurchase)
    8.         {
    9.     Debug.Log(" This Call from restore ::::: Product id"+ args.purchasedProduct.definition.id + );
    10.             _restorepurchased?.Invoke(args.purchasedProduct.definition.id);
    11.         }
    12.  
    13.         if (String.Equals(args.purchasedProduct.definition.id, kSelectedPonitPackId, StringComparison.Ordinal))
    14.             {
    15.             _productpurchased();
    16.         }
    17.          
    18.             else
    19.             {
    20.                 Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    21.             }
    22.  
    23.             // Return a flag indicating whether this product has completely been received, or if the application needs
    24.             // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
    25.             // saving purchased products to the cloud, and when that save is delayed.
    26.             return PurchaseProcessingResult.Complete;
    27.         }
     
  17. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    A Restore purchase is the same as a new purchase, the same code is executed (ProcessPurchase, etc). You should not have ANY different code for the restore process. I would recommend that you remove the extra code that you have added, and just use the recommended/provided code. The error is from code that you added, so remove it.
     
  18. komaltii22

    komaltii22

    Joined:
    Apr 12, 2022
    Posts:
    5
    Hi, to me ProcessPurchase method is not getting called as I am testing app via Testflight. Any help would be appreciated Although it prompts that purchase was successful.
     
  19. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    226
    Hello,
    We encourage you to start a new thread for your problem since this one is a few years old and solved.

    Could you also provide us with more information about your problem such as the IAP version, steps to reproduce and logs so we can provide better assistance?

    Does the OnPurchaseSucceeded get called?
     
  20. Arnaud_Gorain

    Arnaud_Gorain

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    178
    This thread is now closed. Feel free to reach out via a new thread if you encounter further issue.
    Thanks!
     
Thread Status:
Not open for further replies.