@capgo/native-purchases 0.0.30 → 0.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -209,61 +209,67 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
209
209
|
.setProductList(productList)
|
|
210
210
|
.build();
|
|
211
211
|
this.initBillingClient(call);
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
212
|
+
try {
|
|
213
|
+
billingClient.queryProductDetailsAsync(
|
|
214
|
+
params,
|
|
215
|
+
new ProductDetailsResponseListener() {
|
|
216
|
+
public void onProductDetailsResponse(
|
|
217
|
+
BillingResult billingResult,
|
|
218
|
+
List<ProductDetails> productDetailsList
|
|
219
|
+
) {
|
|
220
|
+
if (productDetailsList.size() == 0) {
|
|
221
|
+
billingClient.endConnection();
|
|
222
|
+
billingClient = null;
|
|
223
|
+
call.reject("Product not found");
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// Process the result
|
|
227
|
+
List<BillingFlowParams.ProductDetailsParams> productDetailsParamsList = new ArrayList<>();
|
|
228
|
+
for (ProductDetails productDetailsItem : productDetailsList) {
|
|
229
|
+
BillingFlowParams.ProductDetailsParams.Builder productDetailsParams = BillingFlowParams.ProductDetailsParams
|
|
230
|
+
.newBuilder()
|
|
231
|
+
.setProductDetails(productDetailsItem);
|
|
232
|
+
if (productType.equals("subs")) {
|
|
233
|
+
// list the SubscriptionOfferDetails and find the one who match the planIdentifier if not found get the first one
|
|
234
|
+
ProductDetails.SubscriptionOfferDetails selectedOfferDetails =
|
|
235
|
+
null;
|
|
236
|
+
for (ProductDetails.SubscriptionOfferDetails offerDetails : productDetailsItem.getSubscriptionOfferDetails()) {
|
|
237
|
+
if (offerDetails.getOfferId().equals(planIdentifier)) {
|
|
238
|
+
selectedOfferDetails = offerDetails;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
239
241
|
}
|
|
242
|
+
if (selectedOfferDetails == null) {
|
|
243
|
+
selectedOfferDetails =
|
|
244
|
+
productDetailsItem.getSubscriptionOfferDetails().get(0);
|
|
245
|
+
}
|
|
246
|
+
productDetailsParams.setOfferToken(
|
|
247
|
+
selectedOfferDetails.getOfferToken()
|
|
248
|
+
);
|
|
240
249
|
}
|
|
241
|
-
|
|
242
|
-
selectedOfferDetails =
|
|
243
|
-
productDetailsItem.getSubscriptionOfferDetails().get(0);
|
|
244
|
-
}
|
|
245
|
-
productDetailsParams.setOfferToken(
|
|
246
|
-
selectedOfferDetails.getOfferToken()
|
|
247
|
-
);
|
|
250
|
+
productDetailsParamsList.add(productDetailsParams.build());
|
|
248
251
|
}
|
|
249
|
-
|
|
252
|
+
BillingFlowParams billingFlowParams = BillingFlowParams
|
|
253
|
+
.newBuilder()
|
|
254
|
+
.setProductDetailsParamsList(productDetailsParamsList)
|
|
255
|
+
.build();
|
|
256
|
+
// Launch the billing flow
|
|
257
|
+
BillingResult billingResult2 = billingClient.launchBillingFlow(
|
|
258
|
+
getActivity(),
|
|
259
|
+
billingFlowParams
|
|
260
|
+
);
|
|
261
|
+
Log.i(
|
|
262
|
+
"NativePurchases",
|
|
263
|
+
"onProductDetailsResponse2" + billingResult2
|
|
264
|
+
);
|
|
250
265
|
}
|
|
251
|
-
BillingFlowParams billingFlowParams = BillingFlowParams
|
|
252
|
-
.newBuilder()
|
|
253
|
-
.setProductDetailsParamsList(productDetailsParamsList)
|
|
254
|
-
.build();
|
|
255
|
-
// Launch the billing flow
|
|
256
|
-
BillingResult billingResult2 = billingClient.launchBillingFlow(
|
|
257
|
-
getActivity(),
|
|
258
|
-
billingFlowParams
|
|
259
|
-
);
|
|
260
|
-
Log.i(
|
|
261
|
-
"NativePurchases",
|
|
262
|
-
"onProductDetailsResponse2" + billingResult2
|
|
263
|
-
);
|
|
264
266
|
}
|
|
265
|
-
|
|
266
|
-
)
|
|
267
|
+
);
|
|
268
|
+
} catch (Exception e) {
|
|
269
|
+
billingClient.endConnection();
|
|
270
|
+
billingClient = null;
|
|
271
|
+
call.reject(e.getMessage());
|
|
272
|
+
}
|
|
267
273
|
}
|
|
268
274
|
|
|
269
275
|
@PluginMethod
|
|
@@ -283,7 +289,9 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
283
289
|
call.reject("planIdentifier cannot be empty if productType is subs");
|
|
284
290
|
return;
|
|
285
291
|
}
|
|
286
|
-
if (
|
|
292
|
+
if (
|
|
293
|
+
productIdentifiersArray == null || productIdentifiersArray.length() == 0
|
|
294
|
+
) {
|
|
287
295
|
call.reject("productIdentifiers array missing");
|
|
288
296
|
return;
|
|
289
297
|
}
|
|
@@ -319,109 +327,117 @@ public class NativePurchasesPlugin extends Plugin {
|
|
|
319
327
|
.setProductList(productList)
|
|
320
328
|
.build();
|
|
321
329
|
this.initBillingClient(call);
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
330
|
+
try {
|
|
331
|
+
billingClient.queryProductDetailsAsync(
|
|
332
|
+
params,
|
|
333
|
+
new ProductDetailsResponseListener() {
|
|
334
|
+
public void onProductDetailsResponse(
|
|
335
|
+
BillingResult billingResult,
|
|
336
|
+
List<ProductDetails> productDetailsList
|
|
337
|
+
) {
|
|
338
|
+
if (productDetailsList.size() == 0) {
|
|
339
|
+
billingClient.endConnection();
|
|
340
|
+
billingClient = null;
|
|
341
|
+
call.reject("Product not found");
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
Log.i(
|
|
345
|
+
"NativePurchases",
|
|
346
|
+
"onProductDetailsResponse" + billingResult + productDetailsList
|
|
347
|
+
);
|
|
348
|
+
// Process the result
|
|
349
|
+
JSObject ret = new JSObject();
|
|
350
|
+
JSONArray products = new JSONArray();
|
|
351
|
+
Number productIdIndex = 0;
|
|
352
|
+
for (ProductDetails productDetails : productDetailsList) {
|
|
353
|
+
JSObject product = new JSObject();
|
|
354
|
+
product.put("identifier", productDetails.getProductId());
|
|
355
|
+
product.put("title", productDetails.getTitle());
|
|
356
|
+
product.put("description", productDetails.getDescription());
|
|
357
|
+
if (productType.equals("inapp")) {
|
|
358
|
+
product.put(
|
|
359
|
+
"price",
|
|
360
|
+
productDetails
|
|
361
|
+
.getOneTimePurchaseOfferDetails()
|
|
362
|
+
.getPriceAmountMicros() /
|
|
363
|
+
1000000.0
|
|
364
|
+
);
|
|
365
|
+
product.put(
|
|
366
|
+
"priceString",
|
|
367
|
+
productDetails
|
|
368
|
+
.getOneTimePurchaseOfferDetails()
|
|
369
|
+
.getFormattedPrice()
|
|
370
|
+
);
|
|
371
|
+
product.put(
|
|
372
|
+
"currencyCode",
|
|
373
|
+
productDetails
|
|
374
|
+
.getOneTimePurchaseOfferDetails()
|
|
375
|
+
.getPriceCurrencyCode()
|
|
376
|
+
);
|
|
377
|
+
} else {
|
|
378
|
+
// productIdIndex is used to get the correct SubscriptionOfferDetails by productIdentifiersArray index and increment it
|
|
379
|
+
String subscriptionOfferIdentifier = productIdentifiers.get(
|
|
380
|
+
productIdIndex.intValue()
|
|
381
|
+
);
|
|
382
|
+
productIdIndex = productIdIndex.intValue() + 1;
|
|
383
|
+
// get the SubscriptionOfferDetails who match the subscriptionOfferIdentifier
|
|
384
|
+
ProductDetails.SubscriptionOfferDetails selectedOfferDetails =
|
|
385
|
+
null;
|
|
386
|
+
for (ProductDetails.SubscriptionOfferDetails offerDetails : productDetails.getSubscriptionOfferDetails()) {
|
|
387
|
+
if (
|
|
388
|
+
offerDetails
|
|
389
|
+
.getOfferId()
|
|
390
|
+
.equals(subscriptionOfferIdentifier)
|
|
391
|
+
) {
|
|
392
|
+
selectedOfferDetails = offerDetails;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
383
395
|
}
|
|
396
|
+
if (selectedOfferDetails == null) {
|
|
397
|
+
selectedOfferDetails =
|
|
398
|
+
productDetails.getSubscriptionOfferDetails().get(0);
|
|
399
|
+
}
|
|
400
|
+
product.put(
|
|
401
|
+
"price",
|
|
402
|
+
selectedOfferDetails
|
|
403
|
+
.getPricingPhases()
|
|
404
|
+
.getPricingPhaseList()
|
|
405
|
+
.get(0)
|
|
406
|
+
.getPriceAmountMicros() /
|
|
407
|
+
1000000.0
|
|
408
|
+
);
|
|
409
|
+
product.put(
|
|
410
|
+
"priceString",
|
|
411
|
+
selectedOfferDetails
|
|
412
|
+
.getPricingPhases()
|
|
413
|
+
.getPricingPhaseList()
|
|
414
|
+
.get(0)
|
|
415
|
+
.getFormattedPrice()
|
|
416
|
+
);
|
|
417
|
+
product.put(
|
|
418
|
+
"currencyCode",
|
|
419
|
+
selectedOfferDetails
|
|
420
|
+
.getPricingPhases()
|
|
421
|
+
.getPricingPhaseList()
|
|
422
|
+
.get(0)
|
|
423
|
+
.getPriceCurrencyCode()
|
|
424
|
+
);
|
|
384
425
|
}
|
|
385
|
-
if (selectedOfferDetails == null) {
|
|
386
|
-
selectedOfferDetails =
|
|
387
|
-
productDetails.getSubscriptionOfferDetails().get(0);
|
|
388
|
-
}
|
|
389
|
-
product.put(
|
|
390
|
-
"price",
|
|
391
|
-
selectedOfferDetails
|
|
392
|
-
.getPricingPhases()
|
|
393
|
-
.getPricingPhaseList()
|
|
394
|
-
.get(0)
|
|
395
|
-
.getPriceAmountMicros() /
|
|
396
|
-
1000000.0
|
|
397
|
-
);
|
|
398
|
-
product.put(
|
|
399
|
-
"priceString",
|
|
400
|
-
selectedOfferDetails
|
|
401
|
-
.getPricingPhases()
|
|
402
|
-
.getPricingPhaseList()
|
|
403
|
-
.get(0)
|
|
404
|
-
.getFormattedPrice()
|
|
405
|
-
);
|
|
406
|
-
product.put(
|
|
407
|
-
"currencyCode",
|
|
408
|
-
selectedOfferDetails
|
|
409
|
-
.getPricingPhases()
|
|
410
|
-
.getPricingPhaseList()
|
|
411
|
-
.get(0)
|
|
412
|
-
.getPriceCurrencyCode()
|
|
413
|
-
);
|
|
414
|
-
}
|
|
415
426
|
|
|
416
|
-
|
|
417
|
-
|
|
427
|
+
product.put("isFamilyShareable", false);
|
|
428
|
+
products.put(product);
|
|
429
|
+
}
|
|
430
|
+
ret.put("products", products);
|
|
431
|
+
billingClient.endConnection();
|
|
432
|
+
billingClient = null;
|
|
433
|
+
call.resolve(ret);
|
|
418
434
|
}
|
|
419
|
-
ret.put("products", products);
|
|
420
|
-
billingClient.endConnection();
|
|
421
|
-
billingClient = null;
|
|
422
|
-
call.resolve(ret);
|
|
423
435
|
}
|
|
424
|
-
|
|
425
|
-
)
|
|
436
|
+
);
|
|
437
|
+
} catch (Exception e) {
|
|
438
|
+
billingClient.endConnection();
|
|
439
|
+
billingClient = null;
|
|
440
|
+
call.reject(e.getMessage());
|
|
441
|
+
}
|
|
426
442
|
}
|
|
427
443
|
}
|