Implementing IAP in Your Android Game: A Step-by-Step Guide for Unity & Unreal

Unity
Unreal
Author image
Erik Bylund25 min read
Cover image

Selecting the right business model and monetizing your games the right way is about as important as it gets in terms of the growth and health of your studio. Whether you’re looking to maintain your current game, work on the next title, establish or build on IP, or develop your team and studio, at the end of the day, you’ll need to keep making money to keep your business thriving.

Today, in-app purchases (IAP) continue to present one of the most popular monetization options among game devs and their players. IAP brings none of the interruptions of ad-based models, and doesn't ask players to pay you before they’ve spent a single moment in the worlds you build. IAP offers a flexible model too. You might harness their power to bring in constant revenue by letting players purchase in-game items with real-world currencies, or even sell a premium variant of your free base game or demo.

The reasons to go with IAP are many, with a surge in their popularity being notable through 2024. And when you consider that Android phones make up 70.69% of the global smartphone market share – with over 3 billion devices in use worldwide – the motivations to release your game on Android devices with full IAP support are clear. The audience is vast, and the potential for revenue and business growth is tremendous.

As such, LootLocker has put together this practical, step-by-step guide to take you through the process of implementing our industry-leading IAP system in your Android game. Read on, and you’ll learn about everything from set-up and testing to configurations and implementation.

This guide is divided into distinct sections so that you can read it top-to-bottom, or simply go straight to the part you want to learn more about.

  1. Prerequisites
  2. Google Play Console Setup
  3. LootLocker Setup
  4. Adding In-App Purchases to Your Game Using Unity
  5. Adding In-App Purchases to Your Game Using Unreal

Prerequisites

Before starting this guide you need to have a game project already set up and capable of producing builds for Android. We suggest checking Unity or Unreal documentation for thorough guides to getting set up for Android. We’ve also written a separate, specific guide for adding Google Sign In to your game using LootLocker, which will greatly inform how you use this IAP walkthrough. Furthermore, to use in-app purchases through the Google Play Store you also need to have your game setup for development with Google Play.

This guide also assumes that you have a project setup in LootLocker. If you already have your own backend, you can skip the LootLocker parts of this guide and get straight into the details about how to add Google in-app purchases to your game. But you may want to consider adopting LootLocker as part of the process. LootLocker offers a powerful plug-and-play game backend that makes cross-platform feel like one platform. It has been built from the ground up to help you elevate your game from local to online with minimum hassle, adding functionality such as cloud saves, cross-platform account management, a versatile economy system, and much more. If you are curious about LootLocker, you can read more here.

To summarize, before you start, please make sure you’ve completed these prerequisites.

Google Play Console Setup

Before getting started, make sure you have completed the list of prerequisites above.

Once you have a game project set up in the Google Play Console (from now on we'll call it the ‘GPlay Console’) then we need to do four things:

  • Enable releases for your app so that you can produce builds that are made available for the configured users in the Play Store, where it can be integrated to Google Play Services.
  • Make your app available to testers so that the releases you make can be installed from the Play Store by the allowed accounts.
  • Create in-app products so that you have products to test your IAP integration with.
  • Enable LootLocker Access so that LootLocker can verify and consume the purchases made and reward the player with the corresponding items.

Enable Releases For Your App

When you make changes to your game and want to test them in a connected environment with integration to Play Games Services, you need to go through a release process and install the new build from the test Play Store listing.

  1. (First time only) Go to Release > Setup > App Signing and set up an app signing key. You get the choice on whether to have Google create one, or generate your own and upload from a keystore. You want to do the latter, because we need the keystore for creating signed builds in Unity and Unreal. You can read more about app signing here and here.
  2. In your editor of choice, build your app for distribution and in a shipping configuration so that it produces an app bundle (*.aab). Make sure to edit the project version value. For each distribution the project version must be higher than any previously used (not just by you, but anyone distributing builds).
  3. Go to GPlay Console > Testing > Internal Testing. There are other test tracks besides Internal Testing, but the same process goes for them as well and Internal Testing is the most useful when developing. Here you can see the project version of the latest release, which can be useful in step 2. Press “Create new release” and upload your newly produced app bundle. Once that’s done, finish the release.
  4. After a while, your new release will be available for install at http://play.google.com/test/<package_name>/<project_version> for the testers you gave permission to that have accepted the invite to be a tester (see next section).

Make Your App Available to Testers

First a note about permissions; this is a tricky subject that you may want to think carefully about. The GPlay Console can do a lot of things for your app, so maybe you want to separate who can change the game settings in the console from who can test the app. Or who can administer in-app products, from who can make releases. This is all doable by configuring permissions and we recommend you read up on what these mean in the GPlay Console. In this short example we will create one permission group with permission to upload builds to testing, test the app, and configure monetization. But make sure to have at least one user with admin access to the full console.

Let’s set the necessary permissions:

  1. Go to GPlay Console > Users and Permissions and either create a permission group or do this for each individual user that should have access.
    1. Add permissions to your game under ‘App Permissions’.
      1. Under ‘App Access’ - Check ‘View app information’
      2. Under ‘Financial Data’ - Check ‘Manage orders and Subscriptions’
      3. Under ‘Releases’ - Check ‘Release apps to testing tracks’ and ‘Manage testing tracks and edit tester lists’
      4. Under ‘Store Presence’ - Check ‘Manage Store Presence’ (gives access to change IAPs)
    2. (For groups only) Fill out the name and description fields.
    3. (For groups only) Add the users to this group that need to be in it under ‘Users in this group’
  2. Inside of your game project, go to Release > Testing > Internal Testing (which is the test track we will be using in this guide; there are others to separate closed testing and open testing). There you need to add all the Google accounts that should be able to download the internal test releases you make. If it makes it easier to manage, you can create a mail list with the users and add that list instead, which enables simply adding the same list in steps 4 and 5.
  3. After having added the testers to Release > Testing > Internal Testing, copy the invite link from under the heading ‘How testers join your test’ and distribute it to the testers in that list. They need to accept this invite to be able to test your game.
  4. Go to Release > Setup > Internal App Sharing and add the same accounts as in step 2.
  5. Go to Play Game Services > Setup and Management > Configuration. If you haven’t already, then set up a play game services project for your game. Then head over to the Testers submenu and under the ‘Testers’ tab, add the same accounts as in step 2.

Create In-App Products

Now, to have in-app purchasing you need in-app products to purchase. To make that happen, follow these steps.

  1. Go to Monetize > Monetization Setup and download your Licensing Key. You will need it for editor setup later on in this guide.
  2. Go to Monetize > Products > In-App Products and create the products you want. Each one needs a unique product ID and you need to save them since this is the unique value you will use to identify what to purchase in your game. Beyond that, fill out the rest of the required fields such as name, description, and price with the correct values for your product. If you are creating a lot of IAPs, consider using the ‘Import from CSV’ functionality. That way you can bulk create IAPs.

Enable LootLocker Access

To let GPlay and LootLocker talk to each other about which products are purchased you need to create a service account in the GPlay Console that LootLocker will use.

  1. Enable the Google Play Android Developer API for your Google Console project and connect it to your GPlay console project.
  2. Go to ‘Service Accounts’ in Google Cloud Console for your game. You can find your way there through GPlay Console > Play Games Services > Setup and Management > Configuration > Press ‘View in Google Cloud Platform’ > IAM & Admin > Service Accounts.
  3. Create a new service account. Give it a descriptive name (like ‘LootLocker IAP Verification Access’ for example, the name is only used for display in the console) and description. Also set a good service account ID. We suggest ‘lootlocker-iap-access’. This service account needs no specific permissions.
  4. Once that is created, in the menu with the newly created service account, press on it to go into its settings and head to the tab ‘Keys’. Press Add Key > Create a new key > Json and download the newly created key.
  5. Go to GPlay Console for your organization (not your game) > Users and Permissions and press ‘Invite New User’.
  6. For email, use the email of the service account you just created.
  7. Under ‘App Permissions’, give the user access to your game and make sure to give it permission to read your app’s financial data (to validate receipts)

LootLocker Setup

Enable Google IAP

  1. Go to Settings > In-App Purchases > Google.
  2. Enter the package name for your app, you can read more about how to find it out here and here.
  3. Upload the JSON Key you got from the service account under Enable LootLocker Access.
  4. Press ‘Save’
  5. In the top right corner, press ‘Enable’
  6. Press ‘Save’ again

Now for the final link in the chain. To make products from your LootLocker game purchasable through Google IAPs, you take the product ID of a Google IAP and connect it to a single catalog listing in LootLocker. That way, when a successful purchase is made towards Google for that product ID and the receipt is sent to LootLocker, we know to reward the player with said catalog item. If you haven’t set up a catalog in LootLocker yet, then read more here. To connect GPlay in-app products to LootLocker catalog listing items, do this:

  1. Go to Content > Economy > Catalog and enter the catalog holding the listing you want to add an IAP link to.
  2. For the catalog listing you want to add an IAP link, press the three ‘more options’ dots to the right of the listing and press ‘Configure IAP’.

  • Under Google Play Store enter the product ID of the IAP you set up that – when purchased – you want to reward this catalog listing.
  • There, that’s it. Your in-app product in GPlay is now linked to a catalog listing in LootLocker. Simply repeat for any other Google IAP and Catalog Listing pair you want to connect.

    Now you are ready to implement Google IAPs in your game using Unity or Unreal.

    Adding In-App Purchases to Your Game Using Unity

    Next we’ll look at adding IAP if you’re a Unity user. Once you have the game configured in GPlay Console and in LootLocker you will have all the necessary input needed to add Google Sign In and IAP support in your Unity-based game.

    Prerequisites

    You need to have set up Unity for development of the platform targets that you will build to. Unity provides some guides on this topic, so make sure that you have properly followed the one for your platform, for example for Android or iOS.

    To be able to make purchases of Google IAPs you will need to authenticate the player with Google.

    Unity Gaming Services

    We will use Unity Gaming Services for this IAP implementation. Refer to Unity Gaming Services terms and conditions for detailed information.

    Configuration

    Build Settings

    • Set build platform to the target of your choice (in this guide we will assume Android).
    • (Optional) Set ‘Development Build’ to true while developing and debugging, but make sure to disable before distributing the game.
    • (Optional) Install Android Logcat from the Package Manager which can help you in development

    Project Settings

    • Enable the setting Player > Publishing Settings > Minify > Release

    • Under Player > Other Settings
      • Under Identification
        • Set ‘Override Default Package Name’ to ‘true’
        • Set the package name to the same package name as in Google Play Console
      • Under Configuration
        • Set the ‘Scripting Backend’ to ‘IL2CPP’
        • Set ‘Target Architectures’ to the ones you need. For most Android devices it will be ‘ARM64’.

    Google Sign-In

    To be able to make purchases your player needs to be logged in and verified to their Google account. Fortunately we have already written a guide on this. So check that out and then continue with your IAP implementation.

    Unity Services IAP Setup

    To enable Unity Services’s IAP feature in your game, follow the steps from Unity’s guide (under the ‘Getting Started’ section).

    Implementation

    You’re all set and configured to start implementation.

    Initialization

    You will likely want a central class that manages your purchasing. So we’ll create one called ‘IAPManager’ for this example. It should inherit from ‘IDetailedStoreListener’ in addition to ‘MonoBehaviour’. This is how you tie it to the Unity Services IAP implementation. When the app starts up, you need to initialize Unity Gaming Services, and then the purchasing modules as well as adding the products you intend to make available for purchase. Let’s put all this into code.

    With that code established the next step is to do the actual purchasing. There are two steps to that process. First you call ‘initiatePurchase’ on the ‘StoreController’ with the product you want to purchase. When the purchase finishes in the Google UI, the ProcessPurchase method will be invoked. If the purchase succeeded, then you call: LootLockerSDKManager.RedeemGooglePlayStorePurchaseForPlayer or LootLockerSDKManager.RedeemGooglePlayStorePurchaseForCharacter depending on your need to redeem that purchase with LootLocker which will give the player the item(s) that you tied to that product ID. These are the additions you need to make to the code above:

    In this code snippet you added the actual purchasing of a product, as well as the redemption of that product towards LootLocker. You may additionally want to add some form of feedback method so that the player that made the purchase will be notified of the purchase’s result. But you have now successfully made the code to use Google IAPs with LootLocker in Unity.

    Adding In-App Purchases to Your Game Using Unreal

    Once you have the game configured in GPlay Console and LootLocker you will have all the necessary input needed to add IAP support in your Unreal Engine-based game. For that we need to do four things:

    • Install the necessary plugins; OnlineSubsystem, OnlineSubsystemNull, OnlineSubsystemGoogle, OnlineSubsystemGooglePlay, and LootLockerSDK
    • Alter the OnlineSubsystemGooglePlay code slightly to allow for generic Google user identification
    • Configure the functionality of the subsystems and LootLocker through configurations in:
      • Ini files such as DefaultEngine.ini
      • The game’s Build.cs file
      • The project settings in the editor
    • Utilize the methods provided by LootLocker in your game logic to sign in and make purchases.

    Prerequisites

    You need to have set up Unreal Engine for development of the platform targets that you will build to. Epic provides some guides on this topic, so make sure that you have properly followed the one for your platform, for example Android or iOS.

    Limitations

    Online Subsystems Have Limited Support

    This guide is written for Unreal Engine 5.4 and makes use of the Unreal Engine Online Subsystems. If you are using versions above 5.4 then be aware that Epic has deprecated the Online Subsystems and they will be replaced in some future version of Unreal Engine. If you are using versions below 5.4, then be aware that there have been bugs in the engine Android code that you will need to fix, which means you need an Engine source build.

    Different Solutions to the IAP Problem

    There are some inherent limitations to the Google and Google Play subsystems. The Google subsystem unfortunately has no support for purchases. Meanwhile, the Google Play subsystem does not have support for third party authentication (it does not have the ability to return the ID Token needed for server (and thus LootLocker) authentication).

    There are a few different ways to solve this problem. This guide will lead you through the first one, but depending on your needs you could explore one of the other options. A few options are:

    • (The solution in this guide) Utilize both the Google and Google Play subsystems but alter the Play subsystem so that it can make purchases on behalf of the Google subsystem without being signed in.
    • Use both the Google and Google Play subsystems but sign in to both (user will get dual sign-in prompts). Use the Google subsystem for LootLocker authentication and Google Play for purchases.
    • Implement purchasing into the Google subsystem.
    • Implement ID Token support into the Google Play subsystem.
    • Use only the Google Play subsystem and sacrifice the integration to third-party actors like LootLocker.
    • Use another authentication system with LootLocker. For example you could use White Label Login with some combination of secret data from the Google Play user as username and password.

    Configuration

    Install Online Subsystems

    For this implementation we will be utilizing the Online Subsystems for Google and for Google Play. You can read about the subsystems and how they are designed here.

    • In your Unreal Editor, open plugins and install the subsystems ‘OnlineSubsystem’, ‘OnlineSubsystemNULL’, ‘OnlineSubsystemGoogle’, and ‘OnlineSubsystemGooglePlay’. The former two are for shared code and for the generic interface to work regardless of platform (instead of being absent). Remember to restart your editor.
    • If you are using an installed version of the editor: copy the subsystem plugin code into the project’s plugins folder. You do this by going to the Engine install location and copy the plugin folder (/Engine/Plugins/Online/OnlineSubsystemGoogle & /Engine/Plugins/Online/Android/OnlineSubsystemGooglePlay) into your projects plugin folder (/Plugins and /Plugins/Android respectively, if they don’t exist yet then create them).

    Changes to OnlineSubsystemGooglePlay

    Before we begin, we need to make a small adaptation to the Epic plugin OnlineSubsystemGooglePlay. This is possible even if you’re not building your engine from source since we copied the plugin code to your project plugin folder. The reason for this change is that the subsystem checks that the ID sent in for purchasing comes from the Google Play subsystem, but we will send in the one from the Google subsystem which under the hood points to the same Google user.

    Open the file ‘OnlinePurchaseGooglePlay.cpp’ and change the field ‘UserId’ in the class ‘FOnlinePurchaseGooglePlay::FOnlinePurchaseInProgressTransaction’ to be of the type ‘FUniqueNetIdPtr’ instead of ‘FUniqueNetIdGooglePlayRef’. This is the generic ID pointer used in Unreal Engine instead of the specific Google one.

    Install LootLockerSDK

    For the integration with LootLocker you will need the LootLocker SDK. You can find it on our Github, and we also have extensive documentation on how to get started with the SDK. For this guide you need to have at least version 4.1.1 of the SDK.

    Configurations in Ini Files

    Decide which ini file to add these settings in. If you are only building your game for one platform, then ‘DefaultEngine.ini’ is fine. See below for an example of the described changes.

    • Set DefaultPlatformService to Google
    • Add the necessary settings for the Google online subsystem authentication (the GamesAppID, ClientId, ServerClientId and ClientSecret from the GCloud configuration as well as userinfo.email and userinfo.profile)
    • Add the necessary settings for OnlineSubsystemGooglePlay (the GamesAppID, ClientId, ServerClientId and ClientSecret from the GCloud configuration as well as setting it as enabled)
    • You also need a couple of settings for the proper functioning of the Google Play purchases. Note that bDisableLocalAcknowledgeAndConsume is needed to allow for server-side purchase acknowledge and consume functionality. If you are following this guide and are not using server-side functionality like that, then remove this line.
    • OPTIONAL: If you're going to be using logging to debug your app on device while building IAP, then you can add some logging configurations to enable logging where it matters and silence noisy logging where you don't care for the moment. Here's an example:

    Configurations in Your Game’s Build.cs File

    You need to tell Unreal Engine that you want the Online Subsystem modules included in your Android builds. This requires that your project supports code changes and is not a blueprint project (though if it is a BP project then you can easily add code support). Add the following to your Build.cs file:

    Configurations in Editor Project Settings

    Under Project > Packaging > Project:

    • Set ‘Build Configuration’ to ‘Shipping’
    • Set ‘For Distribution’ to ‘True’.

    Under Platforms > Android > APK Packaging:

    • Set ‘Android Package Name’ to your package name from Google Play Console.
    • Set ‘Store Version’: Every time you build and ship (even for internal testing), this number needs to be incremented.
    • Set your application display name.
    • Set ‘Minimum SDK Version’ to the minimum Android version you want to support. Google Play has requirements on what you set here.
    • Set ‘Target SDK Version’ to the android version you're aiming to target. Google Play has requirements on what you set here.
    • Set ‘Use ExternalFilesDir for UnrealGame files’ to ‘True’. If this is false then Unreal Engine will try to request WRITE_EXTERNAL_STORAGE permission during runtime which is not allowed in SDK Version 33+.

    Under Platforms > Android > App Bundles:

    • Enable ‘Generate Bundle (AAB)’. This is what you will use to make releases in the Google Play console.

    Under Platforms > Android > Advanced APK Packaging:

    • Add ‘android.vending.BILLING’ to the ‘Extra Permissions’ array. This is required for in app purchases.

    Under Platforms > Android > Distribution Signing:

    • You need to add the configuration for the keystore you used to set the Upload Key Certificate under Google Setup. Epic also provides a detailed guide in addition to Google’s documentation that you can find here. To do this, copy the keystore file into your Project folders ‘Build/Android’ path and then enter the settings for it: file name, alias, and passwords.

    Under Platforms > Android > Google Play Services:

    Implementation

    The Online Subsystems do not natively have much Blueprint exposure, but fortunatelyLootLocker’s SDK provides a convenient helper class that makes implementation trivial for you regardless of if you’re making your game logic in C++ or Blueprints. Below we will outline the necessary control flows and method calls needed using this helper class. We will show these in Blueprint format because of the visualization nature of them, but each node is available as a method in C++ and functions the same way there.

    If you do not want to use our provided solution, then you can have a look at the source code to mimic it (and if you do, then remember to set LootLockerSDK.bEnableGoogleSubsystemHelper = false; in your game’s Build.cs file).

    Initialization

    Copy this Blueprint

    Before making use of the helper class we need to initialize it. This will under the hood initialize the Google subsystems and make sure that they are available for usage. Two convenience methods are also provided for checking whether the respective subsystems are available. This can be used to enable/disable control flows or parts of your UI for example. The Google subsystem is needed for sign in and the Google Play subsystem for purchasing. Note that both of these will be false for platforms that do not support the subsystems.

    Sign In

    Copy this Blueprint

    To sign in with Google, first make sure that the subsystem is available. Then call the sign-in with Google node on the LootLocker Google Subsystem Helper class. This will bring up the sign in prompt for the player and once that is completed the callback will be invoked. Make sure to handle errors, but if the call was successful then the returned ID Token can be used to start a LootLocker Google session. There are two different nodes for this, one that takes a platform and one that does not. We recommend you use the platform specific one.

    Once that call completes the callback will be invoked. Make sure to handle errors here. A successful call will give you a lot of information about the player such as various ids that will be important when calling other LootLocker functions, so you may want to save a few of those.

    Convert User Action to a Purchasable Product Identifier

    Copy this Blueprint

    Before purchasing IAPs you need the user to decide to purchase one, and from this decision you need to get the Google product identifier that you configured. The provided blueprint is a mockup of such a flow where the essentials is that the user should be provided a selection from the catalog items you configured in LootLocker. When a selection has been made, then you will be able to get the corresponding product identifier for that catalog item. This value you can then use to make the IAP purchase.

    Reading Information About In-App Products

    Copy this Blueprint

    The LootLocker SDK provides a convenient method to read information about IAPs you have configured for the game. You need to be signed in with Google as well as have the Google Play subsystem available. Then supply an offer id from the ones you created. Make sure to handle any errors. On success you will be provided with a lot of valuable information about the in-app product.

    Purchase an In-App Product

    Copy this Blueprint

    To purchase a product there are some prerequisites. Both the Google and the Google Play subsystem have to be enabled and available. The user also needs to be signed in with a Google or Google Play user. If those prerequisites are met, then call the Purchase Offer node with the necessary information. This will prompt the user with a purchase confirmation dialog from Google Play. When the process is completed then the callback will be invoked. Make sure to handle errors. If the call succeeded then the offer id and purchase token can be supplied to the ‘RedeemGooglePlayStorePurchaseForPlayer node’ (note that you can also redeem for a character if wanted). When that call is completed the corresponding callback will be invoked. Make sure again to handle errors. If the call was successful then the catalog item you configured for that product ID will have been given to the player.

    Conclusion

    And there you have it – implementing in-app purchases with Google in both Unity and Unreal Engine brings powerful potential, and isn’t as hard as you might have thought. We hope that these guides have made your life considerably easier, giving you more time to spend actually making your game. If you liked this guide, please let us know in our Discord channel or on Twitter.

    And if you want to learn more about LootLocker, check out our website or get in touch through email and more.

    Stay up to date.

    Join our newsletter and get these posts sent directly to your inbox.