question

Michael Brilz avatar image
Michael Brilz asked

problem with PurchaseItemRequest

I would like to pass 2 parameters to the PurchaseItemRequest, i.e. the name and price. If I now click on the button an error occurs. Can someone help me what i'm doing wrong i am a beginner

public class BuySkins : MonoBehaviour
{

    public Button spacie;
    public Button Ninjo;
    public Item i;

    public void Start()
    {

        i = GameObject.FindObjectOfType<Item>();

        Ninjo.GetComponent<Button>().onClick.AddListener(delegate { MakePurchase(i.Name, i.Coast); });
        spacie.GetComponent<Button>().onClick.AddListener(delegate { MakePurchase(i.Name, i.Coast); });


    }
   

    public void MakePurchase(string name, int price)
    {
        PlayFabClientAPI.PurchaseItem(new PurchaseItemRequest
        {
            // In your game, this should just be a constant matching your primary catalog
            CatalogVersion = "Heros",
            VirtualCurrency = "DC",
            ItemId = name,
            Price = price,

        }, LogSuccess, LogFailure) ;
    }

    private void LogFailure(PlayFabError obj)
    {
        print("fehler aufgetretten beim kaufen");
    }

    private void LogSuccess(PurchaseItemResult obj)
    {
        print("gekauft");
    }
}
unity3dIn-Game EconomyPlayer Inventory
4 comments
10 |1200

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

Sarah Zhang avatar image Sarah Zhang commented ·

Could you please provide the corresponding error messages and error code?

0 Likes 0 ·
Michael Brilz avatar image Michael Brilz Sarah Zhang commented ·

Invalid input parameters
UnityEngine.Debug:Log(Object)

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Michael Brilz commented ·

Could you please use this statement in the LogFailure function?

  private void LogFailure(PlayFabError obj)
    {
        Debug.Log(obj.GenerateErrorReport());
    }
0 Likes 0 ·
Show more comments

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Please check if your itemId is right, this API returns the error "Item not found".

10 |1200

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

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.