cancel
Showing results for 
Search instead for 
Did you mean: 

Having Trouble Consuming IAP I do it and it doesnt work

tastytot
Honored Guest

Hello so i am having issues trying to consume a IAP consumable sku even though i can purchase it once but cant consume it and cant figure out the issue because debugging is hard on Meta Quest 

Heres the code:

using Oculus.Platform;
using Oculus.Platform.Models;
using UnityEngine;
using PlayFab;
using PlayFab.ClientModels;
using TMPro;
 
public class PlayFabShopManager : MonoBehaviour
{
    [SerializeField] private string skuToPurchase;
    [SerializeField] private int currencyAmount;
    [SerializeField] private CosmeticsManager CM;
    public TextMeshPro ErrorTest;
 
    private string[] skus = { "1000Nanas", "2500Nanas", "5000Nanas" };
 
 
    void Awake()
    {
        Oculus.Platform.Core.Initialize();
    }
    void Start()
    {
 
        GetPrices();
        GetPurchases();
    }
 
    private void GetPrices()
    {
        IAP.GetProductsBySKU(skus).OnComplete(GetPricesCallback);
    }
 
    private void GetPricesCallback(Message<ProductList> msg)
    {
        if (msg.IsError) return;
    }
 
    private void GetPurchases()
    {
        IAP.GetViewerPurchases().OnComplete(GetPurchasesCallback);
    }
 
    private void GetPurchasesCallback(Message<PurchaseList> msg)
    {
        if (msg.IsError) return;
    }
 
    public void BuyProduct()
    {
        IAP.LaunchCheckoutFlow(skuToPurchase).OnComplete(BuyProductCallback);
    }
 
    private void BuyProductCallback(Message<Oculus.Platform.Models.Purchase> msg)
    {
        if (msg.IsError) return;
        IAP.ConsumePurchase(skuToPurchase).OnComplete(ConsumePurchaseCallback);
 
    }
 
    private void ConsumePurchaseCallback(Message msg)
    {
        if (!msg.IsError)
        {
        var request = new AddUserVirtualCurrencyRequest
        {
            Amount = currencyAmount,
            VirtualCurrency = "HS"
        };
 
            ErrorTest.text = msg.ToString();
        PlayFabClientAPI.AddUserVirtualCurrency(request, OnAddCurrencySuccess, OnAddCurrencyFailure);
        }
        else
        {
            ErrorTest.text = msg.ToString();
            Debug.Log("Error Consuming Purchase" + msg);
        }
    }
   
 
    private void OnAddCurrencySuccess(ModifyUserVirtualCurrencyResult result)
    {
       Debug.Log("Currency added: " + result.Balance);
       Playfablogin.instance.GetVirtualCurrencies();
 
    }
 
    private void OnAddCurrencyFailure(PlayFabError error)
    {
        Debug.LogError("Failed to add currency: " + error.ErrorMessage);
    }
 
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("HandTag"))
        {
            BuyProduct();
            Playfablogin.instance.GetVirtualCurrencies();
        }
    }
}
0 REPLIES 0