Search in sources :

Example 6 with OnFailureListener

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

the class IapRequestHelper method obtainOwnedPurchases.

/**
 * query information about all subscribed in-app products, including consumables, non-consumables, and auto-renewable subscriptions.</br>
 * If consumables are returned, the system needs to deliver them and calls the consumeOwnedPurchase API to consume the products.
 * If non-consumables are returned, the in-app products do not need to be consumed.
 * If subscriptions are returned, all existing subscription relationships of the user under the app are returned.
 * @param mClient IapClient instance to call the obtainOwnedPurchases API.
 * @param type In-app product type.
 *             The value contains: 0: consumable 1: non-consumable 2 auto-renewable subscription
 * @param callback IapApiCallback
 */
public static void obtainOwnedPurchases(IapClient mClient, final int type, String continuationToken, final IapApiCallback callback) {
    Log.i(TAG, "call obtainOwnedPurchases");
    Task<OwnedPurchasesResult> task = mClient.obtainOwnedPurchases(IapRequestHelper.createOwnedPurchasesReq(type, continuationToken));
    task.addOnSuccessListener(new OnSuccessListener<OwnedPurchasesResult>() {

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

        @Override
        public void onFailure(Exception e) {
            Log.e(TAG, "obtainOwnedPurchases, 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 7 with OnFailureListener

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

the class IapRequestHelper method consumeOwnedPurchase.

/**
 * Consume all the unconsumed purchases with priceType 0.
 * @param iapClient IapClient instance to call the consumeOwnedPurchase API.
 * @param purchaseToken which is generated by the Huawei payment server during product payment and returned to the app through InAppPurchaseData.
 */
public static void consumeOwnedPurchase(IapClient iapClient, String purchaseToken) {
    Log.i(TAG, "call consumeOwnedPurchase");
    Task<ConsumeOwnedPurchaseResult> task = iapClient.consumeOwnedPurchase(createConsumeOwnedPurchaseReq(purchaseToken));
    task.addOnSuccessListener(new OnSuccessListener<ConsumeOwnedPurchaseResult>() {

        @Override
        public void onSuccess(ConsumeOwnedPurchaseResult result) {
            // Consume success.
            Log.i(TAG, "consumeOwnedPurchase success");
        }
    }).addOnFailureListener(new OnFailureListener() {

        @Override
        public void onFailure(Exception e) {
            if (e instanceof IapApiException) {
                IapApiException apiException = (IapApiException) e;
                int returnCode = apiException.getStatusCode();
                Log.e(TAG, "consumeOwnedPurchase fail, IapApiException returnCode: " + returnCode);
            } else {
                // Other external errors
                Log.e(TAG, e.getMessage());
            }
        }
    });
}
Also used : ConsumeOwnedPurchaseResult(com.huawei.hms.iap.entity.ConsumeOwnedPurchaseResult) IapApiException(com.huawei.hms.iap.IapApiException) 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