expo-iap 2.8.5 → 2.8.7
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/CHANGELOG.md +36 -0
- package/README.md +8 -7
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +117 -4
- package/build/index.d.ts +50 -7
- package/build/index.d.ts.map +1 -1
- package/build/index.js +56 -25
- package/build/index.js.map +1 -1
- package/build/modules/android.js +1 -1
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +23 -4
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +41 -16
- package/build/modules/ios.js.map +1 -1
- package/build/useIAP.d.ts +15 -5
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +17 -7
- package/build/useIAP.js.map +1 -1
- package/ios/ExpoIapModule.swift +49 -25
- package/package.json +1 -1
- package/src/index.ts +84 -24
- package/src/modules/android.ts +1 -1
- package/src/modules/ios.ts +46 -18
- package/src/useIAP.ts +42 -13
package/src/index.ts
CHANGED
|
@@ -124,7 +124,7 @@ export function initConnection(): Promise<boolean> {
|
|
|
124
124
|
|
|
125
125
|
export const getProducts = async (skus: string[]): Promise<Product[]> => {
|
|
126
126
|
console.warn(
|
|
127
|
-
"`getProducts` is deprecated. Use `
|
|
127
|
+
"`getProducts` is deprecated. Use `fetchProducts({ skus, type: 'inapp' })` instead. This function will be removed in version 3.0.0.",
|
|
128
128
|
);
|
|
129
129
|
if (!skus?.length) {
|
|
130
130
|
return Promise.reject(new Error('"skus" is required'));
|
|
@@ -132,7 +132,7 @@ export const getProducts = async (skus: string[]): Promise<Product[]> => {
|
|
|
132
132
|
|
|
133
133
|
return Platform.select({
|
|
134
134
|
ios: async () => {
|
|
135
|
-
const rawItems = await ExpoIapModule.
|
|
135
|
+
const rawItems = await ExpoIapModule.fetchProducts(skus);
|
|
136
136
|
return rawItems.filter((item: unknown) => {
|
|
137
137
|
if (!isProductIOS(item)) return false;
|
|
138
138
|
return (
|
|
@@ -145,7 +145,7 @@ export const getProducts = async (skus: string[]): Promise<Product[]> => {
|
|
|
145
145
|
}) as Product[];
|
|
146
146
|
},
|
|
147
147
|
android: async () => {
|
|
148
|
-
const products = await ExpoIapModule.
|
|
148
|
+
const products = await ExpoIapModule.fetchProducts('inapp', skus);
|
|
149
149
|
return products.filter((product: unknown) =>
|
|
150
150
|
isProductAndroid<Product>(product),
|
|
151
151
|
);
|
|
@@ -158,7 +158,7 @@ export const getSubscriptions = async (
|
|
|
158
158
|
skus: string[],
|
|
159
159
|
): Promise<SubscriptionProduct[]> => {
|
|
160
160
|
console.warn(
|
|
161
|
-
"`getSubscriptions` is deprecated. Use `
|
|
161
|
+
"`getSubscriptions` is deprecated. Use `fetchProducts({ skus, type: 'subs' })` instead. This function will be removed in version 3.0.0.",
|
|
162
162
|
);
|
|
163
163
|
if (!skus?.length) {
|
|
164
164
|
return Promise.reject(new Error('"skus" is required'));
|
|
@@ -166,7 +166,7 @@ export const getSubscriptions = async (
|
|
|
166
166
|
|
|
167
167
|
return Platform.select({
|
|
168
168
|
ios: async () => {
|
|
169
|
-
const rawItems = await ExpoIapModule.
|
|
169
|
+
const rawItems = await ExpoIapModule.fetchProducts(skus);
|
|
170
170
|
return rawItems.filter((item: unknown) => {
|
|
171
171
|
if (!isProductIOS(item)) return false;
|
|
172
172
|
return (
|
|
@@ -179,7 +179,7 @@ export const getSubscriptions = async (
|
|
|
179
179
|
}) as SubscriptionProduct[];
|
|
180
180
|
},
|
|
181
181
|
android: async () => {
|
|
182
|
-
const rawItems = await ExpoIapModule.
|
|
182
|
+
const rawItems = await ExpoIapModule.fetchProducts('subs', skus);
|
|
183
183
|
return rawItems.filter((item: unknown) => {
|
|
184
184
|
if (!isProductAndroid(item)) return false;
|
|
185
185
|
return (
|
|
@@ -200,28 +200,28 @@ export async function endConnection(): Promise<boolean> {
|
|
|
200
200
|
}
|
|
201
201
|
|
|
202
202
|
/**
|
|
203
|
-
*
|
|
203
|
+
* Fetch products with unified API (v2.7.0+)
|
|
204
204
|
*
|
|
205
|
-
* @param params - Product
|
|
205
|
+
* @param params - Product fetch configuration
|
|
206
206
|
* @param params.skus - Array of product SKUs to fetch
|
|
207
207
|
* @param params.type - Type of products: 'inapp' for regular products (default) or 'subs' for subscriptions
|
|
208
208
|
*
|
|
209
209
|
* @example
|
|
210
210
|
* ```typescript
|
|
211
211
|
* // Regular products
|
|
212
|
-
* const products = await
|
|
212
|
+
* const products = await fetchProducts({
|
|
213
213
|
* skus: ['product1', 'product2'],
|
|
214
214
|
* type: 'inapp'
|
|
215
215
|
* });
|
|
216
216
|
*
|
|
217
217
|
* // Subscriptions
|
|
218
|
-
* const subscriptions = await
|
|
218
|
+
* const subscriptions = await fetchProducts({
|
|
219
219
|
* skus: ['sub1', 'sub2'],
|
|
220
220
|
* type: 'subs'
|
|
221
221
|
* });
|
|
222
222
|
* ```
|
|
223
223
|
*/
|
|
224
|
-
export const
|
|
224
|
+
export const fetchProducts = async ({
|
|
225
225
|
skus,
|
|
226
226
|
type = 'inapp',
|
|
227
227
|
}: {
|
|
@@ -233,7 +233,7 @@ export const requestProducts = async ({
|
|
|
233
233
|
}
|
|
234
234
|
|
|
235
235
|
if (Platform.OS === 'ios') {
|
|
236
|
-
const rawItems = await ExpoIapModule.
|
|
236
|
+
const rawItems = await ExpoIapModule.fetchProducts(skus);
|
|
237
237
|
const filteredItems = rawItems.filter((item: unknown) => {
|
|
238
238
|
if (!isProductIOS(item)) return false;
|
|
239
239
|
return (
|
|
@@ -251,7 +251,7 @@ export const requestProducts = async ({
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
if (Platform.OS === 'android') {
|
|
254
|
-
const items = await ExpoIapModule.
|
|
254
|
+
const items = await ExpoIapModule.fetchProducts(type, skus);
|
|
255
255
|
const filteredItems = items.filter((item: unknown) => {
|
|
256
256
|
if (!isProductAndroid(item)) return false;
|
|
257
257
|
return (
|
|
@@ -271,38 +271,92 @@ export const requestProducts = async ({
|
|
|
271
271
|
throw new Error('Unsupported platform');
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* @deprecated Use `fetchProducts` instead. This method will be removed in version 3.0.0.
|
|
276
|
+
*
|
|
277
|
+
* The 'request' prefix should only be used for event-based operations that trigger
|
|
278
|
+
* purchase flows. Since this function simply fetches product information, it has been
|
|
279
|
+
* renamed to `fetchProducts` to follow OpenIAP terminology guidelines.
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* ```typescript
|
|
283
|
+
* // Old way (deprecated)
|
|
284
|
+
* const products = await requestProducts({
|
|
285
|
+
* skus: ['com.example.product1'],
|
|
286
|
+
* type: 'inapp'
|
|
287
|
+
* });
|
|
288
|
+
*
|
|
289
|
+
* // New way (recommended)
|
|
290
|
+
* const products = await fetchProducts({
|
|
291
|
+
* skus: ['com.example.product1'],
|
|
292
|
+
* type: 'inapp'
|
|
293
|
+
* });
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export const requestProducts = async ({
|
|
297
|
+
skus,
|
|
298
|
+
type = 'inapp',
|
|
299
|
+
}: {
|
|
300
|
+
skus: string[];
|
|
301
|
+
type?: 'inapp' | 'subs';
|
|
302
|
+
}): Promise<Product[] | SubscriptionProduct[]> => {
|
|
303
|
+
console.warn(
|
|
304
|
+
"`requestProducts` is deprecated. Use `fetchProducts` instead. The 'request' prefix should only be used for event-based operations. This method will be removed in version 3.0.0.",
|
|
305
|
+
);
|
|
306
|
+
return fetchProducts({skus, type});
|
|
307
|
+
};
|
|
308
|
+
|
|
274
309
|
/**
|
|
275
310
|
* @deprecated Use `getPurchaseHistories` instead. This function will be removed in version 3.0.0.
|
|
276
311
|
*/
|
|
277
312
|
export const getPurchaseHistory = ({
|
|
278
313
|
alsoPublishToEventListener = false,
|
|
279
314
|
onlyIncludeActiveItems = false,
|
|
315
|
+
alsoPublishToEventListenerIOS,
|
|
316
|
+
onlyIncludeActiveItemsIOS,
|
|
280
317
|
}: {
|
|
318
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
281
319
|
alsoPublishToEventListener?: boolean;
|
|
320
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
282
321
|
onlyIncludeActiveItems?: boolean;
|
|
322
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
323
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
283
324
|
} = {}): Promise<Purchase[]> => {
|
|
284
325
|
console.warn(
|
|
285
326
|
'`getPurchaseHistory` is deprecated. Use `getPurchaseHistories` instead. This function will be removed in version 3.0.0.',
|
|
286
327
|
);
|
|
287
328
|
return getPurchaseHistories({
|
|
288
|
-
|
|
289
|
-
|
|
329
|
+
alsoPublishToEventListenerIOS:
|
|
330
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
331
|
+
onlyIncludeActiveItemsIOS:
|
|
332
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
290
333
|
});
|
|
291
334
|
};
|
|
292
335
|
|
|
336
|
+
/**
|
|
337
|
+
* @deprecated Use getAvailablePurchases instead. This function is just calling getAvailablePurchases internally on iOS
|
|
338
|
+
* and returns an empty array on Android (Google Play Billing v8 removed purchase history API).
|
|
339
|
+
* Will be removed in v2.9.0
|
|
340
|
+
*/
|
|
293
341
|
export const getPurchaseHistories = ({
|
|
294
342
|
alsoPublishToEventListener = false,
|
|
295
343
|
onlyIncludeActiveItems = false,
|
|
344
|
+
alsoPublishToEventListenerIOS,
|
|
345
|
+
onlyIncludeActiveItemsIOS,
|
|
296
346
|
}: {
|
|
347
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
297
348
|
alsoPublishToEventListener?: boolean;
|
|
349
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
298
350
|
onlyIncludeActiveItems?: boolean;
|
|
351
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
352
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
299
353
|
} = {}): Promise<Purchase[]> =>
|
|
300
354
|
(
|
|
301
355
|
Platform.select({
|
|
302
356
|
ios: async () => {
|
|
303
357
|
return ExpoIapModule.getAvailableItems(
|
|
304
|
-
alsoPublishToEventListener,
|
|
305
|
-
onlyIncludeActiveItems,
|
|
358
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
359
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
306
360
|
);
|
|
307
361
|
},
|
|
308
362
|
android: async () => {
|
|
@@ -319,16 +373,22 @@ export const getPurchaseHistories = ({
|
|
|
319
373
|
export const getAvailablePurchases = ({
|
|
320
374
|
alsoPublishToEventListener = false,
|
|
321
375
|
onlyIncludeActiveItems = true,
|
|
376
|
+
alsoPublishToEventListenerIOS,
|
|
377
|
+
onlyIncludeActiveItemsIOS,
|
|
322
378
|
}: {
|
|
379
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
323
380
|
alsoPublishToEventListener?: boolean;
|
|
381
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
324
382
|
onlyIncludeActiveItems?: boolean;
|
|
383
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
384
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
325
385
|
} = {}): Promise<Purchase[]> =>
|
|
326
386
|
(
|
|
327
387
|
Platform.select({
|
|
328
388
|
ios: () =>
|
|
329
389
|
ExpoIapModule.getAvailableItems(
|
|
330
|
-
alsoPublishToEventListener,
|
|
331
|
-
onlyIncludeActiveItems,
|
|
390
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
391
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
332
392
|
),
|
|
333
393
|
android: async () => {
|
|
334
394
|
const products = await ExpoIapModule.getAvailableItemsByType('inapp');
|
|
@@ -430,7 +490,7 @@ export const requestPurchase = (
|
|
|
430
490
|
|
|
431
491
|
return (async () => {
|
|
432
492
|
const offer = offerToRecordIOS(withOffer);
|
|
433
|
-
const purchase = await ExpoIapModule.
|
|
493
|
+
const purchase = await ExpoIapModule.requestPurchase(
|
|
434
494
|
sku,
|
|
435
495
|
andDangerouslyFinishTransactionAutomatically,
|
|
436
496
|
appAccountToken,
|
|
@@ -460,7 +520,7 @@ export const requestPurchase = (
|
|
|
460
520
|
} = normalizedRequest;
|
|
461
521
|
|
|
462
522
|
return (async () => {
|
|
463
|
-
return ExpoIapModule.
|
|
523
|
+
return ExpoIapModule.requestPurchase({
|
|
464
524
|
type: 'inapp',
|
|
465
525
|
skuArr: skus,
|
|
466
526
|
purchaseToken: undefined,
|
|
@@ -486,7 +546,7 @@ export const requestPurchase = (
|
|
|
486
546
|
} = normalizedRequest;
|
|
487
547
|
|
|
488
548
|
return (async () => {
|
|
489
|
-
return ExpoIapModule.
|
|
549
|
+
return ExpoIapModule.requestPurchase({
|
|
490
550
|
type: 'subs',
|
|
491
551
|
skuArr: skus,
|
|
492
552
|
purchaseToken: purchaseTokenAndroid || purchaseToken,
|
|
@@ -586,10 +646,10 @@ export const finishTransaction = ({
|
|
|
586
646
|
}
|
|
587
647
|
|
|
588
648
|
if (isConsumable) {
|
|
589
|
-
return ExpoIapModule.
|
|
649
|
+
return ExpoIapModule.consumeProductAndroid(token);
|
|
590
650
|
}
|
|
591
651
|
|
|
592
|
-
return ExpoIapModule.
|
|
652
|
+
return ExpoIapModule.acknowledgePurchaseAndroid(token);
|
|
593
653
|
},
|
|
594
654
|
}) || (() => Promise.reject(new Error('Unsupported Platform')))
|
|
595
655
|
)();
|
package/src/modules/android.ts
CHANGED
|
@@ -113,7 +113,7 @@ export const acknowledgePurchaseAndroid = ({
|
|
|
113
113
|
}: {
|
|
114
114
|
token: string;
|
|
115
115
|
}): Promise<PurchaseResult | boolean | void> => {
|
|
116
|
-
return ExpoIapModule.
|
|
116
|
+
return ExpoIapModule.acknowledgePurchaseAndroid(token);
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
/**
|
package/src/modules/ios.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {purchaseUpdatedListener} from '..';
|
|
|
5
5
|
import ExpoIapModule from '../ExpoIapModule';
|
|
6
6
|
|
|
7
7
|
// Types
|
|
8
|
-
import {Purchase, PurchaseError} from '../ExpoIap.types';
|
|
8
|
+
import {Product, Purchase, PurchaseError} from '../ExpoIap.types';
|
|
9
9
|
import type {
|
|
10
10
|
ProductStatusIOS,
|
|
11
11
|
AppTransactionIOS,
|
|
@@ -91,7 +91,7 @@ export function isProductIOS<T extends {platform?: string}>(
|
|
|
91
91
|
* @platform iOS
|
|
92
92
|
*/
|
|
93
93
|
export const syncIOS = (): Promise<null> => {
|
|
94
|
-
return ExpoIapModule.
|
|
94
|
+
return ExpoIapModule.syncIOS();
|
|
95
95
|
};
|
|
96
96
|
|
|
97
97
|
/**
|
|
@@ -106,7 +106,7 @@ export const syncIOS = (): Promise<null> => {
|
|
|
106
106
|
export const isEligibleForIntroOfferIOS = (
|
|
107
107
|
groupId: string,
|
|
108
108
|
): Promise<boolean> => {
|
|
109
|
-
return ExpoIapModule.
|
|
109
|
+
return ExpoIapModule.isEligibleForIntroOfferIOS(groupId);
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
/**
|
|
@@ -121,7 +121,7 @@ export const isEligibleForIntroOfferIOS = (
|
|
|
121
121
|
export const subscriptionStatusIOS = (
|
|
122
122
|
sku: string,
|
|
123
123
|
): Promise<ProductStatusIOS[]> => {
|
|
124
|
-
return ExpoIapModule.
|
|
124
|
+
return ExpoIapModule.subscriptionStatusIOS(sku);
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -134,7 +134,7 @@ export const subscriptionStatusIOS = (
|
|
|
134
134
|
* @platform iOS
|
|
135
135
|
*/
|
|
136
136
|
export const currentEntitlementIOS = (sku: string): Promise<Purchase> => {
|
|
137
|
-
return ExpoIapModule.
|
|
137
|
+
return ExpoIapModule.currentEntitlementIOS(sku);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
/**
|
|
@@ -147,7 +147,7 @@ export const currentEntitlementIOS = (sku: string): Promise<Purchase> => {
|
|
|
147
147
|
* @platform iOS
|
|
148
148
|
*/
|
|
149
149
|
export const latestTransactionIOS = (sku: string): Promise<Purchase> => {
|
|
150
|
-
return ExpoIapModule.
|
|
150
|
+
return ExpoIapModule.latestTransactionIOS(sku);
|
|
151
151
|
};
|
|
152
152
|
|
|
153
153
|
/**
|
|
@@ -163,7 +163,7 @@ type RefundRequestStatus = 'success' | 'userCancelled';
|
|
|
163
163
|
export const beginRefundRequestIOS = (
|
|
164
164
|
sku: string,
|
|
165
165
|
): Promise<RefundRequestStatus> => {
|
|
166
|
-
return ExpoIapModule.
|
|
166
|
+
return ExpoIapModule.beginRefundRequestIOS(sku);
|
|
167
167
|
};
|
|
168
168
|
|
|
169
169
|
/**
|
|
@@ -177,7 +177,7 @@ export const beginRefundRequestIOS = (
|
|
|
177
177
|
* @platform iOS
|
|
178
178
|
*/
|
|
179
179
|
export const showManageSubscriptionsIOS = (): Promise<null> => {
|
|
180
|
-
return ExpoIapModule.
|
|
180
|
+
return ExpoIapModule.showManageSubscriptionsIOS();
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
/**
|
|
@@ -191,7 +191,7 @@ export const showManageSubscriptionsIOS = (): Promise<null> => {
|
|
|
191
191
|
* @returns {Promise<string>} Base64 encoded receipt data
|
|
192
192
|
*/
|
|
193
193
|
export const getReceiptIOS = (): Promise<string> => {
|
|
194
|
-
return ExpoIapModule.
|
|
194
|
+
return ExpoIapModule.getReceiptDataIOS();
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
/**
|
|
@@ -205,7 +205,7 @@ export const getReceiptIOS = (): Promise<string> => {
|
|
|
205
205
|
* @platform iOS
|
|
206
206
|
*/
|
|
207
207
|
export const isTransactionVerifiedIOS = (sku: string): Promise<boolean> => {
|
|
208
|
-
return ExpoIapModule.
|
|
208
|
+
return ExpoIapModule.isTransactionVerifiedIOS(sku);
|
|
209
209
|
};
|
|
210
210
|
|
|
211
211
|
/**
|
|
@@ -219,7 +219,7 @@ export const isTransactionVerifiedIOS = (sku: string): Promise<boolean> => {
|
|
|
219
219
|
* @platform iOS
|
|
220
220
|
*/
|
|
221
221
|
export const getTransactionJwsIOS = (sku: string): Promise<string> => {
|
|
222
|
-
return ExpoIapModule.
|
|
222
|
+
return ExpoIapModule.getTransactionJwsIOS(sku);
|
|
223
223
|
};
|
|
224
224
|
|
|
225
225
|
/**
|
|
@@ -261,7 +261,7 @@ export const validateReceiptIOS = async (
|
|
|
261
261
|
* @platform iOS
|
|
262
262
|
*/
|
|
263
263
|
export const presentCodeRedemptionSheetIOS = (): Promise<boolean> => {
|
|
264
|
-
return ExpoIapModule.
|
|
264
|
+
return ExpoIapModule.presentCodeRedemptionSheetIOS();
|
|
265
265
|
};
|
|
266
266
|
|
|
267
267
|
/**
|
|
@@ -279,20 +279,21 @@ export const presentCodeRedemptionSheetIOS = (): Promise<boolean> => {
|
|
|
279
279
|
* @since iOS 16.0
|
|
280
280
|
*/
|
|
281
281
|
export const getAppTransactionIOS = (): Promise<AppTransactionIOS | null> => {
|
|
282
|
-
return ExpoIapModule.
|
|
282
|
+
return ExpoIapModule.getAppTransactionIOS();
|
|
283
283
|
};
|
|
284
284
|
|
|
285
285
|
/**
|
|
286
|
-
* Get
|
|
286
|
+
* Get information about a promoted product if one is available (iOS only).
|
|
287
|
+
* Promoted products are products that the App Store promotes on your behalf.
|
|
287
288
|
* This is called after a promoted product event is received from the App Store.
|
|
288
289
|
*
|
|
289
|
-
* @returns Promise resolving to the promoted product
|
|
290
|
+
* @returns Promise resolving to the promoted product information or null if none available
|
|
290
291
|
* @throws Error if called on non-iOS platform
|
|
291
292
|
*
|
|
292
293
|
* @platform iOS
|
|
293
294
|
*/
|
|
294
|
-
export const getPromotedProductIOS = (): Promise<
|
|
295
|
-
return ExpoIapModule.
|
|
295
|
+
export const getPromotedProductIOS = (): Promise<Product | null> => {
|
|
296
|
+
return ExpoIapModule.getPromotedProductIOS();
|
|
296
297
|
};
|
|
297
298
|
|
|
298
299
|
/**
|
|
@@ -304,8 +305,35 @@ export const getPromotedProductIOS = (): Promise<any | null> => {
|
|
|
304
305
|
*
|
|
305
306
|
* @platform iOS
|
|
306
307
|
*/
|
|
308
|
+
export const requestPurchaseOnPromotedProductIOS = (): Promise<void> => {
|
|
309
|
+
return ExpoIapModule.requestPurchaseOnPromotedProductIOS();
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* @deprecated Use requestPurchaseOnPromotedProductIOS instead. Will be removed in v2.9.0
|
|
314
|
+
*/
|
|
307
315
|
export const buyPromotedProductIOS = (): Promise<void> => {
|
|
308
|
-
return
|
|
316
|
+
return requestPurchaseOnPromotedProductIOS();
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get pending transactions that haven't been finished yet (iOS only).
|
|
321
|
+
*
|
|
322
|
+
* @returns Promise resolving to array of pending transactions
|
|
323
|
+
* @platform iOS
|
|
324
|
+
*/
|
|
325
|
+
export const getPendingTransactionsIOS = (): Promise<any[]> => {
|
|
326
|
+
return ExpoIapModule.getPendingTransactionsIOS();
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Clear a specific transaction (iOS only).
|
|
331
|
+
*
|
|
332
|
+
* @returns Promise resolving when transaction is cleared
|
|
333
|
+
* @platform iOS
|
|
334
|
+
*/
|
|
335
|
+
export const clearTransactionIOS = (): Promise<void> => {
|
|
336
|
+
return ExpoIapModule.clearTransactionIOS();
|
|
309
337
|
};
|
|
310
338
|
|
|
311
339
|
/**
|
package/src/useIAP.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
getPurchaseHistories,
|
|
15
15
|
finishTransaction as finishTransactionInternal,
|
|
16
16
|
requestPurchase as requestPurchaseInternal,
|
|
17
|
-
|
|
17
|
+
fetchProducts,
|
|
18
18
|
validateReceipt as validateReceiptInternal,
|
|
19
19
|
getActiveSubscriptions,
|
|
20
20
|
hasActiveSubscriptions,
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
syncIOS,
|
|
25
25
|
getPromotedProductIOS,
|
|
26
|
-
|
|
26
|
+
requestPurchaseOnPromotedProductIOS,
|
|
27
27
|
} from './modules/ios';
|
|
28
28
|
|
|
29
29
|
// Types
|
|
@@ -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
|
|
69
|
-
* Note: This method internally uses
|
|
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
|
|
74
|
-
* Note: This method internally uses
|
|
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: {
|
|
@@ -87,8 +95,10 @@ type UseIap = {
|
|
|
87
95
|
isSub?: boolean;
|
|
88
96
|
},
|
|
89
97
|
) => Promise<any>;
|
|
90
|
-
restorePurchases: () => Promise<void>;
|
|
91
|
-
getPromotedProductIOS: () => Promise<
|
|
98
|
+
restorePurchases: () => Promise<void>;
|
|
99
|
+
getPromotedProductIOS: () => Promise<Product | null>;
|
|
100
|
+
requestPurchaseOnPromotedProductIOS: () => Promise<void>;
|
|
101
|
+
/** @deprecated Use requestPurchaseOnPromotedProductIOS instead */
|
|
92
102
|
buyPromotedProductIOS: () => Promise<void>;
|
|
93
103
|
getActiveSubscriptions: (
|
|
94
104
|
subscriptionIds?: string[],
|
|
@@ -175,7 +185,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
175
185
|
const getProductsInternal = useCallback(
|
|
176
186
|
async (skus: string[]): Promise<void> => {
|
|
177
187
|
try {
|
|
178
|
-
const result = await
|
|
188
|
+
const result = await fetchProducts({skus, type: 'inapp'});
|
|
179
189
|
setProducts((prevProducts) =>
|
|
180
190
|
mergeWithDuplicateCheck(
|
|
181
191
|
prevProducts,
|
|
@@ -193,7 +203,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
193
203
|
const getSubscriptionsInternal = useCallback(
|
|
194
204
|
async (skus: string[]): Promise<void> => {
|
|
195
205
|
try {
|
|
196
|
-
const result = await
|
|
206
|
+
const result = await fetchProducts({skus, type: 'subs'});
|
|
197
207
|
setSubscriptions((prevSubscriptions) =>
|
|
198
208
|
mergeWithDuplicateCheck(
|
|
199
209
|
prevSubscriptions,
|
|
@@ -208,13 +218,13 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
208
218
|
[mergeWithDuplicateCheck],
|
|
209
219
|
);
|
|
210
220
|
|
|
211
|
-
const
|
|
221
|
+
const fetchProductsInternal = useCallback(
|
|
212
222
|
async (params: {
|
|
213
223
|
skus: string[];
|
|
214
224
|
type?: 'inapp' | 'subs';
|
|
215
225
|
}): Promise<void> => {
|
|
216
226
|
try {
|
|
217
|
-
const result = await
|
|
227
|
+
const result = await fetchProducts(params);
|
|
218
228
|
if (params.type === 'subs') {
|
|
219
229
|
setSubscriptions((prevSubscriptions) =>
|
|
220
230
|
mergeWithDuplicateCheck(
|
|
@@ -239,6 +249,19 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
239
249
|
[mergeWithDuplicateCheck],
|
|
240
250
|
);
|
|
241
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
|
+
|
|
242
265
|
const getAvailablePurchasesInternal = useCallback(async (): Promise<void> => {
|
|
243
266
|
try {
|
|
244
267
|
const result = await getAvailablePurchases();
|
|
@@ -276,6 +299,10 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
276
299
|
[],
|
|
277
300
|
);
|
|
278
301
|
|
|
302
|
+
/**
|
|
303
|
+
* @deprecated Use getAvailablePurchases instead. This function is just calling getAvailablePurchases internally.
|
|
304
|
+
* Will be removed in v2.9.0
|
|
305
|
+
*/
|
|
279
306
|
const getPurchaseHistoriesInternal = useCallback(async (): Promise<void> => {
|
|
280
307
|
setPurchaseHistories(await getPurchaseHistories());
|
|
281
308
|
}, []);
|
|
@@ -448,6 +475,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
448
475
|
clearCurrentPurchaseError,
|
|
449
476
|
getAvailablePurchases: getAvailablePurchasesInternal,
|
|
450
477
|
getPurchaseHistories: getPurchaseHistoriesInternal,
|
|
478
|
+
fetchProducts: fetchProductsInternal,
|
|
451
479
|
requestProducts: requestProductsInternal,
|
|
452
480
|
requestPurchase: requestPurchaseWithReset,
|
|
453
481
|
validateReceipt,
|
|
@@ -455,7 +483,8 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
455
483
|
getProducts: getProductsInternal,
|
|
456
484
|
getSubscriptions: getSubscriptionsInternal,
|
|
457
485
|
getPromotedProductIOS,
|
|
458
|
-
|
|
486
|
+
requestPurchaseOnPromotedProductIOS,
|
|
487
|
+
buyPromotedProductIOS: requestPurchaseOnPromotedProductIOS, // deprecated alias
|
|
459
488
|
getActiveSubscriptions: getActiveSubscriptionsInternal,
|
|
460
489
|
hasActiveSubscriptions: hasActiveSubscriptionsInternal,
|
|
461
490
|
};
|