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

Available Item and User-Purchased Item Lists

Service apps (for example, in response to user input) can generate and get a list of all commercial items currently available to them. These items and their related information, such as price, are currently registered to the service app via the Samsung GALAXY Apps Seller Office.

Service apps (for example, in response to user input) can use one of two methods to get a list of items that the current user has purchased up to the time the list was generated:

  • By requesting Samsung systems to generate a new list that is then locally cached and made available to the service app.
  • By retrieving a locally cached list that was generated the last time the list was generated by the first method. This second method is faster than the first.
 
Getting a list of all items available in the service app

 

Service apps and their users can get a list of all available items currently registered to the Seller Office account of the service app.

OpenIAB_Integration_GeneratingItemList_APICallSequence.png

 

 

To get a list of all available items in the service app

 

  1. In the City Flyer UI, click Query SKU List. The item names are displayed on the left side of the screen.
  2. The button click invokes the function QuerySKUList() of Shop.cs, which calls OpenIAB.querySkuList().

CAUTION: querySKUList() is an OpenIAB method which calls a Samsung IAP method, getItemList(), and is to be used when the current app store is Samsung GALAXY Apps. Using this method with other current app stores will throw a IabException that should be handled by the service app logic and code. It fires the event querySkuListFailedEvent(). The exception can be handled there.

Shop.cs
// Called on the onClick() method of the Query SKU List button
// Starts the process to display a list of all available items for purchase
// Listed in the Samsung Sellers Account for this application

public void QuerySKUList(){
    OpenIAB.querySkuList();
}

 

  1. OpenIAB.querySkuList() calls the querySkuList() function of OpenIAB_Android.cs for Android devices. 
OpenIAB.cs
public static void querySkuList(){
    _billing.querySkuList();
}

 

  1. OpenIAB_Android.querySkuList() uses a Java Native Interface (JNI) to access the querySkuList() method in the UnityPlugin.java file (which is similar to OpenIAB_Android.queryInventory()).  
OpenIAB_Android.cs
public void querySkuList()
{
    if (!IsDevice())
    {
        return;
    }
    IntPtr methodId = AndroidJNI.GetMethodID(_plugin.GetRawClass(), "querySkuList", "()V");
    AndroidJNI.CallVoidMethod(_plugin.GetRawObject(), methodId, new jvalue[] {
});
}

 

  1. After the item list has been retrieved from the IAP server, onQuerySkuListFinished() is invoked. 

When the list generation query is successful:

  1. onQuerySkuListFinished() sends the message with the list back to Shop.cs.
UnityPlugin.java
public void querySkuList()
    UnityPlayer.currentActivity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            _helper.querySkuListAsync(_querySkuListFinishedListener);
        }
    });
}
IabHelper.QuerySkuListFinishedListener_querySkuListFinishedListener = 
new IabHelper.QuerySkuListFinishedListener() {
    public void onQuerySkuListFinished(IabResult result, List<SkuDetails> skuDetails, String type) {
        ...
        UnityPlayer.UnitySendMessage(EVENT_MANAGER, QUERY_SKU_LIST_SUCCEEDED_CALLBACK, jsonSkuDetails);
    }
};

 

  1. The list message is received by OnQuerySkuListSucceeded(). This callback lists the SKUs retrieved from the app store. 
Shop.cs
// Listener callback if a SKU list query is successful

private void OnQuerySkuListSucceeded(List<SkuDetails> skuDetails)
{
    if (!infoCanvas.activeSelf) {
        infoCanvas.SetActive (true);
        infoLog.text = "SKU List Query Success!";
    }
    
    string logString = "SKU List:", menuString = "Available SKU:\n";
    for (int i=0; i<skuDetails.Count; i++) {
        logString += " "+skuDetails[i];
        menuString += i+l + ".) " + skuDetails[i] + "\n";
    }
    shopText.text = menuString;
}

 

When the list generation query fails, OnQuerySkuListFailed() is invoked.

Shop.cs
// Listener callback if a SKU list query fails

private void onQuerySkuListFailed(string error)
{
    if (!infoCanvas.activeSelf) {
        infoCanvas.SetActive (true);
        infoLog.text = error;
    }
}

 

 

Generating and getting a list of purchased items 

 

Service apps can generate and get a list of items the current user has purchased from Samsung servers. 

OpenIAB_Integration_GeneratingPurchasedItemList_APICallSequence.png

 

 

To generate and get a list of user-purchased items

 

  1. In the City Flyer UI, click Query Inventory.
  2. The button click invokes the function QueryInv() of Shop.cs, which calls OpenIAB.queryInventory() and passes the skuList parameter. The Query Inventory function gets the list directly from the current app store, which generates and returns the list.
Shop.cs
// Called on the onClick() method of the Query Inventory button
// Starts the process to display a list of purchased items to-date

public void QueryInv() {
    OpenIAB.queryInventory(skuList);
}

 

  1. OpenIAB.queryInventory() calls the queryInventory() function of OpenIAB_Android.cs for Android devices and passes the skuList in the extraParams parameter.
OpenIAB.cs
        /**
         * Sends a request to get all completed purchases
         * Added extraParams parameter to match function signature
         * @param extraParams this allows additional parameters if needed
         * Function will still work in legacy code **/
        
public static void queryInventory(params object[] extraParams){
    _billing.queryInventory(extraParams);
}

 

  1. OpenIAB_Android.queryInventory uses a Java Native Interface (JNI) to access the queryInventory() method in the UnityPlugin.java file. 
OpenIAB_Android.cs
        /**
         * Added extraParams parameter to match interface
         * @param extraParams this allows additional parameters if needed
         * Function will still work with legacy code 
         **/
         
public void queryInventory(params object[] extraParams){
    ...
    methodId = AndroidJNI.GetMethodID(_plugin.GetRawClass(), "queryInventory", "([Ljava/lang/String;)V");
    AndroidJNI.CallVoidMethod(_plugin.GetRawObject(), methodId, args);
}        

 

  1. UnityPlugin.java accesses the library-level classes that provide the functions for querying the inventories. After the inventory query processing is completed, onQueryInventoryFinished() is invoked. 

When the list generation query is successful:

  1. onQueryInventoryFinished() sends the message with the list back to Shop.cs.
UnityPlugin.java
public void queryInventory(final Object... extraParams){
    UnityPlayer.currentActivity.runOnUiThread(new Runnable(){
        @Override
        public void run(){
        
    _helper.queryInventoryAsync(_queryInventoryListener, extraParams);}
    });
}

IabHelper.QueryInventoryFinishedListener _queryInventoryListener = new
IabHelper.QueryInventoryFinishedListener(){
    public void onQueryInventoryFinished(IabResult result, Inventory inventory){
        ...
        UnityPlayer.UnitySendMessage(EVENT_MANAGER, QUERY_INVENTORY_SUCCEEDED_CALLBACK, jsonInventory);}
};

 

  1. This message is received by OnQueryInventorySucceeded, which displays the list. 
Shop.cs
// Listener callback if an inventory query is successful
private void onQueryInventorySucceeded(Inventory inventory){
    if (!infoCanvas.activeSelf){
        infoCanvas.SetActive (true);
    }
    string item = "";
    foreach(string pchase in inventory.GetAllOwnedSkus()){
        item += pchase+"\n";
    }
    inventoryText.text = "Items bought: \n" + item;
}

 

When the list generation query fails, onQueryInventoryFailed() is invoked.

Shop.cs
// Listener callback if an inventory query fails
private void onQueryInventoryFailed(string error)
        {
            if (!infoCanvas.activeSelf){
                infoCanvas.SetActive (true);
                infoLog.text = error;
            }
        }

 

 

Getting the previously generated list of purchased items

 

Service apps can get a previously generated list of items the current user has purchased from the cache. 

OpenIAB_Integration_GettingPreviouslyGeneratedPurchasedItemList_APICallSequence.png

 

To get the locally cached list of user-purchased items

 

  1. In the City Flyer UI, click Query Cached Inventory.
  2. The button click invokes QueryInvCache(), which calls OpenIAB.queryInventory() with an additional parameter "true" which gets the cached list of items based on the skuList parameter.
Shop.cs
// Called on the onClick() method of the Query Cached Inventory button
// Starts the process to display a list of items currently bought from the cache

public void QueryInvCache(){
    OpenIAB.queryInventory(skuList, "true");
}

The rest of the process follows the same sequence and callbacks as the Query Inventory feature (To generate and get a list of user-purchased items, follow steps 3-5.) EXCEPT that items in the local cache are searched and retrieved.

  • Was this article helpful?