Search Unity

ProcessPurchase not calling in sandbox for subscription in IOS?

Discussion in 'Unity IAP' started by tsangwailam, Apr 28, 2019.

  1. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    I am working on a Unity IAP for purchasing subscription. The flow is working fine in Android. But in IOS, the ProcessPurchase seem not calling when testing in sandbox mode.

    The last log by UnityIAP from Xcode are below.

    Purchasing product asychronously: DUMMY_PRODUCT_ID
    UnityIAP: PurchaseProduct: DUMMY_PRODUCT_ID
    purchase({0}): DUMMY_PRODUCT_ID

    ... No more UnityIAP log after ...
    I want to check if there any log from UnityIAP after purchase success? So, i can check if this is problem of my code or UnityIAP.

    Unity IAP version: 1.20.1
    Unity Version: 5.6.5f1
     
    bballam likes this.
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @tsangwailam Do you actually have a published product named DUMMY_PRODUCT_ID? Please show a screenshot of your iTunes console with the product definitions, and the code where you are loading your products. Can you try with IAP 1.22 and a more recent version of Unity?
     
  3. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Updated to 1.22 help. Thanks.
     
  4. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    I'm having this issue on Unity IAP 4.1.4, Unity 2020.3.18. I tried using both my code and the Sample code in 02 Buying Subscription. ProcessPurchase didn't get called. Pic is my IAP Setup on App Store (ID are editted out)

    When I press Purchase, I can see Apple's IAP process begin, a popup shows showing the price and I press Confirm purchase, I put in Sandbox account's password. A popup show 'You're all set, purchase successful'. After I press Ok, nothing happens, ProcessPurchase does not get called, OnPurchaseFailed does not get called. I waited for 10 minutes and still nothing.

    Other IAP products work fine, Consumable, Non-consumable works.
     

    Attached Files:

    Last edited: Apr 19, 2022
  5. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Can you share your XCode logs, since you are able to reproduce? Are you testing via TestFlight with a new release if you just added this product? If you want to send me a private message, I can provide my Apple ID for TestFlight. Ensure to place numerous Debug.Log statements throughout your code that will show in the logs. I will test subscriptions also. Also (and not directly related to your issue) keep in mind that "5 hints a day" is a consumable feature, a user could Restore multiple times to get multiple hints. https://forum.unity.com/threads/how-to-capturing-device-logs-on-ios.529920/
     
  6. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    I've sent you the log in PM
     
  7. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @cdr9042 As you can see in the logs, the CrossPlatformValidator is throwing an exception. For an immediate fix, you can wrap it in a Try/Catch block. I'm doing the same test now, but apparently since I upgraded my iPhone iOS version recently, I now need to update to Monterey on my Mac, and update XCode. So it's going to take awhile!
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @cdr9042 Works for me! I'm testing with 4.1.3 and using the CrossPlatformValidator without the need for a Try/Catch block. I'm building with IL2CPP and .NET Standard 2.0. Unity version should not matter. I'm using the Sample IAP Project v3, remember to generate your own tangle files first which the validator requires (menu Services/In-App Purchasing/Receipt Validation Obfuscator...) https://forum.unity.com/threads/sample-iap-project.529555/#post-7922275 I would recommend that you get the Sample project with no changes except for package name and projectID and publish it to TestFlight. Ensure you don't add any additional libraries during your test like the Facebook SDK or Firebase, or any other components.
     
  9. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    I'm at a lost. I did nothing and today it worked. The ProcessPurchase get called, everything works as they should.

    I don't know what that exception is, every non-consumable products in my game, I check for its receipt using the code below. If it has valid receipt then I show the products as purchased and disable it. It seems that, if it's a non-consumable product that the user hasn't purchased, it will throw an exception, if they purchased it then it log the receipt, no exception.

    Code (CSharp):
    1. static bool CheckReceipt(Product purchasedProduct)
    2.     {
    3.         if (!InAppPurchaseHelper.Instance.IsInitialized()) return false;
    4.  
    5.         //If we the validator doesn't support the current store, we assume the purchase is valid
    6.         if (IsCurrentStoreSupportedByValidator())
    7.         {
    8.             try
    9.             {
    10.                 var result = Instance.m_Validator.Validate(purchasedProduct.receipt);
    11.                 //The validator returns parsed receipts.
    12.                 LogReceipts(result);
    13.             }
    14.             //If the purchase is deemed invalid, the validator throws an IAPSecurityException.
    15.             catch (IAPSecurityException reason)
    16.             {
    17.                 Debug.Log($"Invalid receipt: {reason}");
    18.                 return false;
    19.             }
    20.         }
    21.  
    22.         return purchasedProduct.hasReceipt;
    23.     }
     
  10. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    @cdr9042 Great, you already have the Try/Catch block. The exception was in your logs. I'm glad it's working for you now.
     
  11. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    should I add a check for if the product has a receipt first before calling m_Validator.Validate(purchasedProduct.receipt)? it seems unnecessary to throw an exception when there is no receipt to check
     
  12. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes. This would be easy to test and confirm.
     
  13. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    Good lord, it happens again today. No ProcessPurchase, no OnPurchaseFailed. What do I do?

    Steps to reproduce maybe?

    - Purchase Subscription.
    - Complete Apple IAP.
    - Purchase Subscription successful. ProcessPurchase is called.
    - Wait 1-4 hours (until sandbox subscription runs out I guess? My subscription period is 7 days, I buy sub again before that. The CheckReceipt should return false and tester can purchase subscription again).
    - Purchase Subscription again.
    - Complete Apple IAP.
    - No ProcessPurchase get called, stuck at waiting for callback.
     
    Last edited: Apr 25, 2022
  14. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    So if you made no code changes, that only leaves one explanation! You'll want to reach out to Apple. I would also suggest creating another test user to compare to ensure it's not time based or user related.
     
  15. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    How do I explain this bug to Apple? What code is Unity using to listen to Apple's IAP? What happened that causes ProcessPurchase to never get called?
     
  16. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Did you try with a second user? Unity IAP uses the Apple StoreKit API and talks directly to the Apple servers from the client device. The only thing changing here is user activity, it's not in your code or Unity IAP. To confirm, create a second test user in case they are throttling purchases. Otherwise, it may be aa problem with the Apple servers.
     
  17. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    I tried with a second user and same thing happens.

    is this the method Unity IAP use? https://developer.apple.com/documentation/storekit/product/3791971-purchase
     
  18. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes. So did you make any changes before it started to not work again? If you made no code changes and did not release or change anything and did not side load a new version or ANYTHING else, it's not the code, would you agree? Please confirm that you made NO changes, and suddenly, out of the blue, it stopped working. This would only leave the Apple side. Are you seeing the exception in the logs again from the CrossPlatformValidator? If so, as a test, I trust you commented out that code to confirm.