Search in sources :

Example 1 with SkuDetailsResponseListener

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

the class BillingManager method querySkuDetailsAsync.

/**
 * Query SKUs available for purchase
 */
public void querySkuDetailsAsync(@SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Creating a runnable from the request to use it inside our connection retry policy below
    Runnable queryRequest = new Runnable() {

        @Override
        public void run() {
            // Query the purchase async
            SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
            params.setSkusList(skuList).setType(itemType);
            mBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {

                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
        }
    };
    executeServiceRequest(queryRequest);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams)

Example 2 with SkuDetailsResponseListener

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

the class BillingManager method querySkuDetailsAsync.

/**
 * Queries SKU Details from Google Play Remote Server of SKU Types (InApp and Subscription).
 *
 * @param skuResultList       contains SKU ID and Price Details returned by the sku details
 *                            query.
 * @param params              contains list of SKU IDs and SKU Type (InApp or Subscription).
 * @param billingType         InApp or Subscription.
 * @param executeWhenFinished contains query for InApp SKU Details that will be run after
 *                            getting results of Subscription based SKU Details.
 */
private void querySkuDetailsAsync(final List<SkuDetails> skuResultList, final SkuDetailsParams.Builder params, @SkuType final String billingType, final Runnable executeWhenFinished) {
    // Creating a runnable from the request to use it inside our connection retry policy below
    final Runnable queryRequest = new Runnable() {

        @Override
        public void run() {
            myBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {

                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    // Process the result.
                    if (responseCode != BillingResponse.OK) {
                        BaseActivity.printLog(TAG, "Unsuccessful query for type: " + billingType + ". Error code: " + responseCode);
                    } else if (skuDetailsList != null && skuDetailsList.size() > 0) {
                        skuResultList.addAll(skuDetailsList);
                    }
                    if (executeWhenFinished != null) {
                        executeWhenFinished.run();
                        return;
                    }
                    if (skuResultList.size() == 0) {
                        BaseActivity.printLog(TAG, "sku error: " + context.getString(R.string.err_no_sku));
                    } else {
                        BaseActivity.printLog(TAG, "storing sku list locally");
                        storeSkuDetailsLocally(skuResultList);
                    }
                }
            });
        }
    };
    executeServiceRequest(queryRequest);
}
Also used : BillingSkuDetails(com.litekite.inappbilling.room.entity.BillingSkuDetails) SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener)

Example 3 with SkuDetailsResponseListener

use of com.android.billingclient.api.SkuDetailsResponseListener in project PhoneProfilesPlus by henrichg.

the class BillingManager method querySkuDetailsAsync.

public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType, final List<String> skuList, final SkuDetailsResponseListener listener) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {

        @Override
        public void run() {
            SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder().setSkusList(skuList).setType(itemType).build();
            mBillingClient.querySkuDetailsAsync(skuDetailsParams, new SkuDetailsResponseListener() {

                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    listener.onSkuDetailsResponse(responseCode, skuDetailsList);
                }
            });
        }
    };
    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams)

Example 4 with SkuDetailsResponseListener

use of com.android.billingclient.api.SkuDetailsResponseListener in project PhoneProfilesPlus by henrichg.

the class DonationFragment method updateGUIAfterBillingConnected.

public void updateGUIAfterBillingConnected() {
    // Start querying for SKUs
    PPApplication.logE(TAG, "handleManagerAndUiReady");
    final List<String> inAppSkus = mBillingProvider.getBillingManager().getSkus(/*!mDebug, */
    BillingClient.SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(BillingClient.SkuType.INAPP, inAppSkus, new SkuDetailsResponseListener() {

        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            PPApplication.logE(TAG, "onSkuDetailsResponse responseCode=" + responseCode);
            String[] prices = new String[] { "1 €", "2 €", "3 €", "5 €", "8 €", "13 €", "20 €" };
            if (skuDetailsList != null)
                PPApplication.logE(TAG, "onSkuDetailsResponse skuDetailsList=" + skuDetailsList.size());
            if (responseCode == BillingClient.BillingResponse.OK && skuDetailsList != null) {
                if (skuDetailsList.size() > 0) {
                    SKU_DETAILS = new ArrayList<>();
                    for (int i = 0; i < inAppSkus.size(); i++) {
                        for (int j = 0; j < skuDetailsList.size(); j++) {
                            if (skuDetailsList.get(j).getSku().equals(inAppSkus.get(i))) {
                                PPApplication.logE(TAG, "Found sku: " + skuDetailsList.get(j));
                                SKU_DETAILS.add(skuDetailsList.get(j));
                                prices[i] = skuDetailsList.get(j).getPrice();
                                break;
                            }
                        }
                    }
                    // update the UI
                    displayAnErrorIfNeeded(BillingClient.BillingResponse.OK);
                    if (getActivity() != null) {
                        ArrayAdapter<CharSequence> adapter;
                        adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, prices);
                        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        mGoogleSpinner.setAdapter(adapter);
                        btGoogle.setEnabled(true);
                    }
                } else {
                    displayAnErrorIfNeeded(BillingClient.BillingResponse.FEATURE_NOT_SUPPORTED);
                }
            }
        }
    });
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) ArrayList(java.util.ArrayList) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with SkuDetailsResponseListener

use of com.android.billingclient.api.SkuDetailsResponseListener in project react-native-iap by dooboolab.

the class RNIapModule method getItemsByType.

@ReactMethod
public void getItemsByType(String type, ReadableArray skus, final Promise promise) {
    if (mService == null) {
        promise.reject(E_NOT_PREPARED, "IAP not prepared. Check if Google Play service is available.");
        return;
    }
    ArrayList<String> skusList = new ArrayList<>();
    for (int i = 0; i < skus.size(); i++) {
        skusList.add(skus.getString(i));
    }
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skusList).setType(type);
    mBillingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {

        @Override
        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
            Log.d(TAG, "responseCode: " + responseCode);
            if (responseCode == BillingClient.BillingResponse.OK) {
                WritableArray items = Arguments.createArray();
                for (SkuDetails skuDetails : skuDetailsList) {
                    WritableMap item = Arguments.createMap();
                    item.putString("productId", skuDetails.getSku());
                    item.putString("price", String.valueOf(skuDetails.getPriceAmountMicros() / 1000000));
                    item.putString("currency", skuDetails.getPriceCurrencyCode());
                    item.putString("type", skuDetails.getType());
                    item.putString("localizedPrice", skuDetails.getPrice());
                    item.putString("title", skuDetails.getTitle());
                    item.putString("description", skuDetails.getDescription());
                    items.pushMap(item);
                }
                promise.resolve(items);
            } else {
                rejectPromiseWithBillingError(promise, responseCode);
            }
        }
    });
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) SkuDetailsResponseListener(com.android.billingclient.api.SkuDetailsResponseListener) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) ArrayList(java.util.ArrayList) SkuDetailsParams(com.android.billingclient.api.SkuDetailsParams) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

SkuDetails (com.android.billingclient.api.SkuDetails)7 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)7 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)4 ArrayList (java.util.ArrayList)3 ArrayAdapter (android.widget.ArrayAdapter)2 ReactMethod (com.facebook.react.bridge.ReactMethod)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 BillingSkuDetails (com.litekite.inappbilling.room.entity.BillingSkuDetails)1