@capgo/native-purchases 8.9.17 → 8.11.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.
- package/README.md +69 -15
- package/android/src/main/java/ee/forgr/nativepurchases/BillingResponseCodes.java +53 -0
- package/android/src/main/java/ee/forgr/nativepurchases/NativePurchasesPlugin.java +621 -72
- package/android/src/main/java/ee/forgr/nativepurchases/SubscriptionOfferSelector.java +15 -0
- package/android/src/main/java/ee/forgr/nativepurchases/SubscriptionReplacementModes.java +69 -0
- package/dist/docs.json +77 -6
- package/dist/esm/definitions.d.ts +96 -7
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +7 -1
- package/dist/esm/web.js +4 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +4 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +4 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/NativePurchasesPlugin/NativePurchasesPlugin.swift +9 -2
- package/package.json +3 -2
|
@@ -99,6 +99,21 @@ public final class SubscriptionOfferSelector {
|
|
|
99
99
|
return isPresent(offerToken) || isPresent(planIdentifier);
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
/**
|
|
103
|
+
* Whether any offer uses the given base plan id.
|
|
104
|
+
*/
|
|
105
|
+
static boolean hasBasePlan(List<Offer> offers, String planIdentifier) {
|
|
106
|
+
if (!isPresent(planIdentifier) || offers == null || offers.isEmpty()) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
for (Offer offer : offers) {
|
|
110
|
+
if (planIdentifier.equals(offer.getBasePlanId())) {
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
|
|
102
117
|
private static boolean isPresent(String value) {
|
|
103
118
|
return value != null && !value.isEmpty();
|
|
104
119
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
package ee.forgr.nativepurchases;
|
|
2
|
+
|
|
3
|
+
import com.android.billingclient.api.BillingFlowParams;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Maps the replacement mode name passed from JavaScript to Play Billing's item-level constant
|
|
7
|
+
* ({@code BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode}).
|
|
8
|
+
*
|
|
9
|
+
* <p>The name is mapped here instead of accepting a number because Play Billing exposes two tables with
|
|
10
|
+
* different values: {@code DEFERRED} is 5 in the item-level table and 6 in
|
|
11
|
+
* {@code SubscriptionUpdateParams.ReplacementMode}, and the exported JS {@code PRORATION_MODE} enum still uses
|
|
12
|
+
* the older ProrationMode numbering (4).
|
|
13
|
+
*/
|
|
14
|
+
final class SubscriptionReplacementModes {
|
|
15
|
+
|
|
16
|
+
/** Returned for a missing or unsupported name. Callers must reject the purchase instead of guessing. */
|
|
17
|
+
static final int UNKNOWN = 0;
|
|
18
|
+
|
|
19
|
+
private SubscriptionReplacementModes() {}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns {@code null} when the replacement options are consistent, otherwise the message to reject the call with.
|
|
23
|
+
*
|
|
24
|
+
* <p>A partial request ({@code oldProductIdentifier} or {@code replacementMode} without {@code oldPurchaseToken}) is
|
|
25
|
+
* rejected instead of being treated as a normal purchase, which would create a second subscription.
|
|
26
|
+
*/
|
|
27
|
+
static String validationError(String productType, String oldPurchaseToken, String oldProductIdentifier, String replacementModeName) {
|
|
28
|
+
boolean hasToken = isSet(oldPurchaseToken);
|
|
29
|
+
if (!hasToken) {
|
|
30
|
+
return isSet(oldProductIdentifier) || isSet(replacementModeName)
|
|
31
|
+
? "oldPurchaseToken is required when oldProductIdentifier or replacementMode is set"
|
|
32
|
+
: null;
|
|
33
|
+
}
|
|
34
|
+
if (!"subs".equals(productType)) {
|
|
35
|
+
return "oldPurchaseToken is only supported for subscriptions";
|
|
36
|
+
}
|
|
37
|
+
if (!isSet(oldProductIdentifier)) {
|
|
38
|
+
return "oldProductIdentifier cannot be empty when oldPurchaseToken is set";
|
|
39
|
+
}
|
|
40
|
+
if (fromName(replacementModeName) == UNKNOWN) {
|
|
41
|
+
return "Unknown replacementMode: " + replacementModeName;
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private static boolean isSet(String value) {
|
|
47
|
+
return value != null && !value.isEmpty();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static int fromName(String name) {
|
|
51
|
+
if (name == null) {
|
|
52
|
+
return UNKNOWN;
|
|
53
|
+
}
|
|
54
|
+
switch (name) {
|
|
55
|
+
case "WITH_TIME_PRORATION":
|
|
56
|
+
return BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode.WITH_TIME_PRORATION;
|
|
57
|
+
case "CHARGE_PRORATED_PRICE":
|
|
58
|
+
return BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode.CHARGE_PRORATED_PRICE;
|
|
59
|
+
case "WITHOUT_PRORATION":
|
|
60
|
+
return BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode.WITHOUT_PRORATION;
|
|
61
|
+
case "CHARGE_FULL_PRICE":
|
|
62
|
+
return BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode.CHARGE_FULL_PRICE;
|
|
63
|
+
case "DEFERRED":
|
|
64
|
+
return BillingFlowParams.ProductDetailsParams.SubscriptionProductReplacementParams.ReplacementMode.DEFERRED;
|
|
65
|
+
default:
|
|
66
|
+
return UNKNOWN;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/dist/docs.json
CHANGED
|
@@ -124,12 +124,12 @@
|
|
|
124
124
|
},
|
|
125
125
|
{
|
|
126
126
|
"name": "purchaseProduct",
|
|
127
|
-
"signature": "(options: { productIdentifier: string; planIdentifier?: string; offerToken?: string; productType?: PURCHASE_TYPE; quantity?: number; billingPlanType?: 'monthly' | 'upFront'; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; }) => Promise<Transaction>",
|
|
127
|
+
"signature": "(options: { productIdentifier: string; planIdentifier?: string; offerToken?: string; productType?: PURCHASE_TYPE; quantity?: number; billingPlanType?: 'monthly' | 'upFront'; appAccountToken?: string; isConsumable?: boolean; autoAcknowledgePurchases?: boolean; oldPurchaseToken?: string; oldProductIdentifier?: string; replacementMode?: SubscriptionReplacementMode; }) => Promise<Transaction>",
|
|
128
128
|
"parameters": [
|
|
129
129
|
{
|
|
130
130
|
"name": "options",
|
|
131
131
|
"docs": "- The product to purchase",
|
|
132
|
-
"type": "{ productIdentifier: string; planIdentifier?: string | undefined; offerToken?: string | undefined; productType?: PURCHASE_TYPE | undefined; quantity?: number | undefined; billingPlanType?: 'upFront' | 'monthly' | undefined; appAccountToken?: string | undefined; isConsumable?: boolean | undefined; autoAcknowledgePurchases?: boolean | undefined; }"
|
|
132
|
+
"type": "{ productIdentifier: string; planIdentifier?: string | undefined; offerToken?: string | undefined; productType?: PURCHASE_TYPE | undefined; quantity?: number | undefined; billingPlanType?: 'upFront' | 'monthly' | undefined; appAccountToken?: string | undefined; isConsumable?: boolean | undefined; autoAcknowledgePurchases?: boolean | undefined; oldPurchaseToken?: string | undefined; oldProductIdentifier?: string | undefined; replacementMode?: SubscriptionReplacementMode | undefined; }"
|
|
133
133
|
}
|
|
134
134
|
],
|
|
135
135
|
"returns": "Promise<Transaction>",
|
|
@@ -173,15 +173,59 @@
|
|
|
173
173
|
{
|
|
174
174
|
"name": "param",
|
|
175
175
|
"text": "options.autoAcknowledgePurchases - When false, this purchase is not auto-finished/acknowledged when\n `autoFinishTransactions` is also true. Does not disable auto-finishing on\n the iOS `transactionUpdated` listener; use `configure({ autoFinishTransactions: false })`\n for manual finishing across purchase and recovery flows. Defaults to true.\n - **Android**: Must acknowledge within 3 days or Google Play will refund\n - **iOS**: Unfinished transactions remain in the queue and may block future purchases"
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
"name": "param",
|
|
179
|
+
"text": "options.oldPurchaseToken - Only Android, the purchase token of the active subscription to replace (upgrade / downgrade).\n When set, `oldProductIdentifier` and `replacementMode` are required and `productType` must be `subs`.\n On iOS, purchasing another product of the same subscription group is already the upgrade / downgrade.\n Call `isSubscriptionReplacementSupported()` first: older native builds ignore this option, which would\n create a second subscription instead of replacing the first one."
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"name": "param",
|
|
183
|
+
"text": "options.oldProductIdentifier - Only Android, the product identifier of the subscription being replaced."
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"name": "param",
|
|
187
|
+
"text": "options.replacementMode - Only Android, how Google Play replaces the old subscription (see `SubscriptionReplacementMode`).\n Google recommends `CHARGE_PRORATED_PRICE` for upgrades and `DEFERRED` for downgrades between different subscription products.\n When `oldProductIdentifier` equals `productIdentifier` (a base plan change within the same subscription),\n use `CHARGE_FULL_PRICE` or `WITHOUT_PRORATION` for auto-renewing base plans.\n For prepaid destination base plans, use `CHARGE_FULL_PRICE` only; `WITHOUT_PRORATION` and other modes fail on Play.\n Play rejects an installment base plan changing to a non-installment base plan within the same product regardless of mode."
|
|
176
188
|
}
|
|
177
189
|
],
|
|
178
|
-
"docs": "Started purchase process for the given product.\n\nOn Android, `offerToken` selects which offer is charged. If the token is\nmissing from the product details returned by the plugin's query, the plugin\nrejects the purchase instead of selecting another offer. Other failures can\nalso reject the purchase. Google Play may still show a different checkout,\nfor example if the offer stops being eligible after the query, so the final\nprice is not guaranteed.\nOffer tokens come from a specific product query and go stale, so read\none from the same `getProducts()` / `getProduct()` call you purchase\nfrom.\n\nFor a **subscription** (`productType: 'subs'`) the order is: an explicit\n`offerToken`, then the first offer whose base plan matches\n`planIdentifier`, then the first offer the store returned.\n`planIdentifier` is the **base plan id**, which `getProducts()` reports\nas `Product.identifier`, not `Product.planIdentifier`, which holds the\nPlay product id. It is required unless an `offerToken` is given, since\na token already identifies one offer on its own.\n\nFor a **one-time product** (`productType: 'inapp'`) there is no base\nplan, so `planIdentifier` plays no part, and an `offerToken` selects one\nof the product's purchase offers. Without a token no offer token is set\nat all whenever the product still has a backward-compatible purchase\noption, which leaves the choice to Play: it charges whichever buy\npurchase option is marked backward-compatible, which is the first\n*created* one by default and another only if one was marked\n`legacyCompatible`. Either way it need not be the first offer\n`getProducts()` returned. Only for a product with no backward-compatible\noption does the first offer in the list get used. So pass the token\nwhenever a specific one-time offer matters.",
|
|
190
|
+
"docs": "Started purchase process for the given product.\n\n**Upgrade / downgrade a subscription (Android):** pass `oldPurchaseToken`, `oldProductIdentifier` and\n`replacementMode` together, with `productType` set to PURCHASE_TYPE.SUBS. Partial replacement options are rejected,\nand a `planIdentifier` that matches no base plan is rejected too (no first-offer fallback).\nOn iOS, purchase the other product of the same subscription group instead (StoreKit handles the change).\n\nOn Android, `offerToken` selects which offer is charged. If the token is\nmissing from the product details returned by the plugin's query, the plugin\nrejects the purchase instead of selecting another offer. Other failures can\nalso reject the purchase. Google Play may still show a different checkout,\nfor example if the offer stops being eligible after the query, so the final\nprice is not guaranteed.\nOffer tokens come from a specific product query and go stale, so read\none from the same `getProducts()` / `getProduct()` call you purchase\nfrom.\n\nFor a **subscription** (`productType: 'subs'`) the order is: an explicit\n`offerToken`, then the first offer whose base plan matches\n`planIdentifier`, then the first offer the store returned.\n`planIdentifier` is the **base plan id**, which `getProducts()` reports\nas `Product.identifier`, not `Product.planIdentifier`, which holds the\nPlay product id. It is required unless an `offerToken` is given, since\na token already identifies one offer on its own.\n\nFor a **one-time product** (`productType: 'inapp'`) there is no base\nplan, so `planIdentifier` plays no part, and an `offerToken` selects one\nof the product's purchase offers. Without a token no offer token is set\nat all whenever the product still has a backward-compatible purchase\noption, which leaves the choice to Play: it charges whichever buy\npurchase option is marked backward-compatible, which is the first\n*created* one by default and another only if one was marked\n`legacyCompatible`. Either way it need not be the first offer\n`getProducts()` returned. Only for a product with no backward-compatible\noption does the first offer in the list get used. So pass the token\nwhenever a specific one-time offer matters.",
|
|
179
191
|
"complexTypes": [
|
|
180
192
|
"Transaction",
|
|
181
|
-
"PURCHASE_TYPE"
|
|
193
|
+
"PURCHASE_TYPE",
|
|
194
|
+
"SubscriptionReplacementMode"
|
|
182
195
|
],
|
|
183
196
|
"slug": "purchaseproduct"
|
|
184
197
|
},
|
|
198
|
+
{
|
|
199
|
+
"name": "isSubscriptionReplacementSupported",
|
|
200
|
+
"signature": "() => Promise<{ supported: boolean; }>",
|
|
201
|
+
"parameters": [],
|
|
202
|
+
"returns": "Promise<{ supported: boolean; }>",
|
|
203
|
+
"tags": [
|
|
204
|
+
{
|
|
205
|
+
"name": "returns",
|
|
206
|
+
"text": "`supported: true` on Android builds that support replacement; `false` on iOS (StoreKit replaces\nwithin a subscription group automatically) and on web."
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "since",
|
|
210
|
+
"text": "8.10.0"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "platform",
|
|
214
|
+
"text": "android Returns true"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "platform",
|
|
218
|
+
"text": "ios Returns false (not needed)"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "example",
|
|
222
|
+
"text": "```typescript\n// Android. On iOS, purchase the other product of the same subscription group instead.\nlet supported = false;\ntry {\n ({ supported } = await NativePurchases.isSubscriptionReplacementSupported());\n} catch {\n // The native build predates this method: treat it as not supported.\n}\nconst { purchases } = await NativePurchases.getPurchases({ productType: PURCHASE_TYPE.SUBS });\nconst current = purchases.find((p) => p.productIdentifier === 'basic');\nif (supported && current?.purchaseToken) {\n await NativePurchases.purchaseProduct({\n productIdentifier: 'premium',\n planIdentifier: 'monthly',\n productType: PURCHASE_TYPE.SUBS,\n oldPurchaseToken: current.purchaseToken,\n oldProductIdentifier: current.productIdentifier,\n replacementMode: 'CHARGE_PRORATED_PRICE',\n });\n}\n```"
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
"docs": "Whether this native build can replace a subscription (`oldPurchaseToken` / `replacementMode` in `purchaseProduct()`).\n\nUse it before an upgrade / downgrade: a native build without this feature ignores the replacement options,\nso the purchase would become a second subscription instead of replacing the current one.\nOn native builds that predate this method the call rejects (not implemented): treat a rejection as not supported.",
|
|
226
|
+
"complexTypes": [],
|
|
227
|
+
"slug": "issubscriptionreplacementsupported"
|
|
228
|
+
},
|
|
185
229
|
{
|
|
186
230
|
"name": "getProducts",
|
|
187
231
|
"signature": "(options: { productIdentifiers: string[]; productType?: PURCHASE_TYPE; }) => Promise<{ products: Product[]; }>",
|
|
@@ -587,7 +631,7 @@
|
|
|
587
631
|
],
|
|
588
632
|
"returns": "Promise<PluginListenerHandle>",
|
|
589
633
|
"tags": [],
|
|
590
|
-
"docs": "Listen for
|
|
634
|
+
"docs": "Listen for purchase transaction updates outside an in-flight `purchaseProduct()` call.\n\n**iOS:** StoreKit Transaction.updates. Fires on app launch for unfinished transactions.\n\n**Android:** Google Play PurchasesUpdatedListener on a persistent billing connection while this\nlistener is registered, plus queryPurchasesAsync when the first listener is added and when the\napp returns to the foreground. Pending purchases that complete later are reported here.\n\nWhen `autoFinishTransactions` is `true` (default), iOS finishes each verified transaction before\nemitting; Android attempts to acknowledge each PURCHASED purchase before emitting (pending\npurchases and failed acknowledgements are still emitted without acknowledgement). When `false`,\npurchased `transactionUpdated` events include `needsFinish: true` when not yet acknowledged; call\n`finishTransaction()` or `acknowledgePurchase()` after backend validation.",
|
|
591
635
|
"complexTypes": [
|
|
592
636
|
"PluginListenerHandle",
|
|
593
637
|
"Transaction"
|
|
@@ -1426,7 +1470,7 @@
|
|
|
1426
1470
|
"name": "platform"
|
|
1427
1471
|
},
|
|
1428
1472
|
{
|
|
1429
|
-
"text": "android
|
|
1473
|
+
"text": "android Present on `transactionUpdated` purchased events when `autoFinishTransactions` is `false` and the purchase is not acknowledged; not set by `getUnfinishedTransactions()`",
|
|
1430
1474
|
"name": "platform"
|
|
1431
1475
|
}
|
|
1432
1476
|
],
|
|
@@ -2270,6 +2314,33 @@
|
|
|
2270
2314
|
"complexTypes": []
|
|
2271
2315
|
}
|
|
2272
2316
|
]
|
|
2317
|
+
},
|
|
2318
|
+
{
|
|
2319
|
+
"name": "SubscriptionReplacementMode",
|
|
2320
|
+
"slug": "subscriptionreplacementmode",
|
|
2321
|
+
"docs": "How Google Play replaces an active subscription when `purchaseProduct()` is called with `oldPurchaseToken`\n(Android only). Passed by name and mapped natively to Play Billing's item-level `ReplacementMode` constants.\nDo not pass numeric `PRORATION_MODE` values; use these names.\n\n- `WITH_TIME_PRORATION`: replace now; the remaining time is credited by moving the next billing date.\n- `CHARGE_PRORATED_PRICE`: replace now and charge the price difference for the rest of the current period\n (upgrades only, where the price per unit of time increases).\n- `WITHOUT_PRORATION`: replace now; the new price is charged at the next renewal.\n- `CHARGE_FULL_PRICE`: replace now and charge the full price of the new plan.\n- `DEFERRED`: replace at the next renewal.",
|
|
2322
|
+
"types": [
|
|
2323
|
+
{
|
|
2324
|
+
"text": "'WITH_TIME_PRORATION'",
|
|
2325
|
+
"complexTypes": []
|
|
2326
|
+
},
|
|
2327
|
+
{
|
|
2328
|
+
"text": "'CHARGE_PRORATED_PRICE'",
|
|
2329
|
+
"complexTypes": []
|
|
2330
|
+
},
|
|
2331
|
+
{
|
|
2332
|
+
"text": "'WITHOUT_PRORATION'",
|
|
2333
|
+
"complexTypes": []
|
|
2334
|
+
},
|
|
2335
|
+
{
|
|
2336
|
+
"text": "'CHARGE_FULL_PRICE'",
|
|
2337
|
+
"complexTypes": []
|
|
2338
|
+
},
|
|
2339
|
+
{
|
|
2340
|
+
"text": "'DEFERRED'",
|
|
2341
|
+
"complexTypes": []
|
|
2342
|
+
}
|
|
2343
|
+
]
|
|
2273
2344
|
}
|
|
2274
2345
|
],
|
|
2275
2346
|
"pluginConfigs": []
|
|
@@ -68,6 +68,21 @@ export declare enum PRORATION_MODE {
|
|
|
68
68
|
*/
|
|
69
69
|
DEFERRED = 4
|
|
70
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* How Google Play replaces an active subscription when `purchaseProduct()` is called with `oldPurchaseToken`
|
|
73
|
+
* (Android only). Passed by name and mapped natively to Play Billing's item-level `ReplacementMode` constants.
|
|
74
|
+
* Do not pass numeric `PRORATION_MODE` values; use these names.
|
|
75
|
+
*
|
|
76
|
+
* - `WITH_TIME_PRORATION`: replace now; the remaining time is credited by moving the next billing date.
|
|
77
|
+
* - `CHARGE_PRORATED_PRICE`: replace now and charge the price difference for the rest of the current period
|
|
78
|
+
* (upgrades only, where the price per unit of time increases).
|
|
79
|
+
* - `WITHOUT_PRORATION`: replace now; the new price is charged at the next renewal.
|
|
80
|
+
* - `CHARGE_FULL_PRICE`: replace now and charge the full price of the new plan.
|
|
81
|
+
* - `DEFERRED`: replace at the next renewal.
|
|
82
|
+
*
|
|
83
|
+
* @since 8.10.0
|
|
84
|
+
*/
|
|
85
|
+
export type SubscriptionReplacementMode = 'WITH_TIME_PRORATION' | 'CHARGE_PRORATED_PRICE' | 'WITHOUT_PRORATION' | 'CHARGE_FULL_PRICE' | 'DEFERRED';
|
|
71
86
|
export declare enum PACKAGE_TYPE {
|
|
72
87
|
/**
|
|
73
88
|
* A package that was defined with a custom identifier.
|
|
@@ -106,6 +121,16 @@ export declare enum PACKAGE_TYPE {
|
|
|
106
121
|
*/
|
|
107
122
|
WEEKLY = "WEEKLY"
|
|
108
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Stable `code` string on rejected plugin calls on Android (Capacitor `error.code`).
|
|
126
|
+
*
|
|
127
|
+
* Use these values instead of parsing localized error messages. Unlisted Play response
|
|
128
|
+
* codes appear as `UNKNOWN_<number>`. Non-purchased states use `PURCHASE_STATE_<number>`.
|
|
129
|
+
*
|
|
130
|
+
* @since 8.10.0
|
|
131
|
+
* @platform android
|
|
132
|
+
*/
|
|
133
|
+
export type NativePurchasesAndroidErrorCode = 'USER_CANCELED' | 'SERVICE_TIMEOUT' | 'SERVICE_UNAVAILABLE' | 'SERVICE_DISCONNECTED' | 'BILLING_UNAVAILABLE' | 'ITEM_UNAVAILABLE' | 'DEVELOPER_ERROR' | 'ERROR' | 'ITEM_ALREADY_OWNED' | 'ITEM_NOT_OWNED' | 'FEATURE_NOT_SUPPORTED' | 'NETWORK_ERROR' | 'PURCHASE_PENDING' | 'PURCHASE_NOT_FOUND' | 'PRODUCT_NOT_FOUND' | 'BILLING_CLIENT_CLOSED' | 'QUERY_PURCHASES_FAILED' | 'BILLING_INTERRUPTED' | 'BILLING_SETUP_TIMEOUT' | 'BILLING_SETUP_FAILED' | 'FINISH_TIMEOUT' | `UNKNOWN_${number}` | `PURCHASE_STATE_${number}`;
|
|
109
134
|
export declare enum INTRO_ELIGIBILITY_STATUS {
|
|
110
135
|
/**
|
|
111
136
|
* doesn't have enough information to determine eligibility.
|
|
@@ -559,7 +584,7 @@ export interface Transaction {
|
|
|
559
584
|
*
|
|
560
585
|
* @since 8.9.0
|
|
561
586
|
* @platform ios Present when the transaction is unfinished in StoreKit 2
|
|
562
|
-
* @platform android
|
|
587
|
+
* @platform android Present on `transactionUpdated` purchased events when `autoFinishTransactions` is `false` and the purchase is not acknowledged; not set by `getUnfinishedTransactions()`
|
|
563
588
|
*/
|
|
564
589
|
readonly needsFinish?: boolean;
|
|
565
590
|
/**
|
|
@@ -1156,6 +1181,11 @@ export interface NativePurchasesPlugin {
|
|
|
1156
1181
|
/**
|
|
1157
1182
|
* Started purchase process for the given product.
|
|
1158
1183
|
*
|
|
1184
|
+
* **Upgrade / downgrade a subscription (Android):** pass `oldPurchaseToken`, `oldProductIdentifier` and
|
|
1185
|
+
* `replacementMode` together, with `productType` set to PURCHASE_TYPE.SUBS. Partial replacement options are rejected,
|
|
1186
|
+
* and a `planIdentifier` that matches no base plan is rejected too (no first-offer fallback).
|
|
1187
|
+
* On iOS, purchase the other product of the same subscription group instead (StoreKit handles the change).
|
|
1188
|
+
*
|
|
1159
1189
|
* On Android, `offerToken` selects which offer is charged. If the token is
|
|
1160
1190
|
* missing from the product details returned by the plugin's query, the plugin
|
|
1161
1191
|
* rejects the purchase instead of selecting another offer. Other failures can
|
|
@@ -1206,6 +1236,18 @@ export interface NativePurchasesPlugin {
|
|
|
1206
1236
|
* for manual finishing across purchase and recovery flows. Defaults to true.
|
|
1207
1237
|
* - **Android**: Must acknowledge within 3 days or Google Play will refund
|
|
1208
1238
|
* - **iOS**: Unfinished transactions remain in the queue and may block future purchases
|
|
1239
|
+
* @param options.oldPurchaseToken - Only Android, the purchase token of the active subscription to replace (upgrade / downgrade).
|
|
1240
|
+
* When set, `oldProductIdentifier` and `replacementMode` are required and `productType` must be `subs`.
|
|
1241
|
+
* On iOS, purchasing another product of the same subscription group is already the upgrade / downgrade.
|
|
1242
|
+
* Call `isSubscriptionReplacementSupported()` first: older native builds ignore this option, which would
|
|
1243
|
+
* create a second subscription instead of replacing the first one.
|
|
1244
|
+
* @param options.oldProductIdentifier - Only Android, the product identifier of the subscription being replaced.
|
|
1245
|
+
* @param options.replacementMode - Only Android, how Google Play replaces the old subscription (see `SubscriptionReplacementMode`).
|
|
1246
|
+
* Google recommends `CHARGE_PRORATED_PRICE` for upgrades and `DEFERRED` for downgrades between different subscription products.
|
|
1247
|
+
* When `oldProductIdentifier` equals `productIdentifier` (a base plan change within the same subscription),
|
|
1248
|
+
* use `CHARGE_FULL_PRICE` or `WITHOUT_PRORATION` for auto-renewing base plans.
|
|
1249
|
+
* For prepaid destination base plans, use `CHARGE_FULL_PRICE` only; `WITHOUT_PRORATION` and other modes fail on Play.
|
|
1250
|
+
* Play rejects an installment base plan changing to a non-installment base plan within the same product regardless of mode.
|
|
1209
1251
|
*/
|
|
1210
1252
|
purchaseProduct(options: {
|
|
1211
1253
|
productIdentifier: string;
|
|
@@ -1217,7 +1259,49 @@ export interface NativePurchasesPlugin {
|
|
|
1217
1259
|
appAccountToken?: string;
|
|
1218
1260
|
isConsumable?: boolean;
|
|
1219
1261
|
autoAcknowledgePurchases?: boolean;
|
|
1262
|
+
oldPurchaseToken?: string;
|
|
1263
|
+
oldProductIdentifier?: string;
|
|
1264
|
+
replacementMode?: SubscriptionReplacementMode;
|
|
1220
1265
|
}): Promise<Transaction>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Whether this native build can replace a subscription (`oldPurchaseToken` / `replacementMode` in `purchaseProduct()`).
|
|
1268
|
+
*
|
|
1269
|
+
* Use it before an upgrade / downgrade: a native build without this feature ignores the replacement options,
|
|
1270
|
+
* so the purchase would become a second subscription instead of replacing the current one.
|
|
1271
|
+
* On native builds that predate this method the call rejects (not implemented): treat a rejection as not supported.
|
|
1272
|
+
*
|
|
1273
|
+
* @returns `supported: true` on Android builds that support replacement; `false` on iOS (StoreKit replaces
|
|
1274
|
+
* within a subscription group automatically) and on web.
|
|
1275
|
+
* @since 8.10.0
|
|
1276
|
+
* @platform android Returns true
|
|
1277
|
+
* @platform ios Returns false (not needed)
|
|
1278
|
+
*
|
|
1279
|
+
* @example
|
|
1280
|
+
* ```typescript
|
|
1281
|
+
* // Android. On iOS, purchase the other product of the same subscription group instead.
|
|
1282
|
+
* let supported = false;
|
|
1283
|
+
* try {
|
|
1284
|
+
* ({ supported } = await NativePurchases.isSubscriptionReplacementSupported());
|
|
1285
|
+
* } catch {
|
|
1286
|
+
* // The native build predates this method: treat it as not supported.
|
|
1287
|
+
* }
|
|
1288
|
+
* const { purchases } = await NativePurchases.getPurchases({ productType: PURCHASE_TYPE.SUBS });
|
|
1289
|
+
* const current = purchases.find((p) => p.productIdentifier === 'basic');
|
|
1290
|
+
* if (supported && current?.purchaseToken) {
|
|
1291
|
+
* await NativePurchases.purchaseProduct({
|
|
1292
|
+
* productIdentifier: 'premium',
|
|
1293
|
+
* planIdentifier: 'monthly',
|
|
1294
|
+
* productType: PURCHASE_TYPE.SUBS,
|
|
1295
|
+
* oldPurchaseToken: current.purchaseToken,
|
|
1296
|
+
* oldProductIdentifier: current.productIdentifier,
|
|
1297
|
+
* replacementMode: 'CHARGE_PRORATED_PRICE',
|
|
1298
|
+
* });
|
|
1299
|
+
* }
|
|
1300
|
+
* ```
|
|
1301
|
+
*/
|
|
1302
|
+
isSubscriptionReplacementSupported(): Promise<{
|
|
1303
|
+
supported: boolean;
|
|
1304
|
+
}>;
|
|
1221
1305
|
/**
|
|
1222
1306
|
* Gets the product info associated with a list of product identifiers.
|
|
1223
1307
|
*
|
|
@@ -1531,14 +1615,19 @@ export interface NativePurchasesPlugin {
|
|
|
1531
1615
|
storefrontId?: string;
|
|
1532
1616
|
}>;
|
|
1533
1617
|
/**
|
|
1534
|
-
* Listen for
|
|
1535
|
-
* Fires on app launch if there are unfinished transactions, and for any updates afterward.
|
|
1618
|
+
* Listen for purchase transaction updates outside an in-flight `purchaseProduct()` call.
|
|
1536
1619
|
*
|
|
1537
|
-
*
|
|
1538
|
-
* before emitting the event. When `false`, the event includes `needsFinish: true` and you must call
|
|
1539
|
-
* `finishTransaction()` after backend validation.
|
|
1620
|
+
* **iOS:** StoreKit Transaction.updates. Fires on app launch for unfinished transactions.
|
|
1540
1621
|
*
|
|
1541
|
-
*
|
|
1622
|
+
* **Android:** Google Play PurchasesUpdatedListener on a persistent billing connection while this
|
|
1623
|
+
* listener is registered, plus queryPurchasesAsync when the first listener is added and when the
|
|
1624
|
+
* app returns to the foreground. Pending purchases that complete later are reported here.
|
|
1625
|
+
*
|
|
1626
|
+
* When `autoFinishTransactions` is `true` (default), iOS finishes each verified transaction before
|
|
1627
|
+
* emitting; Android attempts to acknowledge each PURCHASED purchase before emitting (pending
|
|
1628
|
+
* purchases and failed acknowledgements are still emitted without acknowledgement). When `false`,
|
|
1629
|
+
* purchased `transactionUpdated` events include `needsFinish: true` when not yet acknowledged; call
|
|
1630
|
+
* `finishTransaction()` or `acknowledgePurchase()` after backend validation.
|
|
1542
1631
|
*/
|
|
1543
1632
|
addListener(eventName: 'transactionUpdated', listenerFunc: (transaction: Transaction) => void): Promise<PluginListenerHandle>;
|
|
1544
1633
|
/**
|