@choochmeque/tauri-plugin-iap-api 0.7.1 → 0.8.2
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 +13 -1
- package/dist-js/index.cjs +25 -0
- package/dist-js/index.d.ts +38 -0
- package/dist-js/index.js +26 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@ A Tauri plugin for In-App Purchases (IAP) with support for subscriptions on iOS
|
|
|
21
21
|
- Fraud prevention with obfuscated account/profile IDs (Android)
|
|
22
22
|
- App account token support for tracking (iOS)
|
|
23
23
|
- Automatic offer token selection (Android)
|
|
24
|
+
- Subscription upgrades/downgrades with proration modes (Android)
|
|
24
25
|
|
|
25
26
|
## Platform Support
|
|
26
27
|
|
|
@@ -45,7 +46,7 @@ Add the plugin to your Tauri project's `Cargo.toml`:
|
|
|
45
46
|
|
|
46
47
|
```toml
|
|
47
48
|
[dependencies]
|
|
48
|
-
tauri-plugin-iap = "0.
|
|
49
|
+
tauri-plugin-iap = "0.8"
|
|
49
50
|
```
|
|
50
51
|
|
|
51
52
|
Configure the plugin permissions in your `capabilities/default.json`:
|
|
@@ -148,6 +149,15 @@ const purchaseResult = await purchase('subscription_id_1', 'subs', {
|
|
|
148
149
|
appAccountToken: '550e8400-e29b-41d4-a716-446655440000'
|
|
149
150
|
});
|
|
150
151
|
|
|
152
|
+
// Upgrade/downgrade subscription (Android)
|
|
153
|
+
import { SubscriptionReplacementMode } from '@choochmeque/tauri-plugin-iap-api';
|
|
154
|
+
|
|
155
|
+
const upgraded = await purchase('premium_subscription', 'subs', {
|
|
156
|
+
offerToken: 'premium_offer_token',
|
|
157
|
+
oldPurchaseToken: currentSubscription.purchaseToken,
|
|
158
|
+
subscriptionReplacementMode: SubscriptionReplacementMode.WITH_TIME_PRORATION
|
|
159
|
+
});
|
|
160
|
+
|
|
151
161
|
// Restore purchases (specify product type)
|
|
152
162
|
const restored = await restorePurchases('subs');
|
|
153
163
|
|
|
@@ -251,6 +261,8 @@ Initiates a purchase flow with enhanced options for fraud prevention and account
|
|
|
251
261
|
- `obfuscatedAccountId`: (Android) Hashed account ID for fraud prevention
|
|
252
262
|
- `obfuscatedProfileId`: (Android) Hashed profile ID for fraud prevention
|
|
253
263
|
- `appAccountToken`: (iOS) UUID string for account tracking and fraud prevention
|
|
264
|
+
- `oldPurchaseToken`: (Android) Purchase token of existing subscription to replace for upgrades/downgrades
|
|
265
|
+
- `subscriptionReplacementMode`: (Android) Proration mode using `SubscriptionReplacementMode` enum (defaults to `WITH_TIME_PRORATION`)
|
|
254
266
|
|
|
255
267
|
**Returns:** Purchase object with transaction details
|
|
256
268
|
|
package/dist-js/index.cjs
CHANGED
|
@@ -11,6 +11,24 @@ exports.PurchaseState = void 0;
|
|
|
11
11
|
PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
|
|
12
12
|
PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
|
|
13
13
|
})(exports.PurchaseState || (exports.PurchaseState = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Google Play subscription replacement modes for upgrades/downgrades.
|
|
16
|
+
* Used with `subscriptionReplacementMode` in `PurchaseOptions`.
|
|
17
|
+
* @see https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode
|
|
18
|
+
*/
|
|
19
|
+
exports.SubscriptionReplacementMode = void 0;
|
|
20
|
+
(function (SubscriptionReplacementMode) {
|
|
21
|
+
/** Replacement takes effect when the old plan expires, and the new price is charged at the same time. */
|
|
22
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["DEFERRED"] = 6] = "DEFERRED";
|
|
23
|
+
/** Replacement takes effect immediately. The billing cycle remains the same. The remaining value from the old price is prorated for the new plan. */
|
|
24
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["WITH_TIME_PRORATION"] = 1] = "WITH_TIME_PRORATION";
|
|
25
|
+
/** Replacement takes effect immediately. The new price is charged immediately and in full. Any remaining period from the old plan is used to extend the new billing date. */
|
|
26
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["CHARGE_FULL_PRICE"] = 5] = "CHARGE_FULL_PRICE";
|
|
27
|
+
/** Replacement takes effect immediately. The new plan price is reduced by the prorated cost of the old plan for the remaining period. */
|
|
28
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["CHARGE_PRORATED_PRICE"] = 2] = "CHARGE_PRORATED_PRICE";
|
|
29
|
+
/** Replacement takes effect immediately with no proration. The user is charged full price for the new plan. */
|
|
30
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["WITHOUT_PRORATION"] = 3] = "WITHOUT_PRORATION";
|
|
31
|
+
})(exports.SubscriptionReplacementMode || (exports.SubscriptionReplacementMode = {}));
|
|
14
32
|
/**
|
|
15
33
|
* Initialize the IAP plugin.
|
|
16
34
|
*
|
|
@@ -65,6 +83,13 @@ async function getProducts(productIds, productType = "subs") {
|
|
|
65
83
|
* obfuscatedAccountId: 'user_account_id',
|
|
66
84
|
* obfuscatedProfileId: 'user_profile_id'
|
|
67
85
|
* });
|
|
86
|
+
*
|
|
87
|
+
* // Subscription upgrade/downgrade (Android)
|
|
88
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
89
|
+
* offerToken: 'new_plan_offer_token',
|
|
90
|
+
* oldPurchaseToken: 'existing_subscription_purchase_token',
|
|
91
|
+
* subscriptionReplacementMode: SubscriptionReplacementMode.WITH_TIME_PRORATION
|
|
92
|
+
* });
|
|
68
93
|
* ```
|
|
69
94
|
*/
|
|
70
95
|
async function purchase(productId, productType = "subs", options) {
|
package/dist-js/index.d.ts
CHANGED
|
@@ -131,6 +131,23 @@ export interface ProductStatus {
|
|
|
131
131
|
isAcknowledged?: boolean;
|
|
132
132
|
purchaseToken?: string;
|
|
133
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Google Play subscription replacement modes for upgrades/downgrades.
|
|
136
|
+
* Used with `subscriptionReplacementMode` in `PurchaseOptions`.
|
|
137
|
+
* @see https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode
|
|
138
|
+
*/
|
|
139
|
+
export declare enum SubscriptionReplacementMode {
|
|
140
|
+
/** Replacement takes effect when the old plan expires, and the new price is charged at the same time. */
|
|
141
|
+
DEFERRED = 6,
|
|
142
|
+
/** Replacement takes effect immediately. The billing cycle remains the same. The remaining value from the old price is prorated for the new plan. */
|
|
143
|
+
WITH_TIME_PRORATION = 1,
|
|
144
|
+
/** Replacement takes effect immediately. The new price is charged immediately and in full. Any remaining period from the old plan is used to extend the new billing date. */
|
|
145
|
+
CHARGE_FULL_PRICE = 5,
|
|
146
|
+
/** Replacement takes effect immediately. The new plan price is reduced by the prorated cost of the old plan for the remaining period. */
|
|
147
|
+
CHARGE_PRORATED_PRICE = 2,
|
|
148
|
+
/** Replacement takes effect immediately with no proration. The user is charged full price for the new plan. */
|
|
149
|
+
WITHOUT_PRORATION = 3
|
|
150
|
+
}
|
|
134
151
|
/**
|
|
135
152
|
* Optional parameters for purchase requests
|
|
136
153
|
*/
|
|
@@ -143,6 +160,20 @@ export interface PurchaseOptions {
|
|
|
143
160
|
obfuscatedProfileId?: string;
|
|
144
161
|
/** App account token - must be a valid UUID string (iOS only) */
|
|
145
162
|
appAccountToken?: string;
|
|
163
|
+
/**
|
|
164
|
+
* Purchase token of the existing subscription to replace (Android only).
|
|
165
|
+
* When set, the purchase becomes a subscription upgrade/downgrade.
|
|
166
|
+
* Obtain this from a previous purchase's `purchaseToken` field.
|
|
167
|
+
*/
|
|
168
|
+
oldPurchaseToken?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Replacement mode for subscription upgrades/downgrades (Android only).
|
|
171
|
+
* Determines how the transition between old and new subscription is handled.
|
|
172
|
+
* Use values from the `SubscriptionReplacementMode` enum.
|
|
173
|
+
* Defaults to `WITH_TIME_PRORATION` if not specified.
|
|
174
|
+
* @see SubscriptionReplacementMode
|
|
175
|
+
*/
|
|
176
|
+
subscriptionReplacementMode?: SubscriptionReplacementMode;
|
|
146
177
|
}
|
|
147
178
|
/**
|
|
148
179
|
* Initialize the IAP plugin.
|
|
@@ -189,6 +220,13 @@ export declare function getProducts(productIds: string[], productType?: "subs" |
|
|
|
189
220
|
* obfuscatedAccountId: 'user_account_id',
|
|
190
221
|
* obfuscatedProfileId: 'user_profile_id'
|
|
191
222
|
* });
|
|
223
|
+
*
|
|
224
|
+
* // Subscription upgrade/downgrade (Android)
|
|
225
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
226
|
+
* offerToken: 'new_plan_offer_token',
|
|
227
|
+
* oldPurchaseToken: 'existing_subscription_purchase_token',
|
|
228
|
+
* subscriptionReplacementMode: SubscriptionReplacementMode.WITH_TIME_PRORATION
|
|
229
|
+
* });
|
|
192
230
|
* ```
|
|
193
231
|
*/
|
|
194
232
|
export declare function purchase(productId: string, productType?: "subs" | "inapp", options?: PurchaseOptions): Promise<Purchase>;
|
package/dist-js/index.js
CHANGED
|
@@ -9,6 +9,24 @@ var PurchaseState;
|
|
|
9
9
|
PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
|
|
10
10
|
PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
|
|
11
11
|
})(PurchaseState || (PurchaseState = {}));
|
|
12
|
+
/**
|
|
13
|
+
* Google Play subscription replacement modes for upgrades/downgrades.
|
|
14
|
+
* Used with `subscriptionReplacementMode` in `PurchaseOptions`.
|
|
15
|
+
* @see https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode
|
|
16
|
+
*/
|
|
17
|
+
var SubscriptionReplacementMode;
|
|
18
|
+
(function (SubscriptionReplacementMode) {
|
|
19
|
+
/** Replacement takes effect when the old plan expires, and the new price is charged at the same time. */
|
|
20
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["DEFERRED"] = 6] = "DEFERRED";
|
|
21
|
+
/** Replacement takes effect immediately. The billing cycle remains the same. The remaining value from the old price is prorated for the new plan. */
|
|
22
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["WITH_TIME_PRORATION"] = 1] = "WITH_TIME_PRORATION";
|
|
23
|
+
/** Replacement takes effect immediately. The new price is charged immediately and in full. Any remaining period from the old plan is used to extend the new billing date. */
|
|
24
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["CHARGE_FULL_PRICE"] = 5] = "CHARGE_FULL_PRICE";
|
|
25
|
+
/** Replacement takes effect immediately. The new plan price is reduced by the prorated cost of the old plan for the remaining period. */
|
|
26
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["CHARGE_PRORATED_PRICE"] = 2] = "CHARGE_PRORATED_PRICE";
|
|
27
|
+
/** Replacement takes effect immediately with no proration. The user is charged full price for the new plan. */
|
|
28
|
+
SubscriptionReplacementMode[SubscriptionReplacementMode["WITHOUT_PRORATION"] = 3] = "WITHOUT_PRORATION";
|
|
29
|
+
})(SubscriptionReplacementMode || (SubscriptionReplacementMode = {}));
|
|
12
30
|
/**
|
|
13
31
|
* Initialize the IAP plugin.
|
|
14
32
|
*
|
|
@@ -63,6 +81,13 @@ async function getProducts(productIds, productType = "subs") {
|
|
|
63
81
|
* obfuscatedAccountId: 'user_account_id',
|
|
64
82
|
* obfuscatedProfileId: 'user_profile_id'
|
|
65
83
|
* });
|
|
84
|
+
*
|
|
85
|
+
* // Subscription upgrade/downgrade (Android)
|
|
86
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
87
|
+
* offerToken: 'new_plan_offer_token',
|
|
88
|
+
* oldPurchaseToken: 'existing_subscription_purchase_token',
|
|
89
|
+
* subscriptionReplacementMode: SubscriptionReplacementMode.WITH_TIME_PRORATION
|
|
90
|
+
* });
|
|
66
91
|
* ```
|
|
67
92
|
*/
|
|
68
93
|
async function purchase(productId, productType = "subs", options) {
|
|
@@ -181,4 +206,4 @@ async function onPurchaseUpdated(callback) {
|
|
|
181
206
|
return await addPluginListener("iap", "purchaseUpdated", callback);
|
|
182
207
|
}
|
|
183
208
|
|
|
184
|
-
export { PurchaseState, acknowledgePurchase, getProductStatus, getProducts, getPurchaseHistory, initialize, onPurchaseUpdated, purchase, restorePurchases };
|
|
209
|
+
export { PurchaseState, SubscriptionReplacementMode, acknowledgePurchase, getProductStatus, getProducts, getPurchaseHistory, initialize, onPurchaseUpdated, purchase, restorePurchases };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choochmeque/tauri-plugin-iap-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "You",
|
|
6
6
|
"description": "A Tauri v2 plugin that enables In-App Purchases (IAP)",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@vitest/coverage-v8": "^4.0.13",
|
|
41
41
|
"@vitest/ui": "^4.0.13",
|
|
42
42
|
"happy-dom": "^20.0.10",
|
|
43
|
-
"prettier": "3.8.
|
|
43
|
+
"prettier": "3.8.1",
|
|
44
44
|
"rollup": "^4.9.6",
|
|
45
45
|
"tslib": "^2.6.2",
|
|
46
46
|
"typescript": "^5.3.3",
|