Search in sources :

Example 1 with SkuDetails

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

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

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

the class DonationActivity method onSkuDetailsResponse.

@Override
public void onSkuDetailsResponse(@BillingResponse int responseCode, List<SkuDetails> details) {
    log("onSkuDetailsResponse(" + responseCode + ", " + details + ")");
    if (isFinishing() || responseCode != OK) {
        Log.w(TAG, "failed to query inventory: " + responseCode);
        return;
    }
    List<SkuDetails> skuDetailsList = new ArrayList<SkuDetails>();
    for (SkuDetails d : details) {
        if (d.getSku().startsWith(DONATION_PREFIX)) {
            skuDetailsList.add(d);
        }
    }
    showSelectDialog(skuDetailsList);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) ArrayList(java.util.ArrayList)

Example 5 with SkuDetails

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

the class DonationActivity method showSelectDialog.

private void showSelectDialog(List<SkuDetails> skuDetails) {
    if (billingClient == null)
        return;
    ArrayList<Sku> skus = new ArrayList<Sku>(skuDetails.size());
    for (SkuDetails detail : skuDetails) {
        skus.add(new Sku(detail));
    }
    if (DEBUG_IAB) {
        Collections.addAll(skus, Sku.Test.SKUS);
    }
    Collections.sort(skus);
    final DonationListFragment donationList = new DonationListFragment();
    donationList.setArguments(new BundleBuilder().putParcelableArrayList(SKUS, skus).build());
    donationList.show(getSupportFragmentManager(), null);
}
Also used : SkuDetails(com.android.billingclient.api.SkuDetails) BundleBuilder(com.zegoggles.smssync.utils.BundleBuilder) ArrayList(java.util.ArrayList)

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