question

elephrates avatar image
elephrates asked

Playfab and Google IAP

Hi I followed this guide to near to where you setup currency

https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/tutorials/getting-started-with-unity-and-android?tabs=create-currency-gm%2Ccreate-items-gm

But I have question; I have about 12 items and some need to purchase on IAP then give a temporary boost/addition to the player. How would I do this?

And in general Iw anted to have things either purchaseable with the virtual currency i setup or on IAP/google with real money, is there any proper guides how to do that?

As i find the guide above in the link very brief and lacking explanations

And the IAP script example is that needed to start coding these functions or is that justa test example and i should create my own?

apis
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.

elephrates avatar image elephrates commented ·

How can you make an item both purchaseable with virtual currency and purchaseable on google play?

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

>> I have about 12 items and some need to purchase on IAP then give a temporary boost/addition to the player. How would I do this?

As I understand, you want to have items that will be consumed by time. But currently, Economy V2 Items doesn’t support such feature, you may submit a feature request for it. Or implement the function with your code by yourself. If I understand incorrectly, please let me know.

>> And in general I wanted to have things either purchasable with the virtual currency I setup or on IAP/google with real money, is there any proper guides how to do that?

To make an Item purchasable with virtual currency, you may need to set the Price option when you create or edit the Item. Then refer to the PlayFabPurchaseItemByID method in the IAP script example to use the PurchaseInventoryItems API to purchase items with virtual currency. To make the same Item purchasable with real money, you may refer to Redemption with the Google Marketplace - PlayFab | Microsoft Learn to create a bundle and add the Item to the bundle, then set up the Google Marketplace for players to purchase. You may also need to set up the Google add-on. Then refer to ProcessPurchase method in the IAP script example to use RedeemGooglePlayInventoryItems API with GooglePlay receipt to redeem items for player .

>> And the IAP script example is that needed to start coding these functions or is that justa test example and i should create my own?

The IAP script example is a test example, you may refer to the script to create your own.

3 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.

elephrates avatar image elephrates commented ·

As I understand, you want to have items that will be consumed by time. But currently, Economy V2 Items doesn’t support such feature, you may submit a feature request for it. Or implement the function with your code by yourself. If I understand incorrectly, please let me know.

Yes like a one play run thing. How would you implement this in code. I can think to have another profile data, ie purchase x item give profile data Boost = 1

Then check that on game start and end, delete when played for example

Also re the IAP script, does this have all the functions necessary to test IAP and playfab. As i need to test IAP purchases and playfab purchases thne give the player stuff. IS there any tutorials for this?

0 Likes 0 ·
elephrates avatar image elephrates elephrates commented ·

Also here it says test the alpha release; what alpha release

It only gave the IAP example, am i supposed to create a new project with buttons and attach the script to test it ? https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/tutorials/getting-started-with-unity-and-android?tabs=create-currency-gm%2Ccreate-items-gm

0 Likes 0 ·
elephrates avatar image elephrates elephrates commented ·

For that IAP script, so far it wont pull any data from the catalog

IF i run my own code too i get "IAP Service is not initialized!"

The gui message of not initialized logging in stays there

So why doesnt this work out the box, i copied the same code they had

![6617-screenshot-2023-11-29-215318.png][2]

[1]: /storage/attachments/6615-screenshot-2023-11-29-215336.png

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

>> Also, re the IAP script, does this have all the functions necessary to test IAP and playfab. As i need to test IAP purchases and playfab purchases thne give the player stuff. IS there any tutorials for this?

As I mentioned, the IAP example script just a test example, it provides basically necessary functions for you to start test Unity IAP and Playfab.

>> Also here it says test the alpha release; what alpha release. It only gave the IAP example, am i supposed to create a new project with buttons and attach the script to test it ?

The documentation doesn’t mean “test the alpha release”, the Alpha release is some kind testing version of your application that you published in Google Play Console, this is to make sure that you have already set up the application in Google Play Console.

You can copy the IAP example script to your project to test it.

>> For that IAP script, so far it wont pull any data from the catalog. IF i run my own code too i get "IAP Service is not initialized!". The gui message of not initialized logging in stays there. So why doesn’t this work out the box, I copied the same code they had.

According to the IAP example code, the RefreshIAPItems method calls the SearchItem API to get Items with Google Play platform selected to fill the GooglePlayCatalog dictionary. In the SearchItem API request, the code uses Filter property to filter the Google Play platform items, so, you have to create Items with Google Play platform selected. You may need to navigate to [Title Settings]->[EconomyV2]->[Platform] to define the GooglePlay platform, then select the GooglePlay platform when you create or edit bundles.

The process of IAP example script’s initialize part is player logged in first, then execute RefreshIAPItems method to get GooglePlay platform Items for real money purchase and get a store item for virtual currency purchase, then execute InitializePurchasing method to initialize Unity IAP service, the OnInitialized method will be automatically called, then the Initialize part of IAP example is done. In addition, you may refer to Getting Started | In App Purchasing | 4.2.1 (unity3d.com) to have more information about Unity IAP.

Before you test the IAP example script, you may need to get familiar with the EconomyV2 APIs which used in the script, you may test these APIs with Postman first. You may also need to get familiar with the EconomyV2 features, such as Store, bundle etc., you may refer to PlayFab Economy documentation - PlayFab | Microsoft Learn.

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.

elephrates avatar image elephrates commented ·

Fixed i had to add an initialization for unit agem services

So i cant implement timd rewards but what about rewards in general?

I need to implement lives; ie a counter that gets used to unlock the game

Permananet boosts ie a statistic that is multiplied on end game

And the currency which i added the virtual currency but on purchase how do i add that to the player?

And for the the aforementioned boosts the only way i can think is to add a profile data slot and read that on my script. Or is there a proper way?

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

>>So i cant implement timed rewards but what about rewards in general?

If timed rewards refer to periodic rewards for users, you may try to use Scheduled Task feature to implement the timed rewards.

>>I need to implement lives; ie a counter that gets used to unlock the game

Cloud you explain the ”lives” in more detail?

>>Permananet boosts ie a statistic that is multiplied on end game

You could use PlayerData to record permanently boosted data, then read and use it when the game starts, and update it every time the game ends.

>>And the currency which i added the virtual currency but on purchase how do i add that to the player?

If you are using IAP and EconomyV2 and followed Redemption with the Google Marketplace - PlayFab | Microsoft Learn to set up Google and PlayFab, when you call RedeemGooglePlayInventoryItems API with GooglePlay receipt, the bundle with currencies will be grant to Player inventory automatically.

If you are using PurchaseInventoryItems API to purchase items with virtual currency, the Items will be automatically sent to player’s inventory.

2 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.

elephrates avatar image elephrates commented ·

By timed rewards I mean:

Ill explain all that I need here:

I need temporary and permanent boosts to three different metrics; so temporary meaning you buy it on playfab with virtual currency, then it gives you the boost for one gameplay or forever

By lives; Im currently doing it with "profileData" ie you buy lives or watch ads to get lives. So it gives you the amount and you use it to continue games when you die. Just need a counter for that and to link to the playfab and google play purchase items

For your last question: I didnt create any bundles

I created most items on google play; then created them on playfab with matching ID to google play catalog as one of the guides said. But no bundles as i dont want to overcomplicate it; just purchase one item get one reward/item to use

I dont know if its setup correctly though as the IAPexample code currently pulls more items than it should; pulls the store to be purchased twice which i dont know why

Also i dont know if this way i mention above links the google play item to the playfab one

0 Likes 0 ·
elephrates avatar image elephrates elephrates commented ·

As for my catalog I should have about 14 items that are real money purchases ie on google play, with matching ones on PF for the reward items from the purchase

And then 4 that are temporary and virtual currency buys only, which dont exist on google play but on playfab only. So i set that up as items so far

0 Likes 0 ·
elephrates avatar image
elephrates answered

Extra

Why is the documentation/tutorials so bad. Ive searched everywhere and the offical docs are basically useless and dont show you how to use them

For instance if i want to filter the catalog items i pull ie

SearchItemsRequest playCatalogRequest = new() { Count = 50, Type = "Items"

         //Filter = "Platforms/any(platform: platform eq 'GooglePlay')"
     };

None of this documentation shows you how to do it

https://learn.microsoft.com/en-us/rest/api/playfab/economy/catalog/search-items?view=playfab-rest

And all the tutorials are for economy v1 and 4 years old

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.

kylemc@microsoft.com avatar image kylemc@microsoft.com commented ·

I suspect what you're trying to do is the following.

 SearchItemsRequest playCatalogRequest = new()
 {
   Count = 50,
   Filter = "AlternateIds/any(a: a/Type eq 'GooglePlay')"
 };

https://learn.microsoft.com/en-us/gaming/playfab/features/economy-v2/catalog/search#filter

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

For temporary and permanent boost, you could record the boost into player data when player purchase the Boost Item and then check it on game starts, update/delete it on game ends.

The “lives” is the same, you could record the live number into player read only data when player watch ads or purchase lives, then when player dies, you could read, subtract, and check the live number by calling GetUserReadOnlyData and UpdateUserReadOnlyData.

In Economy V2, to link the google play item to the playfab, you need to map Google Play Product Id to catalog items using Alternate Ids (in public preview this is the bundles), catalog items do not support "Marketplace Mapping. The Alternate Id value is some form of the Marketplace Id. So, you may need to follow the Redemption with the Google Marketplace - PlayFab | Microsoft Learn to set up a PlayFab bundle that can be purchased from Google Play Store so that when you call the RedeemGooglePlayInventoryItems API, PlayFab can find the bundle in the catalog that matches to grant to the Player’s Inventory. In addition, you may also need to refer to Marketplace integration - Google - PlayFab | Microsoft Learn to set up the Google Add-on.

In the IAP example script, the RefreshIAPItems method is used to pull two different Item dictionaries, one is the GooglePlay platform Items (bundles that be linked to the GooglePlay items) which filter by the platform property(you may need to navigate to [Title Settings]->[EconomyV2]->[Platform] to define the GooglePlay platform, then select the GooglePlay platform when you create or edit bundles) for real money purchase and another are Items from a store for virtual currency purchase. You may refer to Search - PlayFab | Microsoft Learn to have more information about the Filter.

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.

elephrates avatar image elephrates commented ·

How do you save into playerdata?

And how do you do the post purchase part ie see which item was bought and update player data based on that? do you add the item to the player or just update the playerdata?

As in 3 cases i need to add teh currency amount to the player, and read it ingame

LAstly; should the items be purchaseable inside unity editor? or only on apk/mobile test? I get errors on both attempts of purchases6628-screenshot-2023-12-05-132318.png

6629-screenshot-2023-12-05-132239.png

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

The “is not purchasable” error caused by the Item’s price in PlayFab not set, you may check if the Item price set well.

The “NotConfigureMarketPlace” error means you have not set Google Marketplace and PlayFab well. You may refer to Marketplace integration Google to integrate PlayFab with GooglePlay application and refer to Redemption with the Google Marketplace to set up PlayFab bundles that can be purchased from Google Play Store. (bundle is necessary for now, because when you call RedeemGooglePlayItems Api with valid receipt, PlayFab will look for the matched bundles in catalog).

Sorry, I made a mistake. In fact, you don't need to save the “lives” or “boost” to the player data, you can directly use Player Inventory to achieve your needs. After player purchases “lives” or “boost”, the Items will be sent to Player’s Inventory, then you can call Add Inventory Items and Subtract Inventory Items to update the amount of inventory Items.

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.

elephrates avatar image elephrates commented ·

Price is set on the play fab only items but its set to say 1500 of the virtual currency i setup, so the player has none of that yet. Maybe thats why? I dont know how to manually add that currency to players

Also for some reason its now doign about 50 api calls to buy on te playfab only items, and failing; see screenshot6643-screenshot-2023-12-06-230738.png6651-screenshot-2023-12-06-231305.png

Did your market integration extra part; Getting error as seen attached "internal server error"

For the lives and boost though; would the player need to purchase the inventory item first to even be able to change the number of that item he has with add or subtract?

As I just setup new keys and player data for all those lives and boosts so is there any benefit to using inventory instead of player data?

0 Likes 0 ·
Xiao Zha avatar image
Xiao Zha answered

>> I dont know how to manually add that currency to players

You could refer to Quickstart - PlayFab | Microsoft Learn to know how to grant currencies to players.

>> Also for some reason its now doign about 50 api calls to buy on te playfab only items, and failing

Each PlayFab API has its own request rate limit, once you call the API exceed the rate limit, you will get “request exceed the limit” error. The GetItem API is rate limited to 100 requests per minute. Why you call the API 50 times in your code?

>> Getting error as seen attached "internal server error"

Since the “internal server error” has no error details, you may add some debug sentences to check if the receipt contains the “productId” and “signature” used in RedeemGooglePlayInventoryItems API. Also, may I know if you follow Redemption with the Google Marketplace - PlayFab | Microsoft Learn to set up the bundles that can be purchased from Google Play Store(when you call RedeemGooglePlayInventoryItems Api with valid receipt, PlayFab will only look for bundle in catalog).

>> For the lives and boost though; would the player need to purchase the inventory item first to even be able to change the number of that item he has with add or subtract?

The player doesn’t need to purchase the inventory Items to be able to change the number of the Item he has. The Add Inventory Items API is used when you want to manually grant items to Players. Since normal purchasing will automatically add items into player’s inventory, you don’t need to call Add Inventory Items API when using Redeem API and Purchase API. And the Subtract Inventory Items API is used when player consume Items.

>> is there any benefit to using inventory instead of player data?

If you use player data, you may also need to handle items in the player's inventory since purchased items (via the Redeem API and Purchase API) are automatically sent to the player's inventory.

13 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.

elephrates avatar image elephrates commented ·

"Each PlayFab API has its own request rate limit, once you call the API exceed the rate limit, you will get “request exceed the limit” error. The GetItem API is rate limited to 100 requests per minute. Why you call the API 50 times in your code? " I dont call it 50 times this is your AndroidIAPExample code doing this:

  async public Task<bool> PlayFabPurchaseItemByID(string itemID, PlayFabEconomyAPIAsyncResult result)
     {
         if (!IsInitialized) throw new Exception("IAP Service is not initialized!");
    
         Debug.Log("Player buying product " + itemID);
    
         if (string.IsNullOrEmpty(purchaseIdempotencyId))
         {
             purchaseIdempotencyId = Guid.NewGuid().ToString();
         }
    
         GetItemRequest getSpringStoreRequest = new GetItemRequest()
         {
             AlternateId = new CatalogAlternateId()
             {
                 Type = "FriendlyId",
                 Value = "SpringStorePF"
             },

That debug log at the top runs like a 100 times

0 Likes 0 ·
elephrates avatar image elephrates elephrates commented ·

The only part ive changed so far is store name and the GUI to my UI display

" Redemption with the Google Marketplace - PlayFab | Microsoft Learn" Yes Followed that guide; my bundles match the playstores IDs in marketplace. Both errors here: https://justpaste.it/c1fk6 Null reference and http error

Then for playfab only items i added currency to my player as you said but get these errors plus 100s of API calls https://pastebin.com/MKGHUmPV

Ok so inventory is just already built to do this thing easier I guess; I will look to use that

0 Likes 0 ·
elephrates avatar image elephrates elephrates commented ·

Also this may help previous error or indicate it

Getuserinventory also isnt working; I have the cataolog though

Gets this error on logging the result

Received the following items: UnityEngine.Debug:Log (object) AndroidIAPExample:OnGetInventory (PlayFab.ClientModels.GetUserInventoryResult) (at Assets/Scripts/AndroidIAPExample.cs:484) PlayFab.Internal.PlayFabHttp/<>c__DisplayClass23_0`1:<MakeApiCall>b1 () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabHTTP.cs:219) PlayFab.Internal.PlayFabUnityHttp:OnResponse (string,PlayFab.Internal.CallRequestContainer) (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:207) PlayFab.Internal.PlayFabUnityHttp/d_12:MoveNext () (at Assets/PlayFabSDK/Shared/Internal/PlayFabHttp/PlayFabUnityHttp.cs:159) UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

0 Likes 0 ·
Show more comments

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.