Unity IAP Giving Product While Payment is Pending

Hi,

I clicked a product to buy then I choosed payment method as slow test card. While waiting to process, I clicked the product again and google pop up saying “you already have pending transaction see your pending transactions.” Then i clicked the link and saw my last transaction is pending. But when I check the game, gems already in my balance. Then I immedieatly returned to transaction list and canceled the pending transaction. As a result, I bought a product as free. How can I prevent this situation?

What transaction list are you referring to? What link are you referring to? Why did you already have gems, where do you award the product? Please show your code for ProcessPurchase. You should not award the product if the transaction is Pending.

Please find my attached script to use for iap. Also I send a video about the issue please check your inbox

8404245–1109889–IAPManager.cs (8.86 KB)

The code looks correct, can you answer my questions?

Please check this video, it’s better to understand for the situation and all your questions answer is here

https://drive.google.com/file/d/1kXSKgH0XkiY1oMDbKDuY2S6wGgP2sToJ/view?usp=sharing

Sorry no, I’m not going to an external link. Just use words please. Also, I would advise to not use Slow Credit Card with Failure if that is the option you are using, I have not heard of it ever working correctly, looks like a Google issue

You are right, I added the video here.
palatablerecentinganue

Please use written words to answer my questions, thanks

What transaction list are you referring to? -My google budget & history list.
What link are you referring to? -The links provides me to go to my budget & history list.
Why did you already have gems, where do you award the product? -I attached my script before, I am giving gems after purchase complete.

What links? Please be specific. Are you providing these links to your users? Sorry I’m not following. I’m not a big fan of the “Slow credit card” option as mentioned. Are you using the failure or success option? You might want to disable the purchase buttons until the transaction is complete to avoid the second click/purchase that you are referring to. And your users won’t see the “Slow credit card” option. You would expect to see your debug statements in the log, particularly this one:

Debug.Log($“Purchase Complete - Product: {product.definition.id}”);

No, I am not providing this link. This link is appeared when you click the product again.

Ok, I get it now. Can you please explain how can I know if the transaction is pending when ProcessPurchase method is called back? I couldn’t find it in the example code.

Also if I return pending from the method will it be called again when the transaction is complete?

I see what you mean now, I will test similarly also. It could be a bug. It seems you are properly returning Complete from ProcessPurchase (assuming you are seeing your Debug.Log statement I mentioned above, using adb logcat). To your question, you would check the purchaseState in the receipt https://discussions.unity.com/t/848244/8

Hi Jeff,

I realized something that ProcessPurchase returning null while game starting. I didn’t understand the reason.

NullReferenceException: Object reference not set to an instance of an object.

  at IAPManager.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs args) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseIfNew (UnityEngine.Purchasing.Product product) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseOnStart () [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Purchasing.PurchasingManager.OnProductsRetrieved (System.Collections.Generic.List`1[T] products) [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Purchasing.AppleStoreImpl.OnProductsRetrieved (System.String json) [0x00000] in <00000000000000000000000000000000>:0

  at System.Action.Invoke () [0x00000] in <00000000000000000000000000000000>:0

  at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <00000000000000000000000000000000>:0

and sometimes below methods returning null.

public void BuySpecialBundle()
    {
        m_StoreController.InitiatePurchase(specialBundleId);
    }

    public void BuySmallGem()
    {
        m_StoreController.InitiatePurchase(smallGemId);
    }

    public void BuyMediumGem()
    {
        m_StoreController.InitiatePurchase(mediumGemId);
    }

    public void BuyBigGem()
    {
        m_StoreController.InitiatePurchase(bigGemId);
    }

    public void BuyOffer()
    {
        m_StoreController.InitiatePurchase(offerId);
    }

and here is related error;

NullReferenceException: Object reference not set to an instance of an object. IAPManager.BuyBigGem () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityAction.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.Events.UnityEvent.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule.Process () (at <00000000000000000000000000000000>:0) UnityEngine.EventSystems.StandaloneInputModule:Process()

Separate issue, please open another thread. Please ensure to share the code you are using and what platform you are targeting and when this issue started. I will lock this thread.