@capgo/native-purchases 7.18.0-alpha.0 → 7.19.0

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.
@@ -10,9 +10,12 @@ import com.android.billingclient.api.AcknowledgePurchaseParams;
10
10
  import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
11
11
  import com.android.billingclient.api.BillingClient;
12
12
  import com.android.billingclient.api.BillingClientStateListener;
13
+ import com.android.billingclient.api.BillingConfig;
14
+ import com.android.billingclient.api.BillingConfigResponseListener;
13
15
  import com.android.billingclient.api.BillingFlowParams;
14
16
  import com.android.billingclient.api.BillingResult;
15
17
  import com.android.billingclient.api.ConsumeParams;
18
+ import com.android.billingclient.api.GetBillingConfigParams;
16
19
  import com.android.billingclient.api.PendingPurchasesParams;
17
20
  import com.android.billingclient.api.ProductDetails;
18
21
  import com.android.billingclient.api.ProductDetailsResponseListener;
@@ -30,7 +33,6 @@ import com.google.common.collect.ImmutableList;
30
33
  import java.util.ArrayList;
31
34
  import java.util.Collections;
32
35
  import java.util.List;
33
- import java.util.Objects;
34
36
  import java.util.concurrent.CountDownLatch;
35
37
  import java.util.concurrent.Phaser;
36
38
  import java.util.concurrent.TimeUnit;
@@ -42,7 +44,7 @@ import org.json.JSONArray;
42
44
  @CapacitorPlugin(name = "NativePurchases")
43
45
  public class NativePurchasesPlugin extends Plugin {
44
46
 
45
- private final String pluginVersion = "7.18.0-alpha.0";
47
+ private final String pluginVersion = "7.19.0";
46
48
  public static final String TAG = "NativePurchases";
47
49
  private static final Phaser semaphoreReady = new Phaser(1);
48
50
  private BillingClient billingClient;
@@ -52,10 +54,83 @@ public class NativePurchasesPlugin extends Plugin {
52
54
  @PluginMethod
53
55
  public void isBillingSupported(PluginCall call) {
54
56
  Log.d(TAG, "isBillingSupported() called");
57
+ try {
58
+ // Try to initialize billing client to check if billing is actually available
59
+ // Pass null so initBillingClient doesn't reject the call - we'll handle the result ourselves
60
+ this.initBillingClient(null);
61
+ // If initialization succeeded, billing is supported
62
+ JSObject ret = new JSObject();
63
+ ret.put("isBillingSupported", true);
64
+ Log.d(TAG, "isBillingSupported() returning true - billing client initialized successfully");
65
+ closeBillingClient();
66
+ call.resolve(ret);
67
+ } catch (RuntimeException e) {
68
+ Log.e(TAG, "isBillingSupported() - billing client initialization failed: " + e.getMessage());
69
+ closeBillingClient();
70
+ // Return false instead of rejecting - this is a check method
71
+ JSObject ret = new JSObject();
72
+ ret.put("isBillingSupported", false);
73
+ Log.d(TAG, "isBillingSupported() returning false - billing not available");
74
+ call.resolve(ret);
75
+ } catch (Exception e) {
76
+ Log.e(TAG, "isBillingSupported() - unexpected error: " + e.getMessage());
77
+ closeBillingClient();
78
+ JSObject ret = new JSObject();
79
+ ret.put("isBillingSupported", false);
80
+ Log.d(TAG, "isBillingSupported() returning false - unexpected error");
81
+ call.resolve(ret);
82
+ }
83
+ }
84
+
85
+ @PluginMethod
86
+ public void getStorefront(PluginCall call) {
87
+ Log.d(TAG, "getStorefront() called");
88
+ try {
89
+ // Pass null so initBillingClient doesn't reject the call - getStorefront
90
+ // always resolves and reports an empty countryCode when the storefront
91
+ // can't be determined, mirroring isBillingSupported() and the iOS side.
92
+ this.initBillingClient(null);
93
+ } catch (RuntimeException e) {
94
+ Log.e(TAG, "getStorefront() - billing client init failed: " + e.getMessage());
95
+ closeBillingClient();
96
+ call.resolve(emptyStorefront());
97
+ return;
98
+ }
99
+ try {
100
+ billingClient.getBillingConfigAsync(
101
+ GetBillingConfigParams.newBuilder().build(),
102
+ new BillingConfigResponseListener() {
103
+ @Override
104
+ public void onBillingConfigResponse(@NonNull BillingResult billingResult, BillingConfig billingConfig) {
105
+ JSObject ret = new JSObject();
106
+ if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && billingConfig != null) {
107
+ String countryCode = billingConfig.getCountryCode();
108
+ Log.d(TAG, "getBillingConfig success, countryCode: " + countryCode);
109
+ // JSObject.put(name, null) removes the key, so coalesce to "".
110
+ ret.put("countryCode", countryCode != null ? countryCode : "");
111
+ } else {
112
+ Log.e(
113
+ TAG,
114
+ "getBillingConfig unavailable: " + billingResult.getResponseCode() + " - " + billingResult.getDebugMessage()
115
+ );
116
+ ret.put("countryCode", "");
117
+ }
118
+ closeBillingClient();
119
+ call.resolve(ret);
120
+ }
121
+ }
122
+ );
123
+ } catch (Exception e) {
124
+ Log.e(TAG, "getBillingConfigAsync threw: " + e.getMessage());
125
+ closeBillingClient();
126
+ call.resolve(emptyStorefront());
127
+ }
128
+ }
129
+
130
+ private JSObject emptyStorefront() {
55
131
  JSObject ret = new JSObject();
56
- ret.put("isBillingSupported", true);
57
- Log.d(TAG, "isBillingSupported() returning true");
58
- call.resolve(ret);
132
+ ret.put("countryCode", "");
133
+ return ret;
59
134
  }
60
135
 
61
136
  @Override
@@ -666,44 +741,67 @@ public class NativePurchasesPlugin extends Plugin {
666
741
  if (productType.equals("inapp")) {
667
742
  Log.d(TAG, "Processing as in-app product");
668
743
  product.put("identifier", productDetails.getProductId());
669
- double price =
670
- Objects.requireNonNull(productDetails.getOneTimePurchaseOfferDetails()).getPriceAmountMicros() / 1000000.0;
744
+ ProductDetails.OneTimePurchaseOfferDetails oneTimeOfferDetails =
745
+ productDetails.getOneTimePurchaseOfferDetails();
746
+ if (oneTimeOfferDetails == null) {
747
+ Log.w(TAG, "No one-time purchase offer details found for product: " + productDetails.getProductId());
748
+ closeBillingClient();
749
+ call.reject("No one-time purchase offer details found for product: " + productDetails.getProductId());
750
+ return;
751
+ }
752
+ double price = oneTimeOfferDetails.getPriceAmountMicros() / 1000000.0;
671
753
  product.put("price", price);
672
- product.put("priceString", productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());
673
- product.put("currencyCode", productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
754
+ product.put("priceString", oneTimeOfferDetails.getFormattedPrice());
755
+ product.put("currencyCode", oneTimeOfferDetails.getPriceCurrencyCode());
674
756
  Log.d(TAG, "Price: " + price);
675
- Log.d(TAG, "Formatted price: " + productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());
676
- Log.d(TAG, "Currency: " + productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
757
+ Log.d(TAG, "Formatted price: " + oneTimeOfferDetails.getFormattedPrice());
758
+ Log.d(TAG, "Currency: " + oneTimeOfferDetails.getPriceCurrencyCode());
677
759
  } else {
678
760
  Log.d(TAG, "Processing as subscription product");
679
- ProductDetails.SubscriptionOfferDetails selectedOfferDetails = productDetails
680
- .getSubscriptionOfferDetails()
761
+ List<ProductDetails.SubscriptionOfferDetails> offerDetailsList = productDetails.getSubscriptionOfferDetails();
762
+ if (offerDetailsList == null || offerDetailsList.isEmpty()) {
763
+ Log.w(TAG, "No subscription offer details found for product: " + productDetails.getProductId());
764
+ closeBillingClient();
765
+ call.reject("No subscription offers found for product: " + productDetails.getProductId());
766
+ return;
767
+ }
768
+
769
+ ProductDetails.SubscriptionOfferDetails selectedOfferDetails = null;
770
+ for (ProductDetails.SubscriptionOfferDetails offerDetails : offerDetailsList) {
771
+ if (
772
+ offerDetails.getPricingPhases() != null &&
773
+ !offerDetails.getPricingPhases().getPricingPhaseList().isEmpty()
774
+ ) {
775
+ selectedOfferDetails = offerDetails;
776
+ break;
777
+ }
778
+ }
779
+
780
+ if (selectedOfferDetails == null) {
781
+ Log.w(TAG, "No offers with pricing phases found for product: " + productDetails.getProductId());
782
+ closeBillingClient();
783
+ call.reject("No pricing phases found for product: " + productDetails.getProductId());
784
+ return;
785
+ }
786
+
787
+ ProductDetails.PricingPhase firstPricingPhase = selectedOfferDetails
788
+ .getPricingPhases()
789
+ .getPricingPhaseList()
681
790
  .get(0);
682
791
  product.put("planIdentifier", productDetails.getProductId());
683
792
  product.put("identifier", selectedOfferDetails.getBasePlanId());
684
- double price =
685
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceAmountMicros() / 1000000.0;
793
+ product.put("offerToken", selectedOfferDetails.getOfferToken());
794
+ product.put("offerId", selectedOfferDetails.getOfferId());
795
+ double price = firstPricingPhase.getPriceAmountMicros() / 1000000.0;
686
796
  product.put("price", price);
687
- product.put(
688
- "priceString",
689
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()
690
- );
691
- product.put(
692
- "currencyCode",
693
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceCurrencyCode()
694
- );
797
+ product.put("priceString", firstPricingPhase.getFormattedPrice());
798
+ product.put("currencyCode", firstPricingPhase.getPriceCurrencyCode());
695
799
  Log.d(TAG, "Plan identifier: " + productDetails.getProductId());
696
800
  Log.d(TAG, "Base plan ID: " + selectedOfferDetails.getBasePlanId());
801
+ Log.d(TAG, "Offer token: " + selectedOfferDetails.getOfferToken());
697
802
  Log.d(TAG, "Price: " + price);
698
- Log.d(
699
- TAG,
700
- "Formatted price: " +
701
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()
702
- );
703
- Log.d(
704
- TAG,
705
- "Currency: " + selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceCurrencyCode()
706
- );
803
+ Log.d(TAG, "Formatted price: " + firstPricingPhase.getFormattedPrice());
804
+ Log.d(TAG, "Currency: " + firstPricingPhase.getPriceCurrencyCode());
707
805
  }
708
806
  product.put("isFamilyShareable", false);
709
807
 
@@ -778,58 +876,86 @@ public class NativePurchasesPlugin extends Plugin {
778
876
  JSONArray products = new JSONArray();
779
877
  for (ProductDetails productDetails : productDetailsList) {
780
878
  Log.d(TAG, "Processing product details: " + productDetails.getProductId());
781
- JSObject product = new JSObject();
782
- product.put("title", productDetails.getName());
783
- product.put("description", productDetails.getDescription());
784
879
  Log.d(TAG, "Product title: " + productDetails.getName());
785
880
  Log.d(TAG, "Product description: " + productDetails.getDescription());
786
881
 
787
882
  if (productType.equals("inapp")) {
788
883
  Log.d(TAG, "Processing as in-app product");
884
+ JSObject product = new JSObject();
885
+ product.put("title", productDetails.getName());
886
+ product.put("description", productDetails.getDescription());
789
887
  product.put("identifier", productDetails.getProductId());
790
- double price =
791
- Objects.requireNonNull(productDetails.getOneTimePurchaseOfferDetails()).getPriceAmountMicros() /
792
- 1000000.0;
888
+
889
+ ProductDetails.OneTimePurchaseOfferDetails oneTimeOfferDetails =
890
+ productDetails.getOneTimePurchaseOfferDetails();
891
+ if (oneTimeOfferDetails == null) {
892
+ Log.w(TAG, "No one-time purchase offer details found for product: " + productDetails.getProductId());
893
+ continue;
894
+ }
895
+
896
+ double price = oneTimeOfferDetails.getPriceAmountMicros() / 1000000.0;
793
897
  product.put("price", price);
794
- product.put("priceString", productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());
795
- product.put("currencyCode", productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
898
+ product.put("priceString", oneTimeOfferDetails.getFormattedPrice());
899
+ product.put("currencyCode", oneTimeOfferDetails.getPriceCurrencyCode());
900
+ product.put("isFamilyShareable", false);
796
901
  Log.d(TAG, "Price: " + price);
797
- Log.d(TAG, "Formatted price: " + productDetails.getOneTimePurchaseOfferDetails().getFormattedPrice());
798
- Log.d(TAG, "Currency: " + productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
902
+ Log.d(TAG, "Formatted price: " + oneTimeOfferDetails.getFormattedPrice());
903
+ Log.d(TAG, "Currency: " + oneTimeOfferDetails.getPriceCurrencyCode());
904
+ products.put(product);
799
905
  } else {
800
906
  Log.d(TAG, "Processing as subscription product");
801
- ProductDetails.SubscriptionOfferDetails selectedOfferDetails = productDetails
802
- .getSubscriptionOfferDetails()
803
- .get(0);
804
- product.put("planIdentifier", productDetails.getProductId());
805
- product.put("identifier", selectedOfferDetails.getBasePlanId());
806
- double price =
807
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceAmountMicros() / 1000000.0;
808
- product.put("price", price);
809
- product.put(
810
- "priceString",
811
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()
812
- );
813
- product.put(
814
- "currencyCode",
815
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceCurrencyCode()
816
- );
817
- Log.d(TAG, "Plan identifier: " + productDetails.getProductId());
818
- Log.d(TAG, "Base plan ID: " + selectedOfferDetails.getBasePlanId());
819
- Log.d(TAG, "Price: " + price);
820
- Log.d(
821
- TAG,
822
- "Formatted price: " +
823
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getFormattedPrice()
824
- );
825
- Log.d(
826
- TAG,
827
- "Currency: " +
828
- selectedOfferDetails.getPricingPhases().getPricingPhaseList().get(0).getPriceCurrencyCode()
829
- );
907
+ List<ProductDetails.SubscriptionOfferDetails> offerDetailsList =
908
+ productDetails.getSubscriptionOfferDetails();
909
+ if (offerDetailsList == null || offerDetailsList.isEmpty()) {
910
+ Log.w(TAG, "No subscription offer details found for product: " + productDetails.getProductId());
911
+ continue;
912
+ }
913
+
914
+ int addedOffers = 0;
915
+ for (ProductDetails.SubscriptionOfferDetails offerDetails : offerDetailsList) {
916
+ if (
917
+ offerDetails.getPricingPhases() == null ||
918
+ offerDetails.getPricingPhases().getPricingPhaseList().isEmpty()
919
+ ) {
920
+ Log.w(TAG, "No pricing phases found for offer: " + offerDetails.getBasePlanId());
921
+ continue;
922
+ }
923
+
924
+ JSObject product = new JSObject();
925
+ product.put("title", productDetails.getName());
926
+ product.put("description", productDetails.getDescription());
927
+ product.put("planIdentifier", productDetails.getProductId());
928
+ product.put("identifier", offerDetails.getBasePlanId());
929
+ product.put("offerToken", offerDetails.getOfferToken());
930
+ product.put("offerId", offerDetails.getOfferId());
931
+
932
+ ProductDetails.PricingPhase firstPricingPhase = offerDetails
933
+ .getPricingPhases()
934
+ .getPricingPhaseList()
935
+ .get(0);
936
+ double price = firstPricingPhase.getPriceAmountMicros() / 1000000.0;
937
+ product.put("price", price);
938
+ product.put("priceString", firstPricingPhase.getFormattedPrice());
939
+ product.put("currencyCode", firstPricingPhase.getPriceCurrencyCode());
940
+ product.put("isFamilyShareable", false);
941
+
942
+ Log.d(TAG, "Plan identifier: " + productDetails.getProductId());
943
+ Log.d(TAG, "Base plan ID: " + offerDetails.getBasePlanId());
944
+ Log.d(TAG, "Price: " + price);
945
+ Log.d(TAG, "Formatted price: " + firstPricingPhase.getFormattedPrice());
946
+ Log.d(TAG, "Currency: " + firstPricingPhase.getPriceCurrencyCode());
947
+
948
+ products.put(product);
949
+ addedOffers++;
950
+ }
951
+
952
+ if (addedOffers == 0) {
953
+ Log.w(
954
+ TAG,
955
+ "All subscription offers missing pricing phases for product: " + productDetails.getProductId()
956
+ );
957
+ }
830
958
  }
831
- product.put("isFamilyShareable", false);
832
- products.put(product);
833
959
  }
834
960
  JSObject ret = new JSObject();
835
961
  ret.put("products", products);
package/dist/docs.json CHANGED
@@ -407,6 +407,29 @@
407
407
  "complexTypes": [],
408
408
  "slug": "consumepurchase"
409
409
  },
410
+ {
411
+ "name": "getStorefront",
412
+ "signature": "() => Promise<{ countryCode: string; storefrontId?: string; }>",
413
+ "parameters": [],
414
+ "returns": "Promise<{ countryCode: string; storefrontId?: string | undefined; }>",
415
+ "tags": [
416
+ {
417
+ "name": "returns",
418
+ "text": "the current storefront"
419
+ },
420
+ {
421
+ "name": "since",
422
+ "text": "7.19.0"
423
+ },
424
+ {
425
+ "name": "example",
426
+ "text": "```typescript\nconst { countryCode } = await NativePurchases.getStorefront();\nif (countryCode === 'USA' || countryCode === 'US') {\n // show US-specific payment options\n}\n```"
427
+ }
428
+ ],
429
+ "docs": "Get the user's current App Store / Google Play storefront — the country\ntheir store account is registered to.\n\niOS: reads StoreKit 2 `Storefront.current`. `countryCode` is ISO 3166-1\n**alpha-3** (e.g. `\"USA\"`) and `storefrontId` is the Apple-defined\nstorefront identifier.\nAndroid: reads Google Play Billing `getBillingConfigAsync()`. `countryCode`\nis ISO 3166-1 **alpha-2** (e.g. `\"US\"`); `storefrontId` is omitted (Google\nPlay has no storefront-id concept).\n\nContract note (future-major default candidate): `countryCode` is returned in\neach store's native format and is intentionally NOT normalized across\nplatforms today (iOS alpha-3 vs Android alpha-2), to stay faithful to the\nplatform APIs. Normalizing both to a single scheme (e.g. ISO 3166-1 alpha-2)\nis a candidate default change for the next Capacitor major, deferred so it\ncan be adopted deliberately rather than as a mid-major breaking change.\n\nResolves a `countryCode` of `\"\"` (it does not reject) when the storefront\ncan't be determined on either platform — e.g. apps distributed via iOS\nalternative distribution, or Google Play billing being unavailable.\n\nUseful for region-dependent logic such as localized offers/pricing and\ngating external-purchase entitlements, whose eligibility the platforms key\nto the storefront country. Read it live rather than caching, since the user\ncan change their store region.",
430
+ "complexTypes": [],
431
+ "slug": "getstorefront"
432
+ },
410
433
  {
411
434
  "name": "addListener",
412
435
  "signature": "(eventName: 'transactionUpdated', listenerFunc: (transaction: Transaction) => void) => Promise<PluginListenerHandle>",
@@ -664,9 +687,13 @@
664
687
  {
665
688
  "text": "android Not available (use purchaseToken instead)",
666
689
  "name": "platform"
690
+ },
691
+ {
692
+ "text": "```typescript\nconst transaction = await NativePurchases.purchaseProduct({ ... });\nif (transaction.receipt) {\n // Send to your backend for validation\n await fetch('/api/validate-receipt', {\n method: 'POST',\n body: JSON.stringify({ receipt: transaction.receipt })\n });\n}\n```",
693
+ "name": "example"
667
694
  }
668
695
  ],
669
- "docs": "Receipt data for validation (base64 encoded StoreKit receipt).\n\nSend this to your backend for server-side validation with Apple's receipt verification API.\nThe receipt remains available even after refund - server validation is required to detect refunded transactions.",
696
+ "docs": "Receipt data for validation (base64 encoded StoreKit receipt).\n\n**This is the full verified receipt payload from Apple StoreKit.**\nSend this to your backend for server-side validation with Apple's receipt verification API.\nThe receipt remains available even after refund - server validation is required to detect refunded transactions.\n\n**For backend validation:**\n- Use Apple's receipt verification API: https://buy.itunes.apple.com/verifyReceipt (production)\n- Or sandbox: https://sandbox.itunes.apple.com/verifyReceipt\n- This contains all transaction data needed for validation\n\n**Note:** Apple recommends migrating to App Store Server API v2 with `jwsRepresentation` for new implementations.\nThe legacy receipt verification API continues to work but may be deprecated in the future.",
670
697
  "complexTypes": [],
671
698
  "type": "string | undefined"
672
699
  },
@@ -684,9 +711,13 @@
684
711
  {
685
712
  "text": "android Not available",
686
713
  "name": "platform"
714
+ },
715
+ {
716
+ "text": "```typescript\nconst transaction = await NativePurchases.purchaseProduct({ ... });\nif (transaction.jwsRepresentation) {\n // Send to your backend for validation with App Store Server API v2\n await fetch('/api/validate-jws', {\n method: 'POST',\n body: JSON.stringify({ jws: transaction.jwsRepresentation })\n });\n}\n```",
717
+ "name": "example"
687
718
  }
688
719
  ],
689
- "docs": "StoreKit 2 JSON Web Signature (JWS) payload describing the verified transaction.\n\nSend this to your backend when using Apple's App Store Server API v2 instead of raw receipts.\nOnly available when the transaction originated from StoreKit 2 APIs (e.g. Transaction.updates).",
720
+ "docs": "StoreKit 2 JSON Web Signature (JWS) payload describing the verified transaction.\n\n**This is the full verified receipt in JWS format (StoreKit 2).**\nSend this to your backend when using Apple's App Store Server API v2 instead of raw receipts.\nOnly available when the transaction originated from StoreKit 2 APIs (e.g. Transaction.updates).\n\n**For backend validation:**\n- Use Apple's App Store Server API v2 to decode and verify the JWS\n- This is the modern alternative to the legacy receipt format\n- Contains signed transaction information from Apple",
690
721
  "complexTypes": [],
691
722
  "type": "string | undefined"
692
723
  },
@@ -963,9 +994,13 @@
963
994
  {
964
995
  "text": "android Always present",
965
996
  "name": "platform"
997
+ },
998
+ {
999
+ "text": "```typescript\nconst transaction = await NativePurchases.purchaseProduct({ ... });\nif (transaction.purchaseToken) {\n // Send to your backend for validation\n await fetch('/api/validate-purchase', {\n method: 'POST',\n body: JSON.stringify({\n purchaseToken: transaction.purchaseToken,\n productId: transaction.productIdentifier\n })\n });\n}\n```",
1000
+ "name": "example"
966
1001
  }
967
1002
  ],
968
- "docs": "Purchase token associated with the transaction.\n\nSend this to your backend for server-side validation with Google Play Developer API.\nThis is the Android equivalent of iOS's receipt field.",
1003
+ "docs": "Purchase token associated with the transaction.\n\n**This is the full verified purchase token from Google Play.**\nSend this to your backend for server-side validation with Google Play Developer API.\nThis is the Android equivalent of iOS's receipt field.\n\n**For backend validation:**\n- Use Google Play Developer API v3 to verify the purchase\n- API endpoint: androidpublisher.purchases.products.get() or purchases.subscriptions.get()\n- This token contains all data needed for validation with Google servers\n- Can also be used for subscription status checks and cancellation detection",
969
1004
  "complexTypes": [],
970
1005
  "type": "string | undefined"
971
1006
  },
@@ -1165,7 +1200,7 @@
1165
1200
  {
1166
1201
  "name": "identifier",
1167
1202
  "tags": [],
1168
- "docs": "Product Id.",
1203
+ "docs": "Product Id.\n\nAndroid subscriptions note:\n- `identifier` is the base plan ID (`offerDetails.getBasePlanId()`).\n- `planIdentifier` is the subscription product ID (`productDetails.getProductId()`).\n\nIf you group/filter Android subscription results by `identifier`, you are grouping by base plan.",
1169
1204
  "complexTypes": [],
1170
1205
  "type": "string"
1171
1206
  },
@@ -1225,6 +1260,27 @@
1225
1260
  "complexTypes": [],
1226
1261
  "type": "string"
1227
1262
  },
1263
+ {
1264
+ "name": "planIdentifier",
1265
+ "tags": [],
1266
+ "docs": "Android subscriptions only: Google Play product identifier tied to the offer/base plan set.",
1267
+ "complexTypes": [],
1268
+ "type": "string | undefined"
1269
+ },
1270
+ {
1271
+ "name": "offerToken",
1272
+ "tags": [],
1273
+ "docs": "Android subscriptions only: offer token required when purchasing specific offers.",
1274
+ "complexTypes": [],
1275
+ "type": "string | undefined"
1276
+ },
1277
+ {
1278
+ "name": "offerId",
1279
+ "tags": [],
1280
+ "docs": "Android subscriptions only: offer identifier (null/undefined for base offers).",
1281
+ "complexTypes": [],
1282
+ "type": "string | null | undefined"
1283
+ },
1228
1284
  {
1229
1285
  "name": "subscriptionPeriod",
1230
1286
  "tags": [],
@@ -132,23 +132,60 @@ export interface Transaction {
132
132
  /**
133
133
  * Receipt data for validation (base64 encoded StoreKit receipt).
134
134
  *
135
+ * **This is the full verified receipt payload from Apple StoreKit.**
135
136
  * Send this to your backend for server-side validation with Apple's receipt verification API.
136
137
  * The receipt remains available even after refund - server validation is required to detect refunded transactions.
137
138
  *
139
+ * **For backend validation:**
140
+ * - Use Apple's receipt verification API: https://buy.itunes.apple.com/verifyReceipt (production)
141
+ * - Or sandbox: https://sandbox.itunes.apple.com/verifyReceipt
142
+ * - This contains all transaction data needed for validation
143
+ *
144
+ * **Note:** Apple recommends migrating to App Store Server API v2 with `jwsRepresentation` for new implementations.
145
+ * The legacy receipt verification API continues to work but may be deprecated in the future.
146
+ *
138
147
  * @since 1.0.0
139
148
  * @platform ios Always present
140
149
  * @platform android Not available (use purchaseToken instead)
150
+ * @example
151
+ * ```typescript
152
+ * const transaction = await NativePurchases.purchaseProduct({ ... });
153
+ * if (transaction.receipt) {
154
+ * // Send to your backend for validation
155
+ * await fetch('/api/validate-receipt', {
156
+ * method: 'POST',
157
+ * body: JSON.stringify({ receipt: transaction.receipt })
158
+ * });
159
+ * }
160
+ * ```
141
161
  */
142
162
  readonly receipt?: string;
143
163
  /**
144
164
  * StoreKit 2 JSON Web Signature (JWS) payload describing the verified transaction.
145
165
  *
166
+ * **This is the full verified receipt in JWS format (StoreKit 2).**
146
167
  * Send this to your backend when using Apple's App Store Server API v2 instead of raw receipts.
147
168
  * Only available when the transaction originated from StoreKit 2 APIs (e.g. Transaction.updates).
148
169
  *
170
+ * **For backend validation:**
171
+ * - Use Apple's App Store Server API v2 to decode and verify the JWS
172
+ * - This is the modern alternative to the legacy receipt format
173
+ * - Contains signed transaction information from Apple
174
+ *
149
175
  * @since 7.13.2
150
176
  * @platform ios Present for StoreKit 2 transactions (iOS 15+)
151
177
  * @platform android Not available
178
+ * @example
179
+ * ```typescript
180
+ * const transaction = await NativePurchases.purchaseProduct({ ... });
181
+ * if (transaction.jwsRepresentation) {
182
+ * // Send to your backend for validation with App Store Server API v2
183
+ * await fetch('/api/validate-jws', {
184
+ * method: 'POST',
185
+ * body: JSON.stringify({ jws: transaction.jwsRepresentation })
186
+ * });
187
+ * }
188
+ * ```
152
189
  */
153
190
  readonly jwsRepresentation?: string;
154
191
  /**
@@ -325,12 +362,33 @@ export interface Transaction {
325
362
  /**
326
363
  * Purchase token associated with the transaction.
327
364
  *
365
+ * **This is the full verified purchase token from Google Play.**
328
366
  * Send this to your backend for server-side validation with Google Play Developer API.
329
367
  * This is the Android equivalent of iOS's receipt field.
330
368
  *
369
+ * **For backend validation:**
370
+ * - Use Google Play Developer API v3 to verify the purchase
371
+ * - API endpoint: androidpublisher.purchases.products.get() or purchases.subscriptions.get()
372
+ * - This token contains all data needed for validation with Google servers
373
+ * - Can also be used for subscription status checks and cancellation detection
374
+ *
331
375
  * @since 1.0.0
332
376
  * @platform ios Not available (use receipt instead)
333
377
  * @platform android Always present
378
+ * @example
379
+ * ```typescript
380
+ * const transaction = await NativePurchases.purchaseProduct({ ... });
381
+ * if (transaction.purchaseToken) {
382
+ * // Send to your backend for validation
383
+ * await fetch('/api/validate-purchase', {
384
+ * method: 'POST',
385
+ * body: JSON.stringify({
386
+ * purchaseToken: transaction.purchaseToken,
387
+ * productId: transaction.productIdentifier
388
+ * })
389
+ * });
390
+ * }
391
+ * ```
334
392
  */
335
393
  readonly purchaseToken?: string;
336
394
  /**
@@ -589,6 +647,12 @@ export interface SKProductDiscount {
589
647
  export interface Product {
590
648
  /**
591
649
  * Product Id.
650
+ *
651
+ * Android subscriptions note:
652
+ * - `identifier` is the base plan ID (`offerDetails.getBasePlanId()`).
653
+ * - `planIdentifier` is the subscription product ID (`productDetails.getProductId()`).
654
+ *
655
+ * If you group/filter Android subscription results by `identifier`, you are grouping by base plan.
592
656
  */
593
657
  readonly identifier: string;
594
658
  /**
@@ -623,6 +687,18 @@ export interface Product {
623
687
  * Group identifier for the product.
624
688
  */
625
689
  readonly subscriptionGroupIdentifier: string;
690
+ /**
691
+ * Android subscriptions only: Google Play product identifier tied to the offer/base plan set.
692
+ */
693
+ readonly planIdentifier?: string;
694
+ /**
695
+ * Android subscriptions only: offer token required when purchasing specific offers.
696
+ */
697
+ readonly offerToken?: string;
698
+ /**
699
+ * Android subscriptions only: offer identifier (null/undefined for base offers).
700
+ */
701
+ readonly offerId?: string | null;
626
702
  /**
627
703
  * The Product subscription group identifier.
628
704
  */
@@ -937,6 +1013,48 @@ export interface NativePurchasesPlugin {
937
1013
  consumePurchase(options: {
938
1014
  purchaseToken: string;
939
1015
  }): Promise<void>;
1016
+ /**
1017
+ * Get the user's current App Store / Google Play storefront — the country
1018
+ * their store account is registered to.
1019
+ *
1020
+ * iOS: reads StoreKit 2 `Storefront.current`. `countryCode` is ISO 3166-1
1021
+ * **alpha-3** (e.g. `"USA"`) and `storefrontId` is the Apple-defined
1022
+ * storefront identifier.
1023
+ * Android: reads Google Play Billing `getBillingConfigAsync()`. `countryCode`
1024
+ * is ISO 3166-1 **alpha-2** (e.g. `"US"`); `storefrontId` is omitted (Google
1025
+ * Play has no storefront-id concept).
1026
+ *
1027
+ * Contract note (future-major default candidate): `countryCode` is returned in
1028
+ * each store's native format and is intentionally NOT normalized across
1029
+ * platforms today (iOS alpha-3 vs Android alpha-2), to stay faithful to the
1030
+ * platform APIs. Normalizing both to a single scheme (e.g. ISO 3166-1 alpha-2)
1031
+ * is a candidate default change for the next Capacitor major, deferred so it
1032
+ * can be adopted deliberately rather than as a mid-major breaking change.
1033
+ *
1034
+ * Resolves a `countryCode` of `""` (it does not reject) when the storefront
1035
+ * can't be determined on either platform — e.g. apps distributed via iOS
1036
+ * alternative distribution, or Google Play billing being unavailable.
1037
+ *
1038
+ * Useful for region-dependent logic such as localized offers/pricing and
1039
+ * gating external-purchase entitlements, whose eligibility the platforms key
1040
+ * to the storefront country. Read it live rather than caching, since the user
1041
+ * can change their store region.
1042
+ *
1043
+ * @returns {Promise<{ countryCode: string; storefrontId?: string }>} the current storefront
1044
+ * @since 7.19.0
1045
+ *
1046
+ * @example
1047
+ * ```typescript
1048
+ * const { countryCode } = await NativePurchases.getStorefront();
1049
+ * if (countryCode === 'USA' || countryCode === 'US') {
1050
+ * // show US-specific payment options
1051
+ * }
1052
+ * ```
1053
+ */
1054
+ getStorefront(): Promise<{
1055
+ countryCode: string;
1056
+ storefrontId?: string;
1057
+ }>;
940
1058
  /**
941
1059
  * Listen for StoreKit transaction updates delivered by Apple's Transaction.updates.
942
1060
  * Fires on app launch if there are unfinished transactions, and for any updates afterward.