expo-iap 2.2.7 → 2.2.8-rc.1
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 +1 -4
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js +0 -5
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +13 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +72 -60
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts +0 -5
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +0 -3
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +0 -5
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +0 -3
- package/build/modules/ios.js.map +1 -1
- package/build/useIap.d.ts +4 -2
- package/build/useIap.d.ts.map +1 -1
- package/build/useIap.js +10 -10
- package/build/useIap.js.map +1 -1
- package/iap.md +145 -161
- package/package.json +1 -1
- package/src/ExpoIap.types.ts +1 -5
- package/src/index.ts +139 -111
- package/src/modules/android.ts +0 -6
- package/src/modules/ios.ts +0 -6
- package/src/useIap.ts +18 -13
package/build/ExpoIap.types.d.ts
CHANGED
|
@@ -22,10 +22,7 @@ export type IosPlatform = {
|
|
|
22
22
|
export type AndroidPlatform = {
|
|
23
23
|
platform: 'android';
|
|
24
24
|
};
|
|
25
|
-
export
|
|
26
|
-
InAppPurchase = "inapp",
|
|
27
|
-
Subscription = "subs"
|
|
28
|
-
}
|
|
25
|
+
export type ProductType = 'inapp' | 'subs';
|
|
29
26
|
export type PurchaseBase = {
|
|
30
27
|
id: string;
|
|
31
28
|
transactionId?: string;
|
|
@@ -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,0BAA0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ACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,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;IACb,YAAY,CAAC;IACb,IAAI,CAAC;IACL,SAAS,CAAC;gBALV,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,YAAY,CAAC,oBAAQ,EACrB,YAAY,CAAC,oBAAQ,EACrB,IAAI,CAAC,uBAAW,EAChB,SAAS,CAAC,oBAAQ;CAS5B"}
|
package/build/ExpoIap.types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ExpoIap.types.js","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAmFA,MAAM,CAAN,IAAY,SAkBX;AAlBD,WAAY,SAAS;IACnB,oCAAuB,CAAA;IACvB,kDAAqC,CAAA;IACrC,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA;IACzC,8CAAiC,CAAA;IACjC,gDAAmC,CAAA;IACnC,gDAAmC,CAAA;IACnC,kDAAqC,CAAA;IACrC,oEAAuD,CAAA;IACvD,8CAAiC,CAAA;IACjC,wCAA2B,CAAA;IAC3B,gDAAmC,CAAA;IACnC,oDAAuC,CAAA;IACvC,wFAA2E,CAAA;IAC3E,sDAAyC,CAAA;IACzC,4CAA+B,CAAA;IAC/B,wDAA2C,CAAA;AAC7C,CAAC,EAlBW,SAAS,KAAT,SAAS,QAkBpB;AAED,MAAM,OAAO,aAAa;IAEf;IACA;IACA;IACA;IACA;IACA;IANT,YACS,IAAY,EACZ,OAAe,EACf,YAAqB,EACrB,YAAqB,EACrB,IAAgB,EAChB,SAAkB;QALlB,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,OAAO,CAAQ;QACf,iBAAY,GAAZ,YAAY,CAAS;QACrB,iBAAY,GAAZ,YAAY,CAAS;QACrB,SAAI,GAAJ,IAAI,CAAY;QAChB,cAAS,GAAT,SAAS,CAAS;QAEzB,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF","sourcesContent":["import {\n ProductAndroid,\n ProductPurchaseAndroid,\n RequestPurchaseAndroidProps,\n RequestSubscriptionAndroidProps,\n SubscriptionProductAndroid,\n} from './types/ExpoIapAndroid.types';\nimport {\n ProductIos,\n ProductPurchaseIos,\n RequestPurchaseIosProps,\n RequestSubscriptionIosProps,\n SubscriptionProductIos,\n} from './types/ExpoIapIos.types';\n\nexport type ChangeEventPayload = {\n value: string;\n};\n\n/**\n * Base product type with common properties shared between iOS and Android\n */\nexport type ProductBase = {\n id: string;\n title: string;\n description: string;\n type: ProductType;\n displayName?: string;\n displayPrice: string;\n currency: string;\n price?: number;\n};\n\n// Define literal platform types for better type discrimination\nexport type IosPlatform = {platform: 'ios'};\nexport type AndroidPlatform = {platform: 'android'};\nexport type ProductType = 'inapp' | 'subs';\n\n// Common base purchase type\nexport type PurchaseBase = {\n id: string;\n transactionId?: string;\n transactionDate: number;\n transactionReceipt: string;\n};\n\n// Union type for platform-specific product types with proper discriminators\nexport type Product =\n | (ProductAndroid & AndroidPlatform)\n | (ProductIos & IosPlatform);\n\n// Union type for platform-specific purchase types with proper discriminators\nexport type ProductPurchase =\n | (ProductPurchaseAndroid & AndroidPlatform)\n | (ProductPurchaseIos & IosPlatform);\n\n// Union type for platform-specific subscription purchase types with proper discriminators\nexport type SubscriptionPurchase =\n | (ProductPurchaseAndroid & AndroidPlatform & {autoRenewingAndroid: boolean})\n | (ProductPurchaseIos & IosPlatform);\n\nexport type Purchase = ProductPurchase | SubscriptionPurchase;\n\nexport type RequestPurchaseProps =\n | RequestPurchaseIosProps\n | RequestPurchaseAndroidProps;\n\nexport type SubscriptionProduct =\n | (SubscriptionProductAndroid & AndroidPlatform)\n | (SubscriptionProductIos & IosPlatform);\n\nexport type RequestSubscriptionProps =\n | RequestSubscriptionAndroidProps\n | RequestSubscriptionIosProps;\n\nexport type PurchaseResult = {\n responseCode?: number;\n debugMessage?: string;\n code?: string;\n message?: string;\n purchaseTokenAndroid?: string;\n};\n\nexport enum ErrorCode {\n E_UNKNOWN = 'E_UNKNOWN',\n E_USER_CANCELLED = 'E_USER_CANCELLED',\n E_USER_ERROR = 'E_USER_ERROR',\n E_ITEM_UNAVAILABLE = 'E_ITEM_UNAVAILABLE',\n E_REMOTE_ERROR = 'E_REMOTE_ERROR',\n E_NETWORK_ERROR = 'E_NETWORK_ERROR',\n E_SERVICE_ERROR = 'E_SERVICE_ERROR',\n E_RECEIPT_FAILED = 'E_RECEIPT_FAILED',\n E_RECEIPT_FINISHED_FAILED = 'E_RECEIPT_FINISHED_FAILED',\n E_NOT_PREPARED = 'E_NOT_PREPARED',\n E_NOT_ENDED = 'E_NOT_ENDED',\n E_ALREADY_OWNED = 'E_ALREADY_OWNED',\n E_DEVELOPER_ERROR = 'E_DEVELOPER_ERROR',\n E_BILLING_RESPONSE_JSON_PARSE_ERROR = 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',\n E_DEFERRED_PAYMENT = 'E_DEFERRED_PAYMENT',\n E_INTERRUPTED = 'E_INTERRUPTED',\n E_IAP_NOT_AVAILABLE = 'E_IAP_NOT_AVAILABLE',\n}\n\nexport class PurchaseError implements Error {\n constructor(\n public name: string,\n public message: string,\n public responseCode?: number,\n public debugMessage?: string,\n public code?: ErrorCode,\n public productId?: string,\n ) {\n this.name = '[expo-iap]: PurchaseError';\n this.message = message;\n this.responseCode = responseCode;\n this.debugMessage = debugMessage;\n this.code = code;\n this.productId = productId;\n }\n}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { EventEmitter } from 'expo-modules-core';
|
|
2
2
|
import { Product, ProductPurchase, Purchase, PurchaseError, PurchaseResult, RequestSubscriptionProps, SubscriptionProduct, SubscriptionPurchase } from './ExpoIap.types';
|
|
3
|
-
import { RequestPurchaseAndroidProps } from './types/ExpoIapAndroid.types';
|
|
4
|
-
import { RequestPurchaseIosProps } from './types/ExpoIapIos.types';
|
|
3
|
+
import { RequestPurchaseAndroidProps, RequestSubscriptionAndroidProps } from './types/ExpoIapAndroid.types';
|
|
4
|
+
import { RequestPurchaseIosProps, RequestSubscriptionIosProps } from './types/ExpoIapIos.types';
|
|
5
5
|
export * from './modules/android';
|
|
6
6
|
export * from './modules/ios';
|
|
7
7
|
export declare const PI: any;
|
|
@@ -26,7 +26,17 @@ export declare const getAvailablePurchases: ({ alsoPublishToEventListener, onlyI
|
|
|
26
26
|
alsoPublishToEventListener?: boolean;
|
|
27
27
|
onlyIncludeActiveItems?: boolean;
|
|
28
28
|
}) => Promise<ProductPurchase[]>;
|
|
29
|
-
|
|
29
|
+
type PurchaseRequest = {
|
|
30
|
+
request: RequestPurchaseIosProps | RequestPurchaseAndroidProps;
|
|
31
|
+
type?: 'inapp';
|
|
32
|
+
} | {
|
|
33
|
+
request: RequestSubscriptionAndroidProps | RequestSubscriptionIosProps;
|
|
34
|
+
type: 'subs';
|
|
35
|
+
};
|
|
36
|
+
export declare const requestPurchase: (requestObj: PurchaseRequest) => Promise<ProductPurchase | SubscriptionPurchase | ProductPurchase[] | SubscriptionPurchase[] | void>;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.
|
|
39
|
+
*/
|
|
30
40
|
export declare const requestSubscription: (request: RequestSubscriptionProps) => Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void>;
|
|
31
41
|
export declare const finishTransaction: ({ purchase, isConsumable, }: {
|
|
32
42
|
purchase: Purchase;
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EACL,OAAO,EACP,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAqB,YAAY,EAAC,MAAM,mBAAmB,CAAC;AAEnE,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;AAIlC,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,C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,eAAe,EAAE,GACjB,oBAAoB,EAAE,GACtB,IAAI,CAwFP,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,YACrB,wBAAwB,KAChC,QAAQ,oBAAoB,GAAG,oBAAoB,EAAE,GAAG,IAAI,GAAG,IAAI,CASrE,CAAC;AAEF,eAAO,MAAM,iBAAiB,gCAG3B;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,KAAG,QAAQ,cAAc,GAAG,OAAO,CAiCnC,CAAC;AAEF,cAAc,UAAU,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// and on native platforms to ExpoIap.ts
|
|
3
3
|
import { NativeModulesProxy, EventEmitter } from 'expo-modules-core';
|
|
4
4
|
import { Platform } from 'react-native';
|
|
5
|
-
import { ProductType, } from './ExpoIap.types';
|
|
6
5
|
import ExpoIapModule from './ExpoIapModule';
|
|
7
|
-
import { isProductIos
|
|
8
|
-
import { isProductAndroid
|
|
6
|
+
import { isProductIos } from './modules/ios';
|
|
7
|
+
import { isProductAndroid } from './modules/android';
|
|
9
8
|
export * from './modules/android';
|
|
10
9
|
export * from './modules/ios';
|
|
11
|
-
// Get the native constant value
|
|
10
|
+
// Get the native constant value
|
|
12
11
|
export const PI = ExpoIapModule.PI;
|
|
13
12
|
export var IapEvent;
|
|
14
13
|
(function (IapEvent) {
|
|
@@ -40,7 +39,7 @@ export const getProducts = async (skus) => {
|
|
|
40
39
|
return items.filter((item) => isProductIos(item));
|
|
41
40
|
},
|
|
42
41
|
android: async () => {
|
|
43
|
-
const products = await ExpoIapModule.getItemsByType(
|
|
42
|
+
const products = await ExpoIapModule.getItemsByType('inapp', skus);
|
|
44
43
|
return products.filter((product) => isProductAndroid(product));
|
|
45
44
|
},
|
|
46
45
|
default: () => Promise.reject(new Error('Unsupported Platform')),
|
|
@@ -54,7 +53,7 @@ export const getSubscriptions = async (skus) => {
|
|
|
54
53
|
ios: async () => {
|
|
55
54
|
const rawItems = await ExpoIapModule.getItems(skus);
|
|
56
55
|
return rawItems.filter((item) => {
|
|
57
|
-
if (!
|
|
56
|
+
if (!isProductIos(item))
|
|
58
57
|
return false;
|
|
59
58
|
return (typeof item === 'object' &&
|
|
60
59
|
item !== null &&
|
|
@@ -66,7 +65,7 @@ export const getSubscriptions = async (skus) => {
|
|
|
66
65
|
android: async () => {
|
|
67
66
|
const rawItems = await ExpoIapModule.getItemsByType('subs', skus);
|
|
68
67
|
return rawItems.filter((item) => {
|
|
69
|
-
if (!
|
|
68
|
+
if (!isProductAndroid(item))
|
|
70
69
|
return false;
|
|
71
70
|
return (typeof item === 'object' &&
|
|
72
71
|
item !== null &&
|
|
@@ -86,23 +85,22 @@ export const getPurchaseHistory = ({ alsoPublishToEventListener = false, onlyInc
|
|
|
86
85
|
return ExpoIapModule.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems);
|
|
87
86
|
},
|
|
88
87
|
android: async () => {
|
|
89
|
-
const products = await ExpoIapModule.getPurchaseHistoryByType(
|
|
90
|
-
const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(
|
|
88
|
+
const products = await ExpoIapModule.getPurchaseHistoryByType('inapp');
|
|
89
|
+
const subscriptions = await ExpoIapModule.getPurchaseHistoryByType('subs');
|
|
91
90
|
return products.concat(subscriptions);
|
|
92
91
|
},
|
|
93
92
|
}) || (() => Promise.resolve([])))();
|
|
94
93
|
export const getAvailablePurchases = ({ alsoPublishToEventListener = false, onlyIncludeActiveItems = true, } = {}) => (Platform.select({
|
|
95
94
|
ios: () => ExpoIapModule.getAvailableItems(alsoPublishToEventListener, onlyIncludeActiveItems),
|
|
96
95
|
android: async () => {
|
|
97
|
-
const products = await ExpoIapModule.getAvailableItemsByType(
|
|
98
|
-
const subscriptions = await ExpoIapModule.getAvailableItemsByType(
|
|
96
|
+
const products = await ExpoIapModule.getAvailableItemsByType('inapp');
|
|
97
|
+
const subscriptions = await ExpoIapModule.getAvailableItemsByType('subs');
|
|
99
98
|
return products.concat(subscriptions);
|
|
100
99
|
},
|
|
101
100
|
}) || (() => Promise.resolve([])))();
|
|
102
101
|
const offerToRecordIos = (offer) => {
|
|
103
|
-
if (!offer)
|
|
102
|
+
if (!offer)
|
|
104
103
|
return undefined;
|
|
105
|
-
}
|
|
106
104
|
return {
|
|
107
105
|
identifier: offer.identifier,
|
|
108
106
|
keyIdentifier: offer.keyIdentifier,
|
|
@@ -111,57 +109,71 @@ const offerToRecordIos = (offer) => {
|
|
|
111
109
|
timestamp: offer.timestamp.toString(),
|
|
112
110
|
};
|
|
113
111
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
// Type guards for request objects
|
|
113
|
+
const isIosRequest = (request) => 'sku' in request && typeof request.sku === 'string';
|
|
114
|
+
const isAndroidInAppRequest = (request) => 'skus' in request &&
|
|
115
|
+
Array.isArray(request.skus) &&
|
|
116
|
+
!('subscriptionOffers' in request);
|
|
117
|
+
const isAndroidSubscriptionRequest = (request) => 'skus' in request &&
|
|
118
|
+
Array.isArray(request.skus) &&
|
|
119
|
+
'subscriptionOffers' in request;
|
|
120
|
+
export const requestPurchase = (requestObj) => {
|
|
121
|
+
const { request, type = 'inapp' } = requestObj;
|
|
122
|
+
if (Platform.OS === 'ios') {
|
|
123
|
+
if (!isIosRequest(request)) {
|
|
124
|
+
throw new Error("Invalid request for iOS: Expected a 'RequestPurchaseIosProps' or 'RequestSubscriptionIosProps' object with a valid 'sku' property.");
|
|
118
125
|
}
|
|
119
126
|
const { sku, andDangerouslyFinishTransactionAutomaticallyIOS = false, appAccountToken, quantity, withOffer, } = request;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
+
return (async () => {
|
|
128
|
+
const offer = offerToRecordIos(withOffer);
|
|
129
|
+
const purchase = await ExpoIapModule.buyProduct(sku, andDangerouslyFinishTransactionAutomaticallyIOS, appAccountToken, quantity ?? -1, offer);
|
|
130
|
+
return type === 'inapp'
|
|
131
|
+
? purchase
|
|
132
|
+
: purchase;
|
|
133
|
+
})();
|
|
134
|
+
}
|
|
135
|
+
if (Platform.OS === 'android') {
|
|
136
|
+
if (isAndroidInAppRequest(request)) {
|
|
137
|
+
const { skus, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, isOfferPersonalized, } = request;
|
|
138
|
+
return (async () => {
|
|
139
|
+
return ExpoIapModule.buyItemByType({
|
|
140
|
+
type: 'inapp',
|
|
141
|
+
skuArr: skus,
|
|
142
|
+
purchaseToken: undefined,
|
|
143
|
+
replacementMode: -1,
|
|
144
|
+
obfuscatedAccountId: obfuscatedAccountIdAndroid,
|
|
145
|
+
obfuscatedProfileId: obfuscatedProfileIdAndroid,
|
|
146
|
+
offerTokenArr: [],
|
|
147
|
+
isOfferPersonalized: isOfferPersonalized ?? false,
|
|
148
|
+
});
|
|
149
|
+
})();
|
|
127
150
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
ios: async () => {
|
|
143
|
-
if (!('sku' in request)) {
|
|
144
|
-
throw new Error('sku is required for iOS subscriptions');
|
|
151
|
+
if (isAndroidSubscriptionRequest(request)) {
|
|
152
|
+
const { skus, obfuscatedAccountIdAndroid, obfuscatedProfileIdAndroid, isOfferPersonalized, subscriptionOffers = [], replacementModeAndroid = -1, purchaseTokenAndroid, } = request;
|
|
153
|
+
return (async () => {
|
|
154
|
+
return ExpoIapModule.buyItemByType({
|
|
155
|
+
type: 'subs',
|
|
156
|
+
skuArr: skus,
|
|
157
|
+
purchaseToken: purchaseTokenAndroid,
|
|
158
|
+
replacementMode: replacementModeAndroid,
|
|
159
|
+
obfuscatedAccountId: obfuscatedAccountIdAndroid,
|
|
160
|
+
obfuscatedProfileId: obfuscatedProfileIdAndroid,
|
|
161
|
+
offerTokenArr: subscriptionOffers.map((so) => so.offerToken),
|
|
162
|
+
isOfferPersonalized: isOfferPersonalized ?? false,
|
|
163
|
+
});
|
|
164
|
+
})();
|
|
145
165
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
replacementMode: replacementModeAndroid,
|
|
158
|
-
obfuscatedAccountId: obfuscatedAccountIdAndroid,
|
|
159
|
-
obfuscatedProfileId: obfuscatedProfileIdAndroid,
|
|
160
|
-
offerTokenArr: subscriptionOffers.map((so) => so.offerToken),
|
|
161
|
-
isOfferPersonalized: isOfferPersonalized ?? false,
|
|
162
|
-
});
|
|
163
|
-
},
|
|
164
|
-
}) || (() => Promise.resolve(null)))();
|
|
166
|
+
throw new Error("Invalid request for Android: Expected a 'RequestPurchaseAndroidProps' object with a valid 'skus' array or a 'RequestSubscriptionAndroidProps' object with 'skus' and 'subscriptionOffers'.");
|
|
167
|
+
}
|
|
168
|
+
return Promise.resolve(); // Fallback for unsupported platforms
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.
|
|
172
|
+
*/
|
|
173
|
+
export const requestSubscription = async (request) => {
|
|
174
|
+
console.warn("`requestSubscription` is deprecated. Use `requestPurchase({ request, type: 'subs' })` instead. This method will be removed in version 3.0.0+.");
|
|
175
|
+
return (await requestPurchase({ request, type: 'subs' }));
|
|
176
|
+
};
|
|
165
177
|
export const finishTransaction = ({ purchase, isConsumable, }) => {
|
|
166
178
|
return (Platform.select({
|
|
167
179
|
ios: async () => {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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C;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 ProductType,\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, isSubscriptionProductIos} from './modules/ios';\nimport {\n isProductAndroid,\n isSubscriptionProductAndroid,\n} 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 items = await ExpoIapModule.getItems(skus);\n return items.filter((item: unknown) => isProductIos<Product>(item));\n },\n android: async () => {\n const products = await ExpoIapModule.getItemsByType(\n ProductType.InAppPurchase,\n skus,\n );\n\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 (!isSubscriptionProductIos(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 (!isSubscriptionProductAndroid(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(\n ProductType.InAppPurchase,\n );\n const subscriptions = await ExpoIapModule.getPurchaseHistoryByType(\n ProductType.Subscription,\n );\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(\n ProductType.InAppPurchase,\n );\n const subscriptions = await ExpoIapModule.getAvailableItemsByType(\n ProductType.Subscription,\n );\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) {\n return undefined;\n }\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\nexport const requestPurchase = (\n request: RequestPurchaseIosProps | RequestPurchaseAndroidProps,\n): Promise<ProductPurchase | ProductPurchase[] | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS purchase');\n }\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request;\n const offer = offerToRecordIos(withOffer);\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n return Promise.resolve(purchase);\n },\n android: async () => {\n if (!('skus' in request) || !request.skus.length) {\n throw new Error('skus is required for Android purchase');\n }\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\n return ExpoIapModule.buyItemByType({\n type: ProductType.InAppPurchase,\n skuArr: skus,\n purchaseToken: undefined,\n replacementMode: -1,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: [],\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || Promise.resolve\n )();\n\nexport const requestSubscription = (\n request: RequestSubscriptionProps,\n): Promise<SubscriptionPurchase | SubscriptionPurchase[] | null | void> =>\n (\n Platform.select({\n ios: async () => {\n if (!('sku' in request)) {\n throw new Error('sku is required for iOS subscriptions');\n }\n const {\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS = false,\n appAccountToken,\n quantity,\n withOffer,\n } = request as RequestSubscriptionIosProps;\n const offer = offerToRecordIos(withOffer);\n const purchase = await ExpoIapModule.buyProduct(\n sku,\n andDangerouslyFinishTransactionAutomaticallyIOS,\n appAccountToken,\n quantity ?? -1,\n offer,\n );\n return Promise.resolve(purchase as SubscriptionPurchase);\n },\n android: async () => {\n const {\n skus,\n isOfferPersonalized,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n subscriptionOffers,\n replacementModeAndroid,\n purchaseTokenAndroid,\n } = request as RequestSubscriptionAndroidProps;\n return ExpoIapModule.buyItemByType({\n type: ProductType.Subscription,\n skuArr: skus.map((so) => so),\n purchaseToken: purchaseTokenAndroid,\n replacementMode: replacementModeAndroid,\n obfuscatedAccountId: obfuscatedAccountIdAndroid,\n obfuscatedProfileId: obfuscatedProfileIdAndroid,\n offerTokenArr: subscriptionOffers.map((so) => so.offerToken),\n isOfferPersonalized: isOfferPersonalized ?? false,\n });\n },\n }) || (() => Promise.resolve(null))\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,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,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EAAC,CAAC,CAI9C,CAAC;AACX,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,QAAQ,EACR,YAAY,GAIb,EAAqC,EAAE;IACtC,OAAO,CACL,QAAQ,CAAC,MAAM,CAAC;QACd,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 items = await ExpoIapModule.getItems(skus);\n return items.filter((item: unknown) => isProductIos<Product>(item));\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\nconst isAndroidInAppRequest = (\n request: any,\n): request is RequestPurchaseAndroidProps =>\n 'skus' in request &&\n Array.isArray(request.skus) &&\n !('subscriptionOffers' in request);\n\nconst isAndroidSubscriptionRequest = (\n request: any,\n): request is RequestSubscriptionAndroidProps =>\n 'skus' in request &&\n Array.isArray(request.skus) &&\n 'subscriptionOffers' in request;\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: Expected a 'RequestPurchaseIosProps' or 'RequestSubscriptionIosProps' object with a valid 'sku' property.\",\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 return type === 'inapp'\n ? (purchase as ProductPurchase)\n : (purchase as SubscriptionPurchase);\n })();\n }\n\n if (Platform.OS === 'android') {\n if (isAndroidInAppRequest(request)) {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n } = request;\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 (isAndroidSubscriptionRequest(request)) {\n const {\n skus,\n obfuscatedAccountIdAndroid,\n obfuscatedProfileIdAndroid,\n isOfferPersonalized,\n subscriptionOffers = [],\n replacementModeAndroid = -1,\n purchaseTokenAndroid,\n } = request;\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"]}
|
|
@@ -5,11 +5,6 @@ export declare function isProductAndroid<T extends {
|
|
|
5
5
|
}>(item: unknown): item is T & {
|
|
6
6
|
platform: 'android';
|
|
7
7
|
};
|
|
8
|
-
export declare function isSubscriptionProductAndroid<T extends {
|
|
9
|
-
platform?: string;
|
|
10
|
-
}>(item: unknown): item is T & {
|
|
11
|
-
platform: 'android';
|
|
12
|
-
};
|
|
13
8
|
/**
|
|
14
9
|
* Deep link to subscriptions screen on Android.
|
|
15
10
|
* @param {string} sku The product's SKU (on Android)
|
|
@@ -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
|
|
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,aAExC;IACD,GAAG,EAAE,MAAM,CAAC;CACb,KAAG,QAAQ,IAAI,CAIf,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,kEAMhC;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,QAAQ,cAAc,CAsBzB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,iCAGpC;IACD,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,KAAG,QAAQ,cAAc,GAAG,OAAO,GAAG,IAAI,CAE1C,CAAC"}
|
package/build/modules/android.js
CHANGED
|
@@ -7,9 +7,6 @@ export function isProductAndroid(item) {
|
|
|
7
7
|
'platform' in item &&
|
|
8
8
|
item.platform === 'android');
|
|
9
9
|
}
|
|
10
|
-
export function isSubscriptionProductAndroid(item) {
|
|
11
|
-
return isProductAndroid(item);
|
|
12
|
-
}
|
|
13
10
|
/**
|
|
14
11
|
* Deep link to subscriptions screen on Android.
|
|
15
12
|
* @param {string} sku The product's SKU (on Android)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAGrC,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,IAAI,CAAC,QAAQ,KAAK,SAAS,CAC5B,CAAC;AACJ,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/modules/android.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AAGrC,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAE7C,cAAc;AACd,MAAM,UAAU,gBAAgB,CAC9B,IAAa;IAEb,OAAO,CACL,IAAI,IAAI,IAAI;QACZ,OAAO,IAAI,KAAK,QAAQ;QACxB,UAAU,IAAI,IAAI;QAClB,IAAI,CAAC,QAAQ,KAAK,SAAS,CAC5B,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EAAE,EACnD,GAAG,GAGJ,EAAiB,EAAE;IAClB,OAAO,OAAO,CAAC,OAAO,CACpB,+DAA+D,MAAM,aAAa,CAAC,cAAc,EAAE,QAAQ,GAAG,EAAE,CACjH,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAC3C,WAAW,EACX,SAAS,EACT,YAAY,EACZ,WAAW,EACX,KAAK,GAON,EAA2B,EAAE;IAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC;IAElD,MAAM,GAAG,GACP,0EAA0E;QAC1E,IAAI,WAAW,cAAc,IAAI,IAAI,SAAS,EAAE;QAChD,WAAW,YAAY,iBAAiB,WAAW,EAAE,CAAC;IAExD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,KAAK;QACb,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;SACnC;KACF,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YAClD,UAAU,EAAE,QAAQ,CAAC,MAAM;SAC5B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,EACzC,KAAK,EACL,gBAAgB,GAIjB,EAA4C,EAAE;IAC7C,OAAO,aAAa,CAAC,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC;AACpE,CAAC,CAAC","sourcesContent":["import {Linking} from 'react-native';\nimport {PurchaseResult} from '../ExpoIap.types';\nimport {ReceiptAndroid} from '../types/ExpoIapAndroid.types';\nimport ExpoIapModule from '../ExpoIapModule';\n\n// Type guards\nexport function isProductAndroid<T extends {platform?: string}>(\n item: unknown,\n): item is T & {platform: 'android'} {\n return (\n item != null &&\n typeof item === 'object' &&\n 'platform' in item &&\n item.platform === 'android'\n );\n}\n\n/**\n * Deep link to subscriptions screen on Android.\n * @param {string} sku The product's SKU (on Android)\n * @returns {Promise<void>}\n */\nexport const deepLinkToSubscriptionsAndroid = async ({\n sku,\n}: {\n sku: string;\n}): Promise<void> => {\n return Linking.openURL(\n `https://play.google.com/store/account/subscriptions?package=${await ExpoIapModule.getPackageName()}&sku=${sku}`,\n );\n};\n\n/**\n * Validate receipt for Android. NOTE: This method is here for debugging purposes only. Including\n * your access token in the binary you ship to users is potentially dangerous.\n * Use server side validation instead for your production builds\n * @param {string} packageName package name of your app.\n * @param {string} productId product id for your in app product.\n * @param {string} productToken token for your purchase.\n * @param {string} accessToken accessToken from googleApis.\n * @param {boolean} isSub whether this is subscription or inapp. `true` for subscription.\n * @returns {Promise<object>}\n */\nexport const validateReceiptAndroid = async ({\n packageName,\n productId,\n productToken,\n accessToken,\n isSub,\n}: {\n packageName: string;\n productId: string;\n productToken: string;\n accessToken: string;\n isSub?: boolean;\n}): Promise<ReceiptAndroid> => {\n const type = isSub ? 'subscriptions' : 'products';\n\n const url =\n 'https://androidpublisher.googleapis.com/androidpublisher/v3/applications' +\n `/${packageName}/purchases/${type}/${productId}` +\n `/tokens/${productToken}?access_token=${accessToken}`;\n\n const response = await fetch(url, {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n\n if (!response.ok) {\n throw Object.assign(new Error(response.statusText), {\n statusCode: response.status,\n });\n }\n\n return response.json();\n};\n\n/**\n * Acknowledge a product (on Android.) No-op on iOS.\n * @param {string} token The product's token (on Android)\n * @returns {Promise<PurchaseResult | void>}\n */\nexport const acknowledgePurchaseAndroid = ({\n token,\n developerPayload,\n}: {\n token: string;\n developerPayload?: string;\n}): Promise<PurchaseResult | boolean | void> => {\n return ExpoIapModule.acknowledgePurchase(token, developerPayload);\n};\n"]}
|
package/build/modules/ios.d.ts
CHANGED
|
@@ -10,11 +10,6 @@ export declare function isProductIos<T extends {
|
|
|
10
10
|
}>(item: unknown): item is T & {
|
|
11
11
|
platform: 'ios';
|
|
12
12
|
};
|
|
13
|
-
export declare function isSubscriptionProductIos<T extends {
|
|
14
|
-
platform?: string;
|
|
15
|
-
}>(item: unknown): item is T & {
|
|
16
|
-
platform: 'ios';
|
|
17
|
-
};
|
|
18
13
|
/**
|
|
19
14
|
* Sync state with Appstore (iOS only)
|
|
20
15
|
* https://developer.apple.com/documentation/storekit/appstore/3791906-sync
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAChE,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,eAAO,MAAM,qBAAqB,aACtB,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,6CAO5C,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;
|
|
1
|
+
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../src/modules/ios.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAChE,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,eAAO,MAAM,qBAAqB,aACtB,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,6CAO5C,CAAC;AAGF,wBAAgB,YAAY,CAAC,CAAC,SAAS;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAC,EACxD,IAAI,EAAE,OAAO,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AEH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAA+B,EAAE,CAC7E,aAAa,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAA4B,EAAE,CAC1E,aAAa,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAA4B,EAAE,CACzE,aAAa,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;AAMvC,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAgC,EAAE,CAC9E,aAAa,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAkB,EAAE,CACzD,aAAa,CAAC,uBAAuB,EAAE,CAAC","sourcesContent":["import {Platform} from 'react-native';\nimport {emitter, IapEvent} from '..';\nimport {ProductPurchase, PurchaseError} 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\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 return emitter.addListener(IapEvent.TransactionIapUpdated, listener);\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 *\n */\nexport const showManageSubscriptions = (): Promise<null> =>\n ExpoIapModule.showManageSubscriptions();\n"]}
|
package/build/useIap.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { requestPurchase as requestPurchaseInternal } from './';
|
|
1
2
|
import { Product, ProductPurchase, Purchase, PurchaseError, PurchaseResult, SubscriptionProduct } from './ExpoIap.types';
|
|
2
3
|
type IAP_STATUS = {
|
|
3
4
|
connected: boolean;
|
|
@@ -12,10 +13,11 @@ type IAP_STATUS = {
|
|
|
12
13
|
purchase: Purchase;
|
|
13
14
|
isConsumable?: boolean;
|
|
14
15
|
}) => Promise<string | boolean | PurchaseResult | void>;
|
|
15
|
-
getAvailablePurchases: () => Promise<void>;
|
|
16
|
-
getPurchaseHistories: () => Promise<void>;
|
|
16
|
+
getAvailablePurchases: (skus: string[]) => Promise<void>;
|
|
17
|
+
getPurchaseHistories: (skus: string[]) => Promise<void>;
|
|
17
18
|
getProducts: (skus: string[]) => Promise<void>;
|
|
18
19
|
getSubscriptions: (skus: string[]) => Promise<void>;
|
|
20
|
+
requestPurchase: typeof requestPurchaseInternal;
|
|
19
21
|
};
|
|
20
22
|
export declare function useIAP(): IAP_STATUS;
|
|
21
23
|
export {};
|
package/build/useIap.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIap.d.ts","sourceRoot":"","sources":["../src/useIap.ts"],"names":[],"mappings":"
|
|
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,UAAU,GAAG;IAChB,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,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;CACjD,CAAC;AAEF,wBAAgB,MAAM,IAAI,UAAU,CAsInC"}
|
package/build/useIap.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { endConnection, initConnection, purchaseErrorListener, purchaseUpdatedListener, transactionUpdatedIos, getProducts, getAvailablePurchases, getPurchaseHistory, finishTransaction as finishTransactionInternal, getSubscriptions, } from './';
|
|
1
|
+
import { endConnection, initConnection, purchaseErrorListener, purchaseUpdatedListener, transactionUpdatedIos, getProducts, getAvailablePurchases, getPurchaseHistory, finishTransaction as finishTransactionInternal, getSubscriptions, requestPurchase as requestPurchaseInternal, } from './';
|
|
2
2
|
import { useCallback, useEffect, useState, useRef } from 'react';
|
|
3
3
|
import { Platform } from 'react-native';
|
|
4
4
|
export function useIAP() {
|
|
@@ -10,18 +10,17 @@ export function useIAP() {
|
|
|
10
10
|
const [availablePurchases, setAvailablePurchases] = useState([]);
|
|
11
11
|
const [currentPurchase, setCurrentPurchase] = useState();
|
|
12
12
|
const [currentPurchaseError, setCurrentPurchaseError] = useState();
|
|
13
|
-
// 구독을 훅 인스턴스별로 관리하기 위한 ref
|
|
14
13
|
const subscriptionsRef = useRef({});
|
|
15
|
-
const
|
|
14
|
+
const getProductsInternal = useCallback(async (skus) => {
|
|
16
15
|
setProducts(await getProducts(skus));
|
|
17
16
|
}, []);
|
|
18
|
-
const
|
|
17
|
+
const getSubscriptionsInternal = useCallback(async (skus) => {
|
|
19
18
|
setSubscriptions(await getSubscriptions(skus));
|
|
20
19
|
}, []);
|
|
21
|
-
const
|
|
20
|
+
const getAvailablePurchasesInternal = useCallback(async () => {
|
|
22
21
|
setAvailablePurchases(await getAvailablePurchases());
|
|
23
22
|
}, []);
|
|
24
|
-
const
|
|
23
|
+
const getPurchaseHistoriesInternal = useCallback(async () => {
|
|
25
24
|
setPurchaseHistories(await getPurchaseHistory());
|
|
26
25
|
}, []);
|
|
27
26
|
const finishTransaction = useCallback(async ({ purchase, isConsumable, }) => {
|
|
@@ -85,10 +84,11 @@ export function useIAP() {
|
|
|
85
84
|
availablePurchases,
|
|
86
85
|
currentPurchase,
|
|
87
86
|
currentPurchaseError,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
getAvailablePurchases: getAvailablePurchasesInternal,
|
|
88
|
+
getPurchaseHistories: getPurchaseHistoriesInternal,
|
|
89
|
+
getProducts: getProductsInternal,
|
|
90
|
+
getSubscriptions: getSubscriptionsInternal,
|
|
91
|
+
requestPurchase: requestPurchaseInternal,
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
94
|
//# sourceMappingURL=useIap.js.map
|