Search in sources :

Example 1 with BillingResponse

use of com.android.billingclient.api.BillingClient.BillingResponse in project Android-InAppBilling by LiteKite.

the class BillingManager method consumeAsync.

/**
 * Consumes InApp Product Purchase after successful purchase of InApp Product Purchase. InApp
 * Products cannot be bought after a purchase was made. We need to consume it after a
 * successful purchase, so that we can purchase again and it will become available for the
 * next time we make purchase of the same product that was bought before.
 *
 * @param purchaseToken a token that uniquely identifies a purchase for a given item and user
 *                      pair.
 */
private void consumeAsync(final String purchaseToken) {
    // onActivityResult()
    if (tokensToBeConsumed == null) {
        tokensToBeConsumed = new HashSet<>();
    } else if (tokensToBeConsumed.contains(purchaseToken)) {
        BaseActivity.printLog(TAG, "Token was already scheduled to be consumed - skipping...");
        return;
    }
    tokensToBeConsumed.add(purchaseToken);
    // Generating Consume Response listener
    final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {

        @Override
        public void onConsumeResponse(@BillingResponse int responseCode, String purchaseToken) {
            // If billing service was disconnected, we try to reconnect 1 time
            // (feel free to introduce your retry policy here).
            BaseActivity.printLog(TAG, "Consume Response, Purchase Token: " + purchaseToken);
            logErrorType(responseCode);
        }
    };
    // Creating a runnable from the request to use it inside our connection retry policy below
    Runnable consumeRequest = new Runnable() {

        @Override
        public void run() {
            // Consume the purchase async
            myBillingClient.consumeAsync(purchaseToken, onConsumeListener);
        }
    };
    executeServiceRequest(consumeRequest);
}
Also used : ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) BillingResponse(com.android.billingclient.api.BillingClient.BillingResponse)

Aggregations

BillingResponse (com.android.billingclient.api.BillingClient.BillingResponse)1 ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)1