Skip to main content

Getting started with PlayFab (Legacy Economy), Unity IAP, and Android

Economy v1 APIs are in maintenance mode and will not be receiving any new features, only bug fixes. The v1 APIs will be maintained for the foreseeable future. See the Economy v2 Overview to learn more about the next version of PlayFab Economy!
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

Setting up IAP may be tedious, especially if you are not sure how different services are supposed to integrate and cooperate. The following image illustrates how the Android Billing API and PlayFab work together to provide a solid IAP experience for your client. Android Billing - PlayFab - integration timeline Start by setting up your Product IDs and Prices via PlayMarket. Initially, all the products are faceless - they are digital entities your player is able to purchase - but they have no meaning to PlayFab players. To make those entities useful, we need to mirror them in the PlayFab item catalogs. This turn’s faceless entities into bundles, containers, and individual items. Each has their own unique face, with:
  • Titles
  • Descriptions
  • Tags
  • Types
  • Images
  • Behaviors
All of these are linked to market products by sharing IDs. The best way to access real money items available for purchase is to use GetCatalogItems and GetStoreItems. These are the same API methods that are used by free-currency stores, so the process should be familiar. 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 is then able to validate the receipt and register the purchase, granting the PlayFab player the items that they just bought. This is a rough idea of how IAP integration works, and the following example shows most of it in action.

Setting up a client application

This section shows you how to configure a very primitive application to test IAP using PlayFab, UnityIAP, and the Android Billing API. Prerequisites:
  • A Unity project.
  • The PlayFab SDK imported and configured to work with your title.
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.
Setting up UnityIAP service
  1. Next, navigate to the In-App Purchasing (IAP) service.
Navigate to UnityIAP service
  1. Make sure to enable the Service, by setting the Simplify cross-platform IAP toggle.
  2. Then select the Continue button.
Enable UnityIAP service A page with a list of plugins will appear.
  1. Select the Import button.
UnityIAP service - Import plugins 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.
UnityIAP Create new script AndroidIAPExample.cs will contain the code shown below (please refer to the code comments for further explanation).
  1. Create a new Game object called Code.
  2. Add the AndroidIAPExample component to it (2-step process).
  3. Add the AndroidIAPExample component to it.
  4. Make sure to Save the scene.
UnityIAP create example game object 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.
UnityIAP add example game object Finally, build the application as usual, and ensure you have an APK safe and sound. We have no means to test it just yet. We need to configure PlayMarket and PlayFab first, which is described in the following sections.

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.
Enable PlayMarket Application Useful notes:
  • Getting to that point will require you to have an APK uploaded. Please use the APK we constructed in the previous section.
  • When asked to upload the APK, you may upload it as an Alpha or Beta Application to enable the IAP sandbox.
  • Configuring Content Rating will include questions about how IAP is enabled in the application.
  • PlayMarket does not allow Publishers to use or test IAP - so please, pick another Google account for testing purposes, and add it as a tester for your Alpha/Beta build.
Once you have the application build published:
  1. Select In-app products from the menu.
    • If you are asked for a Merchant Account, link or create one.
  2. Select the Add New Product button.
PlayMarket add new product
  1. On this screen shown below, select Managed Product.
  2. Give it a descriptive Product ID.
  3. Select Continue.
PlayMarket add product ID PlayMarket requires you to fill in a Title (1) and a Description (2). However, these are not much use in our case. We will grab Data Item data exclusively from the PlayFab service, and only require IDs to match. PlayMarket add product title description
  1. Scroll further and select the Add a price button.
PlayMarket add product price
  1. Enter a valid price (notice how price is converted for each country/region independently).
  2. Select the Apply button.
PlayMarket add product apply local prices
  1. Finally, scroll back to the top of your screen, and change the status of the item to Active.
PlayMarket make product active While this concludes configuring the app, we need a couple more tweaks. First, let us save the Licensing Key (this will come in handy for linking PlayFab with PlayMarket.
  1. Navigate to Services & APIs in the menu.
  2. Then locate and save the Base64 version of the Key.
PlayMarket save product licensing 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! PlayMarket enable IAP testing 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.
PlayFab open 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.
PlayFab install Google Add-on Our next step is reflecting our Golden Sword item in PlayFab:
  1. Select Economy.
  2. Verify that the Catalogs sub-tab is selected.
  3. Select New Catalog.
  4. Provide a Catalog version name.
  5. Select Save Catalog.
PlayFab save Catalog If the catalog has no items, it is automatically removed. That’s why any new catalog comes with a pre-added item called One. We can always create a new item, but to keep things clean, let’s modify the existing One item.
  1. Select the item to edit the Item ID to match the ID in PlayMarket.
  2. Now, edit the Display name and add a Description.
Keep in mind that this data has nothing to do with the Play Market Item Title and Description - it is totally independent.
  1. Assign a Price to your Item.
  2. Select Save Item to commit your changes.
PlayFab Edit and Save Catalog Item
In this tutorial, IAP mainly refers to purchases for real money. That’s why we use RM - special Real Money currency. The PlayFab amount is defined in US Cents.
  1. Observe your item in the Item ID list.
PlayFab Catalog Items list This concludes 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.
Test app - Buy Golden Sword button The IAP purchase will be initiated. Follow the Google Play instruction up to the point where purchase is successful. Test app - Google Play - payment successful Finally, navigate to your title in the PlayFab Game Manager dashboard and locate New Events. Game Manager Dashboard new events This means that purchase was successfully provided, validated, and piped to the PlayFab ecosystem. At this point you have successfully integrated UnityIAP and the Android Billing API into your PlayFab application.
Last modified on August 10, 2026