Search in sources :

Example 11 with SkuDetails

use of com.android.billingclient.api.SkuDetails in project PhoneProfiles 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 12 with SkuDetails

use of com.android.billingclient.api.SkuDetails in project PhoneProfiles by henrichg.

the class DonationFragment method purchaseUnsuccessful.

public void purchaseUnsuccessful(List<Purchase> purchases) {
    if (purchases != null) {
        for (Purchase purchase : purchases) {
            String sku = purchase.getSku();
            for (SkuDetails skuDetail : SKU_DETAILS) {
                if (skuDetail.getSku().equals(sku)) {
                    PPApplication.logE(TAG, "purchaseUnsuccessful - sku=" + sku);
                    PPApplication.logE(TAG, "purchaseUnsuccessful - currency=" + skuDetail.getPriceCurrencyCode());
                    PPApplication.logE(TAG, "purchaseUnsuccessful - priceS=" + skuDetail.getPrice());
                    PPApplication.logE(TAG, "purchaseUnsuccessful - priceMicros=" + skuDetail.getPriceAmountMicros());
                    PPApplication.logE(TAG, "purchaseUnsuccessful - price=" + skuDetail.getPriceAmountMicros() / 1000000.0);
                    Answers.getInstance().logPurchase(new PurchaseEvent().putItemPrice(BigDecimal.valueOf(skuDetail.getPriceAmountMicros() / 1000000.0)).putCurrency(Currency.getInstance(skuDetail.getPriceCurrencyCode())).putItemName("Donation").putItemId(sku).putSuccess(false));
                }
            }
        }
    }
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) PurchaseEvent(com.crashlytics.android.answers.PurchaseEvent) Purchase(com.android.billingclient.api.Purchase)

Example 13 with SkuDetails

use of com.android.billingclient.api.SkuDetails in project PhoneProfiles 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 14 with SkuDetails

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

the class BillingManager method storeSkuDetailsLocally.

/**
 * Stores SKU Details on local storage.
 *
 * @param skuDetailsList list of SKU Details returned from the queries.
 */
private void storeSkuDetailsLocally(List<SkuDetails> skuDetailsList) {
    final List<BillingSkuDetails> billingSkuDetailsList = new ArrayList<>();
    for (SkuDetails skuDetails : skuDetailsList) {
        BillingSkuDetails billingSkuDetails = new BillingSkuDetails();
        billingSkuDetails.skuID = skuDetails.getSku();
        billingSkuDetails.skuType = skuDetails.getType();
        billingSkuDetails.skuPrice = skuDetails.getPrice();
        billingSkuDetailsList.add(billingSkuDetails);
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            AppDatabase.getAppDatabase(context).getBillingDao().insertSkuDetails(billingSkuDetailsList);
        }
    }).start();
}
Also used : BillingSkuDetails(com.litekite.inappbilling.room.entity.BillingSkuDetails) SkuDetails(com.android.billingclient.api.SkuDetails) ArrayList(java.util.ArrayList) BillingSkuDetails(com.litekite.inappbilling.room.entity.BillingSkuDetails)

Aggregations

SkuDetails (com.android.billingclient.api.SkuDetails)14 SkuDetailsResponseListener (com.android.billingclient.api.SkuDetailsResponseListener)7 ArrayList (java.util.ArrayList)6 Purchase (com.android.billingclient.api.Purchase)4 SkuDetailsParams (com.android.billingclient.api.SkuDetailsParams)4 PurchaseEvent (com.crashlytics.android.answers.PurchaseEvent)4 ArrayAdapter (android.widget.ArrayAdapter)2 BillingSkuDetails (com.litekite.inappbilling.room.entity.BillingSkuDetails)2 ReactMethod (com.facebook.react.bridge.ReactMethod)1 WritableArray (com.facebook.react.bridge.WritableArray)1 WritableMap (com.facebook.react.bridge.WritableMap)1 BundleBuilder (com.zegoggles.smssync.utils.BundleBuilder)1