expo-iap 3.0.3 → 3.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/CLAUDE.md +2 -0
- package/build/helpers/subscription.d.ts +1 -12
- package/build/helpers/subscription.d.ts.map +1 -1
- package/build/helpers/subscription.js +12 -7
- package/build/helpers/subscription.js.map +1 -1
- package/build/index.d.ts +8 -6
- 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 +7 -6
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +19 -4
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +7 -10
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +3 -1
- package/build/modules/ios.js.map +1 -1
- package/build/purchase-error.d.ts +69 -0
- package/build/purchase-error.d.ts.map +1 -0
- package/build/purchase-error.js +164 -0
- package/build/purchase-error.js.map +1 -0
- package/build/types.d.ts +649 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +100 -0
- package/build/types.js.map +1 -0
- package/build/useIAP.d.ts +5 -4
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +1 -1
- package/build/useIAP.js.map +1 -1
- package/build/utils/errorMapping.d.ts +1 -1
- package/build/utils/errorMapping.d.ts.map +1 -1
- package/build/utils/errorMapping.js +19 -3
- package/build/utils/errorMapping.js.map +1 -1
- package/jest.config.js +1 -1
- package/package.json +1 -1
- package/src/helpers/subscription.ts +12 -20
- package/src/index.ts +14 -14
- package/src/modules/android.ts +28 -10
- package/src/modules/ios.ts +11 -13
- package/src/purchase-error.ts +268 -0
- package/src/types.ts +738 -0
- package/src/useIAP.ts +8 -8
- package/src/utils/errorMapping.ts +24 -3
- package/build/ExpoIap.types.d.ts +0 -307
- package/build/ExpoIap.types.d.ts.map +0 -1
- package/build/ExpoIap.types.js +0 -235
- package/build/ExpoIap.types.js.map +0 -1
- package/build/types/ExpoIapAndroid.types.d.ts +0 -114
- package/build/types/ExpoIapAndroid.types.d.ts.map +0 -1
- package/build/types/ExpoIapAndroid.types.js +0 -29
- package/build/types/ExpoIapAndroid.types.js.map +0 -1
- package/build/types/ExpoIapIOS.types.d.ts +0 -149
- package/build/types/ExpoIapIOS.types.d.ts.map +0 -1
- package/build/types/ExpoIapIOS.types.js +0 -8
- package/build/types/ExpoIapIOS.types.js.map +0 -1
- package/src/ExpoIap.types.ts +0 -444
- package/src/types/ExpoIapAndroid.types.ts +0 -133
- package/src/types/ExpoIapIOS.types.ts +0 -172
package/src/useIAP.ts
CHANGED
|
@@ -29,13 +29,13 @@ import {
|
|
|
29
29
|
import {
|
|
30
30
|
Product,
|
|
31
31
|
Purchase,
|
|
32
|
-
PurchaseError,
|
|
33
|
-
PurchaseResult,
|
|
34
32
|
ProductSubscription,
|
|
35
33
|
RequestPurchaseProps,
|
|
36
|
-
|
|
34
|
+
RequestSubscriptionPropsByPlatforms,
|
|
37
35
|
ErrorCode,
|
|
38
|
-
|
|
36
|
+
VoidResult,
|
|
37
|
+
} from './types';
|
|
38
|
+
import {PurchaseError} from './purchase-error';
|
|
39
39
|
import {
|
|
40
40
|
getUserFriendlyErrorMessage,
|
|
41
41
|
isUserCancelledError,
|
|
@@ -65,15 +65,15 @@ type UseIap = {
|
|
|
65
65
|
}: {
|
|
66
66
|
purchase: Purchase;
|
|
67
67
|
isConsumable?: boolean;
|
|
68
|
-
}) => Promise<
|
|
69
|
-
getAvailablePurchases: (
|
|
68
|
+
}) => Promise<VoidResult | boolean>;
|
|
69
|
+
getAvailablePurchases: () => Promise<void>;
|
|
70
70
|
fetchProducts: (params: {
|
|
71
71
|
skus: string[];
|
|
72
72
|
type?: 'inapp' | 'subs';
|
|
73
73
|
}) => Promise<void>;
|
|
74
74
|
|
|
75
75
|
requestPurchase: (params: {
|
|
76
|
-
request: RequestPurchaseProps |
|
|
76
|
+
request: RequestPurchaseProps | RequestSubscriptionPropsByPlatforms;
|
|
77
77
|
type?: 'inapp' | 'subs';
|
|
78
78
|
}) => Promise<any>;
|
|
79
79
|
validateReceipt: (
|
|
@@ -267,7 +267,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
|
|
|
267
267
|
}: {
|
|
268
268
|
purchase: Purchase;
|
|
269
269
|
isConsumable?: boolean;
|
|
270
|
-
}): Promise<
|
|
270
|
+
}): Promise<VoidResult | boolean> => {
|
|
271
271
|
try {
|
|
272
272
|
return await finishTransactionInternal({
|
|
273
273
|
purchase,
|
|
@@ -3,17 +3,38 @@
|
|
|
3
3
|
* Provides helper functions for handling platform-specific errors
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {ErrorCode} from '../
|
|
6
|
+
import {ErrorCode} from '../types';
|
|
7
7
|
|
|
8
8
|
type ErrorLike = string | {code?: ErrorCode | string; message?: string};
|
|
9
9
|
|
|
10
|
+
const ERROR_CODES = new Set<string>(Object.values(ErrorCode));
|
|
11
|
+
|
|
12
|
+
const normalizeErrorCode = (code?: string | null): string | undefined => {
|
|
13
|
+
if (!code) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (ERROR_CODES.has(code)) {
|
|
18
|
+
return code;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (code.startsWith('E_')) {
|
|
22
|
+
const trimmed = code.substring(2);
|
|
23
|
+
if (ERROR_CODES.has(trimmed)) {
|
|
24
|
+
return trimmed;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return code;
|
|
29
|
+
};
|
|
30
|
+
|
|
10
31
|
function extractCode(error: unknown): string | undefined {
|
|
11
32
|
if (typeof error === 'string') {
|
|
12
|
-
return error;
|
|
33
|
+
return normalizeErrorCode(error);
|
|
13
34
|
}
|
|
14
35
|
|
|
15
36
|
if (error && typeof error === 'object' && 'code' in error) {
|
|
16
|
-
return (error as {code?: string}).code;
|
|
37
|
+
return normalizeErrorCode((error as {code?: string}).code);
|
|
17
38
|
}
|
|
18
39
|
|
|
19
40
|
return undefined;
|
package/build/ExpoIap.types.d.ts
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import type { ProductAndroid, PurchaseAndroid, ProductSubscriptionAndroid } from './types/ExpoIapAndroid.types';
|
|
2
|
-
import type { ProductIOS, PurchaseIOS, ProductSubscriptionIOS } from './types/ExpoIapIOS.types';
|
|
3
|
-
export type ChangeEventPayload = {
|
|
4
|
-
value: string;
|
|
5
|
-
};
|
|
6
|
-
export type ProductType = 'inapp' | 'subs';
|
|
7
|
-
export declare enum PurchaseState {
|
|
8
|
-
Pending = "pending",
|
|
9
|
-
Purchased = "purchased",
|
|
10
|
-
Failed = "failed",
|
|
11
|
-
Restored = "restored",
|
|
12
|
-
Deferred = "deferred",
|
|
13
|
-
Unknown = "unknown"
|
|
14
|
-
}
|
|
15
|
-
export type ProductCommon = {
|
|
16
|
-
id: string;
|
|
17
|
-
title: string;
|
|
18
|
-
description: string;
|
|
19
|
-
type: ProductType;
|
|
20
|
-
displayName?: string;
|
|
21
|
-
displayPrice: string;
|
|
22
|
-
currency: string;
|
|
23
|
-
price?: number;
|
|
24
|
-
debugDescription?: string;
|
|
25
|
-
platform?: string;
|
|
26
|
-
};
|
|
27
|
-
export type PurchaseCommon = {
|
|
28
|
-
id: string;
|
|
29
|
-
productId: string;
|
|
30
|
-
ids?: string[];
|
|
31
|
-
transactionId?: string;
|
|
32
|
-
transactionDate: number;
|
|
33
|
-
purchaseToken?: string;
|
|
34
|
-
platform?: string;
|
|
35
|
-
quantity?: number;
|
|
36
|
-
purchaseState?: PurchaseState;
|
|
37
|
-
isAutoRenewing?: boolean;
|
|
38
|
-
};
|
|
39
|
-
export type ProductSubscriptionCommon = ProductCommon & {
|
|
40
|
-
type: 'subs';
|
|
41
|
-
};
|
|
42
|
-
export type IosPlatform = {
|
|
43
|
-
platform: 'ios';
|
|
44
|
-
};
|
|
45
|
-
export type AndroidPlatform = {
|
|
46
|
-
platform: 'android';
|
|
47
|
-
};
|
|
48
|
-
export type Product = (ProductAndroid & AndroidPlatform) | (ProductIOS & IosPlatform);
|
|
49
|
-
export type ProductSubscription = (ProductSubscriptionAndroid & AndroidPlatform) | (ProductSubscriptionIOS & IosPlatform);
|
|
50
|
-
export type SubscriptionProduct = ProductSubscription;
|
|
51
|
-
export * from './types/ExpoIapAndroid.types';
|
|
52
|
-
export * from './types/ExpoIapIOS.types';
|
|
53
|
-
export type Purchase = (PurchaseAndroid & AndroidPlatform) | (PurchaseIOS & IosPlatform);
|
|
54
|
-
export type PurchaseResult = {
|
|
55
|
-
responseCode?: number;
|
|
56
|
-
debugMessage?: string;
|
|
57
|
-
code?: string;
|
|
58
|
-
message?: string;
|
|
59
|
-
purchaseToken?: string;
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* Centralized error codes for expo-iap
|
|
63
|
-
* These are mapped to platform-specific error codes and provide consistent error handling
|
|
64
|
-
*/
|
|
65
|
-
export declare enum ErrorCode {
|
|
66
|
-
Unknown = "E_UNKNOWN",
|
|
67
|
-
UserCancelled = "E_USER_CANCELLED",
|
|
68
|
-
UserError = "E_USER_ERROR",
|
|
69
|
-
ItemUnavailable = "E_ITEM_UNAVAILABLE",
|
|
70
|
-
RemoteError = "E_REMOTE_ERROR",
|
|
71
|
-
NetworkError = "E_NETWORK_ERROR",
|
|
72
|
-
ServiceError = "E_SERVICE_ERROR",
|
|
73
|
-
ReceiptFailed = "E_RECEIPT_FAILED",
|
|
74
|
-
ReceiptFinished = "E_RECEIPT_FINISHED",
|
|
75
|
-
ReceiptFinishedFailed = "E_RECEIPT_FINISHED_FAILED",
|
|
76
|
-
NotPrepared = "E_NOT_PREPARED",
|
|
77
|
-
NotEnded = "E_NOT_ENDED",
|
|
78
|
-
AlreadyOwned = "E_ALREADY_OWNED",
|
|
79
|
-
DeveloperError = "E_DEVELOPER_ERROR",
|
|
80
|
-
BillingResponseJsonParseError = "E_BILLING_RESPONSE_JSON_PARSE_ERROR",
|
|
81
|
-
DeferredPayment = "E_DEFERRED_PAYMENT",
|
|
82
|
-
Interrupted = "E_INTERRUPTED",
|
|
83
|
-
IapNotAvailable = "E_IAP_NOT_AVAILABLE",
|
|
84
|
-
PurchaseError = "E_PURCHASE_ERROR",
|
|
85
|
-
SyncError = "E_SYNC_ERROR",
|
|
86
|
-
TransactionValidationFailed = "E_TRANSACTION_VALIDATION_FAILED",
|
|
87
|
-
ActivityUnavailable = "E_ACTIVITY_UNAVAILABLE",
|
|
88
|
-
AlreadyPrepared = "E_ALREADY_PREPARED",
|
|
89
|
-
Pending = "E_PENDING",
|
|
90
|
-
ConnectionClosed = "E_CONNECTION_CLOSED",
|
|
91
|
-
InitConnection = "E_INIT_CONNECTION",
|
|
92
|
-
ServiceDisconnected = "E_SERVICE_DISCONNECTED",
|
|
93
|
-
QueryProduct = "E_QUERY_PRODUCT",
|
|
94
|
-
SkuNotFound = "E_SKU_NOT_FOUND",
|
|
95
|
-
SkuOfferMismatch = "E_SKU_OFFER_MISMATCH",
|
|
96
|
-
ItemNotOwned = "E_ITEM_NOT_OWNED",
|
|
97
|
-
BillingUnavailable = "E_BILLING_UNAVAILABLE",
|
|
98
|
-
FeatureNotSupported = "E_FEATURE_NOT_SUPPORTED",
|
|
99
|
-
EmptySkuList = "E_EMPTY_SKU_LIST"
|
|
100
|
-
}
|
|
101
|
-
export declare const ErrorCodeMapping: {
|
|
102
|
-
readonly ios: {
|
|
103
|
-
readonly E_UNKNOWN: "E_UNKNOWN";
|
|
104
|
-
readonly E_USER_CANCELLED: "E_USER_CANCELLED";
|
|
105
|
-
readonly E_USER_ERROR: "E_USER_ERROR";
|
|
106
|
-
readonly E_ITEM_UNAVAILABLE: "E_ITEM_UNAVAILABLE";
|
|
107
|
-
readonly E_REMOTE_ERROR: "E_REMOTE_ERROR";
|
|
108
|
-
readonly E_NETWORK_ERROR: "E_NETWORK_ERROR";
|
|
109
|
-
readonly E_SERVICE_ERROR: "E_SERVICE_ERROR";
|
|
110
|
-
readonly E_RECEIPT_FAILED: "E_RECEIPT_FAILED";
|
|
111
|
-
readonly E_RECEIPT_FINISHED: "E_RECEIPT_FINISHED";
|
|
112
|
-
readonly E_RECEIPT_FINISHED_FAILED: "E_RECEIPT_FINISHED_FAILED";
|
|
113
|
-
readonly E_NOT_PREPARED: "E_NOT_PREPARED";
|
|
114
|
-
readonly E_NOT_ENDED: "E_NOT_ENDED";
|
|
115
|
-
readonly E_ALREADY_OWNED: "E_ALREADY_OWNED";
|
|
116
|
-
readonly E_DEVELOPER_ERROR: "E_DEVELOPER_ERROR";
|
|
117
|
-
readonly E_BILLING_RESPONSE_JSON_PARSE_ERROR: "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
|
|
118
|
-
readonly E_DEFERRED_PAYMENT: "E_DEFERRED_PAYMENT";
|
|
119
|
-
readonly E_INTERRUPTED: "E_INTERRUPTED";
|
|
120
|
-
readonly E_IAP_NOT_AVAILABLE: "E_IAP_NOT_AVAILABLE";
|
|
121
|
-
readonly E_PURCHASE_ERROR: "E_PURCHASE_ERROR";
|
|
122
|
-
readonly E_SYNC_ERROR: "E_SYNC_ERROR";
|
|
123
|
-
readonly E_TRANSACTION_VALIDATION_FAILED: "E_TRANSACTION_VALIDATION_FAILED";
|
|
124
|
-
readonly E_ACTIVITY_UNAVAILABLE: "E_ACTIVITY_UNAVAILABLE";
|
|
125
|
-
readonly E_ALREADY_PREPARED: "E_ALREADY_PREPARED";
|
|
126
|
-
readonly E_PENDING: "E_PENDING";
|
|
127
|
-
readonly E_CONNECTION_CLOSED: "E_CONNECTION_CLOSED";
|
|
128
|
-
readonly E_INIT_CONNECTION: "E_INIT_CONNECTION";
|
|
129
|
-
readonly E_SERVICE_DISCONNECTED: "E_SERVICE_DISCONNECTED";
|
|
130
|
-
readonly E_QUERY_PRODUCT: "E_QUERY_PRODUCT";
|
|
131
|
-
readonly E_SKU_NOT_FOUND: "E_SKU_NOT_FOUND";
|
|
132
|
-
readonly E_SKU_OFFER_MISMATCH: "E_SKU_OFFER_MISMATCH";
|
|
133
|
-
readonly E_ITEM_NOT_OWNED: "E_ITEM_NOT_OWNED";
|
|
134
|
-
readonly E_BILLING_UNAVAILABLE: "E_BILLING_UNAVAILABLE";
|
|
135
|
-
readonly E_FEATURE_NOT_SUPPORTED: "E_FEATURE_NOT_SUPPORTED";
|
|
136
|
-
readonly E_EMPTY_SKU_LIST: "E_EMPTY_SKU_LIST";
|
|
137
|
-
};
|
|
138
|
-
readonly android: {
|
|
139
|
-
readonly E_UNKNOWN: "E_UNKNOWN";
|
|
140
|
-
readonly E_USER_CANCELLED: "E_USER_CANCELLED";
|
|
141
|
-
readonly E_USER_ERROR: "E_USER_ERROR";
|
|
142
|
-
readonly E_ITEM_UNAVAILABLE: "E_ITEM_UNAVAILABLE";
|
|
143
|
-
readonly E_REMOTE_ERROR: "E_REMOTE_ERROR";
|
|
144
|
-
readonly E_NETWORK_ERROR: "E_NETWORK_ERROR";
|
|
145
|
-
readonly E_SERVICE_ERROR: "E_SERVICE_ERROR";
|
|
146
|
-
readonly E_RECEIPT_FAILED: "E_RECEIPT_FAILED";
|
|
147
|
-
readonly E_RECEIPT_FINISHED: "E_RECEIPT_FINISHED";
|
|
148
|
-
readonly E_RECEIPT_FINISHED_FAILED: "E_RECEIPT_FINISHED_FAILED";
|
|
149
|
-
readonly E_NOT_PREPARED: "E_NOT_PREPARED";
|
|
150
|
-
readonly E_NOT_ENDED: "E_NOT_ENDED";
|
|
151
|
-
readonly E_ALREADY_OWNED: "E_ALREADY_OWNED";
|
|
152
|
-
readonly E_DEVELOPER_ERROR: "E_DEVELOPER_ERROR";
|
|
153
|
-
readonly E_BILLING_RESPONSE_JSON_PARSE_ERROR: "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
|
|
154
|
-
readonly E_DEFERRED_PAYMENT: "E_DEFERRED_PAYMENT";
|
|
155
|
-
readonly E_INTERRUPTED: "E_INTERRUPTED";
|
|
156
|
-
readonly E_IAP_NOT_AVAILABLE: "E_IAP_NOT_AVAILABLE";
|
|
157
|
-
readonly E_PURCHASE_ERROR: "E_PURCHASE_ERROR";
|
|
158
|
-
readonly E_SYNC_ERROR: "E_SYNC_ERROR";
|
|
159
|
-
readonly E_TRANSACTION_VALIDATION_FAILED: "E_TRANSACTION_VALIDATION_FAILED";
|
|
160
|
-
readonly E_ACTIVITY_UNAVAILABLE: "E_ACTIVITY_UNAVAILABLE";
|
|
161
|
-
readonly E_ALREADY_PREPARED: "E_ALREADY_PREPARED";
|
|
162
|
-
readonly E_PENDING: "E_PENDING";
|
|
163
|
-
readonly E_CONNECTION_CLOSED: "E_CONNECTION_CLOSED";
|
|
164
|
-
readonly E_INIT_CONNECTION: "E_INIT_CONNECTION";
|
|
165
|
-
readonly E_SERVICE_DISCONNECTED: "E_SERVICE_DISCONNECTED";
|
|
166
|
-
readonly E_QUERY_PRODUCT: "E_QUERY_PRODUCT";
|
|
167
|
-
readonly E_SKU_NOT_FOUND: "E_SKU_NOT_FOUND";
|
|
168
|
-
readonly E_SKU_OFFER_MISMATCH: "E_SKU_OFFER_MISMATCH";
|
|
169
|
-
readonly E_ITEM_NOT_OWNED: "E_ITEM_NOT_OWNED";
|
|
170
|
-
readonly E_BILLING_UNAVAILABLE: "E_BILLING_UNAVAILABLE";
|
|
171
|
-
readonly E_FEATURE_NOT_SUPPORTED: "E_FEATURE_NOT_SUPPORTED";
|
|
172
|
-
readonly E_EMPTY_SKU_LIST: "E_EMPTY_SKU_LIST";
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
export type PurchaseErrorProps = {
|
|
176
|
-
message: string;
|
|
177
|
-
responseCode?: number;
|
|
178
|
-
debugMessage?: string;
|
|
179
|
-
code?: ErrorCode;
|
|
180
|
-
productId?: string;
|
|
181
|
-
platform?: 'ios' | 'android';
|
|
182
|
-
};
|
|
183
|
-
export declare class PurchaseError implements Error {
|
|
184
|
-
name: string;
|
|
185
|
-
message: string;
|
|
186
|
-
responseCode?: number;
|
|
187
|
-
debugMessage?: string;
|
|
188
|
-
code?: ErrorCode;
|
|
189
|
-
productId?: string;
|
|
190
|
-
platform?: 'ios' | 'android';
|
|
191
|
-
constructor(messageOrProps: string | PurchaseErrorProps, ...rest: any[]);
|
|
192
|
-
/**
|
|
193
|
-
* Creates a PurchaseError from platform-specific error data
|
|
194
|
-
* @param errorData Raw error data from native modules
|
|
195
|
-
* @param platform Platform where the error occurred
|
|
196
|
-
* @returns Properly typed PurchaseError instance
|
|
197
|
-
*/
|
|
198
|
-
static fromPlatformError(errorData: any, platform: 'ios' | 'android'): PurchaseError;
|
|
199
|
-
/**
|
|
200
|
-
* Gets the platform-specific error code for this error
|
|
201
|
-
* @returns Platform-specific error code
|
|
202
|
-
*/
|
|
203
|
-
getPlatformCode(): string | number | undefined;
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Utility functions for error code mapping and validation
|
|
207
|
-
*/
|
|
208
|
-
export declare const ErrorCodeUtils: {
|
|
209
|
-
/**
|
|
210
|
-
* Gets the native error code for the current platform
|
|
211
|
-
* @param errorCode ErrorCode enum value
|
|
212
|
-
* @returns Platform-specific error code from native constants
|
|
213
|
-
*/
|
|
214
|
-
getNativeErrorCode: (errorCode: ErrorCode) => string;
|
|
215
|
-
/**
|
|
216
|
-
* Maps a platform-specific error code back to the standardized ErrorCode enum
|
|
217
|
-
* @param platformCode Platform-specific error code (string for Android, number for iOS)
|
|
218
|
-
* @param platform Target platform
|
|
219
|
-
* @returns Corresponding ErrorCode enum value or E_UNKNOWN if not found
|
|
220
|
-
*/
|
|
221
|
-
fromPlatformCode: (platformCode: string | number, platform: "ios" | "android") => ErrorCode;
|
|
222
|
-
/**
|
|
223
|
-
* Maps an ErrorCode enum to platform-specific code
|
|
224
|
-
* @param errorCode ErrorCode enum value
|
|
225
|
-
* @param platform Target platform
|
|
226
|
-
* @returns Platform-specific error code
|
|
227
|
-
*/
|
|
228
|
-
toPlatformCode: (errorCode: ErrorCode, platform: "ios" | "android") => string | number;
|
|
229
|
-
/**
|
|
230
|
-
* Checks if an error code is valid for the specified platform
|
|
231
|
-
* @param errorCode ErrorCode enum value
|
|
232
|
-
* @param platform Target platform
|
|
233
|
-
* @returns True if the error code is supported on the platform
|
|
234
|
-
*/
|
|
235
|
-
isValidForPlatform: (errorCode: ErrorCode, platform: "ios" | "android") => boolean;
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* Unified request props that work on both iOS and Android platforms
|
|
239
|
-
* iOS will use 'sku', Android will use 'skus' (or convert sku to skus array)
|
|
240
|
-
*/
|
|
241
|
-
export interface UnifiedRequestPurchaseProps {
|
|
242
|
-
readonly sku?: string;
|
|
243
|
-
readonly skus?: string[];
|
|
244
|
-
readonly andDangerouslyFinishTransactionAutomatically?: boolean;
|
|
245
|
-
readonly appAccountToken?: string;
|
|
246
|
-
readonly quantity?: number;
|
|
247
|
-
readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;
|
|
248
|
-
readonly obfuscatedAccountIdAndroid?: string;
|
|
249
|
-
readonly obfuscatedProfileIdAndroid?: string;
|
|
250
|
-
readonly isOfferPersonalized?: boolean;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* iOS-specific purchase request parameters
|
|
254
|
-
*/
|
|
255
|
-
export interface RequestPurchaseIosProps {
|
|
256
|
-
readonly sku: string;
|
|
257
|
-
readonly andDangerouslyFinishTransactionAutomatically?: boolean;
|
|
258
|
-
readonly appAccountToken?: string;
|
|
259
|
-
readonly quantity?: number;
|
|
260
|
-
readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Android-specific purchase request parameters
|
|
264
|
-
*/
|
|
265
|
-
export interface RequestPurchaseAndroidProps {
|
|
266
|
-
readonly skus: string[];
|
|
267
|
-
readonly obfuscatedAccountIdAndroid?: string;
|
|
268
|
-
readonly obfuscatedProfileIdAndroid?: string;
|
|
269
|
-
readonly isOfferPersonalized?: boolean;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Android-specific subscription request parameters
|
|
273
|
-
*/
|
|
274
|
-
export interface RequestSubscriptionAndroidProps extends RequestPurchaseAndroidProps {
|
|
275
|
-
readonly purchaseTokenAndroid?: string;
|
|
276
|
-
readonly replacementModeAndroid?: number;
|
|
277
|
-
readonly subscriptionOffers: {
|
|
278
|
-
sku: string;
|
|
279
|
-
offerToken: string;
|
|
280
|
-
}[];
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Modern platform-specific request structure (v2.7.0+)
|
|
284
|
-
* Allows clear separation of iOS and Android parameters
|
|
285
|
-
*/
|
|
286
|
-
export interface RequestPurchasePropsByPlatforms {
|
|
287
|
-
readonly ios?: RequestPurchaseIosProps;
|
|
288
|
-
readonly android?: RequestPurchaseAndroidProps;
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Modern platform-specific subscription request structure (v2.7.0+)
|
|
292
|
-
*/
|
|
293
|
-
export interface RequestSubscriptionPropsByPlatforms {
|
|
294
|
-
readonly ios?: RequestPurchaseIosProps;
|
|
295
|
-
readonly android?: RequestSubscriptionAndroidProps;
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
* Modern request purchase parameters (v2.7.0+)
|
|
299
|
-
* This is the recommended API moving forward
|
|
300
|
-
*/
|
|
301
|
-
export type RequestPurchaseProps = RequestPurchasePropsByPlatforms;
|
|
302
|
-
/**
|
|
303
|
-
* Modern request subscription parameters (v2.7.0+)
|
|
304
|
-
* This is the recommended API moving forward
|
|
305
|
-
*/
|
|
306
|
-
export type RequestSubscriptionProps = RequestSubscriptionPropsByPlatforms;
|
|
307
|
-
//# sourceMappingURL=ExpoIap.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoIap.types.d.ts","sourceRoot":"","sources":["../src/ExpoIap.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eA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AM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC;IACxB,QAAQ,CAAC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAC7C,QAAQ,CAAC,0BAA0B,CAAC,EAAE,MAAM,CAAC;IAC7C,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,+BACf,SAAQ,2BAA2B;IACnC,QAAQ,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACzC,QAAQ,CAAC,kBAAkB,EAAE;QAC3B,GAAG,EAAE,MAAM,CAAC;QACZ,UAAU,EAAE,MAAM,CAAC;KACpB,EAAE,CAAC;CACL;AAED;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,GAAG,CAAC,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,2BAA2B,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,GAAG,CAAC,EAAE,uBAAuB,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,EAAE,+BAA+B,CAAC;CACpD;AAED;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAEnE;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,mCAAmC,CAAC"}
|
package/build/ExpoIap.types.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { NATIVE_ERROR_CODES } from './ExpoIapModule';
|
|
2
|
-
export var PurchaseState;
|
|
3
|
-
(function (PurchaseState) {
|
|
4
|
-
PurchaseState["Pending"] = "pending";
|
|
5
|
-
PurchaseState["Purchased"] = "purchased";
|
|
6
|
-
PurchaseState["Failed"] = "failed";
|
|
7
|
-
PurchaseState["Restored"] = "restored";
|
|
8
|
-
PurchaseState["Deferred"] = "deferred";
|
|
9
|
-
PurchaseState["Unknown"] = "unknown";
|
|
10
|
-
})(PurchaseState || (PurchaseState = {}));
|
|
11
|
-
// Re-export all platform-specific types to avoid deep imports
|
|
12
|
-
export * from './types/ExpoIapAndroid.types';
|
|
13
|
-
export * from './types/ExpoIapIOS.types';
|
|
14
|
-
/**
|
|
15
|
-
* Centralized error codes for expo-iap
|
|
16
|
-
* These are mapped to platform-specific error codes and provide consistent error handling
|
|
17
|
-
*/
|
|
18
|
-
export var ErrorCode;
|
|
19
|
-
(function (ErrorCode) {
|
|
20
|
-
ErrorCode["Unknown"] = "E_UNKNOWN";
|
|
21
|
-
ErrorCode["UserCancelled"] = "E_USER_CANCELLED";
|
|
22
|
-
ErrorCode["UserError"] = "E_USER_ERROR";
|
|
23
|
-
ErrorCode["ItemUnavailable"] = "E_ITEM_UNAVAILABLE";
|
|
24
|
-
ErrorCode["RemoteError"] = "E_REMOTE_ERROR";
|
|
25
|
-
ErrorCode["NetworkError"] = "E_NETWORK_ERROR";
|
|
26
|
-
ErrorCode["ServiceError"] = "E_SERVICE_ERROR";
|
|
27
|
-
ErrorCode["ReceiptFailed"] = "E_RECEIPT_FAILED";
|
|
28
|
-
ErrorCode["ReceiptFinished"] = "E_RECEIPT_FINISHED";
|
|
29
|
-
ErrorCode["ReceiptFinishedFailed"] = "E_RECEIPT_FINISHED_FAILED";
|
|
30
|
-
ErrorCode["NotPrepared"] = "E_NOT_PREPARED";
|
|
31
|
-
ErrorCode["NotEnded"] = "E_NOT_ENDED";
|
|
32
|
-
ErrorCode["AlreadyOwned"] = "E_ALREADY_OWNED";
|
|
33
|
-
ErrorCode["DeveloperError"] = "E_DEVELOPER_ERROR";
|
|
34
|
-
ErrorCode["BillingResponseJsonParseError"] = "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
|
|
35
|
-
ErrorCode["DeferredPayment"] = "E_DEFERRED_PAYMENT";
|
|
36
|
-
ErrorCode["Interrupted"] = "E_INTERRUPTED";
|
|
37
|
-
ErrorCode["IapNotAvailable"] = "E_IAP_NOT_AVAILABLE";
|
|
38
|
-
ErrorCode["PurchaseError"] = "E_PURCHASE_ERROR";
|
|
39
|
-
ErrorCode["SyncError"] = "E_SYNC_ERROR";
|
|
40
|
-
ErrorCode["TransactionValidationFailed"] = "E_TRANSACTION_VALIDATION_FAILED";
|
|
41
|
-
ErrorCode["ActivityUnavailable"] = "E_ACTIVITY_UNAVAILABLE";
|
|
42
|
-
ErrorCode["AlreadyPrepared"] = "E_ALREADY_PREPARED";
|
|
43
|
-
ErrorCode["Pending"] = "E_PENDING";
|
|
44
|
-
ErrorCode["ConnectionClosed"] = "E_CONNECTION_CLOSED";
|
|
45
|
-
// Additional detailed errors (Android-focused, kept cross-platform)
|
|
46
|
-
ErrorCode["InitConnection"] = "E_INIT_CONNECTION";
|
|
47
|
-
ErrorCode["ServiceDisconnected"] = "E_SERVICE_DISCONNECTED";
|
|
48
|
-
ErrorCode["QueryProduct"] = "E_QUERY_PRODUCT";
|
|
49
|
-
ErrorCode["SkuNotFound"] = "E_SKU_NOT_FOUND";
|
|
50
|
-
ErrorCode["SkuOfferMismatch"] = "E_SKU_OFFER_MISMATCH";
|
|
51
|
-
ErrorCode["ItemNotOwned"] = "E_ITEM_NOT_OWNED";
|
|
52
|
-
ErrorCode["BillingUnavailable"] = "E_BILLING_UNAVAILABLE";
|
|
53
|
-
ErrorCode["FeatureNotSupported"] = "E_FEATURE_NOT_SUPPORTED";
|
|
54
|
-
ErrorCode["EmptySkuList"] = "E_EMPTY_SKU_LIST";
|
|
55
|
-
})(ErrorCode || (ErrorCode = {}));
|
|
56
|
-
// Fast lookup set for validating standardized error code strings
|
|
57
|
-
const OPENIAP_ERROR_CODE_SET = new Set(Object.values(ErrorCode));
|
|
58
|
-
/**
|
|
59
|
-
* Platform-specific error code mappings
|
|
60
|
-
* Maps ErrorCode enum values to platform-specific integer codes
|
|
61
|
-
*/
|
|
62
|
-
// Shared OpenIAP string code mapping for both platforms
|
|
63
|
-
const COMMON_ERROR_CODE_MAP = {
|
|
64
|
-
[ErrorCode.Unknown]: 'E_UNKNOWN',
|
|
65
|
-
[ErrorCode.UserCancelled]: 'E_USER_CANCELLED',
|
|
66
|
-
[ErrorCode.UserError]: 'E_USER_ERROR',
|
|
67
|
-
[ErrorCode.ItemUnavailable]: 'E_ITEM_UNAVAILABLE',
|
|
68
|
-
[ErrorCode.RemoteError]: 'E_REMOTE_ERROR',
|
|
69
|
-
[ErrorCode.NetworkError]: 'E_NETWORK_ERROR',
|
|
70
|
-
[ErrorCode.ServiceError]: 'E_SERVICE_ERROR',
|
|
71
|
-
[ErrorCode.ReceiptFailed]: 'E_RECEIPT_FAILED',
|
|
72
|
-
[ErrorCode.ReceiptFinished]: 'E_RECEIPT_FINISHED',
|
|
73
|
-
[ErrorCode.ReceiptFinishedFailed]: 'E_RECEIPT_FINISHED_FAILED',
|
|
74
|
-
[ErrorCode.NotPrepared]: 'E_NOT_PREPARED',
|
|
75
|
-
[ErrorCode.NotEnded]: 'E_NOT_ENDED',
|
|
76
|
-
[ErrorCode.AlreadyOwned]: 'E_ALREADY_OWNED',
|
|
77
|
-
[ErrorCode.DeveloperError]: 'E_DEVELOPER_ERROR',
|
|
78
|
-
[ErrorCode.BillingResponseJsonParseError]: 'E_BILLING_RESPONSE_JSON_PARSE_ERROR',
|
|
79
|
-
[ErrorCode.DeferredPayment]: 'E_DEFERRED_PAYMENT',
|
|
80
|
-
[ErrorCode.Interrupted]: 'E_INTERRUPTED',
|
|
81
|
-
[ErrorCode.IapNotAvailable]: 'E_IAP_NOT_AVAILABLE',
|
|
82
|
-
[ErrorCode.PurchaseError]: 'E_PURCHASE_ERROR',
|
|
83
|
-
[ErrorCode.SyncError]: 'E_SYNC_ERROR',
|
|
84
|
-
[ErrorCode.TransactionValidationFailed]: 'E_TRANSACTION_VALIDATION_FAILED',
|
|
85
|
-
[ErrorCode.ActivityUnavailable]: 'E_ACTIVITY_UNAVAILABLE',
|
|
86
|
-
[ErrorCode.AlreadyPrepared]: 'E_ALREADY_PREPARED',
|
|
87
|
-
[ErrorCode.Pending]: 'E_PENDING',
|
|
88
|
-
[ErrorCode.ConnectionClosed]: 'E_CONNECTION_CLOSED',
|
|
89
|
-
[ErrorCode.InitConnection]: 'E_INIT_CONNECTION',
|
|
90
|
-
[ErrorCode.ServiceDisconnected]: 'E_SERVICE_DISCONNECTED',
|
|
91
|
-
[ErrorCode.QueryProduct]: 'E_QUERY_PRODUCT',
|
|
92
|
-
[ErrorCode.SkuNotFound]: 'E_SKU_NOT_FOUND',
|
|
93
|
-
[ErrorCode.SkuOfferMismatch]: 'E_SKU_OFFER_MISMATCH',
|
|
94
|
-
[ErrorCode.ItemNotOwned]: 'E_ITEM_NOT_OWNED',
|
|
95
|
-
[ErrorCode.BillingUnavailable]: 'E_BILLING_UNAVAILABLE',
|
|
96
|
-
[ErrorCode.FeatureNotSupported]: 'E_FEATURE_NOT_SUPPORTED',
|
|
97
|
-
[ErrorCode.EmptySkuList]: 'E_EMPTY_SKU_LIST',
|
|
98
|
-
};
|
|
99
|
-
export const ErrorCodeMapping = {
|
|
100
|
-
// iOS: standardized OpenIAP string codes
|
|
101
|
-
ios: COMMON_ERROR_CODE_MAP,
|
|
102
|
-
// Android: standardized OpenIAP string codes
|
|
103
|
-
android: COMMON_ERROR_CODE_MAP,
|
|
104
|
-
};
|
|
105
|
-
export class PurchaseError {
|
|
106
|
-
name;
|
|
107
|
-
message;
|
|
108
|
-
responseCode;
|
|
109
|
-
debugMessage;
|
|
110
|
-
code;
|
|
111
|
-
productId;
|
|
112
|
-
platform;
|
|
113
|
-
// Backwards-compatible constructor: accepts either props object or legacy positional args
|
|
114
|
-
constructor(messageOrProps, ...rest) {
|
|
115
|
-
this.name = '[expo-iap]: PurchaseError';
|
|
116
|
-
if (typeof messageOrProps === 'string') {
|
|
117
|
-
// Legacy signature: (name, message, responseCode?, debugMessage?, code?, productId?, platform?)
|
|
118
|
-
// The first legacy argument was a name which we always override, so treat it as message here
|
|
119
|
-
const message = messageOrProps;
|
|
120
|
-
this.message = message;
|
|
121
|
-
this.responseCode = rest[0];
|
|
122
|
-
this.debugMessage = rest[1];
|
|
123
|
-
this.code = rest[2];
|
|
124
|
-
this.productId = rest[3];
|
|
125
|
-
this.platform = rest[4];
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const props = messageOrProps;
|
|
129
|
-
this.message = props.message;
|
|
130
|
-
this.responseCode = props.responseCode;
|
|
131
|
-
this.debugMessage = props.debugMessage;
|
|
132
|
-
this.code = props.code;
|
|
133
|
-
this.productId = props.productId;
|
|
134
|
-
this.platform = props.platform;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Creates a PurchaseError from platform-specific error data
|
|
139
|
-
* @param errorData Raw error data from native modules
|
|
140
|
-
* @param platform Platform where the error occurred
|
|
141
|
-
* @returns Properly typed PurchaseError instance
|
|
142
|
-
*/
|
|
143
|
-
static fromPlatformError(errorData, platform) {
|
|
144
|
-
const errorCode = errorData.code
|
|
145
|
-
? ErrorCodeUtils.fromPlatformCode(errorData.code, platform)
|
|
146
|
-
: ErrorCode.Unknown;
|
|
147
|
-
return new PurchaseError({
|
|
148
|
-
message: errorData.message || 'Unknown error occurred',
|
|
149
|
-
responseCode: errorData.responseCode,
|
|
150
|
-
debugMessage: errorData.debugMessage,
|
|
151
|
-
code: errorCode,
|
|
152
|
-
productId: errorData.productId,
|
|
153
|
-
platform,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Gets the platform-specific error code for this error
|
|
158
|
-
* @returns Platform-specific error code
|
|
159
|
-
*/
|
|
160
|
-
getPlatformCode() {
|
|
161
|
-
if (!this.code || !this.platform)
|
|
162
|
-
return undefined;
|
|
163
|
-
return ErrorCodeUtils.toPlatformCode(this.code, this.platform);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Utility functions for error code mapping and validation
|
|
168
|
-
*/
|
|
169
|
-
export const ErrorCodeUtils = {
|
|
170
|
-
/**
|
|
171
|
-
* Gets the native error code for the current platform
|
|
172
|
-
* @param errorCode ErrorCode enum value
|
|
173
|
-
* @returns Platform-specific error code from native constants
|
|
174
|
-
*/
|
|
175
|
-
getNativeErrorCode: (errorCode) => {
|
|
176
|
-
return NATIVE_ERROR_CODES[errorCode] || errorCode;
|
|
177
|
-
},
|
|
178
|
-
/**
|
|
179
|
-
* Maps a platform-specific error code back to the standardized ErrorCode enum
|
|
180
|
-
* @param platformCode Platform-specific error code (string for Android, number for iOS)
|
|
181
|
-
* @param platform Target platform
|
|
182
|
-
* @returns Corresponding ErrorCode enum value or E_UNKNOWN if not found
|
|
183
|
-
*/
|
|
184
|
-
fromPlatformCode: (platformCode, platform) => {
|
|
185
|
-
// If native sent standardized string code, accept it directly
|
|
186
|
-
if (typeof platformCode === 'string' && platformCode.startsWith('E_')) {
|
|
187
|
-
if (OPENIAP_ERROR_CODE_SET.has(platformCode)) {
|
|
188
|
-
return platformCode;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
// Prefer dynamic native mapping for iOS to avoid drift
|
|
192
|
-
if (platform === 'ios') {
|
|
193
|
-
for (const [, value] of Object.entries(NATIVE_ERROR_CODES || {})) {
|
|
194
|
-
if (value === platformCode) {
|
|
195
|
-
// Native maps friendly keys to standardized 'E_*' codes
|
|
196
|
-
if (typeof value === 'string' && OPENIAP_ERROR_CODE_SET.has(value)) {
|
|
197
|
-
return value;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
const mapping = ErrorCodeMapping[platform];
|
|
203
|
-
for (const [errorCode, mappedCode] of Object.entries(mapping)) {
|
|
204
|
-
if (mappedCode === platformCode) {
|
|
205
|
-
return errorCode;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
return ErrorCode.Unknown;
|
|
209
|
-
},
|
|
210
|
-
/**
|
|
211
|
-
* Maps an ErrorCode enum to platform-specific code
|
|
212
|
-
* @param errorCode ErrorCode enum value
|
|
213
|
-
* @param platform Target platform
|
|
214
|
-
* @returns Platform-specific error code
|
|
215
|
-
*/
|
|
216
|
-
toPlatformCode: (errorCode, platform) => {
|
|
217
|
-
if (platform === 'ios') {
|
|
218
|
-
const native = NATIVE_ERROR_CODES?.[errorCode];
|
|
219
|
-
if (native !== undefined)
|
|
220
|
-
return native;
|
|
221
|
-
}
|
|
222
|
-
const mapping = ErrorCodeMapping[platform];
|
|
223
|
-
return mapping[errorCode] ?? 'E_UNKNOWN';
|
|
224
|
-
},
|
|
225
|
-
/**
|
|
226
|
-
* Checks if an error code is valid for the specified platform
|
|
227
|
-
* @param errorCode ErrorCode enum value
|
|
228
|
-
* @param platform Target platform
|
|
229
|
-
* @returns True if the error code is supported on the platform
|
|
230
|
-
*/
|
|
231
|
-
isValidForPlatform: (errorCode, platform) => {
|
|
232
|
-
return errorCode in ErrorCodeMapping[platform];
|
|
233
|
-
},
|
|
234
|
-
};
|
|
235
|
-
//# sourceMappingURL=ExpoIap.types.js.map
|