Using In-App Purchases on Android

Using in-app purchases to offer additional paid content for your Android game.

Choose your operating system:

Windows

macOS

Linux

Configuration

  1. Set up your in-app purchase in Google Play:

    Google Play requires the id to be all lowercase, and it's best to have the ID for iOS and Android match for ease of Blueprint setup.

    image alt text

  2. Make a note of the ID you use, as well as if the item is consumable or non-consumable.

  3. If you have a Blueprint project, you're set to go. If you have a code project and have not already set up your project to use online subsystems, add the following block to your project's Build.cs file:

    if (Target.Platform == UnrealTargetPlatform.Android)
    {
        PrivateDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "OnlineSubsystem" });
        DynamicallyLoadedModuleNames.Add("OnlineSubsystemGooglePlay");
    }
  4. In Project Settings > Platforms > Android , find the Advanced APKPackaging section.

  5. Add an element to ExtraPermissions called "com.android.vending.BILLING".

    image alt text

  6. Edit [ProjectName]/Config/Android/AndroidEngine.ini:

    [OnlineSubsystem]
    DefaultPlatformService=GooglePlay
    
    [OnlineSubsystemGooglePlay.Store]
    bSupportsInAppPurchasing=True

Reading Purchase Information

image alt text

You can read the in-app purchase information using the Read In-App Purchase Information Blueprint node (or associated C++ function call). Like most other online subsystems functions, it takes a Player Controller as input, as well as an array of your product identifiers. Note that Make In-App Purchase below takes a single identifier, while Read can process an array of information. The function returns an array of In App Purchase structs, and each element of the array can be broken out to get the name, description, price, and other data to display in your UI or use in your gameplay logic.

Completing a Purchase

image alt text

To make an in-app purchase, use the Make an In-App Purchase Blueprint node (or associated C++ function call). It takes the Player Controller as input, as well as a Product Request struct. A Product Request is just the product identifier from iTunes Connect or the Google Play Developer console (in this case, match3theme_night), as well as whether or not the product is consumable.

The Make an In-App Purchase node is latent, so any gameplay behavior you want to have rely on whether the purchase succeeds or fails should use those two execution pins. They will only execute after a response has come back from the online service. The node also returns the completion status of the purchase (such as Success, Failed, Restored) and the detailed In App Purchase Information struct.

There is a non-latent version of this function (the Blueprint node will display without the clock). The exit execution pin here does not wait for a response from the online service, and you will generally want to use the latent version.

Testing

To test on Android, you need to upload the packaged APK to Google Play, as well as set up the correct testing profiles. You'll also need your custom key store.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss