MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / getProducts

Method getProducts

src/plugins/iap/src/com/foxdebug/iap/Iap.java:195–259  ·  view source on GitHub ↗
(
    List<String> idList,
    CallbackContext callbackContext
  )

Source from the content-addressed store, hash-verified

193 }
194
195 private void getProducts(
196 List<String> idList,
197 CallbackContext callbackContext
198 ) {
199 if (billingClient == null) {
200 billingClient = getBillingClient();
201 callbackContext.error("Billing client is not connected");
202 return;
203 }
204 List<QueryProductDetailsParams.Product> productList = new ArrayList<>();
205 for (String productId : idList) {
206 productList.add(
207 QueryProductDetailsParams.Product.newBuilder()
208 .setProductId(productId)
209 .setProductType(BillingClient.ProductType.INAPP)
210 .build()
211 );
212 }
213 QueryProductDetailsParams params = QueryProductDetailsParams.newBuilder()
214 .setProductList(productList)
215 .build();
216
217 billingClient.queryProductDetailsAsync(
218 params,
219 new ProductDetailsResponseListener() {
220 public void onProductDetailsResponse(
221 BillingResult billingResult,
222 QueryProductDetailsResult queryProductDetailsResult
223 ) {
224 try {
225 int responseCode = billingResult.getResponseCode();
226 if (responseCode == BillingResponseCode.OK) {
227 List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
228 JSONArray products = new JSONArray();
229 for (ProductDetails productDetails : productDetailsList) {
230 JSONObject product = new JSONObject();
231 ProductDetails.OneTimePurchaseOfferDetails offerDetails = productDetails.getOneTimePurchaseOfferDetails();
232 if (offerDetails != null) {
233 product.put("productId", productDetails.getProductId());
234 product.put("title", productDetails.getTitle());
235 product.put("description", productDetails.getDescription());
236 product.put("price", offerDetails.getFormattedPrice());
237 product.put(
238 "priceAmountMicros",
239 offerDetails.getPriceAmountMicros()
240 );
241 product.put(
242 "priceCurrencyCode",
243 offerDetails.getPriceCurrencyCode()
244 );
245 product.put("type", productDetails.getProductType());
246 }
247 products.put(product);
248 }
249 callbackContext.success(products);
250 } else {
251 callbackContext.error(responseCode);
252 }

Callers 1

runMethod · 0.95

Calls 3

getBillingClientMethod · 0.95
addMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected