Billing
Configure
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.public_key"
android:value="@string/billing_public_key"/>
<meta-data android:name="com.platform101xp.sdk.billing.reconnect_enabled"
android:value="@bool/billing_reconnect_enabled"/>
<meta-data android:name="com.platform101xp.sdk.billing.reconnect_count"
android:value="@integer/billing_reconnect_count"/>
<meta-data android:name="com.platform101xp.sdk.billing.reconnect_time"
android:value="@integer/billing_reconnect_time"/>
@bool/billing_enabled - switching-on of the billing function
@string/billing_sku - list of ID's of products available in the game (from Huawei Developer Console) separation by ",". For example: "product1,product2,product3"
@string/billing_public_key - public key of the app from Huawei Developer Console.
@bool/billing_reconnect_enabled - switching-on of the billing recconect else internet disconnected or error connection
@integer/billing_reconnect_count - count try for recconect purchase complete
@integer/billing_reconnect_time - time between recconect try
Checking payment on 101XP Billing Server
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. The result will come in 2 iterations. onPurchaseProductResult() return 2 iterations. First IN_APP_CONSUMABLE, Second IN_APP_NONCONSUMABLE
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?){
}
Consumable products
Without calling finishPurchase() you'll get the following error on the second purchase:
Item already owned