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.
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.
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:
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.
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:
Now, to have in-app purchasing you need in-app products to purchase. To make that happen, follow these steps.
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.
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:
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.
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.
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.
We will use Unity Gaming Services for this IAP implementation. Refer to Unity Gaming Services terms and conditions for detailed information.
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.
To enable Unity Services’s IAP feature in your game, follow the steps from Unity’s guide (under the ‘Getting Started’ section).
You’re all set and configured to start implementation.
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.
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:
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.
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.
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:
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.
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.
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.
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.
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:
Under Project > Packaging > Project:
Under Platforms > Android > APK Packaging:
Under Platforms > Android > App Bundles:
Under Platforms > Android > Advanced APK Packaging:
Under Platforms > Android > Distribution Signing:
Under Platforms > Android > Google Play Services:
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).
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.
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.
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.
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.
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.
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.