@capgo/native-purchases 8.8.3 → 8.9.1

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@ Sell in-app purchases and subscriptions in your Capacitor app with StoreKit on i
5
5
  <a href="https://capgo.app/?ref=plugin_native_purchases"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-native-purchases" alt="Capgo - Instant updates for Capacitor" /></a>
6
6
 
7
7
  <div align="center">
8
- <p><b>Capgo</b>: open-source live updates for Ionic and Capacitor apps. Ship OTA fixes and features instantly, without waiting for app store review.</p>
8
+ <p><b>Capgo</b>: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.</p>
9
9
  <h2><a href="https://capgo.app/register/?ref=plugin_native_purchases">➡️ Get started for free</a></h2>
10
10
  <p>14-day unlimited free trial. No credit card required</p>
11
11
  <p><a href="https://capgo.app/consulting/?ref=plugin_native_purchases">Missing a feature? We'll build the plugin for you 💪</a></p>
@@ -1720,10 +1720,32 @@ Comments on best practices:
1720
1720
 
1721
1721
  This approach balances immediate user gratification with proper server-side validation, adhering to Apple and Google's guidelines while still maintaining the integrity of your purchase system.
1722
1722
 
1723
+ ## Manual transaction finishing
1724
+
1725
+ By default the plugin finishes StoreKit 2 transactions and acknowledges Google Play purchases automatically. If you must validate on your backend before finishing, disable automatic finishing and complete transactions yourself.
1726
+
1727
+ | Setting | Scope |
1728
+ | -------- | ----- |
1729
+ | `autoFinishTransactions` (default `true`) | Plugin-wide: iOS `transactionUpdated` and `purchaseProduct` when combined with `autoAcknowledgePurchases`. Android `restorePurchases` recovery and `purchaseProduct` when combined with `autoAcknowledgePurchases`. |
1730
+ | `autoAcknowledgePurchases` on `purchaseProduct()` (default `true`) | Per purchase call. Effective auto finish/ack requires both flags to be true. Does not change the iOS `transactionUpdated` listener by itself. |
1731
+
1732
+ Set `autoFinishTransactions: false` in `capacitor.config` under `plugins.NativePurchases` so iOS applies it before the native update listener starts, or call `NativePurchases.configure({ autoFinishTransactions: false })` at startup.
1733
+
1734
+ **iOS recovery flow**
1735
+
1736
+ 1. On launch, call `getUnfinishedTransactions()` or listen for `transactionUpdated` (events include `needsFinish: true` when manual mode is on).
1737
+ 2. Validate on your backend.
1738
+ 3. Call `finishTransaction({ transactionId })` or `acknowledgePurchase({ purchaseToken: transactionId })`. Repeated calls on an already finished transaction succeed.
1739
+
1740
+ **Android**
1741
+
1742
+ After validation when automatic acknowledgment is off (for example `configure({ autoFinishTransactions: false })` or `purchaseProduct({ autoAcknowledgePurchases: false })`), call `consumePurchase({ purchaseToken })` for consumable in-app products (acknowledges and consumes), or `acknowledgePurchase({ purchaseToken })` for non-consumables and subscriptions. `finishTransaction()` is iOS-only and rejects on Android. With `autoFinishTransactions: false`, `restorePurchases()` does not auto-acknowledge; use `getUnfinishedTransactions()` to list unacknowledged purchases in the `PURCHASED` state (`isAcknowledged === false`).
1743
+
1723
1744
  ## API
1724
1745
 
1725
1746
  <docgen-index>
1726
1747
 
1748
+ * [`configure(...)`](#configure)
1727
1749
  * [`restorePurchases()`](#restorepurchases)
1728
1750
  * [`getAppTransaction()`](#getapptransaction)
1729
1751
  * [`isEntitledToOldBusinessModel(...)`](#isentitledtooldbusinessmodel)
@@ -1736,6 +1758,8 @@ This approach balances immediate user gratification with proper server-side vali
1736
1758
  * [`manageSubscriptions()`](#managesubscriptions)
1737
1759
  * [`presentOfferCodeRedeemSheet()`](#presentoffercoderedeemsheet)
1738
1760
  * [`acknowledgePurchase(...)`](#acknowledgepurchase)
1761
+ * [`finishTransaction(...)`](#finishtransaction)
1762
+ * [`getUnfinishedTransactions()`](#getunfinishedtransactions)
1739
1763
  * [`consumePurchase(...)`](#consumepurchase)
1740
1764
  * [`getStorefront()`](#getstorefront)
1741
1765
  * [`addListener('transactionUpdated', ...)`](#addlistenertransactionupdated-)
@@ -1750,6 +1774,41 @@ This approach balances immediate user gratification with proper server-side vali
1750
1774
  <docgen-api>
1751
1775
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
1752
1776
 
1777
+ ### configure(...)
1778
+
1779
+ ```typescript
1780
+ configure(options?: { autoFinishTransactions?: boolean | undefined; } | undefined) => Promise<void>
1781
+ ```
1782
+
1783
+ Configure plugin-wide purchase finishing behavior.
1784
+
1785
+ Call this as early as possible (ideally before other NativePurchases APIs). You can also set
1786
+ `autoFinishTransactions` in `capacitor.config` under `plugins.NativePurchases` so iOS applies
1787
+ the value before the native `transactionUpdated` listener starts.
1788
+
1789
+ **`autoFinishTransactions` (default `true`)**
1790
+
1791
+ - **iOS (StoreKit 2)**: When `true`, the plugin finishes transactions automatically for
1792
+ `transactionUpdated`, `restorePurchases`, and `purchaseProduct` (when
1793
+ `autoAcknowledgePurchases` is also true). When `false`, transactions stay unfinished until you call
1794
+ `finishTransaction()` (or `acknowledgePurchase()` with the transaction ID).
1795
+ - **Android**: When `true`, `restorePurchases()` may auto-acknowledge unacknowledged purchases
1796
+ (recovery flow). When `false`, recovery does not acknowledge; use `acknowledgePurchase()`.
1797
+ `purchaseProduct()` auto-acknowledges only when both `autoFinishTransactions` and
1798
+ `autoAcknowledgePurchases` are true.
1799
+
1800
+ **`autoAcknowledgePurchases`** applies only to the `purchaseProduct()` call and does not change
1801
+ how the iOS `transactionUpdated` listener finishes transactions. Use this method (or config) for that.
1802
+
1803
+ | Param | Type |
1804
+ | ------------- | -------------------------------------------------- |
1805
+ | **`options`** | <code>{ autoFinishTransactions?: boolean; }</code> |
1806
+
1807
+ **Since:** 8.9.0
1808
+
1809
+ --------------------
1810
+
1811
+
1753
1812
  ### restorePurchases()
1754
1813
 
1755
1814
  ```typescript
@@ -1963,7 +2022,9 @@ acknowledgePurchase(options: { purchaseToken: string; }) => Promise<void>
1963
2022
 
1964
2023
  Manually acknowledge/finish a purchase transaction.
1965
2024
 
1966
- This method is only needed when you set `autoAcknowledgePurchases: false` in purchaseProduct().
2025
+ Call this when automatic finishing or acknowledgment is disabled, for example
2026
+ `purchaseProduct({ autoAcknowledgePurchases: false })`, `configure({ autoFinishTransactions: false })`
2027
+ (Android recovery or iOS updates), or when a returned transaction has `needsFinish: true`.
1967
2028
 
1968
2029
  **Platform Behavior:**
1969
2030
  - **Android**: Acknowledges the purchase with Google Play. Must be called within 3 days or the purchase will be refunded.
@@ -2000,6 +2061,51 @@ await NativePurchases.acknowledgePurchase({
2000
2061
  --------------------
2001
2062
 
2002
2063
 
2064
+ ### finishTransaction(...)
2065
+
2066
+ ```typescript
2067
+ finishTransaction(options: { transactionId: string; }) => Promise<void>
2068
+ ```
2069
+
2070
+ Finish a StoreKit 2 transaction on iOS after you validate delivery on your backend.
2071
+
2072
+ Equivalent to `acknowledgePurchase({ purchaseToken: transactionId })` on iOS. Safe to call more
2073
+ than once; finishing an already finished transaction resolves successfully.
2074
+
2075
+ **Android**: Google Play uses purchase acknowledgment, not StoreKit finishing. Call
2076
+ `acknowledgePurchase({ purchaseToken })` instead. This method rejects on Android.
2077
+
2078
+ | Param | Type |
2079
+ | ------------- | --------------------------------------- |
2080
+ | **`options`** | <code>{ transactionId: string; }</code> |
2081
+
2082
+ **Since:** 8.9.0
2083
+
2084
+ --------------------
2085
+
2086
+
2087
+ ### getUnfinishedTransactions()
2088
+
2089
+ ```typescript
2090
+ getUnfinishedTransactions() => Promise<{ transactions: Transaction[]; }>
2091
+ ```
2092
+
2093
+ Returns transactions that still need finishing on iOS, or unacknowledged purchases on Android.
2094
+
2095
+ Use on app launch when `autoFinishTransactions` is `false` to recover work after a restart.
2096
+
2097
+ **Android recovery:** After validation, call `consumePurchase({ purchaseToken })` for consumable
2098
+ in-app products (acknowledges and consumes). Call `acknowledgePurchase({ purchaseToken })` for
2099
+ non-consumables and subscriptions. Includes only purchases in the `PURCHASED` state that are not
2100
+ yet acknowledged. Pending purchases are excluded until Google Play marks them purchased.
2101
+
2102
+ **Returns:** <code>Promise&lt;{ transactions: Transaction[]; }&gt;</code>
2103
+
2104
+ **Since:** 8.9.0
2105
+
2106
+ --------------------
2107
+
2108
+
2003
2109
  ### consumePurchase(...)
2004
2110
 
2005
2111
  ```typescript
@@ -2076,6 +2182,11 @@ addListener(eventName: 'transactionUpdated', listenerFunc: (transaction: Transac
2076
2182
 
2077
2183
  Listen for StoreKit transaction updates delivered by Apple's <a href="#transaction">Transaction</a>.updates.
2078
2184
  Fires on app launch if there are unfinished transactions, and for any updates afterward.
2185
+
2186
+ When `autoFinishTransactions` is `true` (default), the plugin finishes each verified transaction
2187
+ before emitting the event. When `false`, the event includes `needsFinish: true` and you must call
2188
+ `finishTransaction()` after backend validation.
2189
+
2079
2190
  iOS only.
2080
2191
 
2081
2192
  | Param | Type |
@@ -2172,6 +2283,7 @@ which is useful for determining if users are entitled to features from earlier b
2172
2283
  | **`isTrialPeriod`** | <code>boolean</code> | Whether the transaction is in a trial period. - `true`: Currently in free trial period - `false`: Not in trial period | | 1.0.0 |
2173
2284
  | **`isInIntroPricePeriod`** | <code>boolean</code> | Whether the transaction is in an introductory price period. Introductory pricing is a discounted rate, different from a free trial. - `true`: Currently using introductory pricing - `false`: Not in intro period | | 1.0.0 |
2174
2285
  | **`isInGracePeriod`** | <code>boolean</code> | Whether the transaction is in a grace period. Grace period allows users to fix payment issues while maintaining access. You typically want to continue providing access during this time. - `true`: Subscription payment failed but user still has access - `false`: Not in grace period | | 1.0.0 |
2286
+ | **`needsFinish`** | <code>boolean</code> | Whether the StoreKit transaction still needs to be finished with `finishTransaction()`. Present when the transaction is returned from `getUnfinishedTransactions()` or from `transactionUpdated` while `autoFinishTransactions` is `false`. | | 8.9.0 |
2175
2287
 
2176
2288
 
2177
2289
  #### TransactionCommitmentInfo
@@ -2230,6 +2342,7 @@ which is useful for determining if users are entitled to features from earlier b
2230
2342
  | **`pricingTerms`** | <code>SubscriptionPricingTerms[]</code> | iOS subscriptions only: StoreKit pricing terms by billing plan. For subscriptions with a monthly billing plan and 12-month commitment, this includes both the standard up-front plan and the monthly commitment plan. Display both `billingDisplayPrice` and `commitmentInfo.priceString` before starting a monthly commitment purchase. | 8.3.8 |
2231
2343
  | **`subscriptionPeriod`** | <code><a href="#subscriptionperiod">SubscriptionPeriod</a></code> | The <a href="#product">Product</a> subscription group identifier. | |
2232
2344
  | **`introductoryPrice`** | <code><a href="#skproductdiscount">SKProductDiscount</a> \| null</code> | The <a href="#product">Product</a> introductory Price. | |
2345
+ | **`introEligibility`** | <code><a href="#intro_eligibility_status">INTRO_ELIGIBILITY_STATUS</a></code> | Whether the current store account is eligible for an introductory offer on this subscription. | 8.8.3 |
2233
2346
  | **`discounts`** | <code>SKProductDiscount[]</code> | The <a href="#product">Product</a> discounts list. | |
2234
2347
 
2235
2348
 
@@ -2334,6 +2447,15 @@ Android one-time product discount display metadata.
2334
2447
  | **`INAPP`** | <code>'inapp'</code> | A type of SKU for in-app products. |
2335
2448
  | **`SUBS`** | <code>'subs'</code> | A type of SKU for subscriptions. |
2336
2449
 
2450
+
2451
+ #### INTRO_ELIGIBILITY_STATUS
2452
+
2453
+ | Members | Value | Description |
2454
+ | ----------------------------------------- | -------------- | ---------------------------------------------------------------------------- |
2455
+ | **`INTRO_ELIGIBILITY_STATUS_UNKNOWN`** | <code>0</code> | doesn't have enough information to determine eligibility. |
2456
+ | **`INTRO_ELIGIBILITY_STATUS_INELIGIBLE`** | <code>1</code> | The user is not eligible for a free trial or intro pricing for this product. |
2457
+ | **`INTRO_ELIGIBILITY_STATUS_ELIGIBLE`** | <code>2</code> | The user is eligible for a free trial or intro pricing for this product. |
2458
+
2337
2459
  </docgen-api>
2338
2460
 
2339
2461
  ## App Store Compliance
@@ -20,6 +20,9 @@ apply plugin: 'com.android.library'
20
20
  android {
21
21
  namespace = "ee.forgr.nativepurchases"
22
22
  compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
23
+ buildFeatures {
24
+ buildConfig true
25
+ }
23
26
  defaultConfig {
24
27
  minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
25
28
  targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
@@ -49,7 +52,6 @@ repositories {
49
52
 
50
53
 
51
54
  dependencies {
52
- implementation "com.google.guava:guava:33.7.2-android"
53
55
  def billing_version = "9.1.0"
54
56
  implementation "com.android.billingclient:billing:$billing_version"
55
57
  implementation fileTree(dir: 'libs', include: ['*.jar'])
@@ -0,0 +1,69 @@
1
+ package ee.forgr.nativepurchases;
2
+
3
+ import android.util.Log;
4
+ import com.android.billingclient.api.Purchase;
5
+
6
+ /**
7
+ * Centralized logging for the plugin. Debug logs are emitted only when the app is a debug build
8
+ * or {@code debugLogging} is enabled in the plugin config. Sensitive purchase fields are never logged.
9
+ */
10
+ public final class NativePurchasesLog {
11
+
12
+ private static volatile boolean explicitDebugLogging;
13
+
14
+ private NativePurchasesLog() {}
15
+
16
+ public static void configure(boolean debugLogging) {
17
+ explicitDebugLogging = debugLogging;
18
+ }
19
+
20
+ public static boolean isLoggingEnabled() {
21
+ return BuildConfig.DEBUG || explicitDebugLogging;
22
+ }
23
+
24
+ public static void d(String tag, String message) {
25
+ if (isLoggingEnabled()) {
26
+ Log.d(tag, message);
27
+ }
28
+ }
29
+
30
+ public static void i(String tag, String message) {
31
+ if (isLoggingEnabled()) {
32
+ Log.i(tag, message);
33
+ }
34
+ }
35
+
36
+ public static void w(String tag, String message) {
37
+ if (isLoggingEnabled()) {
38
+ Log.w(tag, message);
39
+ }
40
+ }
41
+
42
+ public static void e(String tag, String message) {
43
+ if (isLoggingEnabled()) {
44
+ Log.e(tag, message);
45
+ }
46
+ }
47
+
48
+ public static String redactSensitive(String value) {
49
+ if (value == null || value.isEmpty()) {
50
+ return "[REDACTED]";
51
+ }
52
+ return "[REDACTED]";
53
+ }
54
+
55
+ public static String purchaseDebugSummary(Purchase purchase) {
56
+ if (purchase == null) {
57
+ return "purchase=null";
58
+ }
59
+ return (
60
+ "purchase{productIds=" +
61
+ purchase.getProducts() +
62
+ ", state=" +
63
+ purchase.getPurchaseState() +
64
+ ", acknowledged=" +
65
+ purchase.isAcknowledged() +
66
+ "}"
67
+ );
68
+ }
69
+ }