Skip to main content

Ready to market your stellar app?

Samsung Developer Program is your gateway to app monetization success.

Learn More

Samsung Developer Program

Configuring and Initializing the Open IAB Unity Plugin

The following covers how to set up the Open IAB plugin functions in the City Flyer source code and initialize the plugin.

OpenIAB_Integration_Configuring_APICallSequence.png    

Above illustrates the sequence of method calls to configure and initialize the Open IAB plugin. The components are described in Step 2 below.

 

Configuring and initializing the Open IAB plugin for your service app environment
  1. Set the Open IAB 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.

OpenIAB_Integration_Configuring_Step1A.png

 

  1. Drop the file into your scene.

OpenIAB_Integration_Configuring_Step1B.png

 

 

  1. Subscribe to the plugin purchase and billing events using the OpenIABEventManager by registering listeners. The OnEnable callback function, implemented in the Awake() function of Shop.cs., manages the plugin events. In Unity, the service app calls Awake() when the script instance is being loaded. For more class and method details, see the Samsung Open IAB Unity Plugin API Reference.
Shop.cs
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: 

Open IAB 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. The SKUs (Store Keeping Units) are developer-defined strings that are used by Open IAB for standardization. The SKUs for all commercial items available in your service app must be mapped to each supported app store in the Open IAB Start callback method. In Unity, Start() is invoked before the first frame update. It calls Open IAB's mapSku() functions, which maps the item SKUs to the specified app stores. 

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:

OpenIAB_Integration_Configuring_Step3.png

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).

 

Shop.cs
    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 Open IAB plugin library options:

Library options are specified in Initialize OnePF.Options() object. To customize options for initializing Open IAB, 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 Open IAB selects and initializes an app store. Since 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.

checkInventory

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 the Open IAB Unity Plugin API Reference.

 

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;
storeSearchStrategy

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 the Open IAB Unity Plugin API Reference.

 

INSTALLER: Use the app store the app was downloaded from, or what app store was specified when sideloading via ADB.

var options.storeSearchStrategy = SearchStrategy.INSTALLER;

Currently, Samsung does not support service app sideloading. The following sideload for Google Play™ store can be used.

adb install -i com.android.vending <apk name>

 

BEST_FIT: Open IAB 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. 

preferredStoreNames

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

NOTE: This option setting can override and be overridden by other factors. For details, see the Open IAB Unity Plugin API Reference.

 

[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};
verifyMode

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: Open IAB checks all item purchases.

VERIFY_ONLY_KNOWN: Open IAB 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 Open IAB 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. 

OpenIAB.storeModeSamsung(false); 
Shop.cs
private void Start () {
        ...
        // Set library options
           var options = new OnePF.Options();
           options.checkInventory = false;
           options.storeSearchStrategy = SearchStrategy.BEST_FIT;
           OpenIAB.samsungIapMode(1);
           OpenIAB.samsungForcedMode(true);
           OpenIAB.init(options);
        ...
    }             

 

 

  1. Initialize the Open IAB object using the created options object instance, which is implemented in the Start() function. 
Shop.cs
private void Start () {
        ...
        // Initialize OpenIAB with options defined above
        OpenIAB.init(options);
        ...
    } 
  • Was this article helpful?