Players get charged on *unconfirmed* pending transactions

Hi,

I’ve recently implemented IAP in my Android app and ran into a problem that I haven’t been able to fix: even when not confirming a pending transaction, the payment goes through anyway. Or is there something I misunderstood about how Pending works?

What i’m trying to establish is the following flow:

  • initiate purchase
  • put it in Pending state
  • process the purchase on server
  • only if successful, confirm the pending purchase

Here’s a summary of the code i use to try establish that (i’ve removed irrelevant pieces of code):

private IStoreController controller;

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) {
    StartCoroutine(ProcessPurchaseOnServer(e.purchasedProduct));
    return PurchaseProcessingResult.Pending;
}

public IEnumerator ProcessPurchaseOnServer(Product theProduct) {           
    UnityWebRequest www = UnityWebRequest.Get(someURL);
    yield return www.SendWebRequest();
    string serverResponse = www.downloadHandler.text.Trim();
    if (serverResponse is fine) {           
        controller.ConfirmPendingPurchase(theProduct);
        Debug.Log("Server success - purchase confirmed");
    } else {
        Debug.Log("Server error - purchase not confirmed");
    }
}

My understanding is that the payment should only go through if controller.ConfirmPendingPurchase is called after the purchase if put into Pending state, i.e., when it goes through the “success” branch of the if-else statement.

Nowhere else in my code is there a call to the ConfirmPendingPurchase method, nor does it contain a return PurchaseProcessingResult.Complete statement. Yet, we see the payments going through even when there is a server error :-/

Any hints on how to solve this would be appreciated!

Never mind - i think i understand it now. “Pending” doesn’t seem to mean that the payment is pending, but it means that the purchase process is pending - and as long as it is pending, the store will remind the app that it has an uncompleted purchase (e.g. when app restarts).

1 Like