@choochmeque/tauri-plugin-iap-api 0.2.1 → 0.3.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/dist-js/index.cjs +146 -14
- package/dist-js/index.d.ts +183 -4
- package/dist-js/index.js +146 -14
- package/package.json +6 -3
package/dist-js/index.cjs
CHANGED
|
@@ -3,60 +3,192 @@
|
|
|
3
3
|
var core = require('@tauri-apps/api/core');
|
|
4
4
|
var event = require('@tauri-apps/api/event');
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Purchase state enumeration
|
|
8
|
+
*/
|
|
6
9
|
exports.PurchaseState = void 0;
|
|
7
10
|
(function (PurchaseState) {
|
|
8
11
|
PurchaseState[PurchaseState["PURCHASED"] = 0] = "PURCHASED";
|
|
9
12
|
PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
|
|
10
13
|
PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
|
|
11
14
|
})(exports.PurchaseState || (exports.PurchaseState = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Initialize the IAP plugin.
|
|
17
|
+
* Must be called before any other IAP operations.
|
|
18
|
+
*
|
|
19
|
+
* @returns Promise resolving to initialization status
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const result = await initialize();
|
|
23
|
+
* if (result.success) {
|
|
24
|
+
* console.log('IAP initialized successfully');
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
12
28
|
async function initialize() {
|
|
13
|
-
return await core.invoke(
|
|
29
|
+
return await core.invoke("plugin:iap|initialize");
|
|
14
30
|
}
|
|
15
|
-
|
|
16
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Fetch product information from the app store.
|
|
33
|
+
*
|
|
34
|
+
* @param productIds - Array of product identifiers to fetch
|
|
35
|
+
* @param productType - Type of products: "subs" for subscriptions, "inapp" for one-time purchases
|
|
36
|
+
* @returns Promise resolving to product information
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const { products } = await getProducts(
|
|
40
|
+
* ['com.example.premium', 'com.example.remove_ads'],
|
|
41
|
+
* 'inapp'
|
|
42
|
+
* );
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
async function getProducts(productIds, productType = "subs") {
|
|
46
|
+
return await core.invoke("plugin:iap|get_products", {
|
|
17
47
|
payload: {
|
|
18
48
|
productIds,
|
|
19
49
|
productType,
|
|
20
50
|
},
|
|
21
51
|
});
|
|
22
52
|
}
|
|
23
|
-
|
|
24
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Initiate a purchase for the specified product.
|
|
55
|
+
*
|
|
56
|
+
* @param productId - Product identifier to purchase
|
|
57
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
58
|
+
* @param options - Optional purchase parameters (platform-specific)
|
|
59
|
+
* @returns Promise resolving to purchase transaction details
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* // Simple purchase
|
|
63
|
+
* const purchase = await purchase('com.example.premium', 'subs');
|
|
64
|
+
*
|
|
65
|
+
* // With options (iOS)
|
|
66
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
67
|
+
* appAccountToken: '550e8400-e29b-41d4-a716-446655440000' // Must be valid UUID
|
|
68
|
+
* });
|
|
69
|
+
*
|
|
70
|
+
* // With options (Android)
|
|
71
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
72
|
+
* offerToken: 'offer_token_here',
|
|
73
|
+
* obfuscatedAccountId: 'user_account_id',
|
|
74
|
+
* obfuscatedProfileId: 'user_profile_id'
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
async function purchase(productId, productType = "subs", options) {
|
|
79
|
+
return await core.invoke("plugin:iap|purchase", {
|
|
25
80
|
payload: {
|
|
26
81
|
productId,
|
|
27
82
|
productType,
|
|
28
|
-
|
|
83
|
+
...options,
|
|
29
84
|
},
|
|
30
85
|
});
|
|
31
86
|
}
|
|
32
|
-
|
|
33
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Restore user's previous purchases.
|
|
89
|
+
*
|
|
90
|
+
* @param productType - Type of products to restore: "subs" or "inapp"
|
|
91
|
+
* @returns Promise resolving to list of restored purchases
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const { purchases } = await restorePurchases('subs');
|
|
95
|
+
* purchases.forEach(purchase => {
|
|
96
|
+
* console.log(`Restored: ${purchase.productId}`);
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
async function restorePurchases(productType = "subs") {
|
|
101
|
+
return await core.invoke("plugin:iap|restore_purchases", {
|
|
34
102
|
payload: {
|
|
35
103
|
productType,
|
|
36
104
|
},
|
|
37
105
|
});
|
|
38
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Get the user's purchase history.
|
|
109
|
+
* Note: Not supported on all platforms.
|
|
110
|
+
*
|
|
111
|
+
* @returns Promise resolving to purchase history
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const { history } = await getPurchaseHistory();
|
|
115
|
+
* history.forEach(record => {
|
|
116
|
+
* console.log(`Purchase: ${record.productId} at ${record.purchaseTime}`);
|
|
117
|
+
* });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
39
120
|
async function getPurchaseHistory() {
|
|
40
|
-
return await core.invoke(
|
|
121
|
+
return await core.invoke("plugin:iap|get_purchase_history");
|
|
41
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Acknowledge a purchase (Android only).
|
|
125
|
+
* Purchases must be acknowledged within 3 days or they will be refunded.
|
|
126
|
+
* iOS automatically acknowledges purchases.
|
|
127
|
+
*
|
|
128
|
+
* @param purchaseToken - Purchase token from the transaction
|
|
129
|
+
* @returns Promise resolving to acknowledgment status
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const result = await acknowledgePurchase(purchase.purchaseToken);
|
|
133
|
+
* if (result.success) {
|
|
134
|
+
* console.log('Purchase acknowledged');
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
42
138
|
async function acknowledgePurchase(purchaseToken) {
|
|
43
|
-
return await core.invoke(
|
|
139
|
+
return await core.invoke("plugin:iap|acknowledge_purchase", {
|
|
44
140
|
payload: {
|
|
45
141
|
purchaseToken,
|
|
46
142
|
},
|
|
47
143
|
});
|
|
48
144
|
}
|
|
49
|
-
|
|
50
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Get the current status of a product for the user.
|
|
147
|
+
* Checks if the product is owned, expired, or available for purchase.
|
|
148
|
+
*
|
|
149
|
+
* @param productId - Product identifier to check
|
|
150
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
151
|
+
* @returns Promise resolving to product status
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const status = await getProductStatus('com.example.premium', 'subs');
|
|
155
|
+
* if (status.isOwned) {
|
|
156
|
+
* console.log('User owns this product');
|
|
157
|
+
* if (status.isAutoRenewing) {
|
|
158
|
+
* console.log('Subscription is auto-renewing');
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
async function getProductStatus(productId, productType = "subs") {
|
|
164
|
+
return await core.invoke("plugin:iap|get_product_status", {
|
|
51
165
|
payload: {
|
|
52
166
|
productId,
|
|
53
167
|
productType,
|
|
54
168
|
},
|
|
55
169
|
});
|
|
56
170
|
}
|
|
57
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Listen for purchase updates.
|
|
173
|
+
* This event is triggered when a purchase state changes.
|
|
174
|
+
*
|
|
175
|
+
* @param callback - Function to call when a purchase is updated
|
|
176
|
+
* @returns Cleanup function to stop listening
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* const unsubscribe = onPurchaseUpdated((purchase) => {
|
|
180
|
+
* console.log(`Purchase updated: ${purchase.productId}`);
|
|
181
|
+
* if (purchase.purchaseState === PurchaseState.PURCHASED) {
|
|
182
|
+
* // Handle successful purchase
|
|
183
|
+
* }
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* // Later, stop listening
|
|
187
|
+
* unsubscribe();
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
58
190
|
function onPurchaseUpdated(callback) {
|
|
59
|
-
const unlisten = event.listen(
|
|
191
|
+
const unlisten = event.listen("purchaseUpdated", (event) => {
|
|
60
192
|
callback(event.payload);
|
|
61
193
|
});
|
|
62
194
|
return () => {
|
package/dist-js/index.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Response from IAP initialization
|
|
3
|
+
*/
|
|
1
4
|
export interface InitializeResponse {
|
|
2
5
|
success: boolean;
|
|
3
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Represents a pricing phase for subscription products
|
|
9
|
+
*/
|
|
4
10
|
export interface PricingPhase {
|
|
5
11
|
formattedPrice: string;
|
|
6
12
|
priceCurrencyCode: string;
|
|
@@ -9,12 +15,18 @@ export interface PricingPhase {
|
|
|
9
15
|
billingCycleCount: number;
|
|
10
16
|
recurrenceMode: number;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Subscription offer details including pricing phases
|
|
20
|
+
*/
|
|
12
21
|
export interface SubscriptionOffer {
|
|
13
22
|
offerToken: string;
|
|
14
23
|
basePlanId: string;
|
|
15
24
|
offerId?: string;
|
|
16
25
|
pricingPhases: PricingPhase[];
|
|
17
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Product information from the app store
|
|
29
|
+
*/
|
|
18
30
|
export interface Product {
|
|
19
31
|
productId: string;
|
|
20
32
|
title: string;
|
|
@@ -25,9 +37,15 @@ export interface Product {
|
|
|
25
37
|
priceAmountMicros?: number;
|
|
26
38
|
subscriptionOfferDetails?: SubscriptionOffer[];
|
|
27
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Response containing products fetched from the store
|
|
42
|
+
*/
|
|
28
43
|
export interface GetProductsResponse {
|
|
29
44
|
products: Product[];
|
|
30
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Purchase transaction information
|
|
48
|
+
*/
|
|
31
49
|
export interface Purchase {
|
|
32
50
|
orderId?: string;
|
|
33
51
|
packageName: string;
|
|
@@ -40,9 +58,15 @@ export interface Purchase {
|
|
|
40
58
|
originalJson: string;
|
|
41
59
|
signature: string;
|
|
42
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Response containing restored purchases
|
|
63
|
+
*/
|
|
43
64
|
export interface RestorePurchasesResponse {
|
|
44
65
|
purchases: Purchase[];
|
|
45
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Historical purchase record
|
|
69
|
+
*/
|
|
46
70
|
export interface PurchaseHistoryRecord {
|
|
47
71
|
productId: string;
|
|
48
72
|
purchaseTime: number;
|
|
@@ -51,17 +75,29 @@ export interface PurchaseHistoryRecord {
|
|
|
51
75
|
originalJson: string;
|
|
52
76
|
signature: string;
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Response containing purchase history
|
|
80
|
+
*/
|
|
54
81
|
export interface GetPurchaseHistoryResponse {
|
|
55
82
|
history: PurchaseHistoryRecord[];
|
|
56
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* Response from acknowledging a purchase
|
|
86
|
+
*/
|
|
57
87
|
export interface AcknowledgePurchaseResponse {
|
|
58
88
|
success: boolean;
|
|
59
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Purchase state enumeration
|
|
92
|
+
*/
|
|
60
93
|
export declare enum PurchaseState {
|
|
61
94
|
PURCHASED = 0,
|
|
62
95
|
CANCELED = 1,
|
|
63
96
|
PENDING = 2
|
|
64
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Current status of a product for the user
|
|
100
|
+
*/
|
|
65
101
|
export interface ProductStatus {
|
|
66
102
|
productId: string;
|
|
67
103
|
isOwned: boolean;
|
|
@@ -72,11 +108,154 @@ export interface ProductStatus {
|
|
|
72
108
|
isAcknowledged?: boolean;
|
|
73
109
|
purchaseToken?: string;
|
|
74
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Optional parameters for purchase requests
|
|
113
|
+
*/
|
|
114
|
+
export interface PurchaseOptions {
|
|
115
|
+
/** Offer token for subscription products (Android) */
|
|
116
|
+
offerToken?: string;
|
|
117
|
+
/** Obfuscated account identifier for fraud prevention (Android only) */
|
|
118
|
+
obfuscatedAccountId?: string;
|
|
119
|
+
/** Obfuscated profile identifier for fraud prevention (Android only) */
|
|
120
|
+
obfuscatedProfileId?: string;
|
|
121
|
+
/** App account token - must be a valid UUID string (iOS only) */
|
|
122
|
+
appAccountToken?: string;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Initialize the IAP plugin.
|
|
126
|
+
* Must be called before any other IAP operations.
|
|
127
|
+
*
|
|
128
|
+
* @returns Promise resolving to initialization status
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const result = await initialize();
|
|
132
|
+
* if (result.success) {
|
|
133
|
+
* console.log('IAP initialized successfully');
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
75
137
|
export declare function initialize(): Promise<InitializeResponse>;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Fetch product information from the app store.
|
|
140
|
+
*
|
|
141
|
+
* @param productIds - Array of product identifiers to fetch
|
|
142
|
+
* @param productType - Type of products: "subs" for subscriptions, "inapp" for one-time purchases
|
|
143
|
+
* @returns Promise resolving to product information
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const { products } = await getProducts(
|
|
147
|
+
* ['com.example.premium', 'com.example.remove_ads'],
|
|
148
|
+
* 'inapp'
|
|
149
|
+
* );
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export declare function getProducts(productIds: string[], productType?: "subs" | "inapp"): Promise<GetProductsResponse>;
|
|
153
|
+
/**
|
|
154
|
+
* Initiate a purchase for the specified product.
|
|
155
|
+
*
|
|
156
|
+
* @param productId - Product identifier to purchase
|
|
157
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
158
|
+
* @param options - Optional purchase parameters (platform-specific)
|
|
159
|
+
* @returns Promise resolving to purchase transaction details
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* // Simple purchase
|
|
163
|
+
* const purchase = await purchase('com.example.premium', 'subs');
|
|
164
|
+
*
|
|
165
|
+
* // With options (iOS)
|
|
166
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
167
|
+
* appAccountToken: '550e8400-e29b-41d4-a716-446655440000' // Must be valid UUID
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* // With options (Android)
|
|
171
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
172
|
+
* offerToken: 'offer_token_here',
|
|
173
|
+
* obfuscatedAccountId: 'user_account_id',
|
|
174
|
+
* obfuscatedProfileId: 'user_profile_id'
|
|
175
|
+
* });
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function purchase(productId: string, productType?: "subs" | "inapp", options?: PurchaseOptions): Promise<Purchase>;
|
|
179
|
+
/**
|
|
180
|
+
* Restore user's previous purchases.
|
|
181
|
+
*
|
|
182
|
+
* @param productType - Type of products to restore: "subs" or "inapp"
|
|
183
|
+
* @returns Promise resolving to list of restored purchases
|
|
184
|
+
* @example
|
|
185
|
+
* ```typescript
|
|
186
|
+
* const { purchases } = await restorePurchases('subs');
|
|
187
|
+
* purchases.forEach(purchase => {
|
|
188
|
+
* console.log(`Restored: ${purchase.productId}`);
|
|
189
|
+
* });
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
export declare function restorePurchases(productType?: "subs" | "inapp"): Promise<RestorePurchasesResponse>;
|
|
193
|
+
/**
|
|
194
|
+
* Get the user's purchase history.
|
|
195
|
+
* Note: Not supported on all platforms.
|
|
196
|
+
*
|
|
197
|
+
* @returns Promise resolving to purchase history
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const { history } = await getPurchaseHistory();
|
|
201
|
+
* history.forEach(record => {
|
|
202
|
+
* console.log(`Purchase: ${record.productId} at ${record.purchaseTime}`);
|
|
203
|
+
* });
|
|
204
|
+
* ```
|
|
205
|
+
*/
|
|
79
206
|
export declare function getPurchaseHistory(): Promise<GetPurchaseHistoryResponse>;
|
|
207
|
+
/**
|
|
208
|
+
* Acknowledge a purchase (Android only).
|
|
209
|
+
* Purchases must be acknowledged within 3 days or they will be refunded.
|
|
210
|
+
* iOS automatically acknowledges purchases.
|
|
211
|
+
*
|
|
212
|
+
* @param purchaseToken - Purchase token from the transaction
|
|
213
|
+
* @returns Promise resolving to acknowledgment status
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* const result = await acknowledgePurchase(purchase.purchaseToken);
|
|
217
|
+
* if (result.success) {
|
|
218
|
+
* console.log('Purchase acknowledged');
|
|
219
|
+
* }
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
80
222
|
export declare function acknowledgePurchase(purchaseToken: string): Promise<AcknowledgePurchaseResponse>;
|
|
81
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Get the current status of a product for the user.
|
|
225
|
+
* Checks if the product is owned, expired, or available for purchase.
|
|
226
|
+
*
|
|
227
|
+
* @param productId - Product identifier to check
|
|
228
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
229
|
+
* @returns Promise resolving to product status
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const status = await getProductStatus('com.example.premium', 'subs');
|
|
233
|
+
* if (status.isOwned) {
|
|
234
|
+
* console.log('User owns this product');
|
|
235
|
+
* if (status.isAutoRenewing) {
|
|
236
|
+
* console.log('Subscription is auto-renewing');
|
|
237
|
+
* }
|
|
238
|
+
* }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export declare function getProductStatus(productId: string, productType?: "subs" | "inapp"): Promise<ProductStatus>;
|
|
242
|
+
/**
|
|
243
|
+
* Listen for purchase updates.
|
|
244
|
+
* This event is triggered when a purchase state changes.
|
|
245
|
+
*
|
|
246
|
+
* @param callback - Function to call when a purchase is updated
|
|
247
|
+
* @returns Cleanup function to stop listening
|
|
248
|
+
* @example
|
|
249
|
+
* ```typescript
|
|
250
|
+
* const unsubscribe = onPurchaseUpdated((purchase) => {
|
|
251
|
+
* console.log(`Purchase updated: ${purchase.productId}`);
|
|
252
|
+
* if (purchase.purchaseState === PurchaseState.PURCHASED) {
|
|
253
|
+
* // Handle successful purchase
|
|
254
|
+
* }
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* // Later, stop listening
|
|
258
|
+
* unsubscribe();
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
82
261
|
export declare function onPurchaseUpdated(callback: (purchase: Purchase) => void): () => void;
|
package/dist-js/index.js
CHANGED
|
@@ -1,60 +1,192 @@
|
|
|
1
1
|
import { invoke } from '@tauri-apps/api/core';
|
|
2
2
|
import { listen } from '@tauri-apps/api/event';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Purchase state enumeration
|
|
6
|
+
*/
|
|
4
7
|
var PurchaseState;
|
|
5
8
|
(function (PurchaseState) {
|
|
6
9
|
PurchaseState[PurchaseState["PURCHASED"] = 0] = "PURCHASED";
|
|
7
10
|
PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
|
|
8
11
|
PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
|
|
9
12
|
})(PurchaseState || (PurchaseState = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Initialize the IAP plugin.
|
|
15
|
+
* Must be called before any other IAP operations.
|
|
16
|
+
*
|
|
17
|
+
* @returns Promise resolving to initialization status
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const result = await initialize();
|
|
21
|
+
* if (result.success) {
|
|
22
|
+
* console.log('IAP initialized successfully');
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
10
26
|
async function initialize() {
|
|
11
|
-
return await invoke(
|
|
27
|
+
return await invoke("plugin:iap|initialize");
|
|
12
28
|
}
|
|
13
|
-
|
|
14
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Fetch product information from the app store.
|
|
31
|
+
*
|
|
32
|
+
* @param productIds - Array of product identifiers to fetch
|
|
33
|
+
* @param productType - Type of products: "subs" for subscriptions, "inapp" for one-time purchases
|
|
34
|
+
* @returns Promise resolving to product information
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const { products } = await getProducts(
|
|
38
|
+
* ['com.example.premium', 'com.example.remove_ads'],
|
|
39
|
+
* 'inapp'
|
|
40
|
+
* );
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
async function getProducts(productIds, productType = "subs") {
|
|
44
|
+
return await invoke("plugin:iap|get_products", {
|
|
15
45
|
payload: {
|
|
16
46
|
productIds,
|
|
17
47
|
productType,
|
|
18
48
|
},
|
|
19
49
|
});
|
|
20
50
|
}
|
|
21
|
-
|
|
22
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Initiate a purchase for the specified product.
|
|
53
|
+
*
|
|
54
|
+
* @param productId - Product identifier to purchase
|
|
55
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
56
|
+
* @param options - Optional purchase parameters (platform-specific)
|
|
57
|
+
* @returns Promise resolving to purchase transaction details
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // Simple purchase
|
|
61
|
+
* const purchase = await purchase('com.example.premium', 'subs');
|
|
62
|
+
*
|
|
63
|
+
* // With options (iOS)
|
|
64
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
65
|
+
* appAccountToken: '550e8400-e29b-41d4-a716-446655440000' // Must be valid UUID
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // With options (Android)
|
|
69
|
+
* const purchase = await purchase('com.example.premium', 'subs', {
|
|
70
|
+
* offerToken: 'offer_token_here',
|
|
71
|
+
* obfuscatedAccountId: 'user_account_id',
|
|
72
|
+
* obfuscatedProfileId: 'user_profile_id'
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
async function purchase(productId, productType = "subs", options) {
|
|
77
|
+
return await invoke("plugin:iap|purchase", {
|
|
23
78
|
payload: {
|
|
24
79
|
productId,
|
|
25
80
|
productType,
|
|
26
|
-
|
|
81
|
+
...options,
|
|
27
82
|
},
|
|
28
83
|
});
|
|
29
84
|
}
|
|
30
|
-
|
|
31
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Restore user's previous purchases.
|
|
87
|
+
*
|
|
88
|
+
* @param productType - Type of products to restore: "subs" or "inapp"
|
|
89
|
+
* @returns Promise resolving to list of restored purchases
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const { purchases } = await restorePurchases('subs');
|
|
93
|
+
* purchases.forEach(purchase => {
|
|
94
|
+
* console.log(`Restored: ${purchase.productId}`);
|
|
95
|
+
* });
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
async function restorePurchases(productType = "subs") {
|
|
99
|
+
return await invoke("plugin:iap|restore_purchases", {
|
|
32
100
|
payload: {
|
|
33
101
|
productType,
|
|
34
102
|
},
|
|
35
103
|
});
|
|
36
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the user's purchase history.
|
|
107
|
+
* Note: Not supported on all platforms.
|
|
108
|
+
*
|
|
109
|
+
* @returns Promise resolving to purchase history
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const { history } = await getPurchaseHistory();
|
|
113
|
+
* history.forEach(record => {
|
|
114
|
+
* console.log(`Purchase: ${record.productId} at ${record.purchaseTime}`);
|
|
115
|
+
* });
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
37
118
|
async function getPurchaseHistory() {
|
|
38
|
-
return await invoke(
|
|
119
|
+
return await invoke("plugin:iap|get_purchase_history");
|
|
39
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Acknowledge a purchase (Android only).
|
|
123
|
+
* Purchases must be acknowledged within 3 days or they will be refunded.
|
|
124
|
+
* iOS automatically acknowledges purchases.
|
|
125
|
+
*
|
|
126
|
+
* @param purchaseToken - Purchase token from the transaction
|
|
127
|
+
* @returns Promise resolving to acknowledgment status
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const result = await acknowledgePurchase(purchase.purchaseToken);
|
|
131
|
+
* if (result.success) {
|
|
132
|
+
* console.log('Purchase acknowledged');
|
|
133
|
+
* }
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
40
136
|
async function acknowledgePurchase(purchaseToken) {
|
|
41
|
-
return await invoke(
|
|
137
|
+
return await invoke("plugin:iap|acknowledge_purchase", {
|
|
42
138
|
payload: {
|
|
43
139
|
purchaseToken,
|
|
44
140
|
},
|
|
45
141
|
});
|
|
46
142
|
}
|
|
47
|
-
|
|
48
|
-
|
|
143
|
+
/**
|
|
144
|
+
* Get the current status of a product for the user.
|
|
145
|
+
* Checks if the product is owned, expired, or available for purchase.
|
|
146
|
+
*
|
|
147
|
+
* @param productId - Product identifier to check
|
|
148
|
+
* @param productType - Type of product: "subs" or "inapp"
|
|
149
|
+
* @returns Promise resolving to product status
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const status = await getProductStatus('com.example.premium', 'subs');
|
|
153
|
+
* if (status.isOwned) {
|
|
154
|
+
* console.log('User owns this product');
|
|
155
|
+
* if (status.isAutoRenewing) {
|
|
156
|
+
* console.log('Subscription is auto-renewing');
|
|
157
|
+
* }
|
|
158
|
+
* }
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
async function getProductStatus(productId, productType = "subs") {
|
|
162
|
+
return await invoke("plugin:iap|get_product_status", {
|
|
49
163
|
payload: {
|
|
50
164
|
productId,
|
|
51
165
|
productType,
|
|
52
166
|
},
|
|
53
167
|
});
|
|
54
168
|
}
|
|
55
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Listen for purchase updates.
|
|
171
|
+
* This event is triggered when a purchase state changes.
|
|
172
|
+
*
|
|
173
|
+
* @param callback - Function to call when a purchase is updated
|
|
174
|
+
* @returns Cleanup function to stop listening
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const unsubscribe = onPurchaseUpdated((purchase) => {
|
|
178
|
+
* console.log(`Purchase updated: ${purchase.productId}`);
|
|
179
|
+
* if (purchase.purchaseState === PurchaseState.PURCHASED) {
|
|
180
|
+
* // Handle successful purchase
|
|
181
|
+
* }
|
|
182
|
+
* });
|
|
183
|
+
*
|
|
184
|
+
* // Later, stop listening
|
|
185
|
+
* unsubscribe();
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
56
188
|
function onPurchaseUpdated(callback) {
|
|
57
|
-
const unlisten = listen(
|
|
189
|
+
const unlisten = listen("purchaseUpdated", (event) => {
|
|
58
190
|
callback(event.payload);
|
|
59
191
|
});
|
|
60
192
|
return () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choochmeque/tauri-plugin-iap-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "You",
|
|
6
6
|
"description": "A Tauri v2 plugin that enables In-App Purchases (IAP)",
|
|
@@ -39,10 +39,13 @@
|
|
|
39
39
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
40
40
|
"rollup": "^4.9.6",
|
|
41
41
|
"tslib": "^2.6.2",
|
|
42
|
-
"typescript": "^5.3.3"
|
|
42
|
+
"typescript": "^5.3.3",
|
|
43
|
+
"prettier": "3.6.2"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "rollup -c",
|
|
46
|
-
"pretest": "pnpm build"
|
|
47
|
+
"pretest": "pnpm build",
|
|
48
|
+
"format": "prettier --write \"./**/*.{cjs,mjs,js,jsx,mts,ts,tsx,html,css,json}\"",
|
|
49
|
+
"format-check": "prettier --check \"./**/*.{cjs,mjs,js,jsx,mts,ts,tsx,html,css,json}\""
|
|
47
50
|
}
|
|
48
51
|
}
|