expo-iap 2.8.5 → 2.8.6
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 +21 -0
- package/README.md +8 -7
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +4 -4
- package/build/index.d.ts +20 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +23 -18
- 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 +3 -1
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +7 -2
- package/build/useIAP.js.map +1 -1
- package/ios/ExpoIapModule.swift +27 -25
- package/package.json +1 -1
- package/src/index.ts +42 -17
- package/src/modules/android.ts +1 -1
- package/src/modules/ios.ts +46 -18
- package/src/useIAP.ts +11 -4
package/src/index.ts
CHANGED
|
@@ -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.requestProducts(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.requestProducts('inapp', skus);
|
|
149
149
|
return products.filter((product: unknown) =>
|
|
150
150
|
isProductAndroid<Product>(product),
|
|
151
151
|
);
|
|
@@ -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.requestProducts(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.requestProducts('subs', skus);
|
|
183
183
|
return rawItems.filter((item: unknown) => {
|
|
184
184
|
if (!isProductAndroid(item)) return false;
|
|
185
185
|
return (
|
|
@@ -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.requestProducts(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.requestProducts(type, skus);
|
|
255
255
|
const filteredItems = items.filter((item: unknown) => {
|
|
256
256
|
if (!isProductAndroid(item)) return false;
|
|
257
257
|
return (
|
|
@@ -277,32 +277,51 @@ export const requestProducts = async ({
|
|
|
277
277
|
export const getPurchaseHistory = ({
|
|
278
278
|
alsoPublishToEventListener = false,
|
|
279
279
|
onlyIncludeActiveItems = false,
|
|
280
|
+
alsoPublishToEventListenerIOS,
|
|
281
|
+
onlyIncludeActiveItemsIOS,
|
|
280
282
|
}: {
|
|
283
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
281
284
|
alsoPublishToEventListener?: boolean;
|
|
285
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
282
286
|
onlyIncludeActiveItems?: boolean;
|
|
287
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
288
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
283
289
|
} = {}): Promise<Purchase[]> => {
|
|
284
290
|
console.warn(
|
|
285
291
|
'`getPurchaseHistory` is deprecated. Use `getPurchaseHistories` instead. This function will be removed in version 3.0.0.',
|
|
286
292
|
);
|
|
287
293
|
return getPurchaseHistories({
|
|
288
|
-
|
|
289
|
-
|
|
294
|
+
alsoPublishToEventListenerIOS:
|
|
295
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
296
|
+
onlyIncludeActiveItemsIOS:
|
|
297
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
290
298
|
});
|
|
291
299
|
};
|
|
292
300
|
|
|
301
|
+
/**
|
|
302
|
+
* @deprecated Use getAvailablePurchases instead. This function is just calling getAvailablePurchases internally on iOS
|
|
303
|
+
* and returns an empty array on Android (Google Play Billing v8 removed purchase history API).
|
|
304
|
+
* Will be removed in v2.9.0
|
|
305
|
+
*/
|
|
293
306
|
export const getPurchaseHistories = ({
|
|
294
307
|
alsoPublishToEventListener = false,
|
|
295
308
|
onlyIncludeActiveItems = false,
|
|
309
|
+
alsoPublishToEventListenerIOS,
|
|
310
|
+
onlyIncludeActiveItemsIOS,
|
|
296
311
|
}: {
|
|
312
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
297
313
|
alsoPublishToEventListener?: boolean;
|
|
314
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
298
315
|
onlyIncludeActiveItems?: boolean;
|
|
316
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
317
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
299
318
|
} = {}): Promise<Purchase[]> =>
|
|
300
319
|
(
|
|
301
320
|
Platform.select({
|
|
302
321
|
ios: async () => {
|
|
303
322
|
return ExpoIapModule.getAvailableItems(
|
|
304
|
-
alsoPublishToEventListener,
|
|
305
|
-
onlyIncludeActiveItems,
|
|
323
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
324
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
306
325
|
);
|
|
307
326
|
},
|
|
308
327
|
android: async () => {
|
|
@@ -319,16 +338,22 @@ export const getPurchaseHistories = ({
|
|
|
319
338
|
export const getAvailablePurchases = ({
|
|
320
339
|
alsoPublishToEventListener = false,
|
|
321
340
|
onlyIncludeActiveItems = true,
|
|
341
|
+
alsoPublishToEventListenerIOS,
|
|
342
|
+
onlyIncludeActiveItemsIOS,
|
|
322
343
|
}: {
|
|
344
|
+
/** @deprecated Use alsoPublishToEventListenerIOS instead */
|
|
323
345
|
alsoPublishToEventListener?: boolean;
|
|
346
|
+
/** @deprecated Use onlyIncludeActiveItemsIOS instead */
|
|
324
347
|
onlyIncludeActiveItems?: boolean;
|
|
348
|
+
alsoPublishToEventListenerIOS?: boolean;
|
|
349
|
+
onlyIncludeActiveItemsIOS?: boolean;
|
|
325
350
|
} = {}): Promise<Purchase[]> =>
|
|
326
351
|
(
|
|
327
352
|
Platform.select({
|
|
328
353
|
ios: () =>
|
|
329
354
|
ExpoIapModule.getAvailableItems(
|
|
330
|
-
alsoPublishToEventListener,
|
|
331
|
-
onlyIncludeActiveItems,
|
|
355
|
+
alsoPublishToEventListenerIOS ?? alsoPublishToEventListener,
|
|
356
|
+
onlyIncludeActiveItemsIOS ?? onlyIncludeActiveItems,
|
|
332
357
|
),
|
|
333
358
|
android: async () => {
|
|
334
359
|
const products = await ExpoIapModule.getAvailableItemsByType('inapp');
|
|
@@ -430,7 +455,7 @@ export const requestPurchase = (
|
|
|
430
455
|
|
|
431
456
|
return (async () => {
|
|
432
457
|
const offer = offerToRecordIOS(withOffer);
|
|
433
|
-
const purchase = await ExpoIapModule.
|
|
458
|
+
const purchase = await ExpoIapModule.requestPurchase(
|
|
434
459
|
sku,
|
|
435
460
|
andDangerouslyFinishTransactionAutomatically,
|
|
436
461
|
appAccountToken,
|
|
@@ -460,7 +485,7 @@ export const requestPurchase = (
|
|
|
460
485
|
} = normalizedRequest;
|
|
461
486
|
|
|
462
487
|
return (async () => {
|
|
463
|
-
return ExpoIapModule.
|
|
488
|
+
return ExpoIapModule.requestPurchase({
|
|
464
489
|
type: 'inapp',
|
|
465
490
|
skuArr: skus,
|
|
466
491
|
purchaseToken: undefined,
|
|
@@ -486,7 +511,7 @@ export const requestPurchase = (
|
|
|
486
511
|
} = normalizedRequest;
|
|
487
512
|
|
|
488
513
|
return (async () => {
|
|
489
|
-
return ExpoIapModule.
|
|
514
|
+
return ExpoIapModule.requestPurchase({
|
|
490
515
|
type: 'subs',
|
|
491
516
|
skuArr: skus,
|
|
492
517
|
purchaseToken: purchaseTokenAndroid || purchaseToken,
|
|
@@ -586,10 +611,10 @@ export const finishTransaction = ({
|
|
|
586
611
|
}
|
|
587
612
|
|
|
588
613
|
if (isConsumable) {
|
|
589
|
-
return ExpoIapModule.
|
|
614
|
+
return ExpoIapModule.consumeProductAndroid(token);
|
|
590
615
|
}
|
|
591
616
|
|
|
592
|
-
return ExpoIapModule.
|
|
617
|
+
return ExpoIapModule.acknowledgePurchaseAndroid(token);
|
|
593
618
|
},
|
|
594
619
|
}) || (() => Promise.reject(new Error('Unsupported Platform')))
|
|
595
620
|
)();
|
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
|
@@ -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
|
|
@@ -87,8 +87,10 @@ type UseIap = {
|
|
|
87
87
|
isSub?: boolean;
|
|
88
88
|
},
|
|
89
89
|
) => Promise<any>;
|
|
90
|
-
restorePurchases: () => Promise<void>;
|
|
91
|
-
getPromotedProductIOS: () => Promise<
|
|
90
|
+
restorePurchases: () => Promise<void>;
|
|
91
|
+
getPromotedProductIOS: () => Promise<Product | null>;
|
|
92
|
+
requestPurchaseOnPromotedProductIOS: () => Promise<void>;
|
|
93
|
+
/** @deprecated Use requestPurchaseOnPromotedProductIOS instead */
|
|
92
94
|
buyPromotedProductIOS: () => Promise<void>;
|
|
93
95
|
getActiveSubscriptions: (
|
|
94
96
|
subscriptionIds?: string[],
|
|
@@ -276,6 +278,10 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
276
278
|
[],
|
|
277
279
|
);
|
|
278
280
|
|
|
281
|
+
/**
|
|
282
|
+
* @deprecated Use getAvailablePurchases instead. This function is just calling getAvailablePurchases internally.
|
|
283
|
+
* Will be removed in v2.9.0
|
|
284
|
+
*/
|
|
279
285
|
const getPurchaseHistoriesInternal = useCallback(async (): Promise<void> => {
|
|
280
286
|
setPurchaseHistories(await getPurchaseHistories());
|
|
281
287
|
}, []);
|
|
@@ -455,7 +461,8 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
455
461
|
getProducts: getProductsInternal,
|
|
456
462
|
getSubscriptions: getSubscriptionsInternal,
|
|
457
463
|
getPromotedProductIOS,
|
|
458
|
-
|
|
464
|
+
requestPurchaseOnPromotedProductIOS,
|
|
465
|
+
buyPromotedProductIOS: requestPurchaseOnPromotedProductIOS, // deprecated alias
|
|
459
466
|
getActiveSubscriptions: getActiveSubscriptionsInternal,
|
|
460
467
|
hasActiveSubscriptions: hasActiveSubscriptionsInternal,
|
|
461
468
|
};
|