com.android.billingclient.api.SkuDetails Java Examples

The following examples show how to use com.android.billingclient.api.SkuDetails. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultBillingManager.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
private void loadProducts() {
    List<String> skuList = new ArrayList<>();
    skuList.add(SKU_DONATION);

    SkuDetailsParams params = SkuDetailsParams.newBuilder()
            .setSkusList(skuList)
            .setType(BillingClient.SkuType.INAPP)
            .build();

    mBillingClient.querySkuDetailsAsync(params, (billingResult, skuDetailsList) -> {
        if (billingResult.getResponseCode() != BillingClient.BillingResponseCode.OK) {
            Log.d(TAG, String.format("Unable to query sku details: %d - %s", billingResult.getResponseCode(), billingResult.getDebugMessage()));
            return;
        }

        ArrayList<BillingProduct> products = new ArrayList<>(skuDetailsList.size());
        for (SkuDetails skuDetails : skuDetailsList)
            products.add(new SkuDetailsBillingProduct(skuDetails));

        mAllProducts.setValue(products);
        invalidateProductsPurchaseStatus();
    });
}
 
Example #2
Source File: GooglePlayBillingVendor.java    From Cashier with Apache License 2.0 6 votes vote down vote up
@Override
public void getProductDetails(@NonNull Context context, @NonNull final String sku, final boolean isSubscription,
                              @NonNull final ProductDetailsListener listener) {
    throwIfUninitialized();

    api.getSkuDetails(
            isSubscription ? SkuType.SUBS : SkuType.INAPP,
            Collections.singletonList(sku),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    if (responseCode == BillingResponse.OK && skuDetailsList.size() == 1) {
                        logSafely("Successfully got sku details for " + sku + "!");
                        listener.success(
                                GooglePlayBillingProduct.create(skuDetailsList.get(0), isSubscription ? SkuType.SUBS : SkuType.INAPP)
                        );
                    } else {
                        logSafely("Error getting sku details for " + sku + " with code "+responseCode);
                        listener.failure(getDetailsError(responseCode));
                    }
                }
            }
    );
}
 
Example #3
Source File: GoogleIap.java    From remixed-dungeon with GNU General Public License v3.0 6 votes vote down vote up
public void querySkuList(final List<String> skuList) {
    Runnable queryRequest = () -> {
        SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
        params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
        mBillingClient.querySkuDetailsAsync(params.build(),
                (billingResult, list) -> {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK
                            && list != null) {
                        mSkuDetails = new HashMap<>();
                        for (SkuDetails skuDetails : list) {
                            mSkuDetails.put(skuDetails.getSku().toLowerCase(Locale.ROOT), skuDetails);
                        }
                    }
                });
    };
    executeServiceRequest(queryRequest);
}
 
Example #4
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
public void startPurchaseFlow(final SkuDetails skuDetails) {
    // Specify a runnable to start when connection to Billing client is established
    Runnable executeOnConnectedService = new Runnable() {
        @Override
        public void run() {
            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                    .setSkuDetails(skuDetails)
                    .build();
            int responseCode = mBillingClient.launchBillingFlow(mActivity, billingFlowParams).getResponseCode();
            //PPApplication.logE(TAG, "startPurchaseFlow responseCode="+responseCode);
            getFragment().displayAnErrorIfNeeded(responseCode);
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #5
Source File: BillingManager.java    From PhoneProfilesPlus with Apache License 2.0 6 votes vote down vote up
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(@NonNull BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                            listener.onSkuDetailsResponse(billingResult, skuDetailsList);
                        }
                    });
        }
    };

    // If Billing client was disconnected, we retry 1 time and if success, execute the query
    startServiceConnectionIfNeeded(executeOnConnectedService);
}
 
Example #6
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 6 votes vote down vote up
private List<Map<String, Object>> getProductsFromSkuDetails(List<SkuDetails> skuDetailsList) {
    List<Map<String, Object>> products = new ArrayList<>();

    for (SkuDetails details : skuDetailsList) {
        String type = getProductType(details.getType());
        if (type == null) continue; // skip unsupported sku type

        Map<String, Object> product = new HashMap<>();
        product.put("identifier", details.getSku());
        product.put("price", details.getPrice());
        product.put("title", details.getTitle());
        product.put("description", details.getDescription());
        product.put("currency", details.getPriceCurrencyCode());
        product.put("amount", details.getPriceAmountMicros() / 10_000L);
        product.put("type", type);
        products.add(product);
    }

    return products;
}
 
Example #7
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    // Start querying for SKUs
    List<String> inAppSkus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, inAppSkus,
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    if (responseCode == BillingResponse.OK
                            && skuDetailsList != null) {
                        for (SkuDetails details : skuDetailsList) {
                            Log.w(TAG, "Got a SKU: " + details);
                        }
                    }
                }
            });
    
    // Show the UI
    displayAnErrorIfNeeded();
}
 
Example #8
Source File: TestHelper.java    From Cashier with Apache License 2.0 6 votes vote down vote up
static void mockSkuDetails(AbstractGooglePlayBillingApi api, String type, final Map<String, SkuDetails> skuDetailsMap) {
    doAnswer(
            new Answer() {
                @Override
                public Object answer(InvocationOnMock invocation) throws Throwable {
                    List<String> skus = invocation.getArgument(1);
                    SkuDetailsResponseListener listener = invocation.getArgument(2);
                    List<SkuDetails> result = new ArrayList<>();
                    for (String sku : skus) {
                        result.add(skuDetailsMap.get(sku));
                    }
                    listener.onSkuDetailsResponse(BillingClient.BillingResponse.OK, result);
                    return null;
                }
            }
    ).when(api).getSkuDetails(
            eq(type),
            Mockito.<String>anyList(),
            any(SkuDetailsResponseListener.class));
}
 
Example #9
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #10
Source File: ActivityBilling.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
private void querySkus(List<String> query) {
    Log.i("IAB query SKUs");
    SkuDetailsParams.Builder builder = SkuDetailsParams.newBuilder();
    builder.setSkusList(query);
    builder.setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(builder.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult result, List<SkuDetails> skuDetailsList) {
                    if (result.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                        for (SkuDetails skuDetail : skuDetailsList) {
                            Log.i("IAB SKU detail=" + skuDetail);
                            skuDetails.put(skuDetail.getSku(), skuDetail);
                            for (IBillingListener listener : listeners)
                                listener.onSkuDetails(skuDetail.getSku(), skuDetail.getPrice());
                        }
                    } else
                        reportError(result, "IAB query SKUs");
                }
            });
}
 
Example #11
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    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);
                }
            });
}
 
Example #12
Source File: TestData.java    From Cashier with Apache License 2.0 5 votes vote down vote up
static SkuDetails getSkuDetail(String sku) {
    try {
        return new TestSkuDetails(productsMap.get(sku));
    } catch (Exception e) {
        return null;
    }
}
 
Example #13
Source File: GooglePlayBillingProduct.java    From Cashier with Apache License 2.0 5 votes vote down vote up
public static Product create(SkuDetails details, @SkuType String type) {
    return Product.create(
            GooglePlayBillingConstants.VENDOR_PACKAGE,
            details.getSku(),
            details.getPrice(),
            details.getPriceCurrencyCode(),
            details.getTitle(),
            details.getDescription(),
            type.equals(SkuType.SUBS),
            details.getPriceAmountMicros()
    );
}
 
Example #14
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                List<SkuDetails> skuDetailsList) {
            // If we successfully got SKUs, add a header in front of it
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #15
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                                         List<SkuDetails> skuDetailsList) {
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #16
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void buyProduct(@NonNull Activity activity, @NonNull SkuDetails product) {
    BillingFlowParams flowParams = BillingFlowParams.newBuilder()
            .setSkuDetails(product)
            .build();

    BillingResult result = billingClient.launchBillingFlow(activity, flowParams);
    if (result.getResponseCode() != BillingResponseCode.OK)
        handleBillingErrors(result.getResponseCode());
}
 
Example #17
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
        final List<String> skuList, final SkuDetailsResponseListener listener) {
    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);
                }
            });
}
 
Example #18
Source File: AcquireFragment.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
/**
 * Executes query for SKU details at the background thread
 */
private void handleManagerAndUiReady() {
    final List<SkuRowData> inList = new ArrayList<>();
    SkuDetailsResponseListener responseListener = new SkuDetailsResponseListener() {
        @Override
        public void onSkuDetailsResponse(int responseCode,
                                         List<SkuDetails> skuDetailsList) {
            if (responseCode == BillingResponse.OK && skuDetailsList != null) {
                // Repacking the result for an adapter
                for (SkuDetails details : skuDetailsList) {
                    Log.i(TAG, "Found sku: " + details);
                    inList.add(new SkuRowData(details.getSku(), details.getTitle(),
                            details.getPrice(), details.getDescription(),
                            details.getType()));
                }
                if (inList.size() == 0) {
                    displayAnErrorIfNeeded();
                } else {
                    mAdapter.updateData(inList);
                    setWaitScreen(false);
                }
            }
        }
    };

    // Start querying for in-app SKUs
    List<String> skus = mBillingProvider.getBillingManager().getSkus(SkuType.INAPP);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.INAPP, skus, responseListener);
    // Start querying for subscriptions SKUs
    skus = mBillingProvider.getBillingManager().getSkus(SkuType.SUBS);
    mBillingProvider.getBillingManager().querySkuDetailsAsync(SkuType.SUBS, skus, responseListener);
}
 
Example #19
Source File: BillingManager.java    From play-billing-codelab with Apache License 2.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList, final SkuDetailsResponseListener listener) {
    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);
                }
            });
}
 
Example #20
Source File: PictureInPictureUpgradeActivity.java    From dtube-mobile-unofficial with Apache License 2.0 5 votes vote down vote up
public void loadSKUs(){
    List<String> skuList = new ArrayList<>();
    skuList.add("upgrade");
    SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
    params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);
    billingClient.querySkuDetailsAsync(params.build(),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(BillingResult billingResult,
                                                 List<SkuDetails> skuDetailsList) {
                    if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && !skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            if (skuDetails.getSku().equals("upgrade")){
                                findViewById(R.id.upgrade_button).setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        BillingFlowParams billingFlowParams = BillingFlowParams
                                                .newBuilder()
                                                .setSkuDetails(skuDetails)
                                                .build();
                                        billingClient.launchBillingFlow(PictureInPictureUpgradeActivity.this, billingFlowParams);
                                    }
                                });
                            }

                        }
                    }
                }
            });
}
 
Example #21
Source File: GooglePlayBillingApi.java    From Cashier with Apache License 2.0 5 votes vote down vote up
@Override
public void launchBillingFlow(@NonNull final Activity activity, @NonNull String sku, @SkuType String itemType) {
    throwIfUnavailable();
    logSafely("Launching billing flow for " + sku + " with type " + itemType);

    getSkuDetails(
            itemType,
            Collections.singletonList(sku),
            new SkuDetailsResponseListener() {
                @Override
                public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                    try {
                        if (responseCode == BillingResponse.OK && skuDetailsList.size() > 0) {
                            BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
                                    .setSkuDetails(skuDetailsList.get(0))
                                    .build();

                            // This will call the {@link PurchasesUpdatedListener} specified in {@link #initialize}
                            billing.launchBillingFlow(activity, billingFlowParams);
                        } else {
                            vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                        }
                    } catch (Exception e) {
                        vendor.onPurchasesUpdated(BillingResponse.ERROR, null);
                    }
                }
            }
    );
}
 
Example #22
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    final SkuDetails item = products.get(position);

    switch (item.getSku()) {
        case "donation.lemonade":
            holder.icon.setImageResource(R.drawable.ic_juice_64dp);
            break;
        case "donation.coffee":
            holder.icon.setImageResource(R.drawable.ic_coffee_64dp);
            break;
        case "donation.hamburger":
            holder.icon.setImageResource(R.drawable.ic_hamburger_64dp);
            break;
        case "donation.pizza":
            holder.icon.setImageResource(R.drawable.ic_pizza_64dp);
            break;
        case "donation.sushi":
            holder.icon.setImageResource(R.drawable.ic_sushi_64dp);
            break;
        case "donation.champagne":
            holder.icon.setImageResource(R.drawable.ic_champagne_64dp);
            break;
    }

    holder.title.setText(item.getTitle());
    holder.description.setText(item.getDescription());
    holder.buy.setText(item.getPrice());
    holder.buy.setOnClickListener(view -> {
        if (listener != null) listener.onItemSelected(item);
    });

    holder.itemView.setOnClickListener(v -> {
        if (listener != null) listener.onItemSelected(item);
    });
}
 
Example #23
Source File: TestData.java    From Cashier with Apache License 2.0 5 votes vote down vote up
static Map<String, SkuDetails> getSkuDetailsMap(List<String> skus) {
    Map<String, SkuDetails> map = new HashMap<>();
    for (String sku : skus) {
        try {
            map.put(sku, new TestSkuDetails(productsMap.get(sku)));
        } catch (Exception e) {}
    }
    return map;
}
 
Example #24
Source File: PreferencesBillingHelper.java    From CommonUtils with Apache License 2.0 5 votes vote down vote up
private void showDonateDialog(@NonNull Activity activity, List<SkuDetails> products) {
    RecyclerView list = new RecyclerView(activity);
    list.setLayoutManager(new LinearLayoutManager(activity, RecyclerView.VERTICAL, false));
    list.setAdapter(new SkuAdapter(activity, products, product -> {
        buyProduct(activity, product);
        listener.dismissDialog();
    }));

    listener.showDialog(new MaterialAlertDialogBuilder(activity)
            .setTitle(activity.getString(R.string.donate))
            .setNegativeButton(android.R.string.cancel, null)
            .setView(list));
}
 
Example #25
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchSubscriptions(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.SUBS)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch Subscriptions!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #26
Source File: BillingPlugin.java    From flutter_billing with Apache License 2.0 5 votes vote down vote up
private void fetchProducts(final List<String> identifiers, final Result result) {
    executeServiceRequest(new Request() {
        @Override
        public void execute() {
            billingClient.querySkuDetailsAsync(
                    SkuDetailsParams.newBuilder()
                                    .setSkusList(identifiers)
                                    .setType(SkuType.INAPP)
                                    .build(),
                    new SkuDetailsResponseListener() {
                        @Override
                        public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
                            if (responseCode == BillingResponse.OK) {
                                List<Map<String, Object>> products = getProductsFromSkuDetails(skuDetailsList);
                                result.success(products);
                            } else {
                                result.error("ERROR", "Failed to fetch products!", null);
                            }
                        }
                    });
        }

        @Override
        public void failed() {
            result.error("UNAVAILABLE", "Billing service is unavailable!", null);
        }
    });
}
 
Example #27
Source File: AccelerateDevelop.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void querySkuDetails() {

        if (!billingServiceConnected) {
            mBillingClient.startConnection(this);
            return;
        }

        SkuDetailsParams.Builder skuDetailsParamsBuilder = SkuDetailsParams.newBuilder();
        List<String> skuList = new ArrayList<>();
        skuList.add(mSkuId);
        skuDetailsParamsBuilder.setSkusList(skuList).setType(BillingClient.SkuType.INAPP);

        mBillingClient.querySkuDetailsAsync(skuDetailsParamsBuilder.build(), new SkuDetailsResponseListener() {
            @Override
            public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
                if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
                    if (!skuDetailsList.isEmpty()) {
                        for (SkuDetails skuDetails : skuDetailsList) {
                            mSkuDetailsMap.put(skuDetails.getSku(), skuDetails);
                        }
                    } else {
                        Log.w(LOG_TAG, "Query SKU details is OK, but SKU list is empty " + billingResult.getDebugMessage());


                    }

                } else {
                    Log.w(LOG_TAG, "Query SKU details warning " + billingResult.getResponseCode() + " " + billingResult.getDebugMessage());
                }
            }
        });
    }
 
Example #28
Source File: BillingManager.java    From SchoolQuest with GNU General Public License v3.0 5 votes vote down vote up
public void querySkuDetailsAsync(@BillingClient.SkuType final String itemType,
                                 final List<String> skuList,
                                 final SkuDetailsResponseListener listener) {
    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);
        }
    });
}
 
Example #29
Source File: PlayBillingWrapper.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public boolean launchPaymentFlow(SkuDetails sku) {
    BillingFlowParams params = BillingFlowParams
            .newBuilder()
            .setSkuDetails(sku)
            .build();

    BillingResult result = mClient.launchBillingFlow(mActivity, params);

    return result.getResponseCode() == BillingClient.BillingResponseCode.OK;
}
 
Example #30
Source File: PaymentActivity.java    From android-browser-helper with Apache License 2.0 5 votes vote down vote up
@Override
public void onGotSkuDetails() {
    List<SkuDetails> details = mWrapper.getSkuDetailsList();

    if (details == null || details.isEmpty()) {
        fail("Play Billing returned did not find SKUs.");
        return;
    }

    if (mWrapper.launchPaymentFlow(mWrapper.getSkuDetailsList().get(0))) return;

    fail("Payment attempt failed (have you already bought the item?).");
}