Search in sources :

Example 1 with PurchaseIntentReq

use of com.huawei.hms.iap.entity.PurchaseIntentReq in project Osmand by osmandapp.

the class IapRequestHelper method createPurchaseIntentReq.

/**
 * Create a PurchaseIntentReq object.
 * @param type In-app product type.
 *             The value contains: 0: consumable 1: non-consumable 2 auto-renewable subscription
 * @param productId ID of the in-app product to be paid.
 *              The in-app product ID is the product ID you set during in-app product configuration in AppGallery Connect.
 * @return PurchaseIntentReq
 */
private static PurchaseIntentReq createPurchaseIntentReq(int type, String productId) {
    PurchaseIntentReq req = new PurchaseIntentReq();
    req.setPriceType(type);
    req.setProductId(productId);
    req.setDeveloperPayload("testPurchase");
    return req;
}
Also used : PurchaseIntentReq(com.huawei.hms.iap.entity.PurchaseIntentReq)

Example 2 with PurchaseIntentReq

use of com.huawei.hms.iap.entity.PurchaseIntentReq in project Osmand by osmandapp.

the class IapRequestHelper method createPurchaseIntent.

public static void createPurchaseIntent(final IapClient iapClient, String productId, int type, String payload, final IapApiCallback callback) {
    Log.i(TAG, "call createPurchaseIntent");
    PurchaseIntentReq req = createPurchaseIntentReq(type, productId);
    req.setDeveloperPayload(payload);
    Task<PurchaseIntentResult> task = iapClient.createPurchaseIntent(req);
    task.addOnSuccessListener(new OnSuccessListener<PurchaseIntentResult>() {

        @Override
        public void onSuccess(PurchaseIntentResult result) {
            Log.i(TAG, "createPurchaseIntent, success");
            callback.onSuccess(result);
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "createPurchaseIntent, fail");
            callback.onFail(e);
        }
    });
}
Also used : PurchaseIntentResult(com.huawei.hms.iap.entity.PurchaseIntentResult) OnSuccessListener(com.huawei.hmf.tasks.OnSuccessListener) PurchaseIntentReq(com.huawei.hms.iap.entity.PurchaseIntentReq) OnFailureListener(com.huawei.hmf.tasks.OnFailureListener) IapApiException(com.huawei.hms.iap.IapApiException)

Aggregations

PurchaseIntentReq (com.huawei.hms.iap.entity.PurchaseIntentReq)2 OnFailureListener (com.huawei.hmf.tasks.OnFailureListener)1 OnSuccessListener (com.huawei.hmf.tasks.OnSuccessListener)1 IapApiException (com.huawei.hms.iap.IapApiException)1 PurchaseIntentResult (com.huawei.hms.iap.entity.PurchaseIntentResult)1