expo-iap 2.8.6 → 2.8.8

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/src/useIAP.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  getPurchaseHistories,
15
15
  finishTransaction as finishTransactionInternal,
16
16
  requestPurchase as requestPurchaseInternal,
17
- requestProducts,
17
+ fetchProducts,
18
18
  validateReceipt as validateReceiptInternal,
19
19
  getActiveSubscriptions,
20
20
  hasActiveSubscriptions,
@@ -60,18 +60,26 @@ type UseIap = {
60
60
  }) => Promise<PurchaseResult | boolean>;
61
61
  getAvailablePurchases: (skus: string[]) => Promise<void>;
62
62
  getPurchaseHistories: (skus: string[]) => Promise<void>;
63
+ fetchProducts: (params: {
64
+ skus: string[];
65
+ type?: 'inapp' | 'subs';
66
+ }) => Promise<void>;
67
+ /**
68
+ * @deprecated Use fetchProducts({ skus, type: 'inapp' | 'subs' }) instead. This method will be removed in version 3.0.0.
69
+ * The 'request' prefix should only be used for event-based operations.
70
+ */
63
71
  requestProducts: (params: {
64
72
  skus: string[];
65
73
  type?: 'inapp' | 'subs';
66
74
  }) => Promise<void>;
67
75
  /**
68
- * @deprecated Use requestProducts({ skus, type: 'inapp' }) instead. This method will be removed in version 3.0.0.
69
- * Note: This method internally uses requestProducts, so no deprecation warning is shown.
76
+ * @deprecated Use fetchProducts({ skus, type: 'inapp' }) instead. This method will be removed in version 3.0.0.
77
+ * Note: This method internally uses fetchProducts, so no deprecation warning is shown.
70
78
  */
71
79
  getProducts: (skus: string[]) => Promise<void>;
72
80
  /**
73
- * @deprecated Use requestProducts({ skus, type: 'subs' }) instead. This method will be removed in version 3.0.0.
74
- * Note: This method internally uses requestProducts, so no deprecation warning is shown.
81
+ * @deprecated Use fetchProducts({ skus, type: 'subs' }) instead. This method will be removed in version 3.0.0.
82
+ * Note: This method internally uses fetchProducts, so no deprecation warning is shown.
75
83
  */
76
84
  getSubscriptions: (skus: string[]) => Promise<void>;
77
85
  requestPurchase: (params: {
@@ -177,7 +185,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
177
185
  const getProductsInternal = useCallback(
178
186
  async (skus: string[]): Promise<void> => {
179
187
  try {
180
- const result = await requestProducts({skus, type: 'inapp'});
188
+ const result = await fetchProducts({skus, type: 'inapp'});
181
189
  setProducts((prevProducts) =>
182
190
  mergeWithDuplicateCheck(
183
191
  prevProducts,
@@ -195,7 +203,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
195
203
  const getSubscriptionsInternal = useCallback(
196
204
  async (skus: string[]): Promise<void> => {
197
205
  try {
198
- const result = await requestProducts({skus, type: 'subs'});
206
+ const result = await fetchProducts({skus, type: 'subs'});
199
207
  setSubscriptions((prevSubscriptions) =>
200
208
  mergeWithDuplicateCheck(
201
209
  prevSubscriptions,
@@ -210,13 +218,13 @@ export function useIAP(options?: UseIAPOptions): UseIap {
210
218
  [mergeWithDuplicateCheck],
211
219
  );
212
220
 
213
- const requestProductsInternal = useCallback(
221
+ const fetchProductsInternal = useCallback(
214
222
  async (params: {
215
223
  skus: string[];
216
224
  type?: 'inapp' | 'subs';
217
225
  }): Promise<void> => {
218
226
  try {
219
- const result = await requestProducts(params);
227
+ const result = await fetchProducts(params);
220
228
  if (params.type === 'subs') {
221
229
  setSubscriptions((prevSubscriptions) =>
222
230
  mergeWithDuplicateCheck(
@@ -241,9 +249,25 @@ export function useIAP(options?: UseIAPOptions): UseIap {
241
249
  [mergeWithDuplicateCheck],
242
250
  );
243
251
 
252
+ const requestProductsInternal = useCallback(
253
+ async (params: {
254
+ skus: string[];
255
+ type?: 'inapp' | 'subs';
256
+ }): Promise<void> => {
257
+ console.warn(
258
+ "`requestProducts` is deprecated in useIAP hook. Use the new `fetchProducts` method instead. The 'request' prefix should only be used for event-based operations.",
259
+ );
260
+ return fetchProductsInternal(params);
261
+ },
262
+ [fetchProductsInternal],
263
+ );
264
+
244
265
  const getAvailablePurchasesInternal = useCallback(async (): Promise<void> => {
245
266
  try {
246
- const result = await getAvailablePurchases();
267
+ const result = await getAvailablePurchases({
268
+ alsoPublishToEventListenerIOS: false,
269
+ onlyIncludeActiveItemsIOS: true,
270
+ });
247
271
  setAvailablePurchases(result);
248
272
  } catch (error) {
249
273
  console.error('Error fetching available purchases:', error);
@@ -454,6 +478,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
454
478
  clearCurrentPurchaseError,
455
479
  getAvailablePurchases: getAvailablePurchasesInternal,
456
480
  getPurchaseHistories: getPurchaseHistoriesInternal,
481
+ fetchProducts: fetchProductsInternal,
457
482
  requestProducts: requestProductsInternal,
458
483
  requestPurchase: requestPurchaseWithReset,
459
484
  validateReceipt,
@@ -0,0 +1,14 @@
1
+ // Centralized product ID constants for examples and internal usage
2
+ // Rename guide: subscriptionIds -> SUBSCRIPTION_PRODUCT_IDS, PRODUCT_IDS remains the same name
3
+
4
+ // One-time purchase product IDs (consumables/non-consumables)
5
+ export const PRODUCT_IDS: string[] = [
6
+ 'dev.hyo.martie.10bulbs',
7
+ 'dev.hyo.martie.30bulbs',
8
+ ];
9
+
10
+ // Subscription product IDs
11
+ export const SUBSCRIPTION_PRODUCT_IDS: string[] = ['dev.hyo.martie.premium'];
12
+
13
+ // Optionally export a single default subscription for convenience
14
+ export const DEFAULT_SUBSCRIPTION_PRODUCT_ID = SUBSCRIPTION_PRODUCT_IDS[0];