Search in sources :

Example 6 with SkuDetails

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

the class DonationFragment method purchaseSuccessful.

public void purchaseSuccessful(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, "purchaseSuccessful - sku=" + sku);
                    PPApplication.logE(TAG, "purchaseSuccessful - currency=" + skuDetail.getPriceCurrencyCode());
                    PPApplication.logE(TAG, "purchaseSuccessful - priceS=" + skuDetail.getPrice());
                    PPApplication.logE(TAG, "purchaseSuccessful - priceMicros=" + skuDetail.getPriceAmountMicros());
                    PPApplication.logE(TAG, "purchaseSuccessful - 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(true));
                }
            }
        }
    }
    if (getActivity() != null) {
        PPApplication.setDonationDonated(getActivity().getApplicationContext());
        Toast.makeText(getActivity().getApplicationContext(), getString(R.string.donation_thanks_dialog), Toast.LENGTH_LONG).show();
    }
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) PurchaseEvent(com.crashlytics.android.answers.PurchaseEvent) Purchase(com.android.billingclient.api.Purchase)

Example 7 with SkuDetails

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

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

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

use of com.android.billingclient.api.SkuDetails 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)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