ProcessPurchase not calling in sandbox for subscription in IOS?

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

1 Like

@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?

Updated to 1.22 help. Thanks.

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.

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://discussions.unity.com/t/700551

I’ve sent you the log in PM

@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!

@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…) Sample IAP Project 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.

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.

static bool CheckReceipt(Product purchasedProduct)
    {
        if (!InAppPurchaseHelper.Instance.IsInitialized()) return false;

        //If we the validator doesn't support the current store, we assume the purchase is valid
        if (IsCurrentStoreSupportedByValidator())
        {
            try
            {
                var result = Instance.m_Validator.Validate(purchasedProduct.receipt);
                //The validator returns parsed receipts.
                LogReceipts(result);
            }
            //If the purchase is deemed invalid, the validator throws an IAPSecurityException.
            catch (IAPSecurityException reason)
            {
                Debug.Log($"Invalid receipt: {reason}");
                return false;
            }
        }

        return purchasedProduct.hasReceipt;
    }

@cdr9042 Great, you already have the Try/Catch block. The exception was in your logs. I’m glad it’s working for you now.

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

Yes. This would be easy to test and confirm.

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.

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.

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?

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.

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

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.