[Solved] What to return in ProcessPurchase when your reward handler throws an exception?

Greetings,

My process purchase function looks like this:

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        try
        {
            // Reward user package
        }
        catch (Exception e)
        {
            Debug.Log("Error: " + e.ToString());
        }

        return (PurchaseProcessingResult.Complete); // Shouldn't this be something different if it fails?
    }

We’re havinga problem atm where there’s an exception thrown and user doesnt get their reward/package content but they’re still charged for it.

My question is, how do I NOT charge them if an exception was thrown? The only other enum type for PurchaseProcessingResult is Pending, should I return that instead?

[Edit] I’m not even sure I could do anything at this point in ProcessPurchase if this gets called AFTER the user pays and the transaction is complete. I guess there’s no way to cancel it then?

Thanks

@vexe

You should only return Pending if you want to be reminded of the purchase. The most common use case is if you are saving your purchases to a server. In that case, you would return Pending, then confirm the purchase on your server, then, outside of ProcessPurchase, you would call ConfirmPendingPurchase. Otherwise, the IAP system would call ProcessPurchase for the same purchase again after the app restarts.

Your edit is correct. You can see in the diagram in the Manual that ProcessPurchase is called after the user has been charged:

https://docs.unity3d.com/Manual/UnityIAPProcessingPurchases.html

The process is started with InitiatePurchase, so you would have to cancel before that call:

https://docs.unity3d.com/Manual/UnityIAPInitiatingPurchases.html

@ap-unity Thanks.

For what it’s worth, the exception was coming from the validation/obfuscation google/apple tangle security code. I created a separate thread about it: [Closed] Security validation NullReferenceException - Unity Services - Unity Discussions

1 Like