UDP Purchase Failing, need to consume first.

Hi, I am having trouble completing the IAP purchase with UDP. I am using a demo project to simplify things, and am able to initialize correctly, with sandbox login. I also get the appropriate prompt from UDP.

But when i attempt to purchase (these are both buttons outside, initialize() and purchaseitem()) I get “Invalid Operation: iap 1500keys needs to be consumed first.”

Could anyone tell what I am doing wrong? Any Help will be appreciated.

From What I can tell, it goes to OnPurchaseFailed() instead of OnPurchase(), where I assume I am supposed to consume the product.

I have already checked the Client ID, Client Secret, etc and they match with the original project’s.

Edit : Error code - 300 on Android Studio.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UDP;
using UnityEngine.UI;

public class UDPManager : MonoBehaviour, IPurchaseListener
{
    #region public variables

    public static UDPManager Instance;

    public Text text;
  
    #endregion

    #region private variables

    private int val = 0;

    private InitListner initListner = new InitListner();

    #endregion

    private void Awake()
    {
        Instance = this;
    }

    public void Initialize()
    {
        text.text = val.ToString();
        StoreService.Initialize(initListner);
        StoreService.QueryInventory(this);
        StoreService.EnableDebugLogging(true);
    }

    public void PurchaseItem()
    {
        StoreService.Purchase("1500keys", "", this);
    }

    public void OnPurchase(PurchaseInfo purchaseInfo)
    {
        StoreService.ConsumePurchase(purchaseInfo, this);
    }

    public void OnPurchaseFailed(string message, PurchaseInfo purchaseInfo)
    {
        Debug.LogError("Purchase Failed ::: " + message);
    }

    public void OnPurchaseRepeated(string productId)
    {
        throw new NotImplementedException();
    }

    public void OnPurchaseConsume(PurchaseInfo purchaseInfo)
    {
        val += 5;
        text.text = val.ToString();

        // AdditiveUIManager.instance.loadingPopup.HideView();
    }

    public void OnPurchaseConsumeFailed(string message, PurchaseInfo purchaseInfo)
    {
        Debug.Log("Purchase Consume Failed!!   " + message);
    }

    public void OnQueryInventory(Inventory inventory)
    {  
        Debug.Log("Query Inventory Successful");
    }

    public void OnQueryInventoryFailed(string message)
    {
        Debug.Log("Query Inventory Failed");
    }
}

Edit: Found solution, the error was asking me to consume the purchase probably made way earlier but not consumed. Using Query Inventory I could get all pending purchase and consume them, after which I was able to do further purchases.

hi , I am struggling with the same issue although the IAP is for non-consumable. could you share a bit more of how you solved this?

@ngfilms , i hope you found out the solution. Just incase you have not, as AakashGupta posted, Querying the inventory and consuming should work. The previous purchases which are not consumed are consumed. For non Consumable just a regular query should give you a list of your purchased products.