tutorials | game, mobile, marketplace

Using the Samsung In-App Purchase SDK in your Unity Games

writer img alt

Diego Lizarazo Rivera

Sr. Developer Evangelist

In this article, you will learn how to integrate the Samsung In-App Purchase (IAP) SDK in your Unity games. You can also follow along on YouTube.

 

Unity Plugin for Samsung IAP

In order to use the Samsung IAP SDK in your Unity game, follow these steps:

  1. Download the Unity Plugin for Samsung IAP
  2. Install the Plugin. In Unity, click Assets -> Import Package -> Custom Package
    Adding the Unity plugin
  3. Drag the script onto a game object. This can be any UI object, or as seen in the video, a character from your game.

Once you have included the script, review the documentation to see in detail how to call the SDK from your game code. Here are the basics:

Operation Mode

In order for Galaxy Store to know if your game is in testing or production mode, you must use the SetOperationMode method.

SamsungIAP.Instance.SetOperationMode(OperationMode.OPERATION_MODE_TEST);

The possible values for the parameter are OperationMode.OPERATION_MODE_TEST, OperationMode.OPERATION_MODE_TEST_FAILURE, and OperationMode.OPERATION_MODE_PRODUCTION.

Request Information About the Items Available for Sale

To find out what items can be offered from the game, you must invoke the GetProductDetails method.

SamsungIAP.Instance.GetProductDetails("com.mygame.product1, com.mygame.product2,com.mygame.product3", OnGetProductsDetails);

In this example, the information for products 1, 2, and 3 is being requested, since the identifiers of those products are being sent, separated by commas.

SamsungIAP.Instance.GetProductDetails("", OnGetProductsDetails);

In this example, the information of all available products is being requested, since no product identifier is being sent.

Start a Payment

In order to start the purchase of a product, the StartPayment method must be invoked.

SamsungIAP.Instance.StartPayment("com.mygame.product1", "pass_through_value", OnPayment);

This example is starting the transaction for "com.mygame.product1".
You can specify the value of the second parameter and use it to verify the success of the purchase.

And finally, the callback is specified, which is the method that will be invoked when the transaction is completed, regardless of whether it was successful or not.

Consumable Items

You can use the ConsumePurchasedItems method to replenish consumable products. For example,The player could buy energy in your game as many times as he wants.

The first parameter is the identifier of the purchase of the item.

SamsungIAP.Instance.ConsumePurchasedItems(purchase_id, OnConsume);

And the second parameter is the OnConsume method that fires when the process has finished, and this contains information about the consumed item and the processing of API calls.

Query Previously Purchased Items

To get the list of all the products that a player has bought, you can use the GetOwnedList method.

SamsungIAP.Instance.GetOwnedList(ItemType.all, OnGetOwnedList);

The first parameter can be ItemType.all, ItemType.item, or ItemType.subscription.

With ItemType.all the method returns all non-consumable items previously purchased, consumable items that have not been consumed, and subscription items with active subscriptions.

With ItemType.item the method returns all non-consumable items purchased and consumable items that have not been consumed.

And finally, with ItemType.subscription the method returns all subscription items purchased with active subscriptions.

The second parameter is the method that will be triggered when the process has finished.

List Your App and Items for Sale in Galaxy Store

The process for selling your game in Galaxy Store, when it includes payments and microtransactions through the Samsung IAP SDK, is as follows:
Publication Process

1. Seller Portal Registration
To create your account and publish in Galaxy Store, go to http://seller.samsungapps.com

Click on the top corner to create your account. If you already have a Samsung account, sign in with it.
Click Here

2. Request Commercial Status
Once you have created your account on the Seller Portal, request commerical seller status by clicking the button indicated in the image. This is necessary to be able to sell different items from your application.
Request Commercial Status

3. App Registration
To see all the details of how to register your application in the Seller Portal, watch this video.

You will be prompted to enter your game information, such as the name, description, and promotional images.

4. Register In-App Items
When your account has been approved as a commerical seller account, you will be able to access the “In-App Purchase” section.

Register in-App Items

Here you can register the different items you are going to sell, such as unlimited lives, special powers, or customization options for the characters in your game.

In the video, you can see a little more detail on how to register each of the items.


Learn more about creating games with Samsung and reaching its global audience: https://developer.samsung.com/galaxy-games

You can connect with Diego, a Sr. Developer Evangelist, on Twitter.

Have questions? Post them in our forums.