Skip to main content

Getting Started with Economy v2, Unity, and Android

Economy v2 is now Generally Available. For support and feedback, go to the PlayFab Forum.
This tutorial shows you how to set up In-App Purchasing (IAP) using PlayFab, the Unity + IAP Service, and the Android Billing API.

Before we start

The Android Billing API and PlayFab work together to provide an IAP experience for your client: Start by setting up your Product IDs and Prices via PlayMarket. Initially, all the products are faceless - digital entities your player is able to purchase - but no meaning to PlayFab players. To make those entities useful, we need to mirror them in the PlayFab item catalogs. PlayFab turns faceless entities into bundles, containers, and individual items. Each has their own unique face, with:
  • Titles
  • Descriptions
  • Tags
  • Types
  • Images
  • Behaviors
All items are linked to market products by sharing IDs. The best way to access real money items available for purchase is to use GetItems. The ID of the item is the link between PlayFab and any external IAP system. So we pass the item ID to the IAP service. At this point, the purchase process begins. The player interacts with the IAP interface and - if the purchase is successful - you obtain a receipt. PlayFab validates the receipt and register the purchase, granting the PlayFab player the items that they just bought.

Setting up a client application

This section shows you how to configure an application to test IAP using PlayFab, UnityIAP, and the Android Billing API. Prerequisites:
  • A Unity project.
  • The PlayFab Unity SDK imported and configured to work with your title.
  • An editor like Visual Studio installed and configured to work with your Unity project.
Our first step is setting up UnityIAP:
  1. Navigate to Services.
  2. Make sure the Services tab is selected.
  3. Select your Unity Services profile or organization.
  4. Select the Create button.
  1. Next, navigate to the In-App Purchasing (IAP) service.
  1. Make sure to enable the Service, by setting the Simplify cross-platform IAP toggle.
  2. Then select the Continue button.
A page with a list of plugins appears.
  1. Select the Import button.
Continue the Unity install, and import procedure up to the point where it has imported all the plugins.
  1. Verify that the plugins are in place.
  2. Then create a new script, called AndroidIAPExample.cs.
AndroidIAPExample.cs containing the following code (refer to the code comments for further explanation).
  1. Create a new GameObject called Code.
  2. Add the AndroidIAPExample component to it (click-and-drag, or).
  3. Make sure to Save the scene.
Finally, navigate to Build Settings.
  1. Verify that your scene has been added to the Scenes In Build area.
  2. Make sure that the Android platform has been selected.
  3. Move to the Player Settings area.
  4. Assign your Package Name.
Make sure to come up with your own package name to avoid any PlayMarket collisions.
Finally, build the application as usual, and ensure there’s an APK. In order to test, we need to configure PlayMarket and PlayFab.

Setting up a PlayMarket application for IAP

This section describes the specifics of how to enable IAP for your PlayMarket application.
Setting up the application itself is beyond the scope of this tutorial. We assume you already have an application, and that is configured to publish at least Alpha releases.
Useful notes:
  • Getting to that point requires you to have an APK uploaded. Use the APK we constructed in the previous section.
  • Upload the APK as an Alpha or Beta Application to enable the IAP sandbox.
  • Configuring Content Rating includes questions about how IAP is enabled in the application.
  • PlayMarket doesn’t allow Publishers to use or test IAP. Pick another Google account for testing purposes, and add it as a tester for your Alpha/Beta build.
  1. Publish the application build.
  2. Select In-app products from the menu.
    • If you’re asked for a Merchant Account, link or create one.
  3. Select the Add New Product button. PlayMarket add new product
  4. On the new product screen, select Managed Product.
  5. Give it a descriptive Product ID such as 100diamonds.
  6. Select Continue. PlayMarket add product ID
  7. PlayMarket requires you to fill in a Title (1) and a Description (2), for example 100 Diamonds and A pack of 100 diamonds to spend in-game. Data Item data comes exclusively from the PlayFab service, and only requires IDs to match. PlayMarket add product title description
  8. Scroll further and select the Add a price button. PlayMarket add product price
  9. Enter a valid price such as “$0.99” (notice how price is converted for each country/region independently).
  10. Select the Apply button. PlayMarket add product apply local prices
  11. Finally, scroll back to the top of your screen, and change the status of the item to Active. PlayMarket make product active
  12. Save the Licensing Key to link PlayFab with PlayMarket.
  13. Navigate to Services & APIs in the menu.
  14. Then locate and save the Base64 version of the Key.
The next step is enabling IAP testing. While sandbox is automatically enabled for Alpha and Beta builds, we need to set up accounts that are authorized to test the app:
  1. Navigate to Home.
  2. Locate and select the Account details in the menu to the left.
  3. Locate the License Testing area.
  4. Verify that your Test Accounts are in the list.
  5. Make sure the License Test Response is set to RESPOND_NORMALLY.
Don’t forget to apply the settings! The Play Market side of the integration should be set up at this point.

Setting up a PlayFab title

Our last step is configuring a PlayFab title to reflect our products, and integrate with the Google Billing API.
  1. Select Add-ons.
  2. Then, select the Google add-on.
  1. Fill in your Package ID.
  2. Fill in the Google App License Key that you acquired in the previous section.
  3. Commit your changes by selecting the Install Google button.
Our next step is reflecting our 100 Diamonds bundle in PlayFab:

Game Manager

  1. Create a new Economy Catalog (V2) Currency.
  2. Edit the Title and add a Description - for example, Diamonds, Our in-game currency of choice..
  3. Add a Friendly ID to make it easier to find your currency, diamonds.
  4. Select Save and publish to complete your changes.
  5. Observe your currency in the Currency list.
  6. Next, create a new Economy Catalog (V2) Bundle.
  7. Edit the Title and add a Description - for example, 100 Diamonds Bundle, A pack of 100 diamonds to spend in-game..
Keep in mind that this data has nothing to do with the Play Market Item Title and Description - it is independent.
  1. You can use Content type to organize your bundles - for example, appstorebundles. Content types are managed in ⚙️ > Title Settings > Economy (V2).
  2. Track real-world prices by adding localized pricing to the Display properties.
  3. Add a new Item to the Bundle. Select Currencies in the filter and choose the Currency you created in the previous set. Set the Quantity to match the amount of Currency you want to sell in this bundle.
  4. Add a new Platform for the “GooglePlay” Marketplace. If you don’t already have the GooglePlay Marketplace, you can create it in the Economy Settings page. Set the Marketplace ID to match the Google Play Console Product ID you created in the previous section.
  5. Select Save and publish to complete your changes.
  6. Observe your bundle in the Bundles list.

REST API


Next, we can set in-game purchases for players to spend their currency on with a PlayFab store to represent an in-game NPC vendor:

Game Manager

  1. Create a new Economy Catalog (V2) Item.
  2. Edit the Title and add a Description - for example, “Golden Sword”, “A sword made of gold.”.
  3. You can add localized keywords to help players find your item in the store. Add Tags and a Content type to help you organize your items for later retrieval via API. Use Display Properties for storing game data such as armor values, a relative path to art assets, or any other data you need to store for your game.
  4. Add a new price and select the Currency you created in the previous step. Set the Amount to the price you want set by default. You can override the Price later in any Store you create.
  5. Select Save and publish to complete your changes.
  6. Observe your item in the Items list.
  7. Finally, create a new Economy Catalog (V2) Store.
  8. Edit the Title and add a Description - for example, Villager Store, A humble store run by a humble villager..
  9. Give it a Friendly ID to make retrieval easier, for example villagerstore.
  10. Add the item you created in the previous step to the store. You can add multiple items to a store, and override any default prices if necessary.
  11. Select Save and publish to complete your changes.
  12. Observe your store in the Stores list.

REST API


We’ve concluded the setup for your PlayFab title.

Testing

For testing purposes, download the app using the Alpha/Beta release.
  • Make sure to use a test account and a real Android device.
  • Once you start the app, you should see IAP initialized, and one button representing your item.
  • Select that button.
The IAP purchase is initiated. Follow the Google Play instruction up to the point where purchase is successful. Finally, navigate to your title in the PlayFab Game Manager dashboard and locate New Events. Verify the purchase was provided, validated, and piped to the PlayFab ecosystem. You have successfully integrated UnityIAP and the Android Billing API into your PlayFab application!

Next Steps

  1. Build a Unity UI Toolkit interface for purchasing to replace the demo IMGUI display.
  2. Create a custom Unity Logger to handle PlayFab errors and display them to the user.
  3. Add icon images to your PlayFab Items Images field to display in the Unity UI.
Last modified on August 10, 2026