Billing
Configure
To set up Google Play Billing dit the AndroidManifest.xml and add required permissions:
<uses-permission android:name="com.android.vending.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.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"/>
<meta-data android:name="com.platform101xp.sdk.billing.xsolla_enabled"
android:value="@bool/billing_xsolla_enabled" />
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_enabled"
android:value="@bool/billing_yookassa_enabled" />
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_client_id"
android:value="@string/billing_yookassa_client_id" />
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_show_log"
android:value="@bool/billing_yookassa_show_log" />
<meta-data android:name="com.platform101xp.sdk.billing.robokassa_enabled"
android:value="@bool/billing_robokassa_enabled" />
For Robokassa in manifest add in application level
<activity
android:name="com.platform101xp.billing.internal.robokassa.RobokassaBillingActivity"
android:exported="true" />
For Yookassa in manifest in YourMainActivity inside <intent-filter> need add <data android:scheme="mobilesdkxp"/>
<activity
android:name="YourMainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
...
...
<data android:scheme="mobilesdkxp"/>
</intent-filter>
</activity>
And add in your build.gradle(application level)
android {
...
defaultConfig {
...
resValue "string", "ym_app_scheme", "mobilesdkxp"
}
}
@bool/billing_enabled - switching-on of the billing function
@string/billing_sku - list of ID's of products available in the game (from Google Play Developer Console) separation by ",". For example: "product1,product2,product3"
@string/billing_public_key - public key of the app from Google Play 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
@bool/billing_yookassa_enabled - switching enable/disable show of yokassa_sdk logs
@bool/billing_yookassa_client_id - authCenterClientId identifier received when registering the application on the site https://yookassa.ru, just ask your manager for this ID.
@bool/billing_yookassa_show_log - switching-on billing from yookassa (default: false)
@bool/billing_xsolla_enabled - switching-on billing from xsolla (default: false)
@bool/billing_robokassa_enabled - switching-on billing from robokassa (default: false)
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.Companion.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.Companion.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.Companion.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.Companion.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
Robokassa
In purchase from Google Play for User's from Russian and Belarus when product info return from store in currency (RUB or BYN) auto redirect to purchase items from Robokassa.
The result of purchaseProduct() is sent to the method of listener.
void onPurchaseProductInternalOrderResult(String productId, InternalOrderStatus status, Platform101XPError error){
}
// Kotlin
override fun onPurchaseProductInternalOrderResult(productId: String?, status: InternalOrderStatus, error: Platform101XPError?){
}
For enable/disable purchase from Robokassa use
<meta-data android:name="com.platform101xp.sdk.billing.robokassa_enabled"
android:value="@bool/billing_robokassa_enabled" />
[default:false] in manifest files. Or billing_robokassa_enabled flag in remote config.
Yookassa
In purchase from Google Play for User's from Russian and Belarus when product info return from store in currency (RUB or BYN) auto redirect to purchase items from Yookassa.
The result of purchaseProduct() is sent to the method of listener.
// Java
void onPurchaseProductInternalOrderResult(String productId, InternalOrderStatus status, Platform101XPError error){
}
// Kotlin
override fun onPurchaseProductInternalOrderResult(productId: String?, status: InternalOrderStatus, error: Platform101XPError?){
}
For enable/disable purchase from Yookassa use
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_enabled"
android:value="@bool/billing_yookassa_enabled" />
[default:false] in manifest files. Or billing_yookassa_enabled flag in remote config.
Add in manifest billing_yookassa_client_id, ask your managert for this ID
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_client_id"
android:value="@string/billing_yookassa_client_id" />
For enable/disable logs from Yookassa SDK use
<meta-data android:name="com.platform101xp.sdk.billing.yookassa_show_log"
android:value="@bool/billing_yookassa_show_log" />
[default:false] in manifest files. Or billing_yookassa_show_log flag in remote config.
Xsolla
In purchase from Google Play for User's from Russian and Belarus when product info return from store in currency (RUB or BYN) auto redirect to purchase items from Xsolla.
The result of purchaseProduct() is sent to the method of listener.
// Java
void onPurchaseProductInternalOrderResult(String productId, InternalOrderStatus status, Platform101XPError error){
}
// Kotlin
override fun onPurchaseProductInternalOrderResult(productId: String?, status: InternalOrderStatus, error: Platform101XPError?){
}
For enable/disable purchase from Xsolla use
<meta-data android:name="com.platform101xp.sdk.billing.xsolla_enabled"
android:value="@bool/billing_xsolla_enabled" />
[default:false] in manifest files. Or billing_xsolla_enabled flag in remote config.
InternalOrderStatus
InternalOrderStatus enum state description
value | description |
---|---|
PLACED | initial status of the created purchase transaction |
ERROR | error, if something went wrong, look $error(Platform101XPError) |
PAYED | successfully purchased |
CANCEL | transaction refund |
CALLBACK_ERROR | it was not possible to send the result to the game, but the purchase was paid |
USER_CANCEL | The user closed the purchase window or canceled it |