Skip to main content
Version: 1.5.x

Billing

Configure

Please, add to AndroidManifest.xml the following values.

Please, ask your manager for those values.

<meta-data android:name="com.platform101xp.sdk_huawei.payment_public_key"
android:value="@string/public_payment_key" />
<meta-data android:name="com.platform101xp.sdk_huawei.billing_test"
android:value="@bool/billing_test" />
<meta-data android:name="com.platform101xp.sdk_huawei.consume_products_ids"
android:value="@string/consume_products_ids" />
<meta-data android:name="com.platform101xp.sdk_huawei.non_consume_products_ids"
android:value="@string/non_consume_products_ids" />

Usage

In your MainActivity, you need to create the SDK instance and set the billing listener:

public class MainActivity extends Activity {
private Platform101XPHuaweiAuthorizeListener authorizeListener;
private Platform101XPHuaweiBillingListener billingListener;
private Platform101XPHuawei platformInstance;
private List<Platform101XPHuaweiProductDetails> availableProductsList;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
// Create AuthorizeListener

billingListener = new Platform101XPHuaweiBillingListener() {
@Override
public void onGetProductsInfo(@Nullable List<Platform101XPHuaweiProductDetails> productsDetailsList,
@Nullable Platform101XPHuaweiError error) {
if (error != null) {
if (productsDetailsList != null){
Log.d(LOG_TAG, "Error: " + error);
//Error Handler
} else {
//Error Handler
}
} else if (productsDetailsList != null && !productsDetailsList.isEmpty()) {
availableProductsList = productsDetailsList;
//Success Handler
} else {
Log.d(LOG_TAG, "Products Details List is empty!");
}
}

@Override
public void onPurchaseProductResult(@Nullable Platform101XPHuaweiPurchasedProduct purchasedProduct,
@Nullable Platform101XPHuaweiError error) {
if (error != null) {
//Error Handler
} else if (purchasedProduct != null) {
//Success Handler
} else {
//Unknown Error Handler
}
}
};

platformInstance = new Platform101XPHuawei
.Builder(this)
.setAuthorizeListener(authorizeListener)
.setBillingListener(billingListener)
.build();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
platformInstance.onActivityResult(requestCode, resultCode, data);
}
}
caution

To process the results of the purchase, it is very important to add a call to the platformInstance.onActivityResult (requestCode, resultCode, data) method in MainActivity

Then, you can make purchase with the method:

Map<String, String>purchaseProperties = new HashMap<String, String>();
purchaseProperties.put("first_purchase_property", "first_property");
purchaseProperties.put("second_purchase_property", "second_property");

platformInstance.purchaseProduct(productId, "9001", purchaseProperties);

Pass product id, server id and purchaseProperties as parameters.

The purchase result is passed to Platform101XPHuaweiBillingListener.onPurchaseProductResult()

Get available products

To get products details list please use getAllProductsDetails() method:

platformInstance.getAllProductsDetails();

The products list result is passed to Platform101XPHuaweiBillingListener.OnGetProductInfo()

Restore products

To restore purchases, use the restoreAllProducts() method:

platformInstance.restoreAllProducts();

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