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
OPERATION_MODE_TEST
OPERATION_MODE_TEST_FAILURE
Sandbox
public void setOperationMode( OperationMode _mode )
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_TEST);
iapHelper.setOperationMode(HelperDefine.OperationMode.OPERATION_MODE_TEST)
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
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
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 } } }
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
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