Search in sources :

Example 1 with OnSuccessListener

use of com.huawei.hmf.tasks.OnSuccessListener in project Osmand by osmandapp.

the class IapRequestHelper method obtainOwnedPurchaseRecord.

/**
 * obtain the historical consumption information about a consumable in-app product or all subscription receipts of a subscription.
 * @param iapClient IapClient instance to call the obtainOwnedPurchaseRecord API.
 * @param priceType In-app product type.
 *                  The value contains: 0: consumable 1: non-consumable 2 auto-renewable subscription.
 * @param continuationToken Data locating flag for supporting query in pagination mode.
 * @param callback IapApiCallback
 */
public static void obtainOwnedPurchaseRecord(IapClient iapClient, int priceType, String continuationToken, final IapApiCallback callback) {
    Log.i(TAG, "call obtainOwnedPurchaseRecord");
    Task<OwnedPurchasesResult> task = iapClient.obtainOwnedPurchaseRecord(createOwnedPurchasesReq(priceType, continuationToken));
    task.addOnSuccessListener(new OnSuccessListener<OwnedPurchasesResult>() {

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

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

Example 2 with OnSuccessListener

use of com.huawei.hmf.tasks.OnSuccessListener in project Osmand by osmandapp.

the class IapRequestHelper method showSubscription.

/**
 * link to subscription manager page
 * @param activity activity
 * @param productId the productId of the subscription product
 */
public static void showSubscription(final Activity activity, String productId) {
    StartIapActivityReq req = new StartIapActivityReq();
    if (TextUtils.isEmpty(productId)) {
        req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_MANAGER_ACTIVITY);
    } else {
        req.setType(StartIapActivityReq.TYPE_SUBSCRIBE_EDIT_ACTIVITY);
        req.setSubscribeProductId(productId);
    }
    IapClient iapClient = Iap.getIapClient(activity);
    Task<StartIapActivityResult> task = iapClient.startIapActivity(req);
    task.addOnSuccessListener(new OnSuccessListener<StartIapActivityResult>() {

        @Override
        public void onSuccess(StartIapActivityResult result) {
            if (result != null) {
                result.startActivity(activity);
            }
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            ExceptionHandle.handle(activity, e);
        }
    });
}
Also used : IapClient(com.huawei.hms.iap.IapClient) StartIapActivityReq(com.huawei.hms.iap.entity.StartIapActivityReq) StartIapActivityResult(com.huawei.hms.iap.entity.StartIapActivityResult) OnSuccessListener(com.huawei.hmf.tasks.OnSuccessListener) OnFailureListener(com.huawei.hmf.tasks.OnFailureListener) IapApiException(com.huawei.hms.iap.IapApiException)

Example 3 with OnSuccessListener

use of com.huawei.hmf.tasks.OnSuccessListener in project Osmand by osmandapp.

the class IapRequestHelper method isEnvReady.

/**
 * To check whether the country or region of the logged in HUAWEI ID is included in the countries or regions supported by HUAWEI IAP.
 * @param mClient IapClient instance to call the isEnvReady API.
 * @param callback IapApiCallback.
 */
public static void isEnvReady(IapClient mClient, final IapApiCallback callback) {
    Log.i(TAG, "call isEnvReady");
    Task<IsEnvReadyResult> task = mClient.isEnvReady();
    task.addOnSuccessListener(new OnSuccessListener<IsEnvReadyResult>() {

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

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

Example 4 with OnSuccessListener

use of com.huawei.hmf.tasks.OnSuccessListener 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)

Example 5 with OnSuccessListener

use of com.huawei.hmf.tasks.OnSuccessListener in project Osmand by osmandapp.

the class IapRequestHelper method obtainProductInfo.

/**
 * Obtain in-app product details configured in AppGallery Connect.
 * @param iapClient IapClient instance to call the obtainProductInfo API.
 * @param productIds ID list of products to be queried. Each product ID must exist and be unique in the current app.
 * @param type In-app product type.
 *             The value contains: 0: consumable 1: non-consumable 2 auto-renewable subscription
 * @param callback IapApiCallback
 */
public static void obtainProductInfo(IapClient iapClient, final List<String> productIds, int type, final IapApiCallback callback) {
    Log.i(TAG, "call obtainProductInfo");
    Task<ProductInfoResult> task = iapClient.obtainProductInfo(createProductInfoReq(type, productIds));
    task.addOnSuccessListener(new OnSuccessListener<ProductInfoResult>() {

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

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

Aggregations

OnFailureListener (com.huawei.hmf.tasks.OnFailureListener)7 OnSuccessListener (com.huawei.hmf.tasks.OnSuccessListener)7 IapApiException (com.huawei.hms.iap.IapApiException)7 OwnedPurchasesResult (com.huawei.hms.iap.entity.OwnedPurchasesResult)2 IapClient (com.huawei.hms.iap.IapClient)1 ConsumeOwnedPurchaseResult (com.huawei.hms.iap.entity.ConsumeOwnedPurchaseResult)1 IsEnvReadyResult (com.huawei.hms.iap.entity.IsEnvReadyResult)1 ProductInfoResult (com.huawei.hms.iap.entity.ProductInfoResult)1 PurchaseIntentReq (com.huawei.hms.iap.entity.PurchaseIntentReq)1 PurchaseIntentResult (com.huawei.hms.iap.entity.PurchaseIntentResult)1 StartIapActivityReq (com.huawei.hms.iap.entity.StartIapActivityReq)1 StartIapActivityResult (com.huawei.hms.iap.entity.StartIapActivityResult)1