@capgo/native-purchases 0.0.24 → 0.0.26

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.
@@ -265,6 +265,7 @@ public class NativePurchasesPlugin extends Plugin {
265
265
  @PluginMethod
266
266
  public void getProducts(PluginCall call) {
267
267
  JSONArray productIdentifiersArray = call.getArray("productIdentifiers");
268
+ String planIdentifier = call.getString("planIdentifier");
268
269
  if (productIdentifiersArray == null) {
269
270
  call.reject("productIdentifiers is missing");
270
271
  return;
@@ -286,7 +287,9 @@ public class NativePurchasesPlugin extends Plugin {
286
287
  productList.add(
287
288
  QueryProductDetailsParams.Product
288
289
  .newBuilder()
289
- .setProductId(productIdentifier)
290
+ .setProductId(
291
+ productType.equals("inapp") ? productIdentifier : planIdentifier
292
+ )
290
293
  .setProductType(
291
294
  productType.equals("inapp")
292
295
  ? BillingClient.ProductType.INAPP
@@ -320,30 +323,80 @@ public class NativePurchasesPlugin extends Plugin {
320
323
  // Process the result
321
324
  JSObject ret = new JSObject();
322
325
  JSONArray products = new JSONArray();
326
+ Number productIdIndex = 0;
323
327
  for (ProductDetails productDetails : productDetailsList) {
324
328
  JSObject product = new JSObject();
325
329
  product.put("identifier", productDetails.getProductId());
326
330
  product.put("title", productDetails.getTitle());
327
331
  product.put("description", productDetails.getDescription());
328
- product.put(
329
- "price",
330
- productDetails
331
- .getOneTimePurchaseOfferDetails()
332
- .getPriceAmountMicros() /
333
- 1000000.0
334
- );
335
- product.put(
336
- "priceString",
337
- productDetails
338
- .getOneTimePurchaseOfferDetails()
339
- .getFormattedPrice()
340
- );
341
- product.put(
342
- "currencyCode",
343
- productDetails
344
- .getOneTimePurchaseOfferDetails()
345
- .getPriceCurrencyCode()
346
- );
332
+ if (productType.equals("inapp")) {
333
+ product.put(
334
+ "price",
335
+ productDetails
336
+ .getOneTimePurchaseOfferDetails()
337
+ .getPriceAmountMicros() /
338
+ 1000000.0
339
+ );
340
+ product.put(
341
+ "priceString",
342
+ productDetails
343
+ .getOneTimePurchaseOfferDetails()
344
+ .getFormattedPrice()
345
+ );
346
+ product.put(
347
+ "currencyCode",
348
+ productDetails
349
+ .getOneTimePurchaseOfferDetails()
350
+ .getPriceCurrencyCode()
351
+ );
352
+ } else {
353
+ // productIdIndex is used to get the correct SubscriptionOfferDetails by productIdentifiersArray index and increment it
354
+ String subscriptionOfferIdentifier = productIdentifiers.get(
355
+ productIdIndex.intValue()
356
+ );
357
+ productIdIndex = productIdIndex.intValue() + 1;
358
+ // get the SubscriptionOfferDetails who match the subscriptionOfferIdentifier
359
+ ProductDetails.SubscriptionOfferDetails selectedOfferDetails =
360
+ null;
361
+ for (ProductDetails.SubscriptionOfferDetails offerDetails : productDetails.getSubscriptionOfferDetails()) {
362
+ if (
363
+ offerDetails.getOfferId().equals(subscriptionOfferIdentifier)
364
+ ) {
365
+ selectedOfferDetails = offerDetails;
366
+ break;
367
+ }
368
+ }
369
+ if (selectedOfferDetails == null) {
370
+ selectedOfferDetails =
371
+ productDetails.getSubscriptionOfferDetails().get(0);
372
+ }
373
+ product.put(
374
+ "price",
375
+ selectedOfferDetails
376
+ .getPricingPhases()
377
+ .getPricingPhaseList()
378
+ .get(0)
379
+ .getPriceAmountMicros() /
380
+ 1000000.0
381
+ );
382
+ product.put(
383
+ "priceString",
384
+ selectedOfferDetails
385
+ .getPricingPhases()
386
+ .getPricingPhaseList()
387
+ .get(0)
388
+ .getFormattedPrice()
389
+ );
390
+ product.put(
391
+ "currencyCode",
392
+ selectedOfferDetails
393
+ .getPricingPhases()
394
+ .getPricingPhaseList()
395
+ .get(0)
396
+ .getPriceCurrencyCode()
397
+ );
398
+ }
399
+
347
400
  product.put("isFamilyShareable", false);
348
401
  products.put(product);
349
402
  }
@@ -1,4 +1,4 @@
1
- import type { NativePurchasesPlugin, PURCHASE_TYPE } from "./definitions";
1
+ import type { NativePurchasesPlugin } from "./definitions";
2
2
  declare const NativePurchases: NativePurchasesPlugin;
3
3
  export * from "./definitions";
4
- export { NativePurchases, PURCHASE_TYPE };
4
+ export { NativePurchases };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,eAAe,GAAG,cAAc,CACpC,iBAAiB,EACjB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;CACnE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAiB,CAAC","sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\n\nimport type { NativePurchasesPlugin, PURCHASE_TYPE } from \"./definitions\";\n\nconst NativePurchases = registerPlugin<NativePurchasesPlugin>(\n \"NativePurchases\",\n {\n web: () => import(\"./web\").then((m) => new m.NativePurchasesWeb()),\n }\n);\n\nexport * from \"./definitions\";\nexport { NativePurchases, PURCHASE_TYPE };\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,eAAe,GAAG,cAAc,CACpC,iBAAiB,EACjB;IACE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;CACnE,CACF,CAAC;AAEF,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\n\nimport type { NativePurchasesPlugin } from \"./definitions\";\n\nconst NativePurchases = registerPlugin<NativePurchasesPlugin>(\n \"NativePurchases\",\n {\n web: () => import(\"./web\").then((m) => new m.NativePurchasesWeb()),\n }\n);\n\nexport * from \"./definitions\";\nexport { NativePurchases };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-purchases",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "description": "In-app Subscriptions Made Easy",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",