[Fixed] iOS late pending purchase call is not possible, any idea how to deal with this?

Hi, on our project we are using pending purchases cuz we use the game server to save the purchase information, if the player do the normal flow works like a charm, but on the use-case I’m gonna state in a while we are trying to make the pending purchase be called after the user has logged to the game server.

USE CASE:

Player bought any IAP item, while processing the player suddenly closes the app or soft close, so the pending purchase is being held by the iOS store server, when the player opens the game we call IAP at the very beginning (this is something we cannot change cuz the project manager wants it to be like that so it ensures IAP is ready when player gets into the game) [Note: Also we added at the loading screen a check to wait for it to be ready but at some low-end devices it take some seconds that the project manager don’t want to be there], so now the PROBLEM IS HERE is there any way to call the pending purchase at a exact time of the app and block the IAPInitialize call so it does not get a duplicate error or a failed purchase?

Or is it possible to make ProcessPurchase method a coroutine to make it wait till user is connected into game server?

Thanks for any help in advance

For any trying to achieve this in the same use-case I had what you can do is at the ProcessPurchase() method after validating if it is a valid purchase you can call a coroutine with your API call waiting for the user being connected to the server and set the purchase as pending again

if (validPurchase)
            {
                SetProductExtraData(p_purchase.purchasedProduct.definition.id);

                Timing.RunCoroutine(C_APIPurchaseCall());
                IEnumerator<float> C_APIPurchaseCall()
                {
                    while (!SharedData.userDataLoaded)
                        yield return Timing.WaitForOneFrame;

                    GameManager.API.CheckIAPPurchase(_purchaseResult, p_purchase.purchasedProduct.definition.id);
                    yield break;
                }

                return PurchaseProcessingResult.Pending;
            }
            else
            {
                return PurchaseProcessingResult.Complete;
            }

something like this, hope this helps someone in the future, also it is possible to use async/await, but the simplier fix is this one

Please test with IAP 2.2.6. We had an issue where ProcessPurchase was being called prior to OnInitialized which has been addressed.