Forum Discussion
tastytot
2 years agoHonored Guest
Having Trouble Consuming IAP I do it and it doesnt work
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();
}
}
}
Replies have been turned off for this discussion
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 2 months ago
- 1 year ago