Search in sources :

Example 1 with ConsumeOwnedPurchaseResult

use of com.huawei.hms.iap.entity.ConsumeOwnedPurchaseResult 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)1 OnSuccessListener (com.huawei.hmf.tasks.OnSuccessListener)1 IapApiException (com.huawei.hms.iap.IapApiException)1 ConsumeOwnedPurchaseResult (com.huawei.hms.iap.entity.ConsumeOwnedPurchaseResult)1