Skip to main content
Version: Next

Billing

Configure

To set up Samsung Billing dit the AndroidManifest.xml and add required permissions:

<uses-permission android:name="com.samsung.android.iap.permission.BILLING"/>

Add permissions to <application> section too:

<meta-data android:name="com.platform101xp.sdk.billing.enabled"
android:value="@bool/billing_enabled"/>
<meta-data android:name="com.platform101xp.sdk.billing.sku"
android:value="@string/billing_sku"/>
<meta-data android:name="com.platform101xp.sdk.billing.billing_samsung_operation_mode"
android:value="@string/billing_samsung_operation_mode" />

@bool/billing_enabled - switching-on of the billing function

@string/billing_sku - list of ID's of products available in the game (from Samsung Developer Console) separation by ",". For example: "product1,product2,product3"

@string/billing_samsung_operation_mode - IAP operation mode. "prod" or "test" or "fail"

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.

IAP operation modeModeDescription
prodOPERATION_MODE_PRODUCTIONrequests are processed as specified, financial transactions do occur for successful requests, and actual results are returned (successful or failed).
Note: For all other IAP Helper requests:
- Only items purchased in OPERATION_MODE_PRODUCTION mode are considered owned items.
testOPERATION_MODE_TESTrequests are processed as specified, except financial transactions do not occur (licensed testers are not billed for item purchases), and successful results are always returned.
Note: For all other IAP Helper requests:
- Only items purchased in OPERATION_MODE_TEST mode are considered owned items.
- In order to purchase in-app items, testers must be registered as a License Tester in the seller's Seller Portal profile. In this mode, licensed testers always get your in-app items for free. All other users see an error message if they try to purchase an in-app item.
failOPERATION_MODE_TEST_FAILUREAll IAP Helper requests fail. It is meant to be a negative testing to ensure that your app can handle errors such as improper input and user actions.
info

Note : 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.

For details of the payment window shown in OPERATION_MODE_TEST mode, see below.

Usage

Initialization

Use a method onBillingInitializeResult() in your listener object:

// Java
@Override
public void onBillingInitializeResult(Platform101XPError error) {
if (error == null) {
// Success initialization!
}
}

// Kotlin
override fun onBillingInitializeResult(error: Platform101XPError?) {
if (error == null) {
// Success initialization!
}
}

Restoring purchases

To restore purchases, use the restoreProducts() method:

// Java
Platform101XP.restoreProducts();

// Kotlin
Platform101XP.restoreProducts()

The result will be returned to onPurchaseProductResult() method in listener, as with a regular purchase.

Getting product information

You can get product by id (from AndroidManifest in com.platform101xp.sdk.billing.sku) with method getProductById:

// Java
Platform101XPProduct product = Platform101XP.getProductById("com.101xp.product");

// Kotlin
val product = Platform101XP.getProductById("com.101xp.product")

Make payment

To make payments, use the Platform101XP.purchaseProduct() method.

Parameters serverId and properties are sent to 101XP Billing Server and to the game server.

// Java
Map<String, String> properties = new HashMap<String, String>();
properties.put("first_purchase_property", your_purchase_property);

String serverId = your_server_id;
Platform101XP.purchaseProduct(product, serverId, properties);

// Kotlin
val properties: MutableMap<String, String> = HashMap()
properties["first_purchase_property"] = "first_property"

val serverId: String = your_server_id;
Platform101XP.purchaseProduct(product, serverId, properties)

The result of purchaseProduct() is sent to the method of listener.

// Java
void onPurchaseProductResult(Platform101XPPurchase purchase, Platform101XPError error);

// Kotlin
override fun onPurchaseProductResult(purchase: Platform101XPPurchase?, error: Platform101XPError?)

Completion of payment

For consumable products, after successful purchase and processing, you need to call the finishPurchase() method.

// Java
Platform101XP.finishPurchase(Platform101XPPurchase purchase);

// Kotlin
Platform101XP.finishPurchase(Platform101XPPurchase purchase);

The result of finishPurchase() is sent to the method of listener.

// Java
void onFinishPurchaseResult(Platform101XPPurchase purchase, Platform101XPError error){
}

// Kotlin
override fun onFinishPurchaseResult(purchase: Platform101XPPurchase?, error: Platform101XPError?){
}
danger

Consumable products

Without calling finishPurchase() you'll get the following error on the second purchase:

Item already owned