LootLocker
The BasicsGame SystemsContent ManagementPlayer Management
LootLocker
  • 📌The Basics
    • Getting Started
    • What is LootLocker?
    • Core Concepts
      • Players
      • Assets
      • Character Classes
      • API Types
      • Web Console
      • Stage & Live Environments
      • Glossary
    • Unity Quick Start
      • Install the SDK
      • Configure the SDK
      • Authenticate Your First Player
      • Update the SDK
    • Unreal Quick Start
      • Install & Configure the SDK
        • Older versions
      • Authenticate Your First Player
    • Godot Quick Start
      • Install the SDK
      • Configure the SDK
      • Authenticate Your First Player
      • Update the SDK
    • SDKs
    • Samples
      • Authentication Samples
      • Leaderboard Samples
      • Progression Samples
      • Player Samples
    • Launching Your Game
    • Support
      • Error Codes
      • Unreal Marketplace Plugin Support
  • 🎭Players
    • Overview
    • Authentication
      • How To
        • Guest Login
        • Steam
        • Apple
        • Apple Game Center
        • Google
        • Epic Games
        • PlayStation
        • Meta / Oculus
        • Xbox
        • Nintendo Switch
    • Files
      • How To
        • Manage Files in Web Console
        • Work with Files In-Game
    • Inventory
      • How To
        • Work with Player Inventory
    • Messages
      • How To
        • Configure Messages in Web Console
    • Names
      • How To
        • Work with Player Names
    • Player Manager
      • How To
        • Manage Players through Web Console
        • Manage Players In-Game
        • Use Player Operations
    • Unified Player Accounts
      • How To
        • Configure UPA in Web Console
        • Use Remote Login In-Game
        • Connect Identiy Provider to Player
        • External Provider Linking
        • Transition from Guest Login to Other Provider
        • Disconnect Identity Provider from Player
    • White Label Login
      • How To
        • Configure White Label Login
        • Create a New White Label User
        • Request User Verification
        • Handle Returning Users
        • Start a White Label Session
  • 🪙Commerce
    • Overview
    • Catalogs
      • How To
        • Configure Catalogs in LootLocker Console
        • List all Catalogs
        • Use Catalogs In-Game
        • Setup In-Game Store
    • Currencies
      • How To
        • Configure a Currency in Web Console
        • Use Currencies In-Game
    • DLC Management
      • How To
        • Configure DLC in Web Console
        • Use DLC In-Game
    • Entitlements
      • How To
        • Work with Entitlements In-Game
    • Real Money Purchases
      • How To
        • Configure In-App Purchase in Web Console
        • Make Purchases through Google Play Store
        • Make Purchases through Apple Store
        • Make Purchases through Steam Store
    • Virtual Purchases
    • Wallets
      • How To
        • Manage a Wallet in Web Console
        • Use Wallets In-Game
  • ⚔️Content
    • Overview
    • Assets
      • How To
        • Create & Configure an Asset
        • Organize & Search for Assets
        • Retrieve Assets In-Game
        • Set up Asset Storage Template
        • Check Grant Notifications
        • Set up a Game Config Asset
        • Create a Loot Box
        • Work with Loot Boxes In-Game
        • Create a Drop Table
        • Work with Drop Tables In-Game
        • Create a Rental Asset
        • Work with Rental Assets In-Game
    • User Generated Content (UGC)
      • How To
        • Create UGC In-Game
    • Twitch Drops
  • 🕹️Game Systems
    • Overview
    • Classes & Heroes
      • How To
        • Base Classes
        • Hero Classes
        • Implement Classes In-Game
        • Implement Heroes In-Game
    • Leaderboards
      • How To
        • Configure Leaderboard in Web Console
        • Use Player Leaderboards
        • Use Generic Leaderboards
        • Use Metadata to Store Additional Information
        • Use Scheduled Reset with Rewards
        • Use Leaderboards for Time Based Rankings
      • Leaderboard FAQ
      • GameMaker References
    • Feedback
      • How To
        • Manage Feedback Categories
        • Create Player Feedback
        • Create UGC Feedback
        • Create Game Feedback
        • View and Manage Feedback
    • Progressions
      • How To
        • Create a Progression
        • Game Progressions
        • Player Progressions
        • Class Progressions
        • Asset Instance Progressions
    • Triggers
      • How To
        • Setup a trigger in the Web Console
        • Invoke trigger from game
  • ⛓️Shared Systems
    • Overview
    • Metadata
      • How To
        • Add Metadata in Console
        • Fetch a Single Metadata In-Game
        • Fetch Metadata In-Game by Tags
        • Fetch Metadata In-Game from Multiple Sources
    • Notifications
      • How To
        • List Notifications and Mark as Read In-Game
  • 🗝️Admin
    • Settings
    • User Settings
    • Organization Settings
    • CORS Allowlist
  • ⭕️ Legacy
    • Deprecations
      • Unity SDK Deprecation Log
        • Version 2.1.5 - Migration to Open UPM
        • Version 2.0.0
      • Unreal SDK Deprecation Log
        • Version 4.0.0
        • Version 3.0.0
    • Legacy Storage
    • Legacy Triggers
      • Activate a trigger
      • Create a trigger
    • Legacy Progressions
      • Create a Progression System
      • Use a Progression System In-Game
Powered by GitBook
On this page
  • Create In App Purchases on Google
  • Creating Purchases In Engine
  • Redeem Purchase For Player
  • Redeem Purchase For Class
  1. 🪙Commerce
  2. Real Money Purchases
  3. How To

Make Purchases through Google Play Store

PreviousConfigure In-App Purchase in Web ConsoleNextMake Purchases through Apple Store

Last updated 9 months ago

In order to use IAP with Google Play Store, you must have an active Google Session, to do this read our Google Sign in Guide or take a look at our in-house feature UPA where you can start a Remote Login Session for Google!

It is presumed that you have at least made an Application in Google Play Console!

Create In App Purchases on Google

To utilize IAP you must make the In App Purchases in Google Play Console.

Some important information to find is your application name; it generally follows this style "com.company.app_name", this name can be found under the overview of all your applications, or inside the application page beneath the title.

Underneath the Monetization page in the left menu list, you will see Products which contains In-app products. This is where you set up your products to use IAP with.

Create new in-app product, supply all the required fields.

Creating Purchases In Engine

To create Purchases in Unity, you must inherit from IDetailedStoreListener and import the required methods that follows.

This is how you add products to your IAPManager:

        builder.AddProduct("<replace_with_product_id>", ProductType.Consumable);

Here is how you'd initiate a Purchase:

    public void Purchase()
    {
        var product = controller.products.WithID("<replace_with_product_id>");

        if (product is { availableToPurchase: true })
        {
            controller.InitiatePurchase(product);
        }
    }

This snippet shows you how you'll connect LootLocker IAP to the flow:

In this example LootLockerIAPManager.cs has a RedeemPurchase(Product product) method which will be described underneath Redeem Purchase For Player and Redeem Purchase For Class

    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        LootLockerIAPManager.RedeemPurchase(e.purchasedProduct);
        return PurchaseProcessingResult.Complete;
    }

This is the complete script:

using Unity.Services.Core;
using Unity.Services.Core.Environments;
using UnityEngine;
using UnityEngine.Purchasing;
using UnityEngine.Purchasing.Extension;

public class IAPManager : MonoBehaviour, IDetailedStoreListener
{

    public IStoreController controller;
    private IExtensionProvider extensions;

    public async void Awake()
    {
        try
        {
            var options = new InitializationOptions()
                .SetEnvironmentName("production");

            await UnityServices.InitializeAsync(options);
        }
        catch (Exception exception)
        {
            Debug.Log(exception);
        }
        //Specifically creates IAP for Google Play Store, using ifdefs to determine which platform is being run is preferable.
        var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance(AppStore.GooglePlay));

        builder.AddProduct("<replace_with_product_id>", ProductType.Consumable);

        StandardPurchasingModule.Instance().useFakeStoreAlways = true;

        UnityPurchasing.Initialize(this, builder);
    }

    public void OnPurchaseClicked(string productId)
    {
        controller.InitiatePurchase(productId);
    }

    public void Purchase()
    {
        var product = controller.products.WithID("<replace_with_product_id>");

        if (product is { availableToPurchase: true })
        {
            controller.InitiatePurchase(product);
        }
    }

    /// <summary>
    /// Called when Unity IAP is ready to make purchases.
    /// </summary>
    public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    {
        this.controller = controller;
        this.extensions = extensions;
    }

    /// <summary>
    /// Called when Unity IAP encounters an unrecoverable initialization error.
    ///
    /// Note that this will not be called if Internet is unavailable; Unity IAP
    /// will attempt initialization until it becomes available.
    /// </summary>
    public void OnInitializeFailed(InitializationFailureReason error)
    {
    }

    /// <summary>
    /// Called when a purchase completes.
    ///
    /// May be called at any time after OnInitialized().
    /// </summary>
    public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
    {
        LootLockerIAPManager.RedeemPurchase(e.purchasedProduct);
        return PurchaseProcessingResult.Complete;
    }

    /// <summary>
    /// Called when a purchase fails.
    /// </summary>
    public void OnPurchaseFailed(Product i, PurchaseFailureReason p)
    {
    }

    public void OnPurchaseFailed(Product product, PurchaseFailureDescription failureDescription)
    {

    }

    public void OnInitializeFailed(InitializationFailureReason error, string message)
    {
        Debug.Log("Error: " + message);
    }
}

A guide is currently in the making as this requires a lot of set up! Once the guide is up, it will be linked here.

Redeem Purchase For Player

Product is from using UnityEngine.Purchasing;

Which is a Package called "In-App Purchasing", read more here.

public void RedeemPurchase(Product product)
{
    string productID = product.definition.id;
    string purchaseToken = product.transactionID;
    LootLockerSDKManager.RedeemGooglePlayStorePurchaseForPlayer(productID, purchaseToken, (result) =>
    {
        if (!result.success)
        {
            Debug.Log("Redeem Purchase unsuccessful!");
            return;
        }

    });
}

To be able to redeem a Google purchase you've made, you need to grab the product id (the same you used to make the purchase) and the purchase token from a successful purchase as input for the redeem.

On a successful redemption, the player will have been rewarded with whatever catalog item that this product id has been set up to reward.

curl --location --request POST 'https://api.lootlocker.io//game/redeem/store/google' \
--header 'x-session-token: {{session_token}}' \
--header 'User-Agent: Apidog/1.0.0 (https://apidog.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
    "sandboxed": true,
    "transaction_id": "2000000316432479"
}'

On a successful Purchase, a 204 will be returned with no body.

Redeem Purchase For Class

Product is from using UnityEngine.Purchasing;

Which is a package called "In-App Purchasing", read more here.

public void RedeemPurchase(Product product)
{
    string productID = product.definition.id;
    string purchaseToken = product.transactionID;
    int classID = 123;
    LootLockerSDKManager.RedeemGooglePlayStorePurchaseForClass(productID, purchaseToken, classID, (result) =>
    {
        if (!result.success)
        {
            Debug.Log("Redeem Purchase unsuccessful!");
            return;
        }

    });
}

To be able to redeem a Google purchase you've made, you need to grab the product id (the same you used to make the purchase) and the purchase token from a successful purchase as input for the redeem.

On a successful redemption, the player will have been rewarded with whatever catalog item that this product id has been set up to reward.

curl --location --request POST 'https://api.lootlocker.io/game/redeem/store/google' \
--header 'x-session-token: {{session_token}}' \
--header 'User-Agent: Apidog/1.0.0 (https://apidog.com)' \
--header 'Content-Type: application/json' \
--data-raw '{
    "sandboxed": true,
    "transaction_id": "2000000316432499",
    "character_id": 123
}'

On a successful Purchase, a 204 will be returned with no body.

Blueprint example of redeeming purchase for player
Blueprint example of redeeming purchase for class