question

ASIM SENYUVA avatar image
ASIM SENYUVA asked

Economy v2 PurchaseInventoryItems

I want to Purchase inventory item below code but i receive error,

         PlayFab.EconomyModels.EntityKey entity = new PlayFab.EconomyModels.EntityKey { Id = ClientEntity.Id, Type = ClientEntity.Type };
         List<PlayFab.EconomyModels.PurchasePriceAmount> PAmounts = new List<PlayFab.EconomyModels.PurchasePriceAmount>();
         PlayFab.EconomyModels.PurchasePriceAmount amountData = new PlayFab.EconomyModels.PurchasePriceAmount();
         amountData.ItemId = mCatItem.Id;
         amountData.Amount = mCatItem.PriceOptions.Prices[0].Amounts[0].Amount;
         PAmounts.Add(amountData);
    
         var requrest = new PlayFab.EconomyModels.PurchaseInventoryItemsRequest
         {
             Amount = 1,
             Entity = entity,
             Item = new PlayFab.EconomyModels.InventoryItemReference
             {
                 Id = mCatItem.Id,
             },
             PriceAmounts = PAmounts,
             DeleteEmptyStacks = false
    
         };
     
         PlayFabEconomyAPI.PurchaseInventoryItems(requrest, OnPurchaseSuccess, OnPurchaseFailure);

On the other hand, I want to add Economy v2 Currency / get Currency for logged in user, can you give me examples about these. I can not find any examples about this request. the documentation shows api referances but its not clear for me.

Regards.

In-Game Economy
5 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.

Neils Shi avatar image Neils Shi commented ·

I tested your code, it works fine. Could you provide more information about the error? If you want to grant Economy v2 Currency to user, you should use the API AddInventoryItems, you can refer to the code below. We don't recommend you call this API on the client side, you can call it via Azure Functions.

 {
   "Item": {
     "Id": "currency Item ID"
   },
   "Amount": 20,
   "Entity": {
                 "Id": "**************",
                 "Type": "title_player_account",
                 "TypeString": "title_player_account"
             }
 }

To get Economy v2 Currency, you should use API GetInventoryItems, you can refer to:

 {
   "Count": 10,
   "GenerateReceipt": true,
   "Filter":"type eq 'currency'"
 }
1 Like 1 ·
ASIM SENYUVA avatar image ASIM SENYUVA Neils Shi commented ·

Hello, i teet addinventoryitems over api. Its works fine. I just have a problem over PurchaseInventoryItem.

I am not remember error. I will send here when i near my computer. The error look likr wrong daha on api call. May be i need to configure on economy 2 settings on playfab.

I plan to use azure func. For add currency. Its more secure :)

I will test again i return back. Thank you

0 Likes 0 ·
ASIM SENYUVA avatar image ASIM SENYUVA Neils Shi commented ·

OnPlayfab Error is here for PlayFabEconomyAPI.PurchaseInventoryItems 5686-image.png

error downloadhandler is

5692-image.png

0 Likes 0 ·
image.png (35.9 KiB)
image.png (14.2 KiB)
ASIM SENYUVA avatar image ASIM SENYUVA commented ·

On PostMan Side I receive same error:

https://{ {TitleId}}.playfabapi.com/inventory/PurchaseInventoryItems?sdk=PostmanCollection-0.175.230306

 {
   "Item": {
     "Id": "03aec075-00be-4490-92bf-194bfcfdb8fe"
   },
   "Amount": 1,
   "PriceAmounts": [
     {
       "ItemId": "c0b29681-c0f1-4b56-8089-ce02f90fe80d",
       "Amount": 1000,
       "IsFromNamespace": false
     }
   ],
   "DeleteEmptyStacks": false
 }

I receive :

 {
     "code": 400,
     "status": "BadRequest",
     "error": "InvalidRequest",
     "errorCode": 1071,
     "errorMessage": "Item cannot be purchased."
 }
0 Likes 0 ·
ASIM SENYUVA avatar image ASIM SENYUVA ASIM SENYUVA commented ·

Into Documentation [quickstart][1] [1]: https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/inventory/quickstart Troubleshooting paraghraph they said,

The item can't be purchased at the specified price If you call PurchaseInventoryItems and receive a 1071 error code, the PriceAmounts field doesn't match the prices specified in the catalog.

0 Likes 0 ·

1 Answer

·
ASIM SENYUVA avatar image
ASIM SENYUVA answered

I Solved :)

Problem comes Content Type of Virtual Currency Settings on Playfab. we should use same content type of purchase item with virtual currency.

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.

Neils Shi avatar image Neils Shi commented ·

I'm glad you solved it, feel free to let me know if there are any other questions.

0 Likes 0 ·

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.