question

hockpongjogo avatar image
hockpongjogo asked

How to resolve a GetCatalogItems

When I log in and enter my game's Store, the exact amount I deposited on PlayFab appears, but I've already added the lists of items I want to buy on PlayFab, but in the game, it won't let me make the purchase. Can anyone help me as I'm new to PlayFab

This is my script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using TMPro;
 using PlayFab;
 using PlayFab.ClientModels;
    
 public class LojaManager : MonoBehaviour
 {
     public int moedas;
     public TMP_Text moedasUI;
     public LojaItemSO[] LojaItensSO;
     public GameObject[] LojaPanelsGO;
     public LojaTemplate[] LojaPanels;
     public Button[] BT_MinhasMoedas;
    
     // Start is called before the first frame update
     void Start()
     {
         for (int i = 0; i < LojaItensSO.Length; i++)
             LojaPanelsGO[i].SetActive(true);
         GetMoedas();
         LoadPanels();
         CheckCompras();
     }
    
     // Update is called once per frame
     void Update()
     {
    
     }
    
     public void GetMoedas()
     {
         PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), result =>
     {
         int moedas = result.VirtualCurrency["RG"];
         moedasUI.text = moedas.ToString();
    
         // Chama a função para verificar as compras do usuário
         CheckCompras();
     }, error => Debug.LogError(error.GenerateErrorReport()));
     }
    
     public void CheckCompras()
     {
         PlayFabClientAPI.GetUserInventory(new GetUserInventoryRequest(), result =>
     {
         // Obtém a lista de itens do usuário
         List<ItemInstance> items = result.Inventory;
    
         for (int i = 0; i < LojaItensSO.Length; i++)
         {
             // Verifica se o item foi comprado pelo usuário
             bool itemComprado = items.Exists(item => item.ItemId == LojaItensSO[i].itemId);
    
             if (itemComprado)
             {
                 BT_MinhasMoedas[i].gameObject.SetActive(false);
             }
             else
             {
                 BT_MinhasMoedas[i].gameObject.SetActive(true);
                 if (moedas >= LojaItensSO[i].basePreco)
                     BT_MinhasMoedas[i].interactable = true;
                 else
                     BT_MinhasMoedas[i].interactable = false;
             }
         }
     }, error => Debug.LogError(error.GenerateErrorReport()));
     }
    
     public void ComprarItens(int BT)
     {
         PlayFabClientAPI.PurchaseItem(new PurchaseItemRequest()
         {
             CatalogVersion = "CATALOG_VERSION",
             ItemId = LojaItensSO[BT].itemId,
             Price = LojaItensSO[BT].basePreco,
             VirtualCurrency = "RG"
         }, result =>
         {
             Debug.Log("Compra realizada com sucesso!");
             GetMoedas();
             CheckCompras();
         }, error => Debug.LogError(error.GenerateErrorReport()));
     }
    
     public void LoadPanels()
     {
         for (int i = 0; i < LojaItensSO.Length; i++)
         {
             LojaPanels[i].tituloTxt.text = LojaItensSO[i].titulo;
             LojaPanels[i].descricaoTxt.text = LojaItensSO[i].descricao;
             LojaPanels[i].preco.text = LojaItensSO[i].basePreco.ToString();
         }
     }
 }
In-Game EconomyPlayer Inventory
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Simon Cui avatar image Simon Cui commented ·

Hello, may I know what is the error message that you got when purchasing?

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.