Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Players get charged on *unconfirmed* pending transactions

Discussion in 'Unity IAP' started by realragnvaldr, Sep 5, 2021.

  1. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    40
    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):

    Code (CSharp):
    1.  
    2.  
    3. private IStoreController controller;
    4.  
    5. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) {
    6.     StartCoroutine(ProcessPurchaseOnServer(e.purchasedProduct));
    7.     return PurchaseProcessingResult.Pending;
    8. }
    9.  
    10. public IEnumerator ProcessPurchaseOnServer(Product theProduct) {          
    11.     UnityWebRequest www = UnityWebRequest.Get(someURL);
    12.     yield return www.SendWebRequest();
    13.     string serverResponse = www.downloadHandler.text.Trim();
    14.     if (serverResponse is fine) {          
    15.         controller.ConfirmPendingPurchase(theProduct);
    16.         Debug.Log("Server success - purchase confirmed");
    17.     } else {
    18.         Debug.Log("Server error - purchase not confirmed");
    19.     }
    20. }
    21.  
    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!
     
  2. realragnvaldr

    realragnvaldr

    Joined:
    Jul 21, 2019
    Posts:
    40
    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).
     
    JeffDUnity3D likes this.