Search in sources :

Example 1 with IapApiException

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

the class ExceptionHandle method handle.

/**
 * Handles the exception returned from the iap api.
 * @param activity The Activity to call the iap api.
 * @param e The exception returned from the iap api.
 * @return int
 */
public static int handle(@Nullable Activity activity, Exception e) {
    if (e instanceof IapApiException) {
        IapApiException iapApiException = (IapApiException) e;
        LOG.info("returnCode: " + iapApiException.getStatusCode());
        switch(iapApiException.getStatusCode()) {
            case OrderStatusCode.ORDER_STATE_CANCEL:
                showToast(activity, "Order has been canceled!");
                return SOLVED;
            case OrderStatusCode.ORDER_STATE_PARAM_ERROR:
                showToast(activity, "Order state param error!");
                return SOLVED;
            case OrderStatusCode.ORDER_STATE_NET_ERROR:
                showToast(activity, "Order state net error!");
                return SOLVED;
            case OrderStatusCode.ORDER_VR_UNINSTALL_ERROR:
                showToast(activity, "Order vr uninstall error!");
                return SOLVED;
            case OrderStatusCode.ORDER_HWID_NOT_LOGIN:
                IapRequestHelper.startResolutionForResult(activity, iapApiException.getStatus(), Constants.REQ_CODE_LOGIN);
                return SOLVED;
            case OrderStatusCode.ORDER_PRODUCT_OWNED:
                showToast(activity, "Product already owned error!");
                return OrderStatusCode.ORDER_PRODUCT_OWNED;
            case OrderStatusCode.ORDER_PRODUCT_NOT_OWNED:
                showToast(activity, "Product not owned error!");
                return SOLVED;
            case OrderStatusCode.ORDER_PRODUCT_CONSUMED:
                showToast(activity, "Product consumed error!");
                return SOLVED;
            case OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED:
                showToast(activity, "Order account area not supported error!");
                return SOLVED;
            case OrderStatusCode.ORDER_NOT_ACCEPT_AGREEMENT:
                showToast(activity, "User does not agree the agreement");
                return SOLVED;
            default:
                // handle other error scenarios
                showToast(activity, "Order unknown error (" + iapApiException.getStatusCode() + ")");
                return SOLVED;
        }
    } else {
        showToast(activity, "External error");
        LOG.error(e.getMessage(), e);
        return SOLVED;
    }
}
Also used : IapApiException(com.huawei.hms.iap.IapApiException)

Example 2 with IapApiException

use of com.huawei.hms.iap.IapApiException 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

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