Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

[Solved]iOS Restore ProcessPurchase Fail

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

  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

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,335
    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

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,335
    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

    Unity Technologies

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

    alexp96

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

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,335
    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

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,335
    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:
    5
    Hi Alex! I'm in the same situation. How do u fix it ? Thanks
     
  13. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    4,335
    Can you elaborate where the product name is null in the Apple code?