EN CN
Before your app can make IAP requests, it must call getInstance() to create a singleton instance of IapHelper.
getInstance()
IapHelper
public static IapHelper getInstance( Context _context )
private IapHelper iapHelper = IapHelper.getInstance(context);
private val iapHelper: IapHelper = IapHelper.getInstance(context)
IAP supports three operational modes. One is for enabling billing for item purchases and the other two are for testing IAP functions without billing app users for item purchases.
If setOperationMode() is not called, operation mode is set to OPERATION_MODE_PRODUCTION by default (testing is not supported, but beta release and normal publication are supported).
setOperationMode()
OPERATION_MODE_PRODUCTION
Ensure the operation mode is set to OPERATION_MODE_PRODUCTION before submitting for Beta test or normal publication. In other words, OPERATION_MODE_TEST or OPERATION_MODE_TEST_FAILURE must be set only if the app status in Seller Portal is Registering or Updating.
OPERATION_MODE_TEST
OPERATION_MODE_TEST_FAILURE
You can review the status of your app in Seller Portal Applications page.
Depending on the operational mode of the app and the status in Seller Portal, the database referenced by IAP Helper requests differs as follows:
If OPERATION_MODE_TEST is set, the pop-up below is displayed and Sandbox is shown at the top right of the payment window to indicate that the app user will not be billed for item purchases.
Sandbox
public void setOperationMode( OperationMode _mode )
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_TEST);
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_TEST)
You must call getOwnedList() whenever launching the application in order to check for unconsumed items or subscription availability.
getOwnedList() returns a list of in-app items that the app user currently has from previous purchases:
getOwnedList()
getOwnedList() also returns item data and processing results specified by the OnGetOwnedListListener interface.
OnGetOwnedListListener
Purchased consumable items must be reported as consumed by calling consumePurchasedItems() to be purchased again, which can be done before or after the app user uses the item in the app. We recommend reporting all listed consumable items that have not been reported as consumed in one consumePurchasedItems() method call in order to avoid system overload or malfunction.
public boolean getOwnedList ( String _productType, OnGetOwnedListListener _onGetOwnedListListener )
item
subscription
all
true
false
void onGetOwnedProducts ( ErrorVo _errorVO, ArrayList<OwnedProductVo> _ownedList )
"item"
"subscription"
public class OwnedList implements OnGetOwnedListListener { IapHelper.getOwnedList(IapHelper.PRODUCT_TYPE_ALL, this); @Override public void onGetOwnedProducts(ErrorVo _errorVo, ArrayList<OwnedProductVo> _ownedList) { if (_errorVo != null) { if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) { if (_ownedList != null) { for (OwnedProductVo item : _ownedList) { if (item.getIsConsumable()) { // TODO: Consume the consumable item not yet consumed } } } } else { // TODO: Handle the error } } } }
iapHelper.getOwnedList(IapHelper.PRODUCT_TYPE_ALL) { _errorVo: ErrorVo?, _ownedList: ArrayList<OwnedProductVo>? -> if (_errorVo != null) { if (_errorVo.errorCode == IapHelper.IAP_ERROR_NONE) { if (_ownedList != null) { for (item in _ownedList) { if (item.isConsumable) { // TODO: Consume the consumable item not yet consumed } } } } else { // TODO: Handle the error } } }
getProductsDetails() returns information for one, more, or all in-app items registered to the app. Returns item data and processing results specified by the OnGetProductsDetailsListener interface.
getProductsDetails()
OnGetProductsDetailsListener
public void getProductsDetails ( String _productIds, OnGetProductsDetailsListener _onGetProductsDetailsListener )
void onGetProducts( ErrorVo _errorVo, ArrayList<ProductVo> _productList )
"YEAR"
"MONTH"
"WEEK"
getSubscriptionDurationUnit()
"Y"
"N"
getTieredSubscriptionDurationUnit()
public class ProductsDetails implements OnGetProductsDetailsListener { IapHelper.getProductsDetails("Nuclear, Claymore, SpeedUp", this); @Override public void onGetProducts(ErrorVo _errorVo, ArrayList<ProductVo> _productList) { if (_errorVo != null) { if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) { if (_productList != null) { for (ProductVo item : _productList) { // TODO: Get details of the item } } } else { // TODO: Handle the error } } } }
iapHelper.getProductsDetails("Nuclear, Claymore, SpeedUp") { _errorVo: ErrorVo?, _productList: ArrayList<ProductVo>? -> if (_errorVo != null) { if (_errorVo.errorCode == IapHelper.IAP_ERROR_NONE) { if (_productList != null) { for (item in _productList) { // TODO: Get details of the item } } } else { // TODO: Handle the error } } }
startPayment() initiates the purchase and payment transaction of the specified in-app item and can notify the end user if the purchase succeeded or failed. Returns the item data and transaction results and data specified in the OnPaymentListener interface.
startPayment()
OnPaymentListener
You can specify a passThroughParam parameter value to enhance purchase security. During purchases with passThroughParam values created and passed by an IAP-integrated application are returned in the responses.
passThroughParam
When the IAP operating mode is OPERATION_MODE_PRODUCTION and the app is being distributed in the Galaxy Store, successful processing results in financial transactions (the app user will be billed for item purchases).
public boolean startPayment ( String _itemId, String _passThroughParam, OnPaymentListener _onPaymentListener )
void onPayment( ErrorVo _errorVO, PurchaseVo _purchaseVO )
getPurchaseId()
public class PurchaseItem implements OnPaymentListener { IapHelper.startPayment("Nuclear", "pLKjLKjLJL87=76df56rf+4f5", this); @Override public void onPayment(ErrorVo _errorVo, PurchaseVo _purchaseVO) { if (_errorVo != null) { if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) { if (_purchaseVO != null) { String passThroughParam = _purchaseVo.getPassThroughParam(); // TODO: If you have set a PassThroughParameter in the request, // you can verify the PassThroughParameter here. if (_purchaseVo.getIsConsumable()) { String purchaseId = _purchaseVo.getPurchaseId(); // TODO: Consume the consumable item by calling `consumePurchasedItems()` } } else { // TODO: Handle the error } } } }
iapHelper.startPayment("Nuclear", "pLKjLKjLJL87=76df56rf+4f5") { _errorVo: ErrorVo?, _purchaseVO: PurchaseVo? -> if (_errorVo != null) { if (_errorVo.errorCode == IapHelper.IAP_ERROR_NONE) { if (_purchaseVO != null) { val passThroughParam: String = _purchaseVO.passThroughParam // TODO: If you have set a PassThroughParameter in the request, // you can verify the PassThroughParameter here. if (_purchaseVO.isConsumable) { val purchaseId: String = _purchaseVO.purchaseId // TODO: Consume the consumable item by calling `consumePurchasedItems()` } } } else { // TODO: Handle the error } } }
When you try to purchase an item in your app, you will see the pop-up windows similar to the ones shown below. You must be signed in to your Samsung account.
consumePurchasedItems() reports one or more purchased consumable items as consumed, which makes the items available for another purchase. The app user may or may not have used the items. Returns item data and processing results specified by the OnConsumePurchasedItemsListener interface.
consumePurchasedItems()
OnConsumePurchasedItemsListener
We recommend reporting purchased consumable items immediately after verifying their purchase and reporting all unreported items in one consumePurchasedItems() method call in order to avoid system overload or malfuction.
public boolean consumePurchasedItems ( String _purchaseIds, OnConsumePurchasedItemsListener _onConsumePurchasedItemsListener )
true: The request was sent to server successfully and the result will be sent to OnConsumePurchasedItemsListener interface listener.
false: The request was not sent to server and was not processed.
void onConsumePurchasedItems ( ErrorVo _errorVo, ArrayList<ConsumeVo> _consumeList );
_consumeList
0
1
2
3
4
5
9
public class ConsumeItems implements OnConsumePurchasedItemsListener { final String PURCHASEID = "d215d9abcd17b12578a21c0ea7d8821747b64939732a3243b538d8bcae245590"; IapHelper.consumePurchasedItems(PURCHASEID, this); @Override public void onConsumePurchasedItems(ErrorVo _errorVo, ArrayList<ConsumeVo> _consumeList) { if (_errorVo != null) { if (_errorVo.getErrorCode() == IapHelper.IAP_ERROR_NONE) { if (_consumeList != null) { for (ConsumeVo item : _consumeList) { // TODO: Get details of the consumption } } } else { // TODO: Handle the error } } } }
val PURCHASEID: String = "d215d9abcd17b12578a21c0ea7d8821747b64939732a3243b538d8bcae245590" iapHelper.consumePurchasedItems(PURCHASEID) { _errorVo: ErrorVo?, _consumeList: ArrayList<ConsumeVo>? -> if (_errorVo != null) { if (_errorVo.errorCode == IapHelper.IAP_ERROR_NONE) { if (_consumeList != null) { for (item in _consumeList) { // TODO: Get details of the consumption } } } else { // TODO: Handle the error } } }
10000
10001
10011
7002
9000
9005
9006
PassThroughParam
9007
9010
9013
9014
9122
9132
9200
9226
9440
9441
9701
100001
100008
100010
9224
9202
9207
9201
9134
9259
In the error code, the first set of digits displayed before the initial slash should correspond to one of the numbers in the description of the response codes above. For example, in the first pop-up window, 9224 appears in the description for the response code IAP_ERROR_ALREADY_PURCHASED. In the second pop-up window, 9014 appears in the description for the response code IAP_ERROR_COMMON.