question

contato avatar image
contato asked

PlayFabEconomyAPI.PurchaseInventoryItems - How to Purchase a Catalog Item

Would you have any example of how to use PlayFabEconomyAPI.PurchaseInventoryItems for a user to purchase an item from Catalog v2? Show full example

apis
10 |1200

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

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

After setting up the catalog items and currency items according to the Economy V2 documentations, you could call the PurchaseInventoryItem Api to allow logged-in players to purchase items. The following is a code example for calling the PurchaseInventoryItem API.

  void PurchaseInventoryItem()
     {
         PlayFabEconomyAPI.PurchaseInventoryItems(new PurchaseInventoryItemsRequest
         {
             Item = new InventoryItemReference { Id = "1ee5ef6c-a739-440a-a913-bfa02dc11025" }, //this Id is the Item you want to purchase
             Amount = 1,
             PriceAmounts=new List<PurchasePriceAmount> { new PurchasePriceAmount { ItemId= "c025c484-1152-46ad-bbbf-242964850cd0",Amount=10 } } //this ItemId is the Currency Item Id for purchasing
         }, re =>
         {
             Debug.Log(re.TransactionIds[0].ToString() + "  purchase success");
         }, er =>
         {
             Debug.Log(er.GenerateErrorReport());
         });
     }
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.