@choochmeque/tauri-plugin-iap-api 0.1.10 → 0.1.12

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
@@ -15,6 +15,7 @@ A Tauri plugin for In-App Purchases (IAP) with support for subscriptions on both
15
15
  - Purchase subscriptions with platform-specific features
16
16
  - Restore previous purchases
17
17
  - Get purchase history
18
+ - Check product ownership and subscription status
18
19
  - Real-time purchase state updates via events
19
20
  - Automatic transaction verification (iOS)
20
21
  - Support for introductory offers and free trials
@@ -75,7 +76,9 @@ import {
75
76
  purchase,
76
77
  restorePurchases,
77
78
  acknowledgePurchase,
78
- onPurchaseUpdated
79
+ getProductStatus,
80
+ onPurchaseUpdated,
81
+ PurchaseState
79
82
  } from 'tauri-plugin-iap-api';
80
83
 
81
84
  // Initialize the billing client
@@ -84,6 +87,15 @@ await initialize();
84
87
  // Get available products
85
88
  const products = await getProducts(['subscription_id_1', 'subscription_id_2'], 'subs');
86
89
 
90
+ // Check if user owns a specific product
91
+ const status = await getProductStatus('subscription_id_1', 'subs');
92
+ if (status.isOwned && status.purchaseState === PurchaseState.PURCHASED) {
93
+ console.log('User has active subscription');
94
+ if (status.isAutoRenewing) {
95
+ console.log('Subscription will auto-renew');
96
+ }
97
+ }
98
+
87
99
  // Purchase a subscription or in-app product
88
100
  // On Android: use the offer token from subscriptionOfferDetails
89
101
  // On iOS: offer token is not used
@@ -163,6 +175,23 @@ Returns the complete purchase history.
163
175
  ### `acknowledgePurchase(purchaseToken: string)`
164
176
  Acknowledges a purchase (required on Android within 3 days, no-op on iOS).
165
177
 
178
+ ### `getProductStatus(productId: string, productType: 'subs' | 'inapp' = 'subs')`
179
+ Checks the ownership and subscription status of a specific product.
180
+
181
+ **Parameters:**
182
+ - `productId`: The product identifier to check
183
+ - `productType`: Type of product ('subs' or 'inapp'), defaults to 'subs'
184
+
185
+ **Returns:** ProductStatus object with:
186
+ - `productId`: Product identifier
187
+ - `isOwned`: Whether the user currently owns the product
188
+ - `purchaseState`: Current state (PURCHASED=0, CANCELED=1, PENDING=2)
189
+ - `purchaseTime`: When the product was purchased (timestamp)
190
+ - `expirationTime`: (subscriptions only) When the subscription expires
191
+ - `isAutoRenewing`: (subscriptions only) Whether auto-renewal is enabled
192
+ - `isAcknowledged`: Whether the purchase has been acknowledged
193
+ - `purchaseToken`: Token for the purchase transaction
194
+
166
195
  ### `onPurchaseUpdated(callback: (purchase: Purchase) => void)`
167
196
  Listens for purchase state changes.
168
197
 
package/dist-js/index.cjs CHANGED
@@ -3,6 +3,12 @@
3
3
  var core = require('@tauri-apps/api/core');
4
4
  var event = require('@tauri-apps/api/event');
5
5
 
6
+ exports.PurchaseState = void 0;
7
+ (function (PurchaseState) {
8
+ PurchaseState[PurchaseState["PURCHASED"] = 0] = "PURCHASED";
9
+ PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
10
+ PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
11
+ })(exports.PurchaseState || (exports.PurchaseState = {}));
6
12
  async function initialize() {
7
13
  return await core.invoke('plugin:iap|initialize');
8
14
  }
@@ -40,6 +46,14 @@ async function acknowledgePurchase(purchaseToken) {
40
46
  },
41
47
  });
42
48
  }
49
+ async function getProductStatus(productId, productType = 'subs') {
50
+ return await core.invoke('plugin:iap|get_product_status', {
51
+ payload: {
52
+ productId,
53
+ productType,
54
+ },
55
+ });
56
+ }
43
57
  // Event listener for purchase updates
44
58
  function onPurchaseUpdated(callback) {
45
59
  const unlisten = event.listen('purchaseUpdated', (event) => {
@@ -51,6 +65,7 @@ function onPurchaseUpdated(callback) {
51
65
  }
52
66
 
53
67
  exports.acknowledgePurchase = acknowledgePurchase;
68
+ exports.getProductStatus = getProductStatus;
54
69
  exports.getProducts = getProducts;
55
70
  exports.getPurchaseHistory = getPurchaseHistory;
56
71
  exports.initialize = initialize;
@@ -57,10 +57,26 @@ export interface GetPurchaseHistoryResponse {
57
57
  export interface AcknowledgePurchaseResponse {
58
58
  success: boolean;
59
59
  }
60
+ export declare enum PurchaseState {
61
+ PURCHASED = 0,
62
+ CANCELED = 1,
63
+ PENDING = 2
64
+ }
65
+ export interface ProductStatus {
66
+ productId: string;
67
+ isOwned: boolean;
68
+ purchaseState?: PurchaseState;
69
+ purchaseTime?: number;
70
+ expirationTime?: number;
71
+ isAutoRenewing?: boolean;
72
+ isAcknowledged?: boolean;
73
+ purchaseToken?: string;
74
+ }
60
75
  export declare function initialize(): Promise<InitializeResponse>;
61
76
  export declare function getProducts(productIds: string[], productType?: 'subs' | 'inapp'): Promise<GetProductsResponse>;
62
77
  export declare function purchase(productId: string, productType?: 'subs' | 'inapp', offerToken?: string): Promise<Purchase>;
63
78
  export declare function restorePurchases(productType?: 'subs' | 'inapp'): Promise<RestorePurchasesResponse>;
64
79
  export declare function getPurchaseHistory(): Promise<GetPurchaseHistoryResponse>;
65
80
  export declare function acknowledgePurchase(purchaseToken: string): Promise<AcknowledgePurchaseResponse>;
81
+ export declare function getProductStatus(productId: string, productType?: 'subs' | 'inapp'): Promise<ProductStatus>;
66
82
  export declare function onPurchaseUpdated(callback: (purchase: Purchase) => void): () => void;
package/dist-js/index.js CHANGED
@@ -1,6 +1,12 @@
1
1
  import { invoke } from '@tauri-apps/api/core';
2
2
  import { listen } from '@tauri-apps/api/event';
3
3
 
4
+ var PurchaseState;
5
+ (function (PurchaseState) {
6
+ PurchaseState[PurchaseState["PURCHASED"] = 0] = "PURCHASED";
7
+ PurchaseState[PurchaseState["CANCELED"] = 1] = "CANCELED";
8
+ PurchaseState[PurchaseState["PENDING"] = 2] = "PENDING";
9
+ })(PurchaseState || (PurchaseState = {}));
4
10
  async function initialize() {
5
11
  return await invoke('plugin:iap|initialize');
6
12
  }
@@ -38,6 +44,14 @@ async function acknowledgePurchase(purchaseToken) {
38
44
  },
39
45
  });
40
46
  }
47
+ async function getProductStatus(productId, productType = 'subs') {
48
+ return await invoke('plugin:iap|get_product_status', {
49
+ payload: {
50
+ productId,
51
+ productType,
52
+ },
53
+ });
54
+ }
41
55
  // Event listener for purchase updates
42
56
  function onPurchaseUpdated(callback) {
43
57
  const unlisten = listen('purchaseUpdated', (event) => {
@@ -48,4 +62,4 @@ function onPurchaseUpdated(callback) {
48
62
  };
49
63
  }
50
64
 
51
- export { acknowledgePurchase, getProducts, getPurchaseHistory, initialize, onPurchaseUpdated, purchase, restorePurchases };
65
+ export { PurchaseState, 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.1.10",
3
+ "version": "0.1.12",
4
4
  "author": "You",
5
5
  "description": "A Tauri v2 plugin that enables In-App Purchases (IAP)",
6
6
  "type": "module",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "homepage": "https://github.com/Choochmeque/tauri-plugin-iap#readme",
35
35
  "dependencies": {
36
- "@tauri-apps/api": ">=2.0.0-beta.6"
36
+ "@tauri-apps/api": "^2.6.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@rollup/plugin-typescript": "^12.1.4",