Search in sources :

Example 1 with AcknowledgePurchaseParams

use of com.android.billingclient.api.AcknowledgePurchaseParams in project apcupsd-monitor by norkator.

the class MainMenu method acknowledgePurchase.

/**
 * Acknowledge purchase required by billing lib 2.x++
 *
 * @param purchase billing purchase
 */
private void acknowledgePurchase(Purchase purchase) {
    AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
    mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, acknowledgePurchaseResponseListener);
}
Also used : AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams)

Example 2 with AcknowledgePurchaseParams

use of com.android.billingclient.api.AcknowledgePurchaseParams in project zype-android by zype.

the class BillingManager method handlePurchases.

public void handlePurchases(List<Purchase> purchases) {
    for (Purchase purchase : purchases) {
        Log.d("BillingManager", "handlePurchases purchase state: " + purchase.getPurchaseState());
        if (/*ITEM_SKU_SUBSCRIBE.equals(purchase.getSku()) && */
        purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
            // if item is purchased and not acknowledged
            this.purchase1 = purchase;
            Log.d("BillingManager", "handlePurchases purchase isAcknowledged: " + purchase.isAcknowledged());
            if (!purchase.isAcknowledged()) {
                AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
                mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, ackPurchase);
            }
        } else {
            mBillingUpdatesListener.onPurchasesUpdated(purchases);
        }
    }
}
Also used : Purchase(com.android.billingclient.api.Purchase) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams)

Example 3 with AcknowledgePurchaseParams

use of com.android.billingclient.api.AcknowledgePurchaseParams in project sms-backup-plus by jberkel.

the class DonationActivity method acknowledgePurchase.

// https://developer.android.com/google/play/billing/billing_library_overview#acknowledge
private void acknowledgePurchase(final Purchase purchase) {
    if (purchase.getPurchaseState() == PURCHASED && !purchase.isAcknowledged() && billingClient != null) {
        AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
        billingClient.acknowledgePurchase(params, new AcknowledgePurchaseResponseListener() {

            @Override
            public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
                log("onAcknowledgePurchaseResponse(" + billingResult + ")");
                if (billingResult.getResponseCode() != OK) {
                    Log.w(TAG, "not acknowledged purchase " + purchase + ":" + billingResult);
                }
            }
        });
    }
}
Also used : AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams) BillingResult(com.android.billingclient.api.BillingResult)

Example 4 with AcknowledgePurchaseParams

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

the class BillingManager method acknowledgeNonConsumablePurchasesAsync.

/**
 * If you do not acknowledge a purchase, the Google Play Store will provide a refund to the
 * users within a few days of the transaction. Therefore you have to implement
 * [BillingClient.acknowledgePurchaseAsync] inside your app.
 *
 * @param purchase list of Purchase Details returned from the queries.
 */
private void acknowledgeNonConsumablePurchasesAsync(Purchase purchase) {
    final AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
    final AcknowledgePurchaseResponseListener listener = billingResult -> {
        if (billingResult.getResponseCode() == BillingResponseCode.OK) {
            MonetizeApp.printLog(TAG, "onAcknowledgePurchaseResponse: " + BillingResponseCode.OK);
        } else {
            MonetizeApp.printLog(TAG, "onAcknowledgePurchaseResponse: " + billingResult.getDebugMessage());
        }
    };
    executeServiceRequest(() -> myBillingClient.acknowledgePurchase(params, listener));
}
Also used : NetworkManager(com.litekite.monetize.network.NetworkManager) Context(android.content.Context) WorkExecutor(com.litekite.monetize.worker.WorkExecutor) NonNull(androidx.annotation.NonNull) BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) AppDatabase(com.litekite.monetize.room.database.AppDatabase) PurchaseHistoryRecord(com.android.billingclient.api.PurchaseHistoryRecord) MonetizeApp(com.litekite.monetize.app.MonetizeApp) HashMap(java.util.HashMap) CallbackProvider(com.litekite.monetize.base.CallbackProvider) Singleton(javax.inject.Singleton) SkuType(com.android.billingclient.api.BillingClient.SkuType) BillingSkuDetails(com.litekite.monetize.room.entity.BillingSkuDetails) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) R(com.litekite.monetize.R) BillingResult(com.android.billingclient.api.BillingResult) PurchasesUpdatedListener(com.android.billingclient.api.PurchasesUpdatedListener) Map(java.util.Map) ConsumeParams(com.android.billingclient.api.ConsumeParams) PurchasesResponseListener(com.android.billingclient.api.PurchasesResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams) SkuDetails(com.android.billingclient.api.SkuDetails) BillingResponseCode(com.android.billingclient.api.BillingClient.BillingResponseCode) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) Set(java.util.Set) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams) PurchaseHistoryResponseListener(com.android.billingclient.api.PurchaseHistoryResponseListener) StringRes(androidx.annotation.StringRes) FeatureType(com.android.billingclient.api.BillingClient.FeatureType) Purchase(com.android.billingclient.api.Purchase) List(java.util.List) Nullable(androidx.annotation.Nullable) BillingClient(com.android.billingclient.api.BillingClient) AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) BillingPurchaseDetails(com.litekite.monetize.room.entity.BillingPurchaseDetails) BillingFlowParams(com.android.billingclient.api.BillingFlowParams) Activity(android.app.Activity) AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams)

Example 5 with AcknowledgePurchaseParams

use of com.android.billingclient.api.AcknowledgePurchaseParams in project Osmand by osmandapp.

the class BillingManager method handlePurchase.

/**
 * Handles the purchase
 * <p>Note: Notice that for each purchase, we check if signature is valid on the client.
 * It's recommended to move this check into your backend.
 * See {@link Security#verifyPurchase(String, String, String)}
 * </p>
 *
 * @param purchase Purchase to be handled
 */
private void handlePurchase(final Purchase purchase) {
    if (!verifyValidSignature(purchase.getOriginalJson(), purchase.getSignature())) {
        LOG.info("Got a purchase: " + purchase + ", but signature is bad. Skipping...");
        return;
    }
    if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
        // Acknowledge the purchase if it hasn't already been acknowledged.
        if (!purchase.isAcknowledged()) {
            AcknowledgePurchaseParams acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
            mBillingClient.acknowledgePurchase(acknowledgePurchaseParams, new AcknowledgePurchaseResponseListener() {

                @Override
                public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
                    if (billingResult.getResponseCode() != BillingResponseCode.OK) {
                        LOG.info("Acknowledge a purchase: " + purchase + " failed (" + billingResult.getResponseCode() + "). " + billingResult.getDebugMessage());
                    }
                }
            });
        }
    } else if (purchase.getPurchaseState() == Purchase.PurchaseState.PENDING) {
        LOG.info("Got a purchase: " + purchase + ", but purchase state is pending. Skipping...");
        return;
    } else {
        LOG.info("Got a purchase: " + purchase + ", but purchase state is " + purchase.getPurchaseState() + ". Skipping...");
        return;
    }
    LOG.debug("Got a verified purchase: " + purchase);
    mPurchases.add(purchase);
}
Also used : AcknowledgePurchaseResponseListener(com.android.billingclient.api.AcknowledgePurchaseResponseListener) AcknowledgePurchaseParams(com.android.billingclient.api.AcknowledgePurchaseParams) BillingResult(com.android.billingclient.api.BillingResult)

Aggregations

AcknowledgePurchaseParams (com.android.billingclient.api.AcknowledgePurchaseParams)5 AcknowledgePurchaseResponseListener (com.android.billingclient.api.AcknowledgePurchaseResponseListener)3 BillingResult (com.android.billingclient.api.BillingResult)3 Purchase (com.android.billingclient.api.Purchase)2 Activity (android.app.Activity)1 Context (android.content.Context)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 BillingClient (com.android.billingclient.api.BillingClient)1 BillingResponseCode (com.android.billingclient.api.BillingClient.BillingResponseCode)1 FeatureType (com.android.billingclient.api.BillingClient.FeatureType)1 SkuType (com.android.billingclient.api.BillingClient.SkuType)1 BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)1 BillingFlowParams (com.android.billingclient.api.BillingFlowParams)1 ConsumeParams (com.android.billingclient.api.ConsumeParams)1 ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)1 PurchaseHistoryRecord (com.android.billingclient.api.PurchaseHistoryRecord)1 PurchaseHistoryResponseListener (com.android.billingclient.api.PurchaseHistoryResponseListener)1 PurchasesResponseListener (com.android.billingclient.api.PurchasesResponseListener)1