IAP SDK Reference - ONE-store/inapp-sdk-eng GitHub Wiki
< NOTE >
This documents are for ONE store IAP SDK v16(API v4). If you are looking for the latest version of ONE store IAP SDK v17(API v5), please refer to the url below:
URL for the latest documents and downloads of ONE store IAP SDK v17(API v5) : https://dev.onestore.co.kr/devpoc/reference/view/IAP_v17
Required Terminology | Description |
---|---|
AID | AID stands for Application Identifier. It is a unique ID value issued for an App once the App is uploaded in ONE store developer center. |
PID | PID stands for Product Identifier. It is a unique ID value issued for an In-App product once the In-App product is added to and published for an uploaded App. |
MDN | MDN is the abbreviation for Mobile Device Number. It is mobile phone number. |
TID | TID should not be created by using the IAP API. But it should be generated within an App itself. Uniqueness must be ensured while the TIP API is used. |
TxID | TxID is an identifier created in the IAP and delivered with e-receipt |
As for the types of In-App Products, you can publish Consumable/Non-Consumable In-App, Non-Renewable In-App, Trial Version In-App, etc. in ONE store developer center IAP. You are required to select the proper In-App product type, considering the characteristics of the service to be provided by an App in the planning stage.
This In-App product is available after being purchased. It is divided into the two types of Non-consumable and Consumable based on whether the purchased product is permanently maintained or not.
Category | Description |
---|---|
Non-consumable | Once purchased, the user can use this product permanently. This product cannot be purchased more than once using the same mobile device number (MDN) |
Consumable | This product provides information on how many times it can be used (or how many items can be deducted) For instanace, items for an App, such as 100 Starts and 1000 Potions, are deducted when this product is used. This product can be purchased more than once. Deduction method and management must be processed in the App or App Server. ONE store developer center IAP does not provide the relevant feature. |
- Non-renewable In-App is available for a specified period of time after being purchased, and this product is categorized based on the period of use as seen below in the table.
- All the non-renewable In-App products cannot be purchased more than once using the same mobile device number (MDN)
- However, if the period of the purchased product expires, the corresponding product can be purchased again
Category | Description |
---|---|
one-day-pass | This product is available for 24 hours upon purchase |
one-week-pass | This product is available for 7 days (168 hours) upon purchase |
one-month-pass | This product is available for 30 days upon purchase |
auto-renewal-month | This product is automatically renewed on a monthly basis Unless the user makes a request for withdrawal, this product is renewed on a monthly basis for one year. |
Once an In-App purchase is made in a Trial Version App which is distributed for free, the App is unlocked and converted to a paid version one.
It is not recommended to use this legacy product type.
The IAP SDK provides 7 Java classes(or interfaces).
Component | Description | Remarks |
---|---|---|
IapPlugin | This is the default IAP Plugin class for interaction with IAP server | |
IapPlugin.RequestCallback | This is the callback interface to receive request results | |
IapPlugin.AbsRequestCallback | This is the callback abstract class to receive request results | New |
Response | This is the response data class | New |
ProcessType | This defines how to process request | New |
ReceiptVerificationTask.RequestCallback | This is the callback interface to receive receipt verification results | New |
ReceiptVerificationTask.AbsRequestCallback | This is the callback abstract class to receive receipt verification results | New |
IapResponse | This is the response data interface |
[Table] com.skplanet.dodo package
Main Functions Are Described as Below :
column name | Description |
---|---|
Description | This describes a function |
Syntax | This is the function code signature |
Parameters | This describes the parameters used in the function |
Return | This is the return value on call |
Methods | Return | Note |
---|---|---|
getPlugin(Context context, String pluginmMode) | IapPlugin | |
exit() | void |
Description
This function creates and returns a new IapPlugin object to request payment or inquiry. On call, it must send a pluginmode string as a required parameter. If normal values are not passed, a commercial server (release) is set by default in the SDK.
On each call, newly created objects are returned. Server settings vary depending on each object
Syntax
static final IapPlugin getPlugin(Context context, String pluginmMode)
Parameters
context
- In the Android Contect, it is recommended to put Activity Context.
pluginmode
-
String: string for commercial/development server configuration
-
development : development server (IapPlugin.DEVELOPMENT_MODE)
-
release : commercial server (IapPlugin.RELEASE_MODE)
Return The IapPlugin instance is returned on success
Description
This function must be called if you have no longer access to the IapPlugin instance (ex. if the developer App is terminated). Call is recommended because the memory leak could occur if the call is not made.
Syntax
void exit()
When the functions are called, requests are made by sending values to parameters.
Methods | Return | Note |
---|---|---|
sendPaymentRequest | String | New |
sendCommandPurchaseHistory | String | New |
sendCommandProductInfo | String | New |
sendCommandCheckPurchasability | String | New |
sendCommandChangeProductProperties | String | New |
sendReceiptVerificationRequest | void | New |
Description
This function requests payment. PaymentParams values required on call are created using PaymentParams.Builder
Syntax
String sendPaymentRequest(RequestCallback requestCallback, PaymentParams params)
Parameters
requestCallback
- Callback to receive the result of the payment request
params
- The content of the payment request generated by PaymentParams.Builder
Return Request identifier(RequestId) is returned on normal request.
Description
This function make a request to ‘check purchase history’. It is available to check single, multi and all products.
Syntax
String sendCommandPurchaseHistory(RequestCallback requestCallback, ProcessType type, String appId, String... productIds)
Parameters
requestCallback
- Callback to receive the result of the checking request
type
- Decides if the request is processed either as Background only (without UI exposure) or as Foreground if needed (with UI exposure).
- ProcessType.BACKGROUND_ONLY
- ProcessType.FOREGROUND_IF_NEEDED
appId
- The ID of the product (App) that you want to check
productIds
- The ID of the product (In-App) you want to check
- It is available to enter multiple IDs of In-App products that you want to check
- If you set “null”, you can check all products (In-App products)
Return Request identifier(RequestId) is returned on normal request.
Description
This function makes a request to ‘check the product information for the app.’
Syntax
String sendCommandProductInfo(RequestCallback requestCallback, ProcessType type, String appId)
Parameters
requestCallback
- Callback to receive the result of the checking request
type
- Decides if the request is processed either as Background only (without UI exposure) or as Foreground if needed(with UI exposure).
- ProcessType.BACKGROUND_ONLY
- ProcessType.FOREGROUND_IF_NEEDED
appId
- The ID of the product (App) that you want to check
Return Request identifier(RequestId) is returned on successful request
Description
This function makes a request to ‘check purchase availability’. It is available to check single, multi and all products
Syntax
String sendCommandCheckPurchasability(RequestCallback requestCallback, ProcessType type, String appId, String... productIds)
Parameters
requestCallback
- Callback to receive the result of the checking request
type
- Decides if the request is processed either as Background only (without UI exposure) or as Foreground if needed(with UI exposure).
- ProcessType.BACKGROUND_ONLY
- ProcessType.FOREGROUND_IF_NEEDED
appId
- The ID of the product (App) that you want to check
productIds
- The ID of the product (In-App) you want to check
- It is available to enter multiple IDs of In-App products that you want to check (‘null’ is not available)
Return Request-identifier(RequestId) is returned on successful request.
Description
This function makes a request to ‘change the status of purchased product’. For subscription, the withdrawal is requested. For consumable product, point subtraction is requested.
Syntax
String sendCommandChnageProductProperties(RequestCallback requestCallback, ProcessType type, String appId, String action, String... productIds)
Parameters
requestCallback
- Callback to receive the result of the checking request
type
- Decides if the request is processed either as Background only (without UI exposure) or as Foreground if needed(with UI exposure).
- ProcessType.BACKGROUND_ONLY
- ProcessType.FOREGROUND_IF_NEEDED
appId
- The ID of the product (App) whose status will be changed
action
- cancel_subscription : action to request the cancellation of the subscription (Action.cancel_subscription.action())
- subtract_points : action to request the subtraction of available points (Action.subtract_points.action())
- Null is not available
productIds
- The ID of the product (In-App) whose status you want to change.
- It is available to enter multiple IDs of In-App products whose status that you want to change (null is not available).
Return Request-identifier(RequestId) is returned on successful request.
Description
This function makes a request for ‘e-receipt verification’.
Syntax
void sendVerifyReceiptRequest(String appId, String txId, String signData, ReceiptVerificationTask.RequestCallback callback)
Parameters
txId
- It is TxID which is received as a result of the purchase
appId
- The ID of the product (App) which will be reviewed
signData
- It is the receipt which is received as a result of the purchase
callback
- Callback to receive the result of the verification request
Unlike explicit call (Request Explicit), parameter values, which are required for payment requests, must be delivered in the JSON format. If not for backward compatibility, explicit call is recommended.
Methods | Return | Note |
---|---|---|
sendPaymentRequest | Bundle | |
sendCommandRequest | Bundle | (type) request_product_info request_purchase_history check_purchasability change_product_properties |
sendCommandRequest | Bundle | New |
Description
This function requests payment, and is provided in the existing version for backward compatibility
Syntax
Bundle sendPaymentRequest(String appId, String pId, String productName, String tId, String bpInfo, RequestCallback requestCallback)
Parameters
appId, pId, productName, tId, bpInfo
Parameter | Type | Mandatory | Limit | sample | Description |
---|---|---|---|---|---|
appid | String | M | 10 | appid=OA12345678
|
This is the Application ID(AID) and has 10 alphanumeric characters, including English letters of O, A and numbers. |
pId | String | M | 10 | product_id=0000000011
|
This is the Product ID (PID, In-App ID) and has 10- figure number. |
productName | String | O | 50 | product_name=custom in-app product name | This is the In-App product name |
tid | String | O | 100 | tid=20150301_purchase_1110112
|
This is the ID value generated by the developer |
bpInfo | String | O | 1024 | utm_source=onestore&utm_medium=iap&utm_campaign=20160325_promotion |
This is the tag that the developer uses freely for campaign statistics, etc. |
- You are allowed to use up to 50 characters in Korean and 100 characters in English for product_name, however, it is recommended to use 50 characters or less for the name.
- You are not allowed to use double quotation for tid and product_name
- You are not allowed to use spacing for tid
requestCallback
- Callback to receive the result of the payment request
Return Information, including request identifier (RequestId), is returned on successful request. (null is returned on failure)
Extra Key in Bundle
- req.id : request identifier
- req.rescode : error code for request
- req.resmsg : result message for request
The IAP server creates and sends the result of the purchase request in the JSON-format response data. The type of response data for purchase processing is as follows:
For the result and error code, refer to IAP Reference Result Code
Parameter | Type | Mandatory | Limit | sample | Description |
---|---|---|---|---|---|
api_version | String | M | 1 | 4 | This is the IAP API version |
identifier | String | M | 10 | 1234567890 |
This is the request identifier |
method | String | M | - | purchase |
This is the request method. The method for purchase request is always ‘ purchase’ |
result | Object | M | - | This is the result object from the request method | |
code | String | M | 4 | 1000 |
This is the result code (refer toIAP Reference Result Code) |
message | String | M | - | The required parameters are insufficient. | This indicates message according to the result code |
txid | String | O | 40 | TSTOREXXXX_20160515102510XXXXXXXXXXXXXXX |
This is the e-receipt ID |
receipt | String | O | Up to 5kbyte | - | This is the signing value for e-receipt and purchase validity |
count | Number | O | 1 | 1 |
This is the number of normally purchased products |
tid | String | O | 1024 | 20150301_purchase_1110112 |
This is the TID issued by the developer |
product | Array | O | Product the information array | ||
id | String | O | 10 | 0000000011 |
This is the In-App product ID |
name | String | O | 200 | custom in-app product name |
This is the In-App product name |
kind | String | O | - |
consumable - non-consumable - consumable - one-day-pass - one-week-pass - one-month-pass |
This is the product type |
price | Number | O | 6 | 300000 |
The In-App product price (up to KRW300,000)is required |
In-App product name returns the value, which is passed at the time of request (if no value is returned, the name registered in the developer center is used). bp_info is not returned in the JSON response.
[Sample TxID for Each Mobile Operator]
Mobile Operator | Form | Remarks |
---|---|---|
SKT | TSTOREXXXX_20150515102510XXXXXXXXXXXXXXX | TSTORE+ a four-figure identifier |
KT | KTXXXXXXXX_20150515102510XXXXXXXXXXXXXXX | KT+ an eight-figure identifier |
LG | LGXXXXXXXX_20150515102510XXXXXXXXXXXXXXX | LG+ an eight- figure identifier |
{
"api_version" : "(api version)",
"identifier" : "(request id)",
"method" : "purchase",
"result" : {
"code" : "(result code)",
"message" : "(result message)",
"txid" : "(id)",
"receipt" : "(encode receipt using Base64)",
"count" : "(count of product)",
"product" : [ { "(product information)" } ]
}
}
Description
This function performs multiple inquiries (requests).
- Checks purchase history
- Fetches product information (Get title/description)
- Checks purchase availability
- Requests the change of the status of purchased product
Syntax
Bundle sendCommandRequest(String param, RequestCallback requestCallback)
Parameters
param
- String value in the JSON format containing required parameters
requestCallback
- Callback to receive the result of the payment request
Return Information, including request identifier (RequestId), is returned on normal request. (null is returned on failure)
Extra Key in Bundle
- req.id : request identifier
- req.rescode : error code for request
- req.resmsg : result message for request
Parameter | Type | Mandatory | Limit | sample | Description |
---|---|---|---|---|---|
method | String | M | - | request_purchase_history |
This is the defined function (method) name |
param | Object | M | - | method to request parameter information | |
appid | String | M | 10 | "appid" : "OA12345678", |
This is the Application ID(AID) |
product_id | Array | O | - | "product_id" : ["0000000020", "0000000021"] } |
This is the In-App product ID. The registration of multiple IDs is available with Array |
action | String | O | - |
cancel_subscription OR subtract_points
|
This is the sub-action of the change_product_properties method |
filter | Object | O | - | - | This is the filter settings(type, kind and date) on the results |
Method Type
Method | Description | Req Parameters |
---|---|---|
request_product_info | This checks the information of all In-App products uploaded with the AID | appid |
request_purchase_history | This checks purchase history(single, multi and all products) | appid, product_id |
check_purchasability | This checks purchase availability | appid, product_id |
change_product_properties | This requests the change of the status of purchased product | appid, product_id, action |
- action: cancel_subscription / action to request the cancellation of the subscription
- action: subtract_points/ action to request the subtraction of available points
Method for Backward Compatibility
The following methods were used in previous version of the IAP, and are not recommended for use
|Method|Description|Req Parameters| |-----|-----|-----| |auth_item|This makes a request to check purchased single/multi products|appid, product_id| |whole_auth_item |This makes a request to check purchased all products |appid| |monthly_withdraw |This makes a request to withdraw from monthly auto renewable subscription |appid, product_id| |item_use |This makes a request to subtract points from consumable products|appid, product_id|
{
"method" : "(method name)",
"param" : {
"appid" : "(application id)",
"product_id" : ["(product id)"],
"action" : "(sub action of method)"
}
}
For the result and error code, refer to IAP Reference Result Code .
Parameter | Type | Mandatory | Limit | sample | Description |
---|---|---|---|---|---|
api_version | String | M | 1 | 4 |
This is the IAP API version |
identifier | String | M | 10 | 1234567890 |
This is the request identifier |
method | String | M | - | request_product_info |
This is the request method |
result | Object | M | - | Thi is the result object generated by the request methodt | |
code | String | M | 4 | 0000 |
This is the result code |
message | String | M | - | This is the message generated by the result code | |
count | Number | O | 1 | 3 |
This is the number of successfully checked products |
product | Array | O | This is the product information array | ||
appid | String | O | 10 | OA00012345 |
This is the AID |
id | String | M | 10 | 0000000020 |
This is the In-App product ID |
name | String | O | 200 | custom product name |
This is the In-App product name |
type | String | O | - | consumable/non-consumablein-app non-renewable in-app trial version in-app auto-renewal-month |
This is the product type |
kind | String | O | - | non-consumable consumable one-day-pass one-week-pass one-month-pass |
This is the product kind |
validity | Number | O | - | non-consumable: 1 (valid) subscription: 7 (7days remaining) monthly auto renewable subscription: 365 (1 year remaining) |
This indicates the validity of non-consumable products, or the number of remaining days available for subscription |
price | Number | O | 6 | 300000 |
This is the product price (up to KRW300,000) |
startDate | String | O | 14 |
20160714104950 (Format: YYYYMMDDhhmmss) |
This is the product purchase date |
endDate | String | O | 14 | 20170714104950 |
This is the product termination date(indicates the expiry date of subscription) |
purchasability | Boolean | O | - |
true / false
|
This is the purchase availability |
status | Object | O | - | Specific method reponses must be included in the Status field | request_purchase_history change_product_properties - - - auth_item item_use monthly_withdraw |
code | String | M | 4 | PH00 |
This is the (Hex)result code |
message | String | M | - | The item is successfully checked. | This is the result message |
Notice
- The type of [auto-renewal-month] should not be used based on the available days. Instead, it should be used based on endDate (product termination date) after being confirmed in the App.
- status must return the result code and message only if the method respose is:
- request_purchase_history
- change_product_properties
- auth_item
- item_use
- monthly_withdraw
Default Response Data Format
{
"api_version" : "(api version)",
"identifier" : "(request id)",
"method" : "purchase",
"result" : {
"code" : "(result code)",
"message" : "(result message)"
}
}
Response Data Format of Query (command) for Checking* In case command for checking is requested, product field is included in the result field of the response data. Field information included in the product field varies depending on each method.
*Query (command) for Checking indidates the method requests defined in '(2)sendCommandRequest' (method types: request_product_info, request_purchase_history, check_purchasability, change_product_properties).
{
"api_version" : "(api version)",
"identifier" : "(request id)",
"method" : "purchase",
"result" : {
"code" : "(result code)",
"message" : "(result message)",
"count" : "(count of product)",
"product" : [ { "(product information)" } ]
}
}
This function is the same as mentioned above, and decides whether Foreground is allowed or not.
Description
This function performs multiple inquiries (requests).
- Checks purchase history
- Fetches product information (Get title/description)
- Checks purchase availability
- Requests the change of the status of purchased product
Syntax
Bundle sendCommandRequest(String param, RequestCallback requestCallback, ProcessType type)
Parameters
param
- String value in the JSON format containing required parameters
requestCallback
- Callback to receive the result of the payment request
type
- Decides if the request is processed either as Background only (without UI exposure) or as Foreground if needed(with UI exposure).
- ProcessType.BACKGROUND_ONLY
- ProcessType.FOREGROUND_IF_NEEDED
Return Information, including request identifier (RequestId), is returned on successful request. (null is returned on failure)
This is the abstract class to receive response results. Upon request, you are required to implement this class, create objects and send parameters.
private IapPlugin.AbsRequestCallback mAbsRequestCallback = new IapPlugin.AbsRequestCallback() {
@Override
protected void onResponse(Response response) {
// Receive normal responses
}
@Override
public void onError(String reqid, String errcode, String errmsg) {
// Error occurs
}
};
AbsRequestCallback provides methods as follows:
Methods | Description |
---|---|
onError | This callback function is called when request processing failed. |
onResponse | This callback function is called when request processing succeeded. |
Description
This callback function is called when request processing failed.
For the onError error code and message definition, refer IAP Reference Result Code.
Syntax
void onError(String reqid, String errcode, String errmsg)
Parameters
- reqid: request ID
- errcode: error code
- errmsg: error message
Description
This callback function is called when request processing succeeded.
Syntax
void onResponse(Response response)
IapResultCallback. This class converts the string type results received from the server into the class type.
In the previous versions, the developer directly converted the results through the helper package in the sample project. However a modification is made in this version to pass the converted results to the developer.
All the fields allow direct access as public. All the fields could be null. If information is not received from the server, the default value will be null.
public class Response {
public final String api_version;
public final String identifier;
public final String method;
public final Result result;
...
}
public static class Result {
public final String message;
public final String code;
public final String txid;
public final String receipt;
public final Integer count;
public final List<Product> product;
...
}
public static class Product {
public String appid;
public String id;
public String name;
public String type;
public String kind;
public Integer validity;
public Double price;
public String startDate;
public String endDate;
public Boolean purchasability;
public Status status;
...
}
public static class Status {
public String code;
public String message;
...
}
This enum defines the type of request processing
public enum ProcessType {
BACKGROUND_ONLY,
FOREGROUND_IF_NEEDED,
}
It is recommended to set FOREGROUND_IF_NEEDED by default.
In some cases, UI exposure is requested in the processing of request. For instance,
- Permission request screen
- ONE store service installation request screen
The cases mentioned above exist. If you want stop the request in these cases and receive error, request BACKGROUND_ONLY.
This callback interface is to receive results by calling IapPlugin.
The callback is set by passing RequestCallback instance. RequestCallback instance is implemented by calling the request method. The corresponsing interface method is called according to the success or failure of request processing.
RequestCallback provides methods as below:
Methods | Description |
---|---|
onError | This callback function is called when request processing failed |
onResponse | This callback function is called when request processing succeeded |
Description
This callback function is called when request processing failed.
For the onError error code and message definition, refer to Home
Syntax
void onError(String rid, String errcode, String errmsg)
Parameters
- rid: request ID
- errcode: error code
- errmsg: error message
Description
This callback function is called when request processing succeeded
For the onResponse result code and message definition, refer to IAP Reference Result Code
Syntax
public void onResponse(IapResponse response)
Parameters
response
IapResponse
The onResponse is the response data as listed below:
Methods | Descreption |
---|---|
getContentLength | This returns the length of the response data |
getContent | This returns the response data as InputStream |
getContentToString | This returns the response data as String |
getContentEncoding | This returns the character data encoding type |
This is an interface to the server response data. The methods are listed as below:
Methods | Descreption |
---|---|
getContentLength | This returns the length of the response data |
getContent | This returns the response data as InputStream |
getContentToString | This returns the response data as String |
getContentEncoding | This returns the character data encoding type |
Description
This method returns the length of the response data.
Syntax
long getContentLength())
Return
The length of the response data
Description
This method returns the response data as InputStream.
Syntax
InputStream getContent() throws IOException
Return
Returns InputStream that can read the response data
Description
This method returns the response data as String. The string is converted to the encoding method, which is returned as getContentEncoding (utf-8 is used as the default encoding method).
Syntax
String getContentToString()
Return
Returns the encoded result as String
Description
This method returns the character data encoding type (utf-8 is used as the default encoding method).
Syntax
String getContentEncoding()
Return Returns the encoding type as String.