question

Orcun Nisli avatar image
Orcun Nisli asked

GooglePlay In-App Purchase to PlayFab Items

Hi there,

I am an old fashioned game-as-a-product developer and I am very new to in-app-purchases and have some confusions and questions about using PlayFab Items with GooglePlay In-App Purchases:

1-) I am very confused with Durable/Consumable Item types. I am developing a match3-like game and I just need to define two types of Items:

  • Hard Currency Packs with diferent quantities (like Small Gem Pack of 20 Gems, Large Gem Pack of 100 Gems etc..) These packs are for Real Money and I already configured their prices on GooglePlay. When player make a purchase i just need to increase Hard Currency (Gems)
  • Different Types of Boosters (like Extra Moves or PowerUps etc.) that could be purchased by Hard Currency. Player buy these boosters anytime and they will use it whenever they need.

Can you explain which item types (Durable/Consumable) I must use for two of them? I guess I need to turn on "Is Stacking" for Boosters, but for Hard Currency Packs, do I need to?

2-) In GooglePlay there are two purchase types: Managed Product / Subscription. I configured my Hard Currency Packs as Managed Products. These types does have any relation with Durable/Consumable types?

3-) I guess I must use the same ID for items/bundles with GooglePlay to PlayFab  synchronize with GooglePlay and open GooglePlay"s own purchase dialog automatically(???) Is that correct? ...or do I need to call anything outside the PlayFab to open the in-app purchase dialog?

4-) If I have some items/bundles that can only be purchased by virtual currency and some other items that can only be purchased by real money. Is it a problem to have some item/bundle IDs that is not matching with the GooglePlay IDs? (...or maybe I must open same IDs inside GooglePlay with zero costs?? I guess it is not the right way...) How PlayFab pipeline works with Items?

5-) I already configured my Items (real money) prices on the GooglePlay side, but how could I get my price informations from the Unity client? Do I need to configure same prices inside PlayFab? Also How could I localize the currency texts on each client?

Thanks for your help.

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.

Paulo Eduardo avatar image Paulo Eduardo commented ·

Now in 2020! How to develop inAPP for unity (Google Play and Apple Store with PLAYFAB)

Hello Brendan! I need to schedule the purchase within my mobile game, which we developed for android and ios. In a simple and more up-to-date way, what would be the best way to implement this need, with the control of products within PLAYFAB? Thank you.

0 Likes 0 ·
brendan avatar image
brendan answered

Sure thing - happy to help. In answer to your questions:

1) Consumable goods are items that get used up, either as they are actively used or over time. For example, a key might only be usable once (to open a lock or chest), or a bonus to a player's damage total might be a "buff" that only lasts 24 hours in real-world time. In your case, you follow a very familiar pattern - here's what I would recommend:

  • Hard currency packs: Make a Bundle in your Catalog which includes the appropriate amount of virtual currency. Set the bundle itself to expire (Usage Period) after 5 seconds. That way, it will deliver the VC, then go away, and you can set it up as an object you sell in your Catalog (since VC can't be an item). Since you're using Google Play, you'll be using receipt validation, so set the Product ID in the Google Play catalog the same as the ItemId in the PlayFab catalog, and we'll take care of everything when you do the receipt validation call - we check that the receipt is good, that it's actually for your title, and that it hasn't been used before, and then we take the item from the catalog and put it in the player inventory.
  • Boosters: This is somewhat dependent upon the booster in question, but if you set it up as being for sale for a certain virtual currency amount, you can then buy it with the PurchaseItem call. Setting the item to expire after a usage period or a number of uses is usually the right thing to do for these. As to whether they stack, that's down to how they should accumulate. If you want players to be able to extend out the period that a boost is working each time they purchase the item, set the Usage Group to some specific string, and we'll make sure to add the Usage Period to the total for each item added. The items should probably be stackable, but again, it depends upon your usage scenario. The complexity there is that stackables use the Usage Count to represent how many items are in the stack. If that works for you, feel free to use it that way.

> 2-) In GooglePlay there are two purchase types: Managed Product / Subscription. I configured my Hard Currency Packs as Managed Products. These types does have any relation with Durable/Consumable types?

Managed products can be both durables and consumables. By the Google definition, the difference is simply that a subscription is something with ongoing payments, and the player only has access while those payments continue. We don't provide a subscription system in PlayFab, but it's trivial to connect access to items in the player inventory in PlayFab with a subscription in any service. If you need to look into that, let us know and we can work through the details with you.

> 3-) I guess I must use the same ID for items/bundles with GooglePlay to PlayFab  synchronize with GooglePlay and open GooglePlay"s own purchase dialog automatically(???) Is that correct? ...or do I need to call anything outside the PlayFab to open the in-app purchase dialog?

Yes, the PlayFab SDKs do not manage the client layer, as that's game-specific. For Google Play purchases, you will need to present the player with a purchase interface, in order to complete the purchase flow.

> 4-) If I have some items/bundles that can only be purchased by virtual currency and some other items that can only be purchased by real money. Is it a problem to have some item/bundle IDs that is not matching with the GooglePlay IDs? (...or maybe I must open same IDs inside GooglePlay with zero costs?? I guess it is not the right way...) How PlayFab pipeline works with Items?

The recommended way to do this is to have items which are purchased with real money set up in the Google Play catalog, with their Product IDs matching the equivalent ItemId in your PlayFab catalog. That way, you can use receipt validation to purchase them. For items which are purchased with virtual currency, you should just set them up in the PlayFab catalog and use PurchaseItem to make the transaction.

> 5-) I already configured my Items (real money) prices on the GooglePlay side, but how could I get my price informations from the Unity client? Do I need to configure same prices inside PlayFab? Also How could I localize the currency texts on each client?

Google does not provide us with the accessors we would need to retrieve the prices from their service, so you will need to present those to the player in the client code, either via an existing plugin, like Prime31, or your own code. Our receipt validation API calls take the currency code and price as input, so you can specify those as part of the call, for accurate tracking. Have a look at this post, for more info on this: https://playfab.com/show-me-money-receipt-validation-ios-and-android/

10 |1200

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

Orcun Nisli avatar image
Orcun Nisli answered

Thank you for your fast response,

But I still have some related questions:

A-) How could I set the bundle itself to expire (Usage Period) after 5 seconds. Do you mean that I must set Item Bundle > Consumable > By Time > 5 seconds from the Item Bundle settings. Also why it is 5 seconds? does that mean that I must wait for 5 seconds to get new Hard Currency value?

B-) I understand that I need to use Unity IAP or similar Unity plugin to make the real transaction with GooglePlay. Is that correct?

C-) I still don't understand the exact way to make a purchase from Google Play on Unity client. Can you tell me my current estimation is correct?:

  • call PlayFabClientAPI.GetCatalogItems to get the list of Items when i logged in to PlayFab (through any login method)
  • from Unity IAP, call UnityPurchasing.Initialize by populating product types from PlayFab Catalog Items (I couldn't found an exact way to check if an item is purchasable by RM or not, but i could check it by looking item class)
  • from Unity IAP, call IStoreController.InitiatePurchase(productId)
  • from the returning result from Uniy IAP, I take the receipt and signature
  • call PlayFabClientAPI.ValidateGooglePlayPurchase with the receipt and signature to validate items and add item to player inventory.

D-) And I estimate that purchising process of a basic Item (with a virtual currency price) would be like this?

  • call PlayFabClientAPI.GetCatalogItems to get the list of Items when i logged in to PlayFab (through any login method)
  • call PlayFabClientAPI.PurchaseItem to purchase item with specific Id from the catalog.
  • then later, call PlayFabClientAPI.ConsumeItem to consume item if it is consumable.

Is there anything else?

E-) Why Price parameter of a PurchaseItemRequest is int and  CatalogItem.VirtualCurrencyPrices[currencyCode] is an uint, so I need to convert uint to int? Because my purchase code is like this:

public void PurchaseItem(string itemId, CurrencyType currencyType)
    {
        CatalogItem item = FindItem(itemId);
        if (item != null)
        {
            PurchaseItemRequest request = new PurchaseItemRequest()
            {
                ItemId = item.ItemId,
                VirtualCurrency = currencyType.ToString(),
                Price = (int)item.VirtualCurrencyPrices[currencyType.ToString()],
            };

            PlayFabClientAPI.PurchaseItem(request, (result) =>
            {
                OnResult(ResultSource.PurchaseItem, ResultType.Successed);
            }, (error) =>
            {
                Debug.Log("Got error while purchasing item " + itemId);
                OnResult(ResultSource.PurchaseItem, ResultType.Error);
            });
        }
    }

10 |1200

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

brendan avatar image
brendan answered

Answers to your new questions:

> A-) How could I set the bundle itself to expire (Usage Period) after 5 seconds. Do you mean that I must set Item Bundle > Consumable > By Time > 5 seconds from the Item Bundle settings.

Yes

> Also why it is 5 seconds?

While it's extremely unlikely, setting it to 1 second could result in the bundle expiring before delivering the VC. It's an extreme corner case, but I like to be 100% certain. A 5 second buffer is more than enough to be sure.

> does that mean that I must wait for 5 seconds to get new Hard Currency value?

No, the VC will be added immediately. When you get the response from the call, you'll see the new balance.

> B-) I understand that I need to use Unity IAP or similar Unity plugin to make the real transaction with GooglePlay. Is that correct?

You need to be able to get the receipt from Google. Many titles use a plugin for this, and yes, Unity IAP gives you the receipt.

> C-) I still don't understand the exact way to make a purchase from Google Play on Unity client. Can you tell me my current estimation is correct?:

We have a walkthrough for this, using Google's In-app billing service, here: https://playfab.com/show-me-money-receipt-validation-ios-and-android/

If you choose to use a plugin, the details of how you call to initiate the purchase with Google (and so, how you get the receipt) will vary, and you should check the plugin's docs for specifics. They keys are that the catalog in PlayFab gives you prices you can show to the players as a base, but the real price for the item lives in Google - they just don't provide an accessor which would allow us to use the current pricing from their service.

> D-) And I estimate that purchising process of a basic Item (with a virtual currency price) would be like this?

Yes, purchases which are just for Virtual Currency would use PurchaseItem. The ConsumeItem call is only needed if you intend to decrement the uses remaining, like with a potion or similar - something the player can use up. If you just want it to expire shortly after arriving in the inventory (like the bundle), you can use the Usage Period.

> E-) Why Price parameter of a PurchaseItemRequest is int and  CatalogItem.VirtualCurrencyPrices[currencyCode] is an uint, so I need to convert uint to int? Because my purchase code is like this:

That's a legacy issue which the tools team is looking to fix in a future update.

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.

Paulo Eduardo avatar image Paulo Eduardo commented ·

Now in 2020, How to develop inAPP for unity (Google Play and Apple Store with PLAYFAB)?
Hello Brendan! I need to schedule the purchase within my mobile game, which we developed for android and ios. In a simple and more up-to-date way, what would be the best way to implement this need, with the control of products within PLAYFAB? Thank you.

0 Likes 0 ·
Orcun Nisli avatar image
Orcun Nisli answered

Really thanks. It was enlightening!

10 |1200

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

Paulo Eduardo avatar image
Paulo Eduardo answered

Google Play in-app purchase has the same mechanism as Apple Store in-app purchase, which is the purchase with receipt validation. In terms of Google platform, you may refer to the documentation on: https://docs.microsoft.com/en-us/gaming/playfab/features/commerce/economy/getting-started-with-unity-iap-android.

In addition, we also provide a tutorial for iOS in-app purchase on: https://blog.playfab.com//blog/show-me-money-receipt-validation-ios-and-android/.

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.