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!