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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

ConfirmPendingPurchase issue

Discussion in 'Unity IAP' started by Steimond1, Mar 2, 2021.

  1. Steimond1

    Steimond1

    Joined:
    Jan 20, 2021
    Posts:
    12
    Hello everyone!
    I have a problem with the Google Play Store in unity.
    I have a game with IAP. My shopping flow:
    1. The player clicks the consumable button and calls IStoreController.InitiatePurchase.
    2. After payment invokes the callback IStoreListener.ProcessPurchase where I return PurchaseProcessingResult.Pending and invoke my processing algorithm, connect to my game server, check the purchase on it and return the check result.
    3. After a successful check on the game server, I call IStoreController.ConfirmPendingPurchase to confirm the purchased consumables.

    Everything works fine, but ... If the network is disconnected in step 2 and streaming to the game server stops, then IStoreController.ConfirmPendingPurchase was not called.
    After that, I reconnect to the network and reopen the app. In IStoreListener.OnInitialized (IStoreController controller, IExtensionProvider extensions) I get controller.products.all and check if any product in the list hasReceipt. If this is true, I am trying to call IStoreController.ConfirmPendingPurchase again for this product.

    But I have an exception
    E / Unity: Google Play Store: Failed to complete transaction with ServiceUnavailable error code and debug message: An internal error has occurred. Please consider calling FinishAdditionalTransaction using an extension.

    Consumables remain pending.

    P.S. If I call IStoreController.ConfirmPendingPurchase a second time within 2 seconds, the pending purchase will be confirmed successfully. But I think this is the wrong flow for this case.
     
    Last edited: Mar 3, 2021
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You will want to call ConfirmPendingPurchase only if the product is properly in Pending state. When it is, you would expect ProcessPurchase to trigger for each such product during IAP Initialization. You don't want to just blindly call ConfirmPendingPurchase for all products with a receipt.
     
  3. Steimond1

    Steimond1

    Joined:
    Jan 20, 2021
    Posts:
    12
    Thanks for the quick response!

    Of course not. But product with receipt is properly in Pending state and already charged. Last step is confirm this pending purchase. But i cant do it the first time. As I say "If I call IStoreController.ConfirmPendingPurchase a second time within 2 seconds, the pending purchase will be confirmed successfully."

    If I don't confirm this pending purchase, a Google Play Cancellation Receipt will come to my mail shortly

    Additional I can say, that while I debugging my app in Android Studio Logcat I caught this
    W/BillingClient: Error consuming purchase with token. Response code: 2

    Response code 2 is "Network connection is down."
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    Yes, you need a working network connection. Perhaps try on a different network. You might compare your code to IAPManager.cs in the Sample IAP Project, I don't see this issue. Don't use co-routines or similar in your code until you have the issue resolved, get the basics working first.. https://forum.unity.com/threads/sample-iap-project.529555/