expo-iap 2.3.8 → 2.4.0
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/ExpoIap.types.d.ts.map +1 -1
- package/build/index.d.ts +13 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/ios.d.ts +16 -1
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +39 -2
- package/build/modules/ios.js.map +1 -1
- package/build/useIap.d.ts.map +1 -1
- package/build/useIap.js +26 -12
- package/build/useIap.js.map +1 -1
- package/bun.lockb +0 -0
- package/ios/ExpoIapModule.swift +1 -5
- package/package.json +7 -7
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/src/index.ts +14 -5
- package/src/modules/ios.ts +52 -3
- package/src/useIap.ts +56 -18
- package/tsconfig.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.d.ts","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,2BAA2B,EAC3B,+BAA+B,EAC/B,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,2BAA2B,EAC3B,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAElC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM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,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,oBAAY,SAAS;IACnB,SAAS,cAAc;IACvB,gBAAgB,qBAAqB;IACrC,YAAY,iBAAiB;IAC7B,kBAAkB,uBAAuB;IACzC,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;IACnC,eAAe,oBAAoB;IACnC,gBAAgB,qBAAqB;IACrC,yBAAyB,8BAA8B;IACvD,cAAc,mBAAmB;IACjC,WAAW,gBAAgB;IAC3B,eAAe,oBAAoB;IACnC,iBAAiB,sBAAsB;IACvC,mCAAmC,wCAAwC;IAC3E,kBAAkB,uBAAuB;IACzC,aAAa,kBAAkB;IAC/B,mBAAmB,wBAAwB;CAC5C;AAED,qBAAa,aAAc,YAAW,KAAK;IAEhC,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,MAAM;IACf,YAAY,CAAC,EAAE,MAAM;IACrB,YAAY,CAAC,EAAE,MAAM;IACrB,IAAI,CAAC,EAAE,SAAS;IAChB,SAAS,CAAC,EAAE,MAAM;gBALlB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,EAAE,MAAM,YAAA,EACrB,YAAY,CAAC,EAAE,MAAM,YAAA,EACrB,IAAI,CAAC,EAAE,SAAS,YAAA,EAChB,SAAS,CAAC,EAAE,MAAM,YAAA;CAS5B"}
|
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EventEmitter } from 'expo-modules-core';
|
|
2
1
|
import { Product, ProductPurchase, Purchase, PurchaseError, PurchaseResult, RequestSubscriptionProps, SubscriptionProduct, SubscriptionPurchase } from './ExpoIap.types';
|
|
3
2
|
import { RequestPurchaseAndroidProps, RequestSubscriptionAndroidProps } from './types/ExpoIapAndroid.types';
|
|
4
3
|
import { RequestPurchaseIosProps, RequestSubscriptionIosProps } from './types/ExpoIapIos.types';
|
|
@@ -8,12 +7,22 @@ export declare const PI: any;
|
|
|
8
7
|
export declare enum IapEvent {
|
|
9
8
|
PurchaseUpdated = "purchase-updated",
|
|
10
9
|
PurchaseError = "purchase-error",
|
|
10
|
+
/** @deprecated Use PurchaseUpdated instead. This will be removed in a future version. */
|
|
11
11
|
TransactionIapUpdated = "iap-transaction-updated"
|
|
12
12
|
}
|
|
13
13
|
export declare function setValueAsync(value: string): any;
|
|
14
|
-
export declare const emitter:
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export declare const emitter: {
|
|
15
|
+
addListener: (eventName: string, listener: (...args: any[]) => void) => {
|
|
16
|
+
remove: () => void;
|
|
17
|
+
};
|
|
18
|
+
removeListener: (eventName: string, listener: (...args: any[]) => void) => void;
|
|
19
|
+
};
|
|
20
|
+
export declare const purchaseUpdatedListener: (listener: (event: Purchase) => void) => {
|
|
21
|
+
remove: () => void;
|
|
22
|
+
};
|
|
23
|
+
export declare const purchaseErrorListener: (listener: (error: PurchaseError) => void) => {
|
|
24
|
+
remove: () => void;
|
|
25
|
+
};
|
|
17
26
|
export declare function initConnection(): any;
|
|
18
27
|
export declare const getProducts: (skus: string[]) => Promise<Product[]>;
|
|
19
28
|
export declare const getSubscriptions: (skus: string[]) => Promise<SubscriptionProduct[]>;
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,EACP,eAAe,EACf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAEL,2BAA2B,EAC3B,+BAA+B,EAChC,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAEL,uBAAuB,EACvB,2BAA2B,EAC5B,MAAM,0BAA0B,CAAC;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CAAC;AAEN,eAAO,MAAM,qBAAqB,GAAI,0DAGnC;IACD,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC7B,KAAG,OAAO,CAAC,eAAe,EAAE,CAe7B,CAAC;AAgBN,KAAK,eAAe,GAChB;IACE,OAAO,EAAE,uBAAuB,GAAG,2BAA2B,CAAC;IAC/D,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB,GACD;IACE,OAAO,EAAE,+BAA+B,GAAG,2BAA2B,CAAC;IACvE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAQN,eAAO,MAAM,eAAe,GAC1B,YAAY,eAAe,KAC1B,OAAO,CACN,eAAe,GACf,oBAAoB,GACpB,eAAe,EAAE,GACjB,oBAAoB,EAAE,GACtB,IAAI,CAyFP,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAC9B,SAAS,wBAAwB,KAChC,OAAO,CAAC,oBAAoB,GAAG,oBAAoB,EAAE,GAAG,IAAI,GAAG,IAAI,CASrE,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,6BAG/B;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,KAAG,OAAO,CAAC,cAAc,GAAG,OAAO,CAiCnC,CAAC;AAEF,cAAc,UAAU,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Import the native module. On web, it will be resolved to ExpoIap.web.ts
|
|
2
2
|
// and on native platforms to ExpoIap.ts
|
|
3
|
-
import { NativeModulesProxy
|
|
3
|
+
import { NativeModulesProxy } from 'expo-modules-core';
|
|
4
4
|
import { Platform } from 'react-native';
|
|
5
5
|
import ExpoIapModule from './ExpoIapModule';
|
|
6
6
|
import { isProductIos } from './modules/ios';
|
|
@@ -13,12 +13,14 @@ export var IapEvent;
|
|
|
13
13
|
(function (IapEvent) {
|
|
14
14
|
IapEvent["PurchaseUpdated"] = "purchase-updated";
|
|
15
15
|
IapEvent["PurchaseError"] = "purchase-error";
|
|
16
|
+
/** @deprecated Use PurchaseUpdated instead. This will be removed in a future version. */
|
|
16
17
|
IapEvent["TransactionIapUpdated"] = "iap-transaction-updated";
|
|
17
18
|
})(IapEvent || (IapEvent = {}));
|
|
18
19
|
export function setValueAsync(value) {
|
|
19
20
|
return ExpoIapModule.setValueAsync(value);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
// Ensure the emitter has proper EventEmitter interface
|
|
23
|
+
export const emitter = (ExpoIapModule || NativeModulesProxy.ExpoIap);
|
|
22
24
|
export const purchaseUpdatedListener = (listener) => {
|
|
23
25
|
const emitterSubscription = emitter.addListener(IapEvent.PurchaseUpdated, listener);
|
|
24
26
|
return emitterSubscription;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAWtC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAW5C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAEnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAE9B,gCAAgC;AAChC,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;AAEnC,MAAM,CAAN,IAAY,QAIX;AAJD,WAAY,QAAQ;IAClB,gDAAoC,CAAA;IACpC,4CAAgC,CAAA;IAChC,6DAAiD,CAAA;AACnD,CAAC,EAJW,QAAQ,KAAR,QAAQ,QAInB;AAED,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,aAAa,C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,GAAG,EAAE,KAAK,IAAI,EAAE;YACd,MAAM,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC;YAC7C,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAC9D,CAAC;YACJ,CAAC;YACD,MAAM,aAAa,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,eAAe,GAAG,QAAkC,CAAC;YAE3D,IAAI,CAAC,CAAC,sBAAsB,IAAI,eAAe,CAAC,EAAE,CAAC;gBACjD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAC7D,CAAC;YACJ,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,aAAa,CAAC,cAAc,CACjC,eAAe,CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,aAAa,CAAC,mBAAmB,CACtC,eAAe,CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC;AAEF,cAAc,UAAU,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy, EventEmitter} from 'expo-modules-core';\nimport {Platform} from 'react-native';\nimport {\n Product,\n ProductPurchase,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {\n ProductPurchaseAndroid,\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n} from './types/ExpoIapIos.types';\nimport {isProductIos} from './modules/ios';\nimport {isProductAndroid} from './modules/android';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport function setValueAsync(value: string) {\n return ExpoIapModule.setValueAsync(value);\n}\n\nexport const emitter = new EventEmitter(\n ExpoIapModule || NativeModulesProxy.ExpoIap,\n);\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener<PurchaseError>(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const rawItems = await ExpoIapModule.getItems(skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductIos(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as Product[];\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType('inapp', skus);\n return products.filter((product: unknown) =>\n isProductAndroid<Product>(product),\n );\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const rawItems = await ExpoIapModule.getItems(skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductIos(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n android: async () => {\n const rawItems = await ExpoIapModule.getItemsByType('subs', skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductAndroid(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType('inapp');\n const subscriptions =\n await ExpoIapModule.getPurchaseHistoryByType('subs');\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType('inapp');\n const subscriptions =\n await ExpoIapModule.getAvailableItemsByType('subs');\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) return undefined;\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\n// Define discriminated union with explicit type parameter\ntype PurchaseRequest =\n | {\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps;\n type?: 'inapp';\n }\n | {\n request: RequestSubscriptionAndroidProps | RequestSubscriptionIosProps;\n type: 'subs';\n };\n\n// Type guards for request objects\nconst isIosRequest = (\n request: any,\n): request is RequestPurchaseIosProps | RequestSubscriptionIosProps =>\n 'sku' in request && typeof request.sku === 'string';\n\nexport const requestPurchase = (\n requestObj: PurchaseRequest,\n): Promise<\n | ProductPurchase\n | SubscriptionPurchase\n | ProductPurchase[]\n | SubscriptionPurchase[]\n | void\n> => {\n const {request, type = 'inapp'} = requestObj;\n\n if (Platform.OS === 'ios') {\n if (!isIosRequest(request)) {\n throw new Error(\n 'Invalid request for iOS. The `sku` property is required and must be a string.',\n );\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n\n return (async () => {\n const offer = offerToRecordIos(withOffer);\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n return type === 'inapp'\n ? (purchase as ProductPurchase)\n : (purchase as SubscriptionPurchase);\n })();\n }\n\n if (Platform.OS === 'android') {\n if (type === 'inapp') {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request as RequestPurchaseAndroidProps;\n\n return (async () => {\n return ExpoIapModule.buyItemByType({\n type: 'inapp',\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n }) as Promise<ProductPurchase[]>;\n })();\n }\n\n if (type === 'subs') {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n subscriptionOffers = [],\n replacementModeAndroid = -1,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return (async () => {\n return ExpoIapModule.buyItemByType({\n type: 'subs',\n skuArr: skus,\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n }) as Promise<SubscriptionPurchase[]>;\n })();\n }\n\n throw new Error(\n \"Invalid request for Android: Expected a 'RequestPurchaseAndroidProps' object with a valid 'skus' array or a 'RequestSubscriptionAndroidProps' object with 'skus' and 'subscriptionOffers'.\",\n );\n }\n\n return Promise.resolve(); // Fallback for unsupported platforms\n};\n\n/**\n * @deprecated Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.\n */\nexport const requestSubscription = async (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> => {\n console.warn(\n \"`requestSubscription` is deprecated. Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.\",\n );\n return (await requestPurchase({request, type: 'subs'})) as\n | SubscriptionPurchase\n | SubscriptionPurchase[]\n | null\n | void;\n};\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n const androidPurchase = purchase as ProductPurchaseAndroid;\n\n if (!('purchaseTokenAndroid' in androidPurchase)) {\n return Promise.reject(\n new Error('purchaseToken is required to finish transaction'),\n );\n }\n if (isConsumable) {\n return ExpoIapModule.consumeProduct(\n androidPurchase.purchaseTokenAndroid,\n );\n } else {\n return ExpoIapModule.acknowledgePurchase(\n androidPurchase.purchaseTokenAndroid,\n );\n }\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n\nexport * from './useIap';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,wCAAwC;AACxC,OAAO,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAWtC,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAW5C,OAAO,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAEnD,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAE9B,gCAAgC;AAChC,MAAM,CAAC,MAAM,EAAE,GAAG,aAAa,CAAC,EAAE,CAAC;AAEnC,MAAM,CAAN,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,gDAAoC,CAAA;IACpC,4CAAgC,CAAA;IAChC,yFAAyF;IACzF,6DAAiD,CAAA;AACnD,CAAC,EALW,QAAQ,KAAR,QAAQ,QAKnB;AAED,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC5C,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,aAAa,IAAI,kBAAkB,CAAC,OAAO,CASlE,CAAC;AAEF,MAAM,C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AAK,CAAC,kDAAkD,CAAC,CAC9D,CAAC;YACJ,CAAC;YACD,MAAM,aAAa,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YACrD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,eAAe,GAAG,QAAkC,CAAC;YAE3D,IAAI,CAAC,CAAC,sBAAsB,IAAI,eAAe,CAAC,EAAE,CAAC;gBACjD,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAC7D,CAAC;YACJ,CAAC;YACD,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,aAAa,CAAC,cAAc,CACjC,eAAe,CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,aAAa,CAAC,mBAAmB,CACtC,eAAe,CAAC,oBAAoB,CACrC,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAChE,EAAE,CAAC;AACN,CAAC,CAAC;AAEF,cAAc,UAAU,CAAC","sourcesContent":["// Import the native module. On web, it will be resolved to ExpoIap.web.ts\n// and on native platforms to ExpoIap.ts\nimport {NativeModulesProxy} from 'expo-modules-core';\nimport {Platform} from 'react-native';\nimport {\n Product,\n ProductPurchase,\n Purchase,\n PurchaseError,\n PurchaseResult,\n RequestSubscriptionProps,\n SubscriptionProduct,\n SubscriptionPurchase,\n} from './ExpoIap.types';\nimport ExpoIapModule from './ExpoIapModule';\nimport {\n ProductPurchaseAndroid,\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n} from './types/ExpoIapAndroid.types';\nimport {\n PaymentDiscount,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n} from './types/ExpoIapIos.types';\nimport {isProductIos} from './modules/ios';\nimport {isProductAndroid} from './modules/android';\n\nexport * from './modules/android';\nexport * from './modules/ios';\n\n// Get the native constant value\nexport const PI = ExpoIapModule.PI;\n\nexport enum IapEvent {\n PurchaseUpdated = 'purchase-updated',\n PurchaseError = 'purchase-error',\n /** @deprecated Use PurchaseUpdated instead. This will be removed in a future version. */\n TransactionIapUpdated = 'iap-transaction-updated',\n}\n\nexport function setValueAsync(value: string) {\n return ExpoIapModule.setValueAsync(value);\n}\n\n// Ensure the emitter has proper EventEmitter interface\nexport const emitter = (ExpoIapModule || NativeModulesProxy.ExpoIap) as {\n addListener: (\n eventName: string,\n listener: (...args: any[]) => void,\n ) => {remove: () => void};\n removeListener: (\n eventName: string,\n listener: (...args: any[]) => void,\n ) => void;\n};\n\nexport const purchaseUpdatedListener = (\n listener: (event: Purchase) => void,\n) => {\n const emitterSubscription = emitter.addListener(\n IapEvent.PurchaseUpdated,\n listener,\n );\n return emitterSubscription;\n};\n\nexport const purchaseErrorListener = (\n listener: (error: PurchaseError) => void,\n) => {\n return emitter.addListener(IapEvent.PurchaseError, listener);\n};\n\nexport function initConnection() {\n return ExpoIapModule.initConnection();\n}\n\nexport const getProducts = async (skus: string[]): Promise<Product[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const rawItems = await ExpoIapModule.getItems(skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductIos(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as Product[];\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType('inapp', skus);\n return products.filter((product: unknown) =>\n isProductAndroid<Product>(product),\n );\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport const getSubscriptions = async (\n skus: string[],\n): Promise<SubscriptionProduct[]> => {\n if (!skus?.length) {\n return Promise.reject(new Error('\"skus\" is required'));\n }\n\n return Platform.select({\n ios: async () => {\n const rawItems = await ExpoIapModule.getItems(skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductIos(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n android: async () => {\n const rawItems = await ExpoIapModule.getItemsByType('subs', skus);\n return rawItems.filter((item: unknown) => {\n if (!isProductAndroid(item)) return false;\n return (\n typeof item === 'object' &&\n item !== null &&\n 'id' in item &&\n typeof item.id === 'string' &&\n skus.includes(item.id)\n );\n }) as SubscriptionProduct[];\n },\n default: () => Promise.reject(new Error('Unsupported Platform')),\n })();\n};\n\nexport async function endConnection(): Promise<boolean> {\n return ExpoIapModule.endConnection();\n}\n\nexport const getPurchaseHistory = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = false,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: async () => {\n return ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n );\n },\n android: async () => {\n const products = await ExpoIapModule.getPurchaseHistoryByType('inapp');\n const subscriptions =\n await ExpoIapModule.getPurchaseHistoryByType('subs');\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nexport const getAvailablePurchases = ({\n alsoPublishToEventListener = false,\n onlyIncludeActiveItems = true,\n}: {\n alsoPublishToEventListener?: boolean;\n onlyIncludeActiveItems?: boolean;\n} = {}): Promise<ProductPurchase[]> =>\n (\n Platform.select({\n ios: () =>\n ExpoIapModule.getAvailableItems(\n alsoPublishToEventListener,\n onlyIncludeActiveItems,\n ),\n android: async () => {\n const products = await ExpoIapModule.getAvailableItemsByType('inapp');\n const subscriptions =\n await ExpoIapModule.getAvailableItemsByType('subs');\n return products.concat(subscriptions);\n },\n }) || (() => Promise.resolve([]))\n )();\n\nconst offerToRecordIos = (\n offer: PaymentDiscount | undefined,\n): Record<keyof PaymentDiscount, string> | undefined => {\n if (!offer) return undefined;\n return {\n identifier: offer.identifier,\n keyIdentifier: offer.keyIdentifier,\n nonce: offer.nonce,\n signature: offer.signature,\n timestamp: offer.timestamp.toString(),\n };\n};\n\n// Define discriminated union with explicit type parameter\ntype PurchaseRequest =\n | {\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps;\n type?: 'inapp';\n }\n | {\n request: RequestSubscriptionAndroidProps | RequestSubscriptionIosProps;\n type: 'subs';\n };\n\n// Type guards for request objects\nconst isIosRequest = (\n request: any,\n): request is RequestPurchaseIosProps | RequestSubscriptionIosProps =>\n 'sku' in request && typeof request.sku === 'string';\n\nexport const requestPurchase = (\n requestObj: PurchaseRequest,\n): Promise<\n | ProductPurchase\n | SubscriptionPurchase\n | ProductPurchase[]\n | SubscriptionPurchase[]\n | void\n> => {\n const {request, type = 'inapp'} = requestObj;\n\n if (Platform.OS === 'ios') {\n if (!isIosRequest(request)) {\n throw new Error(\n 'Invalid request for iOS. The `sku` property is required and must be a string.',\n );\n }\n\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n\n return (async () => {\n const offer = offerToRecordIos(withOffer);\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n\n return type === 'inapp'\n ? (purchase as ProductPurchase)\n : (purchase as SubscriptionPurchase);\n })();\n }\n\n if (Platform.OS === 'android') {\n if (type === 'inapp') {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request as RequestPurchaseAndroidProps;\n\n return (async () => {\n return ExpoIapModule.buyItemByType({\n type: 'inapp',\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n }) as Promise<ProductPurchase[]>;\n })();\n }\n\n if (type === 'subs') {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n subscriptionOffers = [],\n replacementModeAndroid = -1,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n\n return (async () => {\n return ExpoIapModule.buyItemByType({\n type: 'subs',\n skuArr: skus,\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n }) as Promise<SubscriptionPurchase[]>;\n })();\n }\n\n throw new Error(\n \"Invalid request for Android: Expected a 'RequestPurchaseAndroidProps' object with a valid 'skus' array or a 'RequestSubscriptionAndroidProps' object with 'skus' and 'subscriptionOffers'.\",\n );\n }\n\n return Promise.resolve(); // Fallback for unsupported platforms\n};\n\n/**\n * @deprecated Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.\n */\nexport const requestSubscription = async (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> => {\n console.warn(\n \"`requestSubscription` is deprecated. Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.\",\n );\n return (await requestPurchase({request, type: 'subs'})) as\n | SubscriptionPurchase\n | SubscriptionPurchase[]\n | null\n | void;\n};\n\nexport const finishTransaction = ({\n purchase,\n isConsumable,\n}: {\n purchase: Purchase;\n isConsumable?: boolean;\n}): Promise<PurchaseResult | boolean> => {\n return (\n Platform.select({\n ios: async () => {\n const transactionId = purchase.transactionId;\n if (!transactionId) {\n return Promise.reject(\n new Error('transactionId required to finish iOS transaction'),\n );\n }\n await ExpoIapModule.finishTransaction(transactionId);\n return Promise.resolve(true);\n },\n android: async () => {\n const androidPurchase = purchase as ProductPurchaseAndroid;\n\n if (!('purchaseTokenAndroid' in androidPurchase)) {\n return Promise.reject(\n new Error('purchaseToken is required to finish transaction'),\n );\n }\n if (isConsumable) {\n return ExpoIapModule.consumeProduct(\n androidPurchase.purchaseTokenAndroid,\n );\n } else {\n return ExpoIapModule.acknowledgePurchase(\n androidPurchase.purchaseTokenAndroid,\n );\n }\n },\n }) || (() => Promise.reject(new Error('Unsupported Platform')))\n )();\n};\n\nexport * from './useIap';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAI7D,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAC,CAOnC;AAED;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,
|
|
1
|
+
{"version":3,"file":"android.d.ts","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAC,cAAc,EAAC,MAAM,+BAA+B,CAAC;AAI7D,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,SAAS,CAAA;CAAC,CAOnC;AAED;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,GAAU,UAElD;IACD,GAAG,EAAE,MAAM,CAAC;CACb,KAAG,OAAO,CAAC,IAAI,CAIf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,GAAU,+DAM1C;IACD,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,KAAG,OAAO,CAAC,cAAc,CAuBzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,GAAI,8BAGxC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,OAAO,CAAC,cAAc,GAAG,OAAO,GAAG,IAAI,CAE1C,CAAC"}
|
package/build/modules/ios.d.ts
CHANGED
|
@@ -4,7 +4,22 @@ export type TransactionEvent = {
|
|
|
4
4
|
transaction?: ProductPurchase;
|
|
5
5
|
error?: PurchaseError;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use `purchaseUpdatedListener` instead. This function will be removed in a future version.
|
|
9
|
+
*
|
|
10
|
+
* The `transactionUpdatedIos` function is redundant as it simply wraps `purchaseUpdatedListener`.
|
|
11
|
+
* You can achieve the same functionality by using `purchaseUpdatedListener` directly.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Instead of:
|
|
15
|
+
* // transactionUpdatedIos((event) => { ... });
|
|
16
|
+
*
|
|
17
|
+
* // Use:
|
|
18
|
+
* // purchaseUpdatedListener((purchase) => { ... });
|
|
19
|
+
*/
|
|
20
|
+
export declare const transactionUpdatedIos: (listener: (event: TransactionEvent) => void) => {
|
|
21
|
+
remove: () => void;
|
|
22
|
+
};
|
|
8
23
|
export declare function isProductIos<T extends {
|
|
9
24
|
platform?: string;
|
|
10
25
|
}>(item: unknown): item is T & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,eAAe,EACf,aAAa,EAGd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,2BAA2B,CAAC;AAGhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC;AAGF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,qBAAqB,GAChC,UAAU,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI;;CAsC5C,CAAC;AAGF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EACxD,IAAI,EAAE,OAAO,GACZ,IAAI,IAAI,CAAC,GAAG;IAAC,QAAQ,EAAE,KAAK,CAAA;CAAC,CAO/B;AAGD;;;GAGG;AACH,eAAO,MAAM,IAAI,QAAO,OAAO,CAAC,IAAI,CAAyB,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,uBAAuB,GAAI,SAAS,MAAM,KAAG,OAAO,CAAC,OAAO,CACzB,CAAC;AAEjD;;GAEG;AAEH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,gBAAgB,EAAE,CACpC,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,eAAe,CACjC,CAAC;AAExC;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,eAAe,CACjC,CAAC;AAEvC;;GAEG;AACH,KAAK,mBAAmB,GAAG,SAAS,GAAG,eAAe,CAAC;AACvD,eAAO,MAAM,kBAAkB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,mBAAmB,CACrC,CAAC;AAExC;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,QAAO,OAAO,CAAC,IAAI,CACd,CAAC;AAE1C;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,QAAO,OAAO,CAAC,MAAM,CAK9C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,OAAO,CAKlE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG,OAAO,CAAC,MAAM,CAK7D,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,kBAAkB,GAC7B,KAAK,MAAM,KACV,OAAO,CAAC;IACT,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,eAAe,CAAC;CACrC,CAOA,CAAC"}
|
package/build/modules/ios.js
CHANGED
|
@@ -1,12 +1,49 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import {
|
|
2
|
+
import { purchaseUpdatedListener } from '..';
|
|
3
3
|
import ExpoIapModule from '../ExpoIapModule';
|
|
4
4
|
// Listeners
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated Use `purchaseUpdatedListener` instead. This function will be removed in a future version.
|
|
7
|
+
*
|
|
8
|
+
* The `transactionUpdatedIos` function is redundant as it simply wraps `purchaseUpdatedListener`.
|
|
9
|
+
* You can achieve the same functionality by using `purchaseUpdatedListener` directly.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Instead of:
|
|
13
|
+
* // transactionUpdatedIos((event) => { ... });
|
|
14
|
+
*
|
|
15
|
+
* // Use:
|
|
16
|
+
* // purchaseUpdatedListener((purchase) => { ... });
|
|
17
|
+
*/
|
|
5
18
|
export const transactionUpdatedIos = (listener) => {
|
|
6
19
|
if (Platform.OS !== 'ios') {
|
|
7
20
|
throw new Error('This method is only available on iOS');
|
|
8
21
|
}
|
|
9
|
-
|
|
22
|
+
const isProductPurchase = (item) => {
|
|
23
|
+
return (item != null &&
|
|
24
|
+
typeof item === 'object' &&
|
|
25
|
+
'id' in item &&
|
|
26
|
+
'transactionId' in item &&
|
|
27
|
+
'platform' in item);
|
|
28
|
+
};
|
|
29
|
+
// Helper function to safely convert Purchase to TransactionEvent
|
|
30
|
+
const mapPurchaseToTransactionEvent = (purchase) => {
|
|
31
|
+
// Validate the purchase object before casting
|
|
32
|
+
if (isProductPurchase(purchase)) {
|
|
33
|
+
return {
|
|
34
|
+
transaction: purchase,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Fallback: create a basic TransactionEvent structure
|
|
38
|
+
return {
|
|
39
|
+
transaction: purchase,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
return purchaseUpdatedListener((purchase) => {
|
|
43
|
+
// Convert Purchase to TransactionEvent format for backward compatibility
|
|
44
|
+
const event = mapPurchaseToTransactionEvent(purchase);
|
|
45
|
+
listener(event);
|
|
46
|
+
});
|
|
10
47
|
};
|
|
11
48
|
// Type guards
|
|
12
49
|
export function isProductIos(item) {
|
package/build/modules/ios.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAAO,EAAC,uBAAuB,EAAC,MAAM,IAAI,CAAC;AAQ3C,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAO7C,YAAY;AACZ;;;;;;;;;;;;G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GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAmB,EAAE;IAChE,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,aAAa,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,GAAW,EAMV,EAAE;IACH,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import {Platform} from 'react-native';\nimport {purchaseUpdatedListener} from '..';\nimport {\n ProductPurchase,\n PurchaseError,\n Purchase,\n SubscriptionPurchase,\n} from '../ExpoIap.types';\nimport type {ProductStatusIos} from '../types/ExpoIapIos.types';\nimport ExpoIapModule from '../ExpoIapModule';\n\nexport type TransactionEvent = {\n transaction?: ProductPurchase;\n error?: PurchaseError;\n};\n\n// Listeners\n/**\n * @deprecated Use `purchaseUpdatedListener` instead. This function will be removed in a future version.\n *\n * The `transactionUpdatedIos` function is redundant as it simply wraps `purchaseUpdatedListener`.\n * You can achieve the same functionality by using `purchaseUpdatedListener` directly.\n *\n * @example\n * // Instead of:\n * // transactionUpdatedIos((event) => { ... });\n *\n * // Use:\n * // purchaseUpdatedListener((purchase) => { ... });\n */\nexport const transactionUpdatedIos = (\n listener: (event: TransactionEvent) => void,\n) => {\n if (Platform.OS !== 'ios') {\n throw new Error('This method is only available on iOS');\n }\n\n const isProductPurchase = (item: unknown): item is ProductPurchase => {\n return (\n item != null &&\n typeof item === 'object' &&\n 'id' in item &&\n 'transactionId' in item &&\n 'platform' in item\n );\n };\n\n // Helper function to safely convert Purchase to TransactionEvent\n const mapPurchaseToTransactionEvent = (\n purchase: Purchase | SubscriptionPurchase,\n ): TransactionEvent => {\n // Validate the purchase object before casting\n if (isProductPurchase(purchase)) {\n return {\n transaction: purchase as ProductPurchase,\n };\n }\n\n // Fallback: create a basic TransactionEvent structure\n return {\n transaction: purchase as ProductPurchase,\n };\n };\n\n return purchaseUpdatedListener((purchase) => {\n // Convert Purchase to TransactionEvent format for backward compatibility\n const event = mapPurchaseToTransactionEvent(purchase);\n listener(event);\n });\n};\n\n// Type guards\nexport function isProductIos<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'ios'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n item.platform === 'ios'\n );\n}\n\n// Functions\n/**\n * Sync state with Appstore (iOS only)\n * https://developer.apple.com/documentation/storekit/appstore/3791906-sync\n */\nexport const sync = (): Promise<null> => ExpoIapModule.sync();\n\n/**\n *\n */\nexport const isEligibleForIntroOffer = (groupID: string): Promise<boolean> =>\n ExpoIapModule.isEligibleForIntroOffer(groupID);\n\n/**\n *\n */\n\nexport const subscriptionStatus = (sku: string): Promise<ProductStatusIos[]> =>\n ExpoIapModule.subscriptionStatus(sku);\n\n/**\n *\n */\nexport const currentEntitlement = (sku: string): Promise<ProductPurchase> =>\n ExpoIapModule.currentEntitlement(sku);\n\n/**\n *\n */\nexport const latestTransaction = (sku: string): Promise<ProductPurchase> =>\n ExpoIapModule.latestTransaction(sku);\n\n/**\n *\n */\ntype RefundRequestStatus = 'success' | 'userCancelled';\nexport const beginRefundRequest = (sku: string): Promise<RefundRequestStatus> =>\n ExpoIapModule.beginRefundRequest(sku);\n\n/**\n * Shows the system UI for managing subscriptions.\n * When the user changes subscription renewal status, the system will emit events to\n * purchaseUpdatedListener and transactionUpdatedIos listeners.\n * @returns {Promise<null>}\n */\nexport const showManageSubscriptions = (): Promise<null> =>\n ExpoIapModule.showManageSubscriptions();\n\n/**\n * Get the receipt data from the iOS device.\n * This returns the base64 encoded receipt data which can be sent to your server\n * for verification with Apple's server.\n *\n * NOTE: For proper security, always verify receipts on your server using\n * Apple's verifyReceipt endpoint, not directly from the app.\n *\n * @returns {Promise<string>} Base64 encoded receipt data\n */\nexport const getReceiptIos = (): Promise<string> => {\n if (Platform.OS !== 'ios') {\n throw new Error('This method is only available on iOS');\n }\n return ExpoIapModule.getReceiptData();\n};\n\n/**\n * Check if a transaction is verified through StoreKit 2.\n * StoreKit 2 performs local verification of transaction JWS signatures.\n *\n * @param {string} sku The product's SKU (on iOS)\n * @returns {Promise<boolean>} True if the transaction is verified\n */\nexport const isTransactionVerified = (sku: string): Promise<boolean> => {\n if (Platform.OS !== 'ios') {\n throw new Error('This method is only available on iOS');\n }\n return ExpoIapModule.isTransactionVerified(sku);\n};\n\n/**\n * Get the JWS representation of a purchase for server-side verification.\n * The JWS (JSON Web Signature) can be verified on your server using Apple's public keys.\n *\n * @param {string} sku The product's SKU (on iOS)\n * @returns {Promise<string>} JWS representation of the transaction\n */\nexport const getTransactionJws = (sku: string): Promise<string> => {\n if (Platform.OS !== 'ios') {\n throw new Error('This method is only available on iOS');\n }\n return ExpoIapModule.getTransactionJws(sku);\n};\n\n/**\n * Validate receipt for iOS using StoreKit 2's built-in verification.\n * Returns receipt data and verification information to help with server-side validation.\n *\n * NOTE: For proper security, Apple recommends verifying receipts on your server using\n * the verifyReceipt endpoint rather than relying solely on client-side verification.\n *\n * @param {string} sku The product's SKU (on iOS)\n * @returns {Promise<{\n * isValid: boolean;\n * receiptData: string;\n * jwsRepresentation: string;\n * latestTransaction?: ProductPurchase;\n * }>}\n */\nexport const validateReceiptIos = async (\n sku: string,\n): Promise<{\n isValid: boolean;\n receiptData: string;\n jwsRepresentation: string;\n latestTransaction?: ProductPurchase;\n}> => {\n if (Platform.OS !== 'ios') {\n throw new Error('This method is only available on iOS');\n }\n\n const result = await ExpoIapModule.validateReceiptIos(sku);\n return result;\n};\n"]}
|
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,
|
|
1
|
+
{"version":3,"file":"useIap.d.ts","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"AAAA,OAAO,EAUL,eAAe,IAAI,uBAAuB,EAI3C,MAAM,IAAI,CAAC;AAEZ,OAAO,EACL,OAAO,EACP,eAAe,EACf,QAAQ,EACR,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAIzB,KAAK,MAAM,GAAG;IACZ,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,mBAAmB,EAAE,eAAe,EAAE,CAAC;IACvC,aAAa,EAAE,mBAAmB,EAAE,CAAC;IACrC,iBAAiB,EAAE,eAAe,EAAE,CAAC;IACrC,kBAAkB,EAAE,eAAe,EAAE,CAAC;IACtC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,oBAAoB,CAAC,EAAE,aAAa,CAAC;IACrC,oBAAoB,EAAE,MAAM,IAAI,CAAC;IACjC,yBAAyB,EAAE,MAAM,IAAI,CAAC;IACtC,iBAAiB,EAAE,CAAC,EAClB,QAAQ,EACR,YAAY,GACb,EAAE;QACD,QAAQ,EAAE,QAAQ,CAAC;QACnB,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,KAAK,OAAO,CAAC,MAAM,GAAG,OAAO,GAAG,cAAc,GAAG,IAAI,CAAC,CAAC;IACxD,qBAAqB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD,oBAAoB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,gBAAgB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,eAAe,EAAE,OAAO,uBAAuB,CAAC;IAChD,eAAe,EAAE,CACf,GAAG,EAAE,MAAM,EACX,cAAc,CAAC,EAAE;QACf,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;QACrB,WAAW,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,KACE,OAAO,CAAC,GAAG,CAAC,CAAC;IAClB,gBAAgB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,iBAAiB,CAAC,EAAE,CAClB,QAAQ,EAAE,eAAe,GAAG,oBAAoB,KAC7C,IAAI,CAAC;IACV,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACrC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,wBAAgB,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,MAAM,CA6StD"}
|
package/build/useIap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endConnection, initConnection, purchaseErrorListener, purchaseUpdatedListener,
|
|
1
|
+
import { endConnection, initConnection, purchaseErrorListener, purchaseUpdatedListener, getProducts, getAvailablePurchases, getPurchaseHistory, finishTransaction as finishTransactionInternal, getSubscriptions, requestPurchase as requestPurchaseInternal, sync, validateReceiptIos, validateReceiptAndroid, } from './';
|
|
2
2
|
import { useCallback, useEffect, useState, useRef } from 'react';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
4
|
export function useIAP(options) {
|
|
@@ -11,6 +11,17 @@ export function useIAP(options) {
|
|
|
11
11
|
const [currentPurchase, setCurrentPurchase] = useState();
|
|
12
12
|
const [currentPurchaseError, setCurrentPurchaseError] = useState();
|
|
13
13
|
const optionsRef = useRef(options);
|
|
14
|
+
// Helper function to merge arrays with duplicate checking
|
|
15
|
+
const mergeWithDuplicateCheck = useCallback((existingItems, newItems, getKey) => {
|
|
16
|
+
const merged = [...existingItems];
|
|
17
|
+
newItems.forEach((newItem) => {
|
|
18
|
+
const isDuplicate = merged.some((existingItem) => getKey(existingItem) === getKey(newItem));
|
|
19
|
+
if (!isDuplicate) {
|
|
20
|
+
merged.push(newItem);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return merged;
|
|
24
|
+
}, []);
|
|
14
25
|
useEffect(() => {
|
|
15
26
|
optionsRef.current = options;
|
|
16
27
|
}, [options]);
|
|
@@ -26,11 +37,13 @@ export function useIAP(options) {
|
|
|
26
37
|
setCurrentPurchaseError(undefined);
|
|
27
38
|
}, []);
|
|
28
39
|
const getProductsInternal = useCallback(async (skus) => {
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
const newProducts = await getProducts(skus);
|
|
41
|
+
setProducts((prevProducts) => mergeWithDuplicateCheck(prevProducts, newProducts, (product) => product.id));
|
|
42
|
+
}, [mergeWithDuplicateCheck]);
|
|
31
43
|
const getSubscriptionsInternal = useCallback(async (skus) => {
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
const newSubscriptions = await getSubscriptions(skus);
|
|
45
|
+
setSubscriptions((prevSubscriptions) => mergeWithDuplicateCheck(prevSubscriptions, newSubscriptions, (subscription) => subscription.id));
|
|
46
|
+
}, [mergeWithDuplicateCheck]);
|
|
34
47
|
const getAvailablePurchasesInternal = useCallback(async () => {
|
|
35
48
|
setAvailablePurchases(await getAvailablePurchases());
|
|
36
49
|
}, []);
|
|
@@ -145,17 +158,18 @@ export function useIAP(options) {
|
|
|
145
158
|
}
|
|
146
159
|
});
|
|
147
160
|
if (Platform.OS === 'ios') {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
// iOS promoted products are handled through regular purchase updates
|
|
162
|
+
subscriptionsRef.current.promotedProductsIos = purchaseUpdatedListener(async (purchase) => {
|
|
163
|
+
// Add to promoted products if it's a promoted transaction (avoid duplicates)
|
|
164
|
+
setPromotedProductsIOS((prevProducts) => mergeWithDuplicateCheck(prevProducts, [purchase], (product) => product.transactionId || product.id));
|
|
165
|
+
// Refresh subscription status if it's a subscription purchase
|
|
166
|
+
if ('expirationDateIos' in purchase) {
|
|
167
|
+
await refreshSubscriptionStatus(purchase.id);
|
|
154
168
|
}
|
|
155
169
|
});
|
|
156
170
|
}
|
|
157
171
|
}
|
|
158
|
-
}, [refreshSubscriptionStatus]);
|
|
172
|
+
}, [refreshSubscriptionStatus, mergeWithDuplicateCheck]);
|
|
159
173
|
useEffect(() => {
|
|
160
174
|
initIapWithSubscriptions();
|
|
161
175
|
const currentSubscriptions = subscriptionsRef.current;
|
package/build/useIap.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAC1C,IAAI,EACJ,kBAAkB,EAClB,sBAAsB,GACvB,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;AA8CtC,MAAM,UAAU,MAAM,CAAC,OAAuB;IAC5C,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAA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AAW,CAAC,EAAE,CAAC,CAAC;oBACxD,CAAC;gBACH,CAAC,CACF,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAEhC,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,oBAAoB;QACpB,yBAAyB;QACzB,qBAAqB,EAAE,6BAA6B;QACpD,oBAAoB,EAAE,4BAA4B;QAClD,WAAW,EAAE,mBAAmB;QAChC,gBAAgB,EAAE,wBAAwB;QAC1C,eAAe,EAAE,wBAAwB;QACzC,eAAe;QACf,gBAAgB;KACjB,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 sync,\n validateReceiptIos,\n validateReceiptAndroid,\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 clearCurrentPurchase: () => void;\n clearCurrentPurchaseError: () => void;\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 validateReceipt: (\n sku: string,\n androidOptions?: {\n packageName: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n },\n ) => Promise<any>;\n restorePurchases: () => Promise<void>; // 구매 복원 함수 추가\n};\n\nexport interface UseIAPOptions {\n onPurchaseSuccess?: (\n purchase: ProductPurchase | SubscriptionPurchase,\n ) => void;\n onPurchaseError?: (error: PurchaseError) => void;\n onSyncError?: (error: Error) => void;\n shouldAutoSyncPurchases?: boolean; // New option to control auto-syncing\n}\n\nexport function useIAP(options?: UseIAPOptions): 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 optionsRef = useRef<UseIAPOptions | undefined>(options);\n\n useEffect(() => {\n optionsRef.current = options;\n }, [options]);\n\n const subscriptionsRef = useRef<{\n purchaseUpdate?: Subscription;\n purchaseError?: Subscription;\n promotedProductsIos?: Subscription;\n }>({});\n\n const subscriptionsRefState = useRef<SubscriptionProduct[]>([]);\n\n useEffect(() => {\n subscriptionsRefState.current = subscriptions;\n }, [subscriptions]);\n\n const clearCurrentPurchase = useCallback(() => {\n setCurrentPurchase(undefined);\n }, []);\n\n const clearCurrentPurchaseError = useCallback(() => {\n setCurrentPurchaseError(undefined);\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 clearCurrentPurchase();\n }\n if (purchase.id === currentPurchaseError?.productId) {\n clearCurrentPurchaseError();\n }\n }\n },\n [\n currentPurchase?.id,\n currentPurchaseError?.productId,\n clearCurrentPurchase,\n clearCurrentPurchaseError,\n ],\n );\n\n const requestPurchaseWithReset = useCallback(\n async (requestObj: Parameters<typeof requestPurchaseInternal>[0]) => {\n clearCurrentPurchase();\n clearCurrentPurchaseError();\n\n try {\n return await requestPurchaseInternal(requestObj);\n } catch (error) {\n throw error;\n }\n },\n [clearCurrentPurchase, clearCurrentPurchaseError],\n );\n\n const refreshSubscriptionStatus = useCallback(\n async (productId: string) => {\n try {\n if (subscriptionsRefState.current.some((sub) => sub.id === productId)) {\n await getSubscriptionsInternal([productId]);\n await getAvailablePurchasesInternal();\n }\n } catch (error) {\n console.warn('Failed to refresh subscription status:', error);\n }\n },\n [getAvailablePurchasesInternal, getSubscriptionsInternal],\n );\n\n const restorePurchases = useCallback(async (): Promise<void> => {\n try {\n if (Platform.OS === 'ios') {\n await sync().catch((error) => {\n if (optionsRef.current?.onSyncError) {\n optionsRef.current.onSyncError(error);\n } else {\n console.warn('Error restoring purchases:', error);\n }\n });\n }\n await getAvailablePurchasesInternal();\n } catch (error) {\n console.warn('Failed to restore purchases:', error);\n }\n }, [getAvailablePurchasesInternal]);\n\n const validateReceipt = useCallback(\n async (\n sku: string,\n androidOptions?: {\n packageName: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n },\n ) => {\n if (Platform.OS === 'ios') {\n return await validateReceiptIos(sku);\n } else if (Platform.OS === 'android') {\n if (\n !androidOptions ||\n !androidOptions.packageName ||\n !androidOptions.productToken ||\n !androidOptions.accessToken\n ) {\n throw new Error(\n 'Android validation requires packageName, productToken, and accessToken',\n );\n }\n return await validateReceiptAndroid({\n packageName: androidOptions.packageName,\n productId: sku,\n productToken: androidOptions.productToken,\n accessToken: androidOptions.accessToken,\n isSub: androidOptions.isSub,\n });\n } else {\n throw new Error('Platform not supported');\n }\n },\n [],\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 if ('expirationDateIos' in purchase) {\n await refreshSubscriptionStatus(purchase.id);\n }\n\n if (optionsRef.current?.onPurchaseSuccess) {\n optionsRef.current.onPurchaseSuccess(purchase);\n }\n },\n );\n\n subscriptionsRef.current.purchaseError = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n\n if (optionsRef.current?.onPurchaseError) {\n optionsRef.current.onPurchaseError(error);\n }\n },\n );\n\n if (Platform.OS === 'ios') {\n subscriptionsRef.current.promotedProductsIos = transactionUpdatedIos(\n async (event: TransactionEvent) => {\n setPromotedProductsIOS((prevProducts) =>\n event.transaction\n ? [...prevProducts, event.transaction]\n : prevProducts,\n );\n\n if (event.transaction && 'expirationDateIos' in event.transaction) {\n await refreshSubscriptionStatus(event.transaction.id);\n }\n },\n );\n }\n }\n }, [refreshSubscriptionStatus]);\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 clearCurrentPurchase,\n clearCurrentPurchaseError,\n getAvailablePurchases: getAvailablePurchasesInternal,\n getPurchaseHistories: getPurchaseHistoriesInternal,\n getProducts: getProductsInternal,\n getSubscriptions: getSubscriptionsInternal,\n requestPurchase: requestPurchaseWithReset,\n validateReceipt,\n restorePurchases,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useIap.js","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,IAAI,yBAAyB,EAC9C,gBAAgB,EAChB,eAAe,IAAI,uBAAuB,EAC1C,IAAI,EACJ,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,IAAI,CAAC;AACZ,OA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yBAAyB,EAAE,uBAAuB,CAAC,CAAC,CAAC;IAEzD,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,oBAAoB;QACpB,yBAAyB;QACzB,qBAAqB,EAAE,6BAA6B;QACpD,oBAAoB,EAAE,4BAA4B;QAClD,WAAW,EAAE,mBAAmB;QAChC,gBAAgB,EAAE,wBAAwB;QAC1C,eAAe,EAAE,wBAAwB;QACzC,eAAe;QACf,gBAAgB;KACjB,CAAC;AACJ,CAAC","sourcesContent":["import {\n endConnection,\n initConnection,\n purchaseErrorListener,\n purchaseUpdatedListener,\n getProducts,\n getAvailablePurchases,\n getPurchaseHistory,\n finishTransaction as finishTransactionInternal,\n getSubscriptions,\n requestPurchase as requestPurchaseInternal,\n sync,\n validateReceiptIos,\n validateReceiptAndroid,\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 {EventSubscription} 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 clearCurrentPurchase: () => void;\n clearCurrentPurchaseError: () => void;\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 validateReceipt: (\n sku: string,\n androidOptions?: {\n packageName: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n },\n ) => Promise<any>;\n restorePurchases: () => Promise<void>; // 구매 복원 함수 추가\n};\n\nexport interface UseIAPOptions {\n onPurchaseSuccess?: (\n purchase: ProductPurchase | SubscriptionPurchase,\n ) => void;\n onPurchaseError?: (error: PurchaseError) => void;\n onSyncError?: (error: Error) => void;\n shouldAutoSyncPurchases?: boolean; // New option to control auto-syncing\n}\n\nexport function useIAP(options?: UseIAPOptions): 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 optionsRef = useRef<UseIAPOptions | undefined>(options);\n\n // Helper function to merge arrays with duplicate checking\n const mergeWithDuplicateCheck = useCallback(\n <T>(\n existingItems: T[],\n newItems: T[],\n getKey: (item: T) => string,\n ): T[] => {\n const merged = [...existingItems];\n newItems.forEach((newItem) => {\n const isDuplicate = merged.some(\n (existingItem) => getKey(existingItem) === getKey(newItem),\n );\n if (!isDuplicate) {\n merged.push(newItem);\n }\n });\n return merged;\n },\n [],\n );\n\n useEffect(() => {\n optionsRef.current = options;\n }, [options]);\n\n const subscriptionsRef = useRef<{\n purchaseUpdate?: EventSubscription;\n purchaseError?: EventSubscription;\n promotedProductsIos?: EventSubscription;\n }>({});\n\n const subscriptionsRefState = useRef<SubscriptionProduct[]>([]);\n\n useEffect(() => {\n subscriptionsRefState.current = subscriptions;\n }, [subscriptions]);\n\n const clearCurrentPurchase = useCallback(() => {\n setCurrentPurchase(undefined);\n }, []);\n\n const clearCurrentPurchaseError = useCallback(() => {\n setCurrentPurchaseError(undefined);\n }, []);\n\n const getProductsInternal = useCallback(\n async (skus: string[]): Promise<void> => {\n const newProducts = await getProducts(skus);\n setProducts((prevProducts) =>\n mergeWithDuplicateCheck(\n prevProducts,\n newProducts,\n (product) => product.id,\n ),\n );\n },\n [mergeWithDuplicateCheck],\n );\n\n const getSubscriptionsInternal = useCallback(\n async (skus: string[]): Promise<void> => {\n const newSubscriptions = await getSubscriptions(skus);\n setSubscriptions((prevSubscriptions) =>\n mergeWithDuplicateCheck(\n prevSubscriptions,\n newSubscriptions,\n (subscription) => subscription.id,\n ),\n );\n },\n [mergeWithDuplicateCheck],\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 clearCurrentPurchase();\n }\n if (purchase.id === currentPurchaseError?.productId) {\n clearCurrentPurchaseError();\n }\n }\n },\n [\n currentPurchase?.id,\n currentPurchaseError?.productId,\n clearCurrentPurchase,\n clearCurrentPurchaseError,\n ],\n );\n\n const requestPurchaseWithReset = useCallback(\n async (requestObj: Parameters<typeof requestPurchaseInternal>[0]) => {\n clearCurrentPurchase();\n clearCurrentPurchaseError();\n\n try {\n return await requestPurchaseInternal(requestObj);\n } catch (error) {\n throw error;\n }\n },\n [clearCurrentPurchase, clearCurrentPurchaseError],\n );\n\n const refreshSubscriptionStatus = useCallback(\n async (productId: string) => {\n try {\n if (subscriptionsRefState.current.some((sub) => sub.id === productId)) {\n await getSubscriptionsInternal([productId]);\n await getAvailablePurchasesInternal();\n }\n } catch (error) {\n console.warn('Failed to refresh subscription status:', error);\n }\n },\n [getAvailablePurchasesInternal, getSubscriptionsInternal],\n );\n\n const restorePurchases = useCallback(async (): Promise<void> => {\n try {\n if (Platform.OS === 'ios') {\n await sync().catch((error) => {\n if (optionsRef.current?.onSyncError) {\n optionsRef.current.onSyncError(error);\n } else {\n console.warn('Error restoring purchases:', error);\n }\n });\n }\n await getAvailablePurchasesInternal();\n } catch (error) {\n console.warn('Failed to restore purchases:', error);\n }\n }, [getAvailablePurchasesInternal]);\n\n const validateReceipt = useCallback(\n async (\n sku: string,\n androidOptions?: {\n packageName: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n },\n ) => {\n if (Platform.OS === 'ios') {\n return await validateReceiptIos(sku);\n } else if (Platform.OS === 'android') {\n if (\n !androidOptions ||\n !androidOptions.packageName ||\n !androidOptions.productToken ||\n !androidOptions.accessToken\n ) {\n throw new Error(\n 'Android validation requires packageName, productToken, and accessToken',\n );\n }\n return await validateReceiptAndroid({\n packageName: androidOptions.packageName,\n productId: sku,\n productToken: androidOptions.productToken,\n accessToken: androidOptions.accessToken,\n isSub: androidOptions.isSub,\n });\n } else {\n throw new Error('Platform not supported');\n }\n },\n [],\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 if ('expirationDateIos' in purchase) {\n await refreshSubscriptionStatus(purchase.id);\n }\n\n if (optionsRef.current?.onPurchaseSuccess) {\n optionsRef.current.onPurchaseSuccess(purchase);\n }\n },\n );\n\n subscriptionsRef.current.purchaseError = purchaseErrorListener(\n (error: PurchaseError) => {\n setCurrentPurchase(undefined);\n setCurrentPurchaseError(error);\n\n if (optionsRef.current?.onPurchaseError) {\n optionsRef.current.onPurchaseError(error);\n }\n },\n );\n\n if (Platform.OS === 'ios') {\n // iOS promoted products are handled through regular purchase updates\n subscriptionsRef.current.promotedProductsIos = purchaseUpdatedListener(\n async (purchase: Purchase | SubscriptionPurchase) => {\n // Add to promoted products if it's a promoted transaction (avoid duplicates)\n setPromotedProductsIOS((prevProducts) =>\n mergeWithDuplicateCheck(\n prevProducts,\n [purchase as ProductPurchase],\n (product) => product.transactionId || product.id,\n ),\n );\n\n // Refresh subscription status if it's a subscription purchase\n if ('expirationDateIos' in purchase) {\n await refreshSubscriptionStatus(purchase.id);\n }\n },\n );\n }\n }\n }, [refreshSubscriptionStatus, mergeWithDuplicateCheck]);\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 clearCurrentPurchase,\n clearCurrentPurchaseError,\n getAvailablePurchases: getAvailablePurchasesInternal,\n getPurchaseHistories: getPurchaseHistoriesInternal,\n getProducts: getProductsInternal,\n getSubscriptions: getSubscriptionsInternal,\n requestPurchase: requestPurchaseWithReset,\n validateReceipt,\n restorePurchases,\n };\n}\n"]}
|
package/bun.lockb
CHANGED
|
Binary file
|
package/ios/ExpoIapModule.swift
CHANGED
|
@@ -18,7 +18,6 @@ func logDebug(_ message: String) {
|
|
|
18
18
|
struct IapEvent {
|
|
19
19
|
static let PurchaseUpdated = "purchase-updated"
|
|
20
20
|
static let PurchaseError = "purchase-error"
|
|
21
|
-
static let TransactionIapUpdated = "iap-transaction-updated"
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
@available(iOS 15.0, *)
|
|
@@ -191,7 +190,7 @@ public class ExpoIapModule: Module {
|
|
|
191
190
|
"PI": Double.pi
|
|
192
191
|
])
|
|
193
192
|
|
|
194
|
-
Events(IapEvent.PurchaseUpdated, IapEvent.PurchaseError
|
|
193
|
+
Events(IapEvent.PurchaseUpdated, IapEvent.PurchaseError)
|
|
195
194
|
|
|
196
195
|
OnStartObserving {
|
|
197
196
|
self.hasListeners = true
|
|
@@ -774,7 +773,6 @@ public class ExpoIapModule: Module {
|
|
|
774
773
|
if self.hasListeners {
|
|
775
774
|
let serialized = serializeTransaction(transaction, jwsRepresentationIos: result.jwsRepresentation)
|
|
776
775
|
self.sendEvent(IapEvent.PurchaseUpdated, serialized)
|
|
777
|
-
self.sendEvent(IapEvent.TransactionIapUpdated, ["transaction": serialized])
|
|
778
776
|
}
|
|
779
777
|
} catch {
|
|
780
778
|
if self.hasListeners {
|
|
@@ -785,7 +783,6 @@ public class ExpoIapModule: Module {
|
|
|
785
783
|
"message": error.localizedDescription,
|
|
786
784
|
]
|
|
787
785
|
self.sendEvent(IapEvent.PurchaseError, err)
|
|
788
|
-
self.sendEvent(IapEvent.TransactionIapUpdated, ["error": err])
|
|
789
786
|
}
|
|
790
787
|
}
|
|
791
788
|
}
|
|
@@ -885,7 +882,6 @@ public class ExpoIapModule: Module {
|
|
|
885
882
|
}
|
|
886
883
|
|
|
887
884
|
self.sendEvent(IapEvent.PurchaseUpdated, purchaseMap)
|
|
888
|
-
self.sendEvent(IapEvent.TransactionIapUpdated, ["transaction": purchaseMap])
|
|
889
885
|
previousStatuses[sku] = currentWillAutoRenew
|
|
890
886
|
}
|
|
891
887
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-iap",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"description": "In App Purchase module in Expo",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"homepage": "https://github.com/hyochan#readme",
|
|
38
38
|
"dependencies": {},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/react": "~
|
|
40
|
+
"@types/react": "~19.1.7",
|
|
41
41
|
"eslint": "8.57.0",
|
|
42
|
-
"eslint-config-expo": "^
|
|
43
|
-
"eslint-config-prettier": "^
|
|
44
|
-
"eslint-plugin-prettier": "^5.1
|
|
45
|
-
"expo-module-scripts": "^
|
|
46
|
-
"expo-modules-core": "~
|
|
42
|
+
"eslint-config-expo": "^9.2.0",
|
|
43
|
+
"eslint-config-prettier": "^10.1.5",
|
|
44
|
+
"eslint-plugin-prettier": "^5.4.1",
|
|
45
|
+
"expo-module-scripts": "^4.1.7",
|
|
46
|
+
"expo-modules-core": "~2.4.0"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"expo": "*",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["./src/withIAP.ts"],"version":"5.8.3"}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Import the native module. On web, it will be resolved to ExpoIap.web.ts
|
|
2
2
|
// and on native platforms to ExpoIap.ts
|
|
3
|
-
import {NativeModulesProxy
|
|
3
|
+
import {NativeModulesProxy} from 'expo-modules-core';
|
|
4
4
|
import {Platform} from 'react-native';
|
|
5
5
|
import {
|
|
6
6
|
Product,
|
|
@@ -35,6 +35,7 @@ export const PI = ExpoIapModule.PI;
|
|
|
35
35
|
export enum IapEvent {
|
|
36
36
|
PurchaseUpdated = 'purchase-updated',
|
|
37
37
|
PurchaseError = 'purchase-error',
|
|
38
|
+
/** @deprecated Use PurchaseUpdated instead. This will be removed in a future version. */
|
|
38
39
|
TransactionIapUpdated = 'iap-transaction-updated',
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -42,9 +43,17 @@ export function setValueAsync(value: string) {
|
|
|
42
43
|
return ExpoIapModule.setValueAsync(value);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
// Ensure the emitter has proper EventEmitter interface
|
|
47
|
+
export const emitter = (ExpoIapModule || NativeModulesProxy.ExpoIap) as {
|
|
48
|
+
addListener: (
|
|
49
|
+
eventName: string,
|
|
50
|
+
listener: (...args: any[]) => void,
|
|
51
|
+
) => {remove: () => void};
|
|
52
|
+
removeListener: (
|
|
53
|
+
eventName: string,
|
|
54
|
+
listener: (...args: any[]) => void,
|
|
55
|
+
) => void;
|
|
56
|
+
};
|
|
48
57
|
|
|
49
58
|
export const purchaseUpdatedListener = (
|
|
50
59
|
listener: (event: Purchase) => void,
|
|
@@ -59,7 +68,7 @@ export const purchaseUpdatedListener = (
|
|
|
59
68
|
export const purchaseErrorListener = (
|
|
60
69
|
listener: (error: PurchaseError) => void,
|
|
61
70
|
) => {
|
|
62
|
-
return emitter.addListener
|
|
71
|
+
return emitter.addListener(IapEvent.PurchaseError, listener);
|
|
63
72
|
};
|
|
64
73
|
|
|
65
74
|
export function initConnection() {
|
package/src/modules/ios.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import {Platform} from 'react-native';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import {purchaseUpdatedListener} from '..';
|
|
3
|
+
import {
|
|
4
|
+
ProductPurchase,
|
|
5
|
+
PurchaseError,
|
|
6
|
+
Purchase,
|
|
7
|
+
SubscriptionPurchase,
|
|
8
|
+
} from '../ExpoIap.types';
|
|
4
9
|
import type {ProductStatusIos} from '../types/ExpoIapIos.types';
|
|
5
10
|
import ExpoIapModule from '../ExpoIapModule';
|
|
6
11
|
|
|
@@ -10,6 +15,19 @@ export type TransactionEvent = {
|
|
|
10
15
|
};
|
|
11
16
|
|
|
12
17
|
// Listeners
|
|
18
|
+
/**
|
|
19
|
+
* @deprecated Use `purchaseUpdatedListener` instead. This function will be removed in a future version.
|
|
20
|
+
*
|
|
21
|
+
* The `transactionUpdatedIos` function is redundant as it simply wraps `purchaseUpdatedListener`.
|
|
22
|
+
* You can achieve the same functionality by using `purchaseUpdatedListener` directly.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Instead of:
|
|
26
|
+
* // transactionUpdatedIos((event) => { ... });
|
|
27
|
+
*
|
|
28
|
+
* // Use:
|
|
29
|
+
* // purchaseUpdatedListener((purchase) => { ... });
|
|
30
|
+
*/
|
|
13
31
|
export const transactionUpdatedIos = (
|
|
14
32
|
listener: (event: TransactionEvent) => void,
|
|
15
33
|
) => {
|
|
@@ -17,7 +35,38 @@ export const transactionUpdatedIos = (
|
|
|
17
35
|
throw new Error('This method is only available on iOS');
|
|
18
36
|
}
|
|
19
37
|
|
|
20
|
-
|
|
38
|
+
const isProductPurchase = (item: unknown): item is ProductPurchase => {
|
|
39
|
+
return (
|
|
40
|
+
item != null &&
|
|
41
|
+
typeof item === 'object' &&
|
|
42
|
+
'id' in item &&
|
|
43
|
+
'transactionId' in item &&
|
|
44
|
+
'platform' in item
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Helper function to safely convert Purchase to TransactionEvent
|
|
49
|
+
const mapPurchaseToTransactionEvent = (
|
|
50
|
+
purchase: Purchase | SubscriptionPurchase,
|
|
51
|
+
): TransactionEvent => {
|
|
52
|
+
// Validate the purchase object before casting
|
|
53
|
+
if (isProductPurchase(purchase)) {
|
|
54
|
+
return {
|
|
55
|
+
transaction: purchase as ProductPurchase,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Fallback: create a basic TransactionEvent structure
|
|
60
|
+
return {
|
|
61
|
+
transaction: purchase as ProductPurchase,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return purchaseUpdatedListener((purchase) => {
|
|
66
|
+
// Convert Purchase to TransactionEvent format for backward compatibility
|
|
67
|
+
const event = mapPurchaseToTransactionEvent(purchase);
|
|
68
|
+
listener(event);
|
|
69
|
+
});
|
|
21
70
|
};
|
|
22
71
|
|
|
23
72
|
// Type guards
|
package/src/useIap.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
initConnection,
|
|
4
4
|
purchaseErrorListener,
|
|
5
5
|
purchaseUpdatedListener,
|
|
6
|
-
transactionUpdatedIos,
|
|
7
6
|
getProducts,
|
|
8
7
|
getAvailablePurchases,
|
|
9
8
|
getPurchaseHistory,
|
|
@@ -24,8 +23,7 @@ import {
|
|
|
24
23
|
SubscriptionProduct,
|
|
25
24
|
SubscriptionPurchase,
|
|
26
25
|
} from './ExpoIap.types';
|
|
27
|
-
import {
|
|
28
|
-
import {Subscription} from 'expo-modules-core';
|
|
26
|
+
import {EventSubscription} from 'expo-modules-core';
|
|
29
27
|
import {Platform} from 'react-native';
|
|
30
28
|
|
|
31
29
|
type UseIap = {
|
|
@@ -91,14 +89,35 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
91
89
|
|
|
92
90
|
const optionsRef = useRef<UseIAPOptions | undefined>(options);
|
|
93
91
|
|
|
92
|
+
// Helper function to merge arrays with duplicate checking
|
|
93
|
+
const mergeWithDuplicateCheck = useCallback(
|
|
94
|
+
<T>(
|
|
95
|
+
existingItems: T[],
|
|
96
|
+
newItems: T[],
|
|
97
|
+
getKey: (item: T) => string,
|
|
98
|
+
): T[] => {
|
|
99
|
+
const merged = [...existingItems];
|
|
100
|
+
newItems.forEach((newItem) => {
|
|
101
|
+
const isDuplicate = merged.some(
|
|
102
|
+
(existingItem) => getKey(existingItem) === getKey(newItem),
|
|
103
|
+
);
|
|
104
|
+
if (!isDuplicate) {
|
|
105
|
+
merged.push(newItem);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return merged;
|
|
109
|
+
},
|
|
110
|
+
[],
|
|
111
|
+
);
|
|
112
|
+
|
|
94
113
|
useEffect(() => {
|
|
95
114
|
optionsRef.current = options;
|
|
96
115
|
}, [options]);
|
|
97
116
|
|
|
98
117
|
const subscriptionsRef = useRef<{
|
|
99
|
-
purchaseUpdate?:
|
|
100
|
-
purchaseError?:
|
|
101
|
-
promotedProductsIos?:
|
|
118
|
+
purchaseUpdate?: EventSubscription;
|
|
119
|
+
purchaseError?: EventSubscription;
|
|
120
|
+
promotedProductsIos?: EventSubscription;
|
|
102
121
|
}>({});
|
|
103
122
|
|
|
104
123
|
const subscriptionsRefState = useRef<SubscriptionProduct[]>([]);
|
|
@@ -117,16 +136,30 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
117
136
|
|
|
118
137
|
const getProductsInternal = useCallback(
|
|
119
138
|
async (skus: string[]): Promise<void> => {
|
|
120
|
-
|
|
139
|
+
const newProducts = await getProducts(skus);
|
|
140
|
+
setProducts((prevProducts) =>
|
|
141
|
+
mergeWithDuplicateCheck(
|
|
142
|
+
prevProducts,
|
|
143
|
+
newProducts,
|
|
144
|
+
(product) => product.id,
|
|
145
|
+
),
|
|
146
|
+
);
|
|
121
147
|
},
|
|
122
|
-
[],
|
|
148
|
+
[mergeWithDuplicateCheck],
|
|
123
149
|
);
|
|
124
150
|
|
|
125
151
|
const getSubscriptionsInternal = useCallback(
|
|
126
152
|
async (skus: string[]): Promise<void> => {
|
|
127
|
-
|
|
153
|
+
const newSubscriptions = await getSubscriptions(skus);
|
|
154
|
+
setSubscriptions((prevSubscriptions) =>
|
|
155
|
+
mergeWithDuplicateCheck(
|
|
156
|
+
prevSubscriptions,
|
|
157
|
+
newSubscriptions,
|
|
158
|
+
(subscription) => subscription.id,
|
|
159
|
+
),
|
|
160
|
+
);
|
|
128
161
|
},
|
|
129
|
-
[],
|
|
162
|
+
[mergeWithDuplicateCheck],
|
|
130
163
|
);
|
|
131
164
|
|
|
132
165
|
const getAvailablePurchasesInternal = useCallback(async (): Promise<void> => {
|
|
@@ -283,22 +316,27 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
283
316
|
);
|
|
284
317
|
|
|
285
318
|
if (Platform.OS === 'ios') {
|
|
286
|
-
|
|
287
|
-
|
|
319
|
+
// iOS promoted products are handled through regular purchase updates
|
|
320
|
+
subscriptionsRef.current.promotedProductsIos = purchaseUpdatedListener(
|
|
321
|
+
async (purchase: Purchase | SubscriptionPurchase) => {
|
|
322
|
+
// Add to promoted products if it's a promoted transaction (avoid duplicates)
|
|
288
323
|
setPromotedProductsIOS((prevProducts) =>
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
324
|
+
mergeWithDuplicateCheck(
|
|
325
|
+
prevProducts,
|
|
326
|
+
[purchase as ProductPurchase],
|
|
327
|
+
(product) => product.transactionId || product.id,
|
|
328
|
+
),
|
|
292
329
|
);
|
|
293
330
|
|
|
294
|
-
|
|
295
|
-
|
|
331
|
+
// Refresh subscription status if it's a subscription purchase
|
|
332
|
+
if ('expirationDateIos' in purchase) {
|
|
333
|
+
await refreshSubscriptionStatus(purchase.id);
|
|
296
334
|
}
|
|
297
335
|
},
|
|
298
336
|
);
|
|
299
337
|
}
|
|
300
338
|
}
|
|
301
|
-
}, [refreshSubscriptionStatus]);
|
|
339
|
+
}, [refreshSubscriptionStatus, mergeWithDuplicateCheck]);
|
|
302
340
|
|
|
303
341
|
useEffect(() => {
|
|
304
342
|
initIapWithSubscriptions();
|
package/tsconfig.json
CHANGED