Skip to main content
Samsung Developer Program

Configure and Initialize the OpenIAB Unity Plugin

The following diagram shows how to set up OpenIAB plugin functions in the City Flyer demo source code and initialize the plugin. It illustrates the sequence of method calls to configure and initialize the OpenIAB plugin.  


Configure and initialize the OpenIAB plugin for your service app environment

To configure the OpenIAB plugin, you will use the following Unity functions: 

The OnEnable callback function, implemented in the Awake() function of Shop.cs, manages plugin events. In Unity, the service app calls Awake() when the script instance is being loaded. For more class and method details, see the OpenIAB Unity Plugin API ClassesStart() is invoked before the first frame update. It calls OpenIAB's mapSku() functions, which map the item SKUs to the specified app stores. 

  1. Set the OpenIAB plugin event manager to allow your service app to subscribe and unsubscribe to the plugin events:
    1. Drag the OpenIABEventManager.prefab file found in the Assets/Plugins/OpenIAB/Prefabs folder.
    2. Drop the file into your scene.


  1. Subscribe to the plugin purchase and billing events using the OpenIABEventManager by registering listeners.
private void Awake()
            // Subscribe to all billing events
        OpenIABEventManager.billingSupportedEvent += OnBillingSupported;
        OpenIABEventManager.billingNotSupportedEvent += OnBillingNotSupported;
        OpenIABEventManager.queryInventorySucceededEvent += OnQueryInventorySucceeded;
        OpenIABEventManager.queryInventoryFailedEvent += OnQueryInventoryFailed;
        OpenIABEventManager.purchaseSucceededEvent += OnPurchaseSucceeded;
        OpenIABEventManager.purchaseFailedEvent += OnPurchaseFailed;
        OpenIABEventManager.consumePurchaseSucceededEvent += OnConsumePurchaseSucceeded;
        OpenIABEventManager.consumePurchaseFailedEvent += OnConsumePurchaseFailed;
        OpenIABEventManager.transactionRestoredEvent += OnTransactionRestored;
        OpenIABEventManager.restoreSucceededEvent += OnRestoreSucceeded;
        OpenIABEventManager.restoreFailedEvent += OnRestoreFailed;
  1. Map service app item SKUs: 

    OpenIAB allows you to write a single block of code that would work with any popular app store. However, some app stores might have different naming conventions for their items. Store Keeping Units (SKUs) are developer-defined strings that are used by OpenIAB for standardization. The SKUs for all commercial items available in your service app must be mapped to each supported app store in the OpenIAB Start callback method.

    For Samsung In-App Purchase (IAP), commercial item SKUs are the item IDs, which are specified by your service app team and registered with the Samsung GALAXY Apps Seller Office:


    Note: Previously, Samsung Galaxy Apps used a 12-digit item group ID to identify all items within the app. This is deprecated in IAP 3.0. Now, the service app package name automatically identifies the service app. Your service app can still use the item group ID to identify the items' service app, for example, if your service app previously used it.
    private void Start() {
    /* Map SKU
     * Samsung IAP ver. 3 doesn't require the twelve digit itemGroupID
     * but it can still be used as shown with SKU_PLANE_FUEL */
    OpenIAB.mapSku(SKU_PLANE_FUEL, OpenIAB_Android.STORE_SAMSUNG, "100000105847/sku_plane_fuel");
    OpenIAB.mapSku(SKU_CHANGE_PLANE, OpenIAB_Android.STORE_SAMSUNG, "sku_change_plane");
    OpenIAB.mapSku(SKU_INFINITE_FUEL, OpenIAB_Android.STORE_SAMSUNG, "sku_infinite_fuel");
    OpenIAB.mapSku(SKU_GHOST_MODE, OpenIAB_Android.STORE_SAMSUNG, "sku_ghost_mode");


Note: The setup above is only for Samsung Galaxy Apps store.

  1. Set up the OpenIAB plugin library options:

    Library options are specified in Initialize OnePF.Options() object. To customize options for initializing OpenIAB, start by creating a OnePF.Options() object inside the Start() method of Shop.cs.
var options = new OnePF.Options();

The Options class is a way to configure how OpenIAB selects and initializes an app store. Because app stores may behave differently or may have unique features, some options are not applicable for all Android app stores. The following library options are only supported by Android-based service apps.


Controls the app store that an item is to be purchased from:

Note: This option setting can override and be overridden by other factors. This means that if certain conditions for a certain app store have been met, then it would choose that store already, while ignoring the rest of the options. For details, see OpenIAB Unity Plugin API Classes.

true: Checks the app store where you purchased the items and chooses it for the rest of the session.

false: Default. Skips the inventory check process, which makes the app store choice faster, but risks initializing the wrong app store or being unable to find a suitable app store.

options.checkInventory = false;

Controls the app store that an item is to be purchased from:

Note: This option setting can override or be overridden by other factors. For details, see OpenIAB Unity Plugin API Classes.

INSTALLER: Use the app store from which the app was downloaded, or the app store that was specified when sideloading using ADB.

var options.storeSearchStrategy = SearchStrategy.INSTALLER;

Currently, Samsung does not support service app sideloading. Use the following sideload for Google Play™ store instead.

adb install -i <apk name>

BEST_FIT: OpenIAB determines the best app store to purchase from by checking past purchases and purchasable items. 

var options.storeSearchStrategy = SearchStrategy.BEST_FIT; 

INSTALLER_THEN_BEST_FIT: This combines the INSTALLER and BEST_FIT options and is recommended for production service apps. It chooses INSTALLER first, and if no installer has been found either due to an unrecognized app store or app sideload, it then uses BEST_FIT

var options.storeSearchStrategy = SearchStrategy.INSTALLER_THEN_BEST_FIT;

[Option not specified]: Default. This is the default option if no option is specified. 


Controls the app store from which an item is to be purchased:

Note: This option setting can override and be overridden by other factors. For details, see OpenIAB Unity Plugin API Classes.

[App store name(s)]: One or more app stores to be checked for service availability. If the item's service app is available from the first listed app store, then the item is purchased from that app store. If the item's service app is not available from the first listed app store, then the second listed app store is checked, and so on.

If the item's service app is not available from any listed app store, then it returns a "billing unavailable" error.

options.preferredStoreNames = new string[] {OpenIAB_Android.STORE_SAMSUNG};

Controls whether and how each item purchase is checked. Verification requires RSA key pairs for supported Android app stores to verify the item. 

VERIFY_SKIP: Do not check item purchases.

Note: Samsung IAP does not provide public keys. Use VERIFY_SKIP when the current app store is Samsung.

options.verifyMode = OptionsVerifyMode.VERIFY_SKIP;

VERIFY_EVERYTHING: OpenIAB checks all item purchases.

VERIFY_ONLY_KNOWN: OpenIAB checks only the known item purchases.

For testing purposes, Samsung Galaxy Apps can be force-selected. This is done using the following method:

OpenIAB.storeModeSamsung(boolean enabled);

If the parameter is set to true, Samsung Galaxy Apps is selected during OpenIAB initialization.

OpenIAB.storeModeSamsung(true); // Forced to Samsung GALAXY Apps 

If the parameter is set to false, the app store is selected depending on the options specified. 

private void Start () {
        // Set library options
           var options = new OnePF.Options();
           options.checkInventory = false;
           options.storeSearchStrategy = SearchStrategy.BEST_FIT;
  1. Initialize the OpenIAB object using the created options object instance, which is implemented in the Start() function. 
private void Start () {
        // Initialize OpenIAB with options defined above