Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Help Wanted UDP Purchase Failing, need to consume first.

Discussion in 'Unity Distribution Portal (UDP)' started by AakashGupta_umxstudio, Dec 25, 2020.

  1. AakashGupta_umxstudio

    AakashGupta_umxstudio

    Joined:
    Dec 25, 2020
    Posts:
    2
    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.

    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UDP;
    6. using UnityEngine.UI;
    7.  
    8. public class UDPManager : MonoBehaviour, IPurchaseListener
    9. {
    10.     #region public variables
    11.  
    12.     public static UDPManager Instance;
    13.  
    14.     public Text text;
    15.  
    16.     #endregion
    17.  
    18.     #region private variables
    19.  
    20.     private int val = 0;
    21.  
    22.     private InitListner initListner = new InitListner();
    23.  
    24.     #endregion
    25.  
    26.     private void Awake()
    27.     {
    28.         Instance = this;
    29.     }
    30.  
    31.     public void Initialize()
    32.     {
    33.         text.text = val.ToString();
    34.         StoreService.Initialize(initListner);
    35.         StoreService.QueryInventory(this);
    36.         StoreService.EnableDebugLogging(true);
    37.     }
    38.  
    39.     public void PurchaseItem()
    40.     {
    41.         StoreService.Purchase("1500keys", "", this);
    42.     }
    43.  
    44.     public void OnPurchase(PurchaseInfo purchaseInfo)
    45.     {
    46.         StoreService.ConsumePurchase(purchaseInfo, this);
    47.     }
    48.  
    49.     public void OnPurchaseFailed(string message, PurchaseInfo purchaseInfo)
    50.     {
    51.         Debug.LogError("Purchase Failed ::: " + message);
    52.     }
    53.  
    54.     public void OnPurchaseRepeated(string productId)
    55.     {
    56.         throw new NotImplementedException();
    57.     }
    58.  
    59.     public void OnPurchaseConsume(PurchaseInfo purchaseInfo)
    60.     {
    61.         val += 5;
    62.         text.text = val.ToString();
    63.  
    64.         // AdditiveUIManager.instance.loadingPopup.HideView();
    65.     }
    66.  
    67.     public void OnPurchaseConsumeFailed(string message, PurchaseInfo purchaseInfo)
    68.     {
    69.         Debug.Log("Purchase Consume Failed!!   " + message);
    70.     }
    71.  
    72.     public void OnQueryInventory(Inventory inventory)
    73.     {  
    74.         Debug.Log("Query Inventory Successful");
    75.     }
    76.  
    77.     public void OnQueryInventoryFailed(string message)
    78.     {
    79.         Debug.Log("Query Inventory Failed");
    80.     }
    81. }
     
    Last edited: Dec 25, 2020
  2. AakashGupta_umxstudio

    AakashGupta_umxstudio

    Joined:
    Dec 25, 2020
    Posts:
    2
    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.
     
unityunity