Search in sources :

Example 11 with BillingResult

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

the class MarketplaceGateway method queryGooglePlayProduct.

// 
// Google Play
// 
private void queryGooglePlayProduct(final Subscription subscription) {
    // Get sku details from marketplace (Google Play) for specified sku
    Log.d("BillingManager", "queryGooglePlayProduct: subscription: " + subscription);
    if (subscription.getZypePlan().marketplaceIds == null) {
        Logger.d("queryGooglePlayProduct(): marketplaceIds is empty.");
        return;
    }
    final String sku = subscription.getZypePlan().marketplaceIds.googleplay;
    Log.d("BillingManager", "queryGooglePlayProduct: sku: " + sku);
    List<String> skuList = new ArrayList<>();
    skuList.add(sku);
    billingManager.querySkuDetailsAsync(BillingClient.SkuType.SUBS, skuList, new SkuDetailsResponseListener() {

        @Override
        public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<SkuDetails> list) {
            if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
                Logger.e("onSkuDetailsResponse(): Error retrieving sku details from Google Play");
            } else {
                if (list != null) {
                    if (list.size() == 0) {
                        Logger.e("onSkuDetailsResponse(): Sku is not found in Google Play, sku=" + sku);
                    } else {
                        if (list.size() > 1) {
                            Logger.w("onSkuDetailsResponse(): Unexpected number of items (" + list.size() + ") in Google Play, sku=" + sku);
                        }
                        subscription.setMarketplace(list.get(0));
                    }
                }
            }
        }
    });
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) ArrayList(java.util.ArrayList) BillingResult(com.android.billingclient.api.BillingResult)

Example 12 with BillingResult

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

the class BillingManager method clearPurchases.

/**
 * Consumes all purchases.
 * Used only for testing one-time purchases
 */
public void clearPurchases() {
    if (purchases != null) {
        for (Purchase purchase : purchases) {
            ConsumeResponseListener listener = new ConsumeResponseListener() {

                @Override
                public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String s) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    // Handle the success of the consume operation.
                    // For example, increase the number of coins inside the user's basket.
                    }
                }
            };
            ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build();
            mBillingClient.consumeAsync(consumeParams, listener);
        }
    }
}
Also used : Purchase(com.android.billingclient.api.Purchase) ConsumeResponseListener(com.android.billingclient.api.ConsumeResponseListener) ConsumeParams(com.android.billingclient.api.ConsumeParams) NonNull(androidx.annotation.NonNull) BillingResult(com.android.billingclient.api.BillingResult)

Example 13 with BillingResult

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

the class DonationActivity method onCreate.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    billingClient = BillingClient.newBuilder(this).setListener(this).enablePendingPurchases().build();
    billingClient.startConnection(new BillingClientStateListener() {

        @Override
        public void onBillingSetupFinished(BillingResult resultCode) {
            log("onBillingSetupFinished(" + resultCode + ")" + Thread.currentThread().getName());
            switch(resultCode.getResponseCode()) {
                case OK:
                    queryAvailableSkus();
                    break;
                case BILLING_UNAVAILABLE:
                case DEVELOPER_ERROR:
                case ERROR:
                case FEATURE_NOT_SUPPORTED:
                case ITEM_ALREADY_OWNED:
                case ITEM_NOT_OWNED:
                case ITEM_UNAVAILABLE:
                case SERVICE_DISCONNECTED:
                case SERVICE_UNAVAILABLE:
                case USER_CANCELED:
                case SERVICE_TIMEOUT:
                default:
                    Toast.makeText(DonationActivity.this, R.string.donation_error_iab_unavailable, LENGTH_LONG).show();
                    Log.w(TAG, "Problem setting up in-app billing: " + resultCode);
                    finish();
                    break;
            }
        }

        @Override
        public void onBillingServiceDisconnected() {
            Log.d(TAG, "onBillingServiceDisconnected");
        }
    });
}
Also used : BillingClientStateListener(com.android.billingclient.api.BillingClientStateListener) BillingResult(com.android.billingclient.api.BillingResult)

Example 14 with BillingResult

use of com.android.billingclient.api.BillingResult 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 15 with BillingResult

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

the class BillingManager method areSubscriptionsSupported.

/**
 * Checks if subscriptions are supported for current client.
 *
 * <p>Note: This method does not automatically retry for RESULT_SERVICE_DISCONNECTED. It is only
 * used in unit tests and after queryPurchases execution, which already has a retry-mechanism
 * implemented.
 *
 * @return boolean value of whether the subscription is supported or not.
 */
private boolean areSubscriptionsSupported() {
    final BillingResult billingResult = myBillingClient.isFeatureSupported(FeatureType.SUBSCRIPTIONS);
    if (billingResult.getResponseCode() != BillingResponseCode.OK) {
        MonetizeApp.printLog(TAG, "areSubscriptionsSupported() got an error response: " + billingResult.getResponseCode());
        notifyBillingError(R.string.err_subscription_not_supported);
    }
    return billingResult.getResponseCode() == BillingResponseCode.OK;
}
Also used : BillingResult(com.android.billingclient.api.BillingResult)

Aggregations

BillingResult (com.android.billingclient.api.BillingResult)28 SkuDetails (com.android.billingclient.api.SkuDetails)16 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)15 ArrayList (java.util.ArrayList)14 BillingClientStateListener (com.android.billingclient.api.BillingClientStateListener)10 ConsumeResponseListener (com.android.billingclient.api.ConsumeResponseListener)10 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)10 List (java.util.List)10 NonNull (androidx.annotation.NonNull)9 ConsumeParams (com.android.billingclient.api.ConsumeParams)9 Purchase (com.android.billingclient.api.Purchase)9 AcknowledgePurchaseResponseListener (com.android.billingclient.api.AcknowledgePurchaseResponseListener)8 Nullable (androidx.annotation.Nullable)7 AcknowledgePurchaseParams (com.android.billingclient.api.AcknowledgePurchaseParams)7 BillingClient (com.android.billingclient.api.BillingClient)7 BillingFlowParams (com.android.billingclient.api.BillingFlowParams)7 PurchasesUpdatedListener (com.android.billingclient.api.PurchasesUpdatedListener)7 Activity (android.app.Activity)5 Context (android.content.Context)5 StringRes (androidx.annotation.StringRes)5