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

Resolved IAP ProcessPurchase called on startup?

Discussion in 'Unity IAP' started by alikun, Jan 22, 2023.

Thread Status:
Not open for further replies.
  1. alikun

    alikun

    Joined:
    Oct 17, 2018
    Posts:
    16
    For some reason ProcessPayment being called on start. Basically when I purchase an item, quit the game and open it again, it attempts to process the same item that I had just purchased. View the stack trace in the image. The error however is because the payment processing happens before all managers are started.

    Why is ProcessPayment called on start?
     

    Attached Files:

    Last edited: Jan 22, 2023
  2. Baroni

    Baroni

    Joined:
    Aug 20, 2010
    Posts:
    3,168
    ProcessPurchase is called after initialization as long as the purchase transaction is not marked as finished in Unity IAP internally. If you have an exception thrown within ProcessPurchase and did not return "PurchaseProcessingResult.Complete" at the end of it, it will be called again and again.

    If you had an error in your code previously which has been fixed later, you might want to delete all Unity IAP transactions in the editor between testing stages. Call "UnityEngine.Purchasing.UnityPurchasing.ClearTransactionLog();" at runtime to do this.

    Also, ProcessPurchase is called for restoring transactions on Android the first time you launch the app.
     
    Arnaud_Gorain and alikun like this.
  3. alikun

    alikun

    Joined:
    Oct 17, 2018
    Posts:
    16
    Yep, the problem was that I was returning .Pending. Switched to .Complete and it worked!
    Thank you
     

    Attached Files:

  4. Arnaud_Gorain

    Arnaud_Gorain

    Unity Technologies

    Joined:
    Jun 28, 2022
    Posts:
    166
    This thread is now closed. Feel free to reach out via a new thread if you encounter further issues.
    Thanks!
     
    alikun likes this.
Thread Status:
Not open for further replies.