expo-iap 2.2.8-rc.2 → 2.2.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/build/useIap.d.ts +2 -2
- package/build/useIap.d.ts.map +1 -1
- package/build/useIap.js.map +1 -1
- package/iap.md +38 -20
- package/package.json +1 -1
- package/src/useIap.ts +2 -2
package/build/useIap.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { requestPurchase as requestPurchaseInternal } from './';
|
|
2
2
|
import { Product, ProductPurchase, Purchase, PurchaseError, PurchaseResult, SubscriptionProduct } from './ExpoIap.types';
|
|
3
|
-
type
|
|
3
|
+
type UseIap = {
|
|
4
4
|
connected: boolean;
|
|
5
5
|
products: Product[];
|
|
6
6
|
promotedProductsIOS: ProductPurchase[];
|
|
@@ -19,6 +19,6 @@ type IAP_STATUS = {
|
|
|
19
19
|
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
20
20
|
requestPurchase: typeof requestPurchaseInternal;
|
|
21
21
|
};
|
|
22
|
-
export declare function useIAP():
|
|
22
|
+
export declare function useIAP(): UseIap;
|
|
23
23
|
export {};
|
|
24
24
|
//# sourceMappingURL=useIap.d.ts.map
|
package/build/useIap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIap.d.ts","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,eAAe,IAAI,uBAAuB,EAC3C,MAAM,IAAI,CAAC;AAEZ,OAAO,EACL,OAAO,EACP,eAAe,EACf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,mBAAmB,EAEpB,MAAM,iBAAiB,CAAC;AAKzB,KAAK,
|
|
1
|
+
{"version":3,"file":"useIap.d.ts","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,eAAe,IAAI,uBAAuB,EAC3C,MAAM,IAAI,CAAC;AAEZ,OAAO,EACL,O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AAiB;QACjB,iBAAiB;QACjB,kBAAkB;QAClB,eAAe;QACf,oBAAoB;QACpB,qBAAqB,EAAE,6BAA6B;QACpD,oBAAoB,EAAE,4BAA4B;QAClD,WAAW,EAAE,mBAAmB;QAChC,gBAAgB,EAAE,wBAAwB;QAC1C,eAAe,EAAE,uBAAuB;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n endConnection,\n initConnection,\n purchaseErrorListener,\n purchaseUpdatedListener,\n transactionUpdatedIos,\n getProducts,\n getAvailablePurchases,\n getPurchaseHistory,\n finishTransaction as finishTransactionInternal,\n getSubscriptions,\n requestPurchase as requestPurchaseInternal,\n} from './';\nimport {useCallback, useEffect, useState, useRef} from 'react';\nimport {\n Product,\n ProductPurchase,\n Purchase,\n PurchaseError,\n PurchaseResult,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport {TransactionEvent} from './modules/ios';\nimport {Subscription} from 'expo-modules-core';\nimport {Platform} from 'react-native';\n\ntype
|
|
1
|
+
{"version":3,"file":"useIap.js","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,IAAI,yBAAyB,EAC9C,gBAAgB,EAChB,eAAe,IAAI,uBAAuB,GAC3C,MAAM,IAAI,CAAC;AACZ,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAY/D,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAyBtC,MAAM,UAAU,MAAM;IACpB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAU,KAAK,CAAC,CAAC;IAC3D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAY,EAAE,CAAC,CAAC;IACxD,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AAE;oBAC1B,sBAAsB,CAAC,CAAC,YAAY,EAAE,EAAE,CACtC,KAAK,CAAC,WAAW;wBACf,CAAC,CAAC,CAAC,GAAG,YAAY,EAAE,KAAK,CAAC,WAAW,CAAC;wBACtC,CAAC,CAAC,YAAY,CACjB,CAAC;gBACJ,CAAC,CACF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE;QACb,wBAAwB,EAAE,CAAC;QAC3B,MAAM,oBAAoB,GAAG,gBAAgB,CAAC,OAAO,CAAC;QAEtD,OAAO,GAAG,EAAE;YACV,oBAAoB,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC;YAC9C,oBAAoB,CAAC,aAAa,EAAE,MAAM,EAAE,CAAC;YAC7C,oBAAoB,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC;YACnD,aAAa,EAAE,CAAC;YAChB,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,wBAAwB,CAAC,CAAC,CAAC;IAE/B,OAAO;QACL,SAAS;QACT,QAAQ;QACR,mBAAmB;QACnB,aAAa;QACb,iBAAiB;QACjB,iBAAiB;QACjB,kBAAkB;QAClB,eAAe;QACf,oBAAoB;QACpB,qBAAqB,EAAE,6BAA6B;QACpD,oBAAoB,EAAE,4BAA4B;QAClD,WAAW,EAAE,mBAAmB;QAChC,gBAAgB,EAAE,wBAAwB;QAC1C,eAAe,EAAE,uBAAuB;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {\n endConnection,\n initConnection,\n purchaseErrorListener,\n purchaseUpdatedListener,\n transactionUpdatedIos,\n getProducts,\n getAvailablePurchases,\n getPurchaseHistory,\n finishTransaction as finishTransactionInternal,\n getSubscriptions,\n requestPurchase as requestPurchaseInternal,\n} from './';\nimport {useCallback, useEffect, useState, useRef} from 'react';\nimport {\n Product,\n ProductPurchase,\n Purchase,\n PurchaseError,\n PurchaseResult,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport {TransactionEvent} from './modules/ios';\nimport {Subscription} from 'expo-modules-core';\nimport {Platform} from 'react-native';\n\ntype UseIap = {\n connected: boolean;\n products: Product[];\n promotedProductsIOS: ProductPurchase[];\n subscriptions: SubscriptionProduct[];\n purchaseHistories: ProductPurchase[];\n availablePurchases: ProductPurchase[];\n currentPurchase?: ProductPurchase;\n currentPurchaseError?: PurchaseError;\n finishTransaction: ({\n purchase,\n isConsumable,\n }: {\n purchase: Purchase;\n isConsumable?: boolean;\n }) => Promise<string | boolean | PurchaseResult | void>;\n getAvailablePurchases: (skus: string[]) => Promise<void>;\n getPurchaseHistories: (skus: string[]) => Promise<void>;\n getProducts: (skus: string[]) => Promise<void>;\n getSubscriptions: (skus: string[]) => Promise<void>;\n requestPurchase: typeof requestPurchaseInternal;\n};\n\nexport function useIAP(): UseIap {\n const [connected, setConnected] = useState<boolean>(false);\n const [products, setProducts] = useState<Product[]>([]);\n const [promotedProductsIOS, setPromotedProductsIOS] = useState<\n ProductPurchase[]\n >([]);\n const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([]);\n const [purchaseHistories, setPurchaseHistories] = useState<ProductPurchase[]>(\n [],\n );\n const [availablePurchases, setAvailablePurchases] = useState<\n ProductPurchase[]\n >([]);\n const [currentPurchase, setCurrentPurchase] = useState<ProductPurchase>();\n const [currentPurchaseError, setCurrentPurchaseError] =\n useState<PurchaseError>();\n\n const subscriptionsRef = useRef<{\n purchaseUpdate?: Subscription;\n purchaseError?: Subscription;\n promotedProductsIos?: Subscription;\n }>({});\n\n const getProductsInternal = useCallback(\n async (skus: string[]): Promise<void> => {\n setProducts(await getProducts(skus));\n },\n [],\n );\n\n const getSubscriptionsInternal = useCallback(\n async (skus: string[]): Promise<void> => {\n setSubscriptions(await getSubscriptions(skus));\n },\n [],\n );\n\n const getAvailablePurchasesInternal = useCallback(async (): Promise<void> => {\n setAvailablePurchases(await getAvailablePurchases());\n }, []);\n\n const getPurchaseHistoriesInternal = useCallback(async (): Promise<void> => {\n setPurchaseHistories(await getPurchaseHistory());\n }, []);\n\n const finishTransaction = useCallback(\n async ({\n purchase,\n isConsumable,\n }: {\n purchase: ProductPurchase;\n isConsumable?: boolean;\n }): Promise<string | boolean | PurchaseResult | void> => {\n try {\n return await finishTransactionInternal({\n purchase,\n isConsumable,\n });\n } catch (err) {\n throw err;\n } finally {\n if (purchase.id === currentPurchase?.id) {\n setCurrentPurchase(undefined);\n }\n if (purchase.id === currentPurchaseError?.productId) {\n setCurrentPurchaseError(undefined);\n }\n }\n },\n [currentPurchase?.id, currentPurchaseError?.productId],\n );\n\n const initIapWithSubscriptions = useCallback(async (): Promise<void> => {\n const result = await initConnection();\n setConnected(result);\n\n if (result) {\n subscriptionsRef.current.purchaseUpdate = purchaseUpdatedListener(\n async (purchase: Purchase | SubscriptionPurchase) => {\n setCurrentPurchaseError(undefined);\n setCurrentPurchase(purchase);\n },\n );\n\n subscriptionsRef.current.purchaseError = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n },\n );\n\n if (Platform.OS === 'ios') {\n subscriptionsRef.current.promotedProductsIos = transactionUpdatedIos(\n (event: TransactionEvent) => {\n setPromotedProductsIOS((prevProducts) =>\n event.transaction\n ? [...prevProducts, event.transaction]\n : prevProducts,\n );\n },\n );\n }\n }\n }, []);\n\n useEffect(() => {\n initIapWithSubscriptions();\n const currentSubscriptions = subscriptionsRef.current;\n\n return () => {\n currentSubscriptions.purchaseUpdate?.remove();\n currentSubscriptions.purchaseError?.remove();\n currentSubscriptions.promotedProductsIos?.remove();\n endConnection();\n setConnected(false);\n };\n }, [initIapWithSubscriptions]);\n\n return {\n connected,\n products,\n promotedProductsIOS,\n subscriptions,\n purchaseHistories,\n finishTransaction,\n availablePurchases,\n currentPurchase,\n currentPurchaseError,\n getAvailablePurchases: getAvailablePurchasesInternal,\n getPurchaseHistories: getPurchaseHistoriesInternal,\n getProducts: getProductsInternal,\n getSubscriptions: getSubscriptionsInternal,\n requestPurchase: requestPurchaseInternal,\n };\n}\n"]}
|
package/iap.md
CHANGED
|
@@ -209,8 +209,8 @@ Transactions map to `Purchase` or `SubscriptionPurchase` with platform-specific
|
|
|
209
209
|
Below is a simple example of fetching products and making a purchase with `expo-iap` in a managed workflow, updated to use the new `requestPurchase` signature:
|
|
210
210
|
|
|
211
211
|
```tsx
|
|
212
|
-
import {
|
|
213
|
-
import {
|
|
212
|
+
import {useEffect, useState} from 'react';
|
|
213
|
+
import {Button, Text, View} from 'react-native';
|
|
214
214
|
import {
|
|
215
215
|
initConnection,
|
|
216
216
|
endConnection,
|
|
@@ -237,7 +237,7 @@ export default function SimpleIAP() {
|
|
|
237
237
|
|
|
238
238
|
const purchaseListener = purchaseUpdatedListener(async (purchase) => {
|
|
239
239
|
if (purchase) {
|
|
240
|
-
await finishTransaction({
|
|
240
|
+
await finishTransaction({purchase, isConsumable: true});
|
|
241
241
|
alert('Purchase completed!');
|
|
242
242
|
}
|
|
243
243
|
});
|
|
@@ -252,12 +252,12 @@ export default function SimpleIAP() {
|
|
|
252
252
|
const buyItem = async () => {
|
|
253
253
|
if (!product) return;
|
|
254
254
|
await requestPurchase({
|
|
255
|
-
request: {
|
|
255
|
+
request: {skus: [product.id]}, // Android expects 'skus'; iOS would use 'sku'
|
|
256
256
|
});
|
|
257
257
|
};
|
|
258
258
|
|
|
259
259
|
return (
|
|
260
|
-
<View style={{
|
|
260
|
+
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
|
|
261
261
|
<Text>{isConnected ? 'Connected' : 'Connecting...'}</Text>
|
|
262
262
|
{product ? (
|
|
263
263
|
<>
|
|
@@ -277,7 +277,7 @@ export default function SimpleIAP() {
|
|
|
277
277
|
The `useIAP` hook simplifies managing in-app purchases. Below is an example updated to use the new `requestPurchase` signature:
|
|
278
278
|
|
|
279
279
|
```tsx
|
|
280
|
-
import {
|
|
280
|
+
import {useEffect, useState} from 'react';
|
|
281
281
|
import {
|
|
282
282
|
SafeAreaView,
|
|
283
283
|
ScrollView,
|
|
@@ -289,12 +289,20 @@ import {
|
|
|
289
289
|
InteractionManager,
|
|
290
290
|
Alert,
|
|
291
291
|
} from 'react-native';
|
|
292
|
-
import {
|
|
293
|
-
import type {
|
|
292
|
+
import {useIAP} from 'expo-iap';
|
|
293
|
+
import type {ProductPurchase, SubscriptionProduct} from 'expo-iap';
|
|
294
294
|
|
|
295
295
|
// Define SKUs
|
|
296
|
-
const productSkus = [
|
|
297
|
-
|
|
296
|
+
const productSkus = [
|
|
297
|
+
'cpk.points.1000',
|
|
298
|
+
'cpk.points.5000',
|
|
299
|
+
'cpk.points.10000',
|
|
300
|
+
'cpk.points.30000',
|
|
301
|
+
];
|
|
302
|
+
const subscriptionSkus = [
|
|
303
|
+
'cpk.membership.monthly.bronze',
|
|
304
|
+
'cpk.membership.monthly.silver',
|
|
305
|
+
];
|
|
298
306
|
|
|
299
307
|
// Define operations
|
|
300
308
|
const operations = ['getProducts', 'getSubscriptions'] as const;
|
|
@@ -321,7 +329,10 @@ export default function IAPWithHook() {
|
|
|
321
329
|
|
|
322
330
|
const initializeIAP = async () => {
|
|
323
331
|
try {
|
|
324
|
-
await Promise.all([
|
|
332
|
+
await Promise.all([
|
|
333
|
+
getProducts(productSkus),
|
|
334
|
+
getSubscriptions(subscriptionSkus),
|
|
335
|
+
]);
|
|
325
336
|
setIsReady(true);
|
|
326
337
|
} catch (error) {
|
|
327
338
|
console.error('Error initializing IAP:', error);
|
|
@@ -389,7 +400,10 @@ export default function IAPWithHook() {
|
|
|
389
400
|
<View style={styles.buttons}>
|
|
390
401
|
<ScrollView contentContainerStyle={styles.buttonsWrapper} horizontal>
|
|
391
402
|
{operations.map((operation) => (
|
|
392
|
-
<Pressable
|
|
403
|
+
<Pressable
|
|
404
|
+
key={operation}
|
|
405
|
+
onPress={() => handleOperation(operation)}
|
|
406
|
+
>
|
|
393
407
|
<View style={styles.buttonView}>
|
|
394
408
|
<Text>{operation}</Text>
|
|
395
409
|
</View>
|
|
@@ -401,10 +415,10 @@ export default function IAPWithHook() {
|
|
|
401
415
|
{!isReady ? (
|
|
402
416
|
<Text>Loading...</Text>
|
|
403
417
|
) : (
|
|
404
|
-
<View style={{
|
|
405
|
-
<Text style={{
|
|
418
|
+
<View style={{gap: 12}}>
|
|
419
|
+
<Text style={{fontSize: 20}}>Products</Text>
|
|
406
420
|
{products.map((item) => (
|
|
407
|
-
<View key={item.id} style={{
|
|
421
|
+
<View key={item.id} style={{gap: 12}}>
|
|
408
422
|
<Text>
|
|
409
423
|
{item.title} -{' '}
|
|
410
424
|
{item.platform === 'android'
|
|
@@ -415,20 +429,24 @@ export default function IAPWithHook() {
|
|
|
415
429
|
title="Buy"
|
|
416
430
|
onPress={() =>
|
|
417
431
|
requestPurchase({
|
|
418
|
-
request:
|
|
432
|
+
request:
|
|
433
|
+
item.platform === 'android'
|
|
434
|
+
? {skus: [item.id]}
|
|
435
|
+
: {sku: item.id},
|
|
419
436
|
})
|
|
420
437
|
}
|
|
421
438
|
/>
|
|
422
439
|
</View>
|
|
423
440
|
))}
|
|
424
441
|
|
|
425
|
-
<Text style={{
|
|
442
|
+
<Text style={{fontSize: 20}}>Subscriptions</Text>
|
|
426
443
|
{subscriptions.map((item) => (
|
|
427
|
-
<View key={item.id} style={{
|
|
444
|
+
<View key={item.id} style={{gap: 12}}>
|
|
428
445
|
<Text>
|
|
429
446
|
{item.title || item.displayName} -{' '}
|
|
430
447
|
{item.platform === 'android' && item.subscriptionOfferDetails
|
|
431
|
-
? item.subscriptionOfferDetails[0]?.pricingPhases
|
|
448
|
+
? item.subscriptionOfferDetails[0]?.pricingPhases
|
|
449
|
+
.pricingPhaseList[0].formattedPrice
|
|
432
450
|
: item.displayPrice}
|
|
433
451
|
</Text>
|
|
434
452
|
<Button
|
|
@@ -445,7 +463,7 @@ export default function IAPWithHook() {
|
|
|
445
463
|
offerToken: offer.offerToken,
|
|
446
464
|
})) || [],
|
|
447
465
|
}
|
|
448
|
-
: {
|
|
466
|
+
: {sku: item.id},
|
|
449
467
|
type: 'subs',
|
|
450
468
|
})
|
|
451
469
|
}
|
package/package.json
CHANGED
package/src/useIap.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {TransactionEvent} from './modules/ios';
|
|
|
25
25
|
import {Subscription} from 'expo-modules-core';
|
|
26
26
|
import {Platform} from 'react-native';
|
|
27
27
|
|
|
28
|
-
type
|
|
28
|
+
type UseIap = {
|
|
29
29
|
connected: boolean;
|
|
30
30
|
products: Product[];
|
|
31
31
|
promotedProductsIOS: ProductPurchase[];
|
|
@@ -48,7 +48,7 @@ type IAP_STATUS = {
|
|
|
48
48
|
requestPurchase: typeof requestPurchaseInternal;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export function useIAP():
|
|
51
|
+
export function useIAP(): UseIap {
|
|
52
52
|
const [connected, setConnected] = useState<boolean>(false);
|
|
53
53
|
const [products, setProducts] = useState<Product[]>([]);
|
|
54
54
|
const [promotedProductsIOS, setPromotedProductsIOS] = useState<
|