Search in sources :

Example 11 with ConsumeResponseListener

use of com.android.billingclient.api.ConsumeResponseListener in project OsmAnd by osmandapp.

the class BillingManager method consumeAsync.

public void consumeAsync(final ConsumeParams consumeParams) {
    // If we've already scheduled to consume this token - no action is needed (this could happen
    // if you received the token when querying purchases inside onReceive() and later from
    // onActivityResult()
    final String purchaseToken = consumeParams.getPurchaseToken();
    if (mTokensToBeConsumed == null) {
        mTokensToBeConsumed = new HashSet<>();
    } else if (mTokensToBeConsumed.contains(purchaseToken)) {
        LOG.info("Token was already scheduled to be consumed - skipping...");
        return;
    }
    mTokensToBeConsumed.add(purchaseToken);
    // Generating Consume Response listener
    final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {

        @Override
        public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
            // If billing service was disconnected, we try to reconnect 1 time
            // (feel free to introduce your retry policy here).
            mBillingUpdatesListener.onConsumeFinished(purchaseToken, billingResult);
        }
    };
    // 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
            mBillingClient.consumeAsync(consumeParams, onConsumeListener);
        }
    };
    executeServiceRequest(consumeRequest);
}
Also used : ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) BillingResult(com.android.billingclient.api.BillingResult)

Example 12 with ConsumeResponseListener

use of com.android.billingclient.api.ConsumeResponseListener in project getsocial-android-sdk by getsocial-im.

the class PurchaseFragment method consumePurchasedItem.

private void consumePurchasedItem(Purchase purchase) {
    ConsumeParams params = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
    _billingClient.consumeAsync(params, new ConsumeResponseListener() {

        @Override
        public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
            System.out.println("got consumePurchase response");
        }
    });
}
Also used : ConsumeParams(com.android.billingclient.api.ConsumeParams) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) BillingResult(com.android.billingclient.api.BillingResult)

Example 13 with ConsumeResponseListener

use of com.android.billingclient.api.ConsumeResponseListener in project AperoModuleAds by AperoVN.

the class AppPurchase method handlePurchase.

private void handlePurchase(Purchase purchase) {
    // tracking adjust
    double price = getPriceWithoutCurrency(idPurchaseCurrent, typeIap);
    String currentcy = getCurrency(idPurchaseCurrent, typeIap);
    AdjustApero.onTrackRevenuePurchase((float) price, currentcy);
    if (purchaseListioner != null)
        isPurchase = true;
    purchaseListioner.onProductPurchased(purchase.getOrderId(), purchase.getOriginalJson());
    if (isConsumePurchase) {
        ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
        ConsumeResponseListener listener = new ConsumeResponseListener() {

            @Override
            public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
                Log.d(TAG, "onConsumeResponse: " + billingResult.getDebugMessage());
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                }
            }
        };
        billingClient.consumeAsync(consumeParams, listener);
    } else {
        if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
            AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
            if (!purchase.isAcknowledged()) {
                billingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {

                    @Override
                    public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) {
                        Log.d(TAG, "onAcknowledgePurchaseResponse: " + billingResult.getDebugMessage());
                    }
                });
            }
        }
    }
}
Also used : ConsumeParams(com.android.billingclient.api.ConsumeParams) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams) BillingResult(com.android.billingclient.api.BillingResult)

Example 14 with ConsumeResponseListener

use of com.android.billingclient.api.ConsumeResponseListener in project AperoModuleAds by AperoVN.

the class AppPurchase method consumePurchase.

public void consumePurchase(String productId) {
    Purchase pc = null;
    Purchase.PurchasesResult resultINAP = billingClient.queryPurchases(BillingClient.SkuType.INAPP);
    if (resultINAP.getResponseCode() == BillingClient.BillingResponseCode.OK && resultINAP.getPurchasesList() != null) {
        for (Purchase purchase : resultINAP.getPurchasesList()) {
            if (purchase.getSkus().contains(productId)) {
                pc = purchase;
            }
        }
    }
    if (pc == null)
        return;
    try {
        ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(pc.getPurchaseToken()).build();
        ConsumeResponseListener listener = new ConsumeResponseListener() {

            @Override
            public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    Log.e(TAG, "onConsumeResponse: OK");
                    verifyPurchased(false);
                }
            }
        };
        billingClient.consumeAsync(consumeParams, listener);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Purchase(com.android.billingclient.api.Purchase) ConsumeParams(com.android.billingclient.api.ConsumeParams) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) BillingResult(com.android.billingclient.api.BillingResult)

Aggregations

ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)14 BillingResult (com.android.billingclient.api.BillingResult)12 ConsumeParams (com.android.billingclient.api.ConsumeParams)10 Purchase (com.android.billingclient.api.Purchase)4 NonNull (androidx.annotation.NonNull)3 AcknowledgePurchaseResponseListener (com.android.billingclient.api.AcknowledgePurchaseResponseListener)3 Nullable (androidx.annotation.Nullable)2 AcknowledgePurchaseParams (com.android.billingclient.api.AcknowledgePurchaseParams)2 BillingClient (com.android.billingclient.api.BillingClient)2 BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)2 BillingFlowParams (com.android.billingclient.api.BillingFlowParams)2 PurchasesUpdatedListener (com.android.billingclient.api.PurchasesUpdatedListener)2 SkuDetails (com.android.billingclient.api.SkuDetails)2 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1