expo-iap 3.0.2 → 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.
Files changed (59) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/CLAUDE.md +2 -0
  3. package/build/helpers/subscription.d.ts +1 -12
  4. package/build/helpers/subscription.d.ts.map +1 -1
  5. package/build/helpers/subscription.js +12 -7
  6. package/build/helpers/subscription.js.map +1 -1
  7. package/build/index.d.ts +9 -7
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +6 -4
  10. package/build/index.js.map +1 -1
  11. package/build/modules/android.d.ts +7 -6
  12. package/build/modules/android.d.ts.map +1 -1
  13. package/build/modules/android.js +19 -4
  14. package/build/modules/android.js.map +1 -1
  15. package/build/modules/ios.d.ts +7 -10
  16. package/build/modules/ios.d.ts.map +1 -1
  17. package/build/modules/ios.js +3 -1
  18. package/build/modules/ios.js.map +1 -1
  19. package/build/purchase-error.d.ts +69 -0
  20. package/build/purchase-error.d.ts.map +1 -0
  21. package/build/purchase-error.js +164 -0
  22. package/build/purchase-error.js.map +1 -0
  23. package/build/types.d.ts +649 -0
  24. package/build/types.d.ts.map +1 -0
  25. package/build/types.js +100 -0
  26. package/build/types.js.map +1 -0
  27. package/build/useIAP.d.ts +6 -5
  28. package/build/useIAP.d.ts.map +1 -1
  29. package/build/useIAP.js +2 -3
  30. package/build/useIAP.js.map +1 -1
  31. package/build/utils/errorMapping.d.ts +10 -4
  32. package/build/utils/errorMapping.d.ts.map +1 -1
  33. package/build/utils/errorMapping.js +71 -47
  34. package/build/utils/errorMapping.js.map +1 -1
  35. package/jest.config.js +1 -1
  36. package/package.json +1 -1
  37. package/src/helpers/subscription.ts +12 -20
  38. package/src/index.ts +20 -20
  39. package/src/modules/android.ts +28 -10
  40. package/src/modules/ios.ts +11 -13
  41. package/src/purchase-error.ts +268 -0
  42. package/src/types.ts +738 -0
  43. package/src/useIAP.ts +15 -18
  44. package/src/utils/errorMapping.ts +89 -55
  45. package/build/ExpoIap.types.d.ts +0 -294
  46. package/build/ExpoIap.types.d.ts.map +0 -1
  47. package/build/ExpoIap.types.js +0 -226
  48. package/build/ExpoIap.types.js.map +0 -1
  49. package/build/types/ExpoIapAndroid.types.d.ts +0 -115
  50. package/build/types/ExpoIapAndroid.types.d.ts.map +0 -1
  51. package/build/types/ExpoIapAndroid.types.js +0 -29
  52. package/build/types/ExpoIapAndroid.types.js.map +0 -1
  53. package/build/types/ExpoIapIOS.types.d.ts +0 -143
  54. package/build/types/ExpoIapIOS.types.d.ts.map +0 -1
  55. package/build/types/ExpoIapIOS.types.js +0 -2
  56. package/build/types/ExpoIapIOS.types.js.map +0 -1
  57. package/src/ExpoIap.types.ts +0 -429
  58. package/src/types/ExpoIapAndroid.types.ts +0 -136
  59. package/src/types/ExpoIapIOS.types.ts +0 -167
package/src/useIAP.ts CHANGED
@@ -29,13 +29,13 @@ import {
29
29
  import {
30
30
  Product,
31
31
  Purchase,
32
- PurchaseError,
33
- PurchaseResult,
34
- SubscriptionProduct,
32
+ ProductSubscription,
35
33
  RequestPurchaseProps,
36
- RequestSubscriptionProps,
34
+ RequestSubscriptionPropsByPlatforms,
37
35
  ErrorCode,
38
- } from './ExpoIap.types';
36
+ VoidResult,
37
+ } from './types';
38
+ import {PurchaseError} from './purchase-error';
39
39
  import {
40
40
  getUserFriendlyErrorMessage,
41
41
  isUserCancelledError,
@@ -51,7 +51,7 @@ type UseIap = {
51
51
  products: Product[];
52
52
  promotedProductsIOS: Purchase[];
53
53
  promotedProductIdIOS?: string;
54
- subscriptions: SubscriptionProduct[];
54
+ subscriptions: ProductSubscription[];
55
55
  availablePurchases: Purchase[];
56
56
  currentPurchase?: Purchase;
57
57
  currentPurchaseError?: PurchaseError;
@@ -65,15 +65,15 @@ type UseIap = {
65
65
  }: {
66
66
  purchase: Purchase;
67
67
  isConsumable?: boolean;
68
- }) => Promise<PurchaseResult | boolean>;
69
- getAvailablePurchases: (skus: string[]) => Promise<void>;
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 | RequestSubscriptionProps;
76
+ request: RequestPurchaseProps | RequestSubscriptionPropsByPlatforms;
77
77
  type?: 'inapp' | 'subs';
78
78
  }) => Promise<any>;
79
79
  validateReceipt: (
@@ -108,7 +108,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
108
108
  const [connected, setConnected] = useState<boolean>(false);
109
109
  const [products, setProducts] = useState<Product[]>([]);
110
110
  const [promotedProductsIOS] = useState<Purchase[]>([]);
111
- const [subscriptions, setSubscriptions] = useState<SubscriptionProduct[]>([]);
111
+ const [subscriptions, setSubscriptions] = useState<ProductSubscription[]>([]);
112
112
 
113
113
  const [availablePurchases, setAvailablePurchases] = useState<Purchase[]>([]);
114
114
  const [currentPurchase, setCurrentPurchase] = useState<Purchase>();
@@ -159,7 +159,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
159
159
  promotedProductIOS?: EventSubscription;
160
160
  }>({});
161
161
 
162
- const subscriptionsRefState = useRef<SubscriptionProduct[]>([]);
162
+ const subscriptionsRefState = useRef<ProductSubscription[]>([]);
163
163
 
164
164
  useEffect(() => {
165
165
  subscriptionsRefState.current = subscriptions;
@@ -180,7 +180,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
180
180
  setSubscriptions((prevSubscriptions) =>
181
181
  mergeWithDuplicateCheck(
182
182
  prevSubscriptions,
183
- result as SubscriptionProduct[],
183
+ result as ProductSubscription[],
184
184
  (subscription) => subscription.id,
185
185
  ),
186
186
  );
@@ -203,7 +203,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
203
203
  setSubscriptions((prevSubscriptions) =>
204
204
  mergeWithDuplicateCheck(
205
205
  prevSubscriptions,
206
- result as SubscriptionProduct[],
206
+ result as ProductSubscription[],
207
207
  (subscription) => subscription.id,
208
208
  ),
209
209
  );
@@ -267,7 +267,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
267
267
  }: {
268
268
  purchase: Purchase;
269
269
  isConsumable?: boolean;
270
- }): Promise<PurchaseResult | boolean> => {
270
+ }): Promise<VoidResult | boolean> => {
271
271
  try {
272
272
  return await finishTransactionInternal({
273
273
  purchase,
@@ -384,10 +384,7 @@ export function useIAP(options?: UseIAPOptions): UseIap {
384
384
  // Register purchase error listener EARLY. Ignore init-related errors until connected.
385
385
  subscriptionsRef.current.purchaseError = purchaseErrorListener(
386
386
  (error: PurchaseError) => {
387
- if (
388
- !connectedRef.current &&
389
- error.code === ErrorCode.E_INIT_CONNECTION
390
- ) {
387
+ if (!connectedRef.current && error.code === ErrorCode.InitConnection) {
391
388
  return; // Ignore initialization error before connected
392
389
  }
393
390
  const friendly = getUserFriendlyErrorMessage(error);
@@ -3,23 +3,50 @@
3
3
  * Provides helper functions for handling platform-specific errors
4
4
  */
5
5
 
6
- import {ErrorCode} from '../ExpoIap.types';
6
+ import {ErrorCode} from '../types';
7
7
 
8
- /**
9
- * Checks if an error is a user cancellation
10
- * @param error Error object or error code
11
- * @returns True if the error represents user cancellation
12
- */
13
- export function isUserCancelledError(error: any): boolean {
8
+ type ErrorLike = string | {code?: ErrorCode | string; message?: string};
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
+
31
+ function extractCode(error: unknown): string | undefined {
14
32
  if (typeof error === 'string') {
15
- return error === ErrorCode.E_USER_CANCELLED;
33
+ return normalizeErrorCode(error);
16
34
  }
17
35
 
18
- if (error && error.code) {
19
- return error.code === ErrorCode.E_USER_CANCELLED;
36
+ if (error && typeof error === 'object' && 'code' in error) {
37
+ return normalizeErrorCode((error as {code?: string}).code);
20
38
  }
21
39
 
22
- return false;
40
+ return undefined;
41
+ }
42
+
43
+ /**
44
+ * Checks if an error is a user cancellation
45
+ * @param error Error object or error code
46
+ * @returns True if the error represents user cancellation
47
+ */
48
+ export function isUserCancelledError(error: unknown): boolean {
49
+ return extractCode(error) === ErrorCode.UserCancelled;
23
50
  }
24
51
 
25
52
  /**
@@ -27,17 +54,17 @@ export function isUserCancelledError(error: any): boolean {
27
54
  * @param error Error object or error code
28
55
  * @returns True if the error is network-related
29
56
  */
30
- export function isNetworkError(error: any): boolean {
31
- const networkErrors = [
32
- ErrorCode.E_NETWORK_ERROR,
33
- ErrorCode.E_REMOTE_ERROR,
34
- ErrorCode.E_SERVICE_ERROR,
35
- ErrorCode.E_SERVICE_DISCONNECTED,
36
- ErrorCode.E_BILLING_UNAVAILABLE,
57
+ export function isNetworkError(error: unknown): boolean {
58
+ const networkErrors: ErrorCode[] = [
59
+ ErrorCode.NetworkError,
60
+ ErrorCode.RemoteError,
61
+ ErrorCode.ServiceError,
62
+ ErrorCode.ServiceDisconnected,
63
+ ErrorCode.BillingUnavailable,
37
64
  ];
38
65
 
39
- const errorCode = typeof error === 'string' ? error : error?.code;
40
- return networkErrors.includes(errorCode);
66
+ const code = extractCode(error);
67
+ return !!code && (networkErrors as string[]).includes(code);
41
68
  }
42
69
 
43
70
  /**
@@ -45,20 +72,20 @@ export function isNetworkError(error: any): boolean {
45
72
  * @param error Error object or error code
46
73
  * @returns True if the error is potentially recoverable
47
74
  */
48
- export function isRecoverableError(error: any): boolean {
49
- const recoverableErrors = [
50
- ErrorCode.E_NETWORK_ERROR,
51
- ErrorCode.E_REMOTE_ERROR,
52
- ErrorCode.E_SERVICE_ERROR,
53
- ErrorCode.E_INTERRUPTED,
54
- ErrorCode.E_SERVICE_DISCONNECTED,
55
- ErrorCode.E_BILLING_UNAVAILABLE,
56
- ErrorCode.E_QUERY_PRODUCT,
57
- ErrorCode.E_INIT_CONNECTION,
75
+ export function isRecoverableError(error: unknown): boolean {
76
+ const recoverableErrors: ErrorCode[] = [
77
+ ErrorCode.NetworkError,
78
+ ErrorCode.RemoteError,
79
+ ErrorCode.ServiceError,
80
+ ErrorCode.Interrupted,
81
+ ErrorCode.ServiceDisconnected,
82
+ ErrorCode.BillingUnavailable,
83
+ ErrorCode.QueryProduct,
84
+ ErrorCode.InitConnection,
58
85
  ];
59
86
 
60
- const errorCode = typeof error === 'string' ? error : error?.code;
61
- return recoverableErrors.includes(errorCode);
87
+ const code = extractCode(error);
88
+ return !!code && (recoverableErrors as string[]).includes(code);
62
89
  }
63
90
 
64
91
  /**
@@ -66,49 +93,56 @@ export function isRecoverableError(error: any): boolean {
66
93
  * @param error Error object or error code
67
94
  * @returns User-friendly error message
68
95
  */
69
- export function getUserFriendlyErrorMessage(error: any): string {
70
- const errorCode = typeof error === 'string' ? error : error?.code;
96
+ export function getUserFriendlyErrorMessage(error: ErrorLike): string {
97
+ const errorCode = extractCode(error);
71
98
 
72
99
  switch (errorCode) {
73
- case ErrorCode.E_USER_CANCELLED:
100
+ case ErrorCode.UserCancelled:
74
101
  return 'Purchase was cancelled by user';
75
- case ErrorCode.E_NETWORK_ERROR:
102
+ case ErrorCode.NetworkError:
76
103
  return 'Network connection error. Please check your internet connection and try again.';
77
- case ErrorCode.E_RECEIPT_FINISHED:
104
+ case ErrorCode.ReceiptFinished:
78
105
  return 'Receipt already finished';
79
- case ErrorCode.E_SERVICE_DISCONNECTED:
106
+ case ErrorCode.ServiceDisconnected:
80
107
  return 'Billing service disconnected. Please try again.';
81
- case ErrorCode.E_BILLING_UNAVAILABLE:
108
+ case ErrorCode.BillingUnavailable:
82
109
  return 'Billing is unavailable on this device or account.';
83
- case ErrorCode.E_ITEM_UNAVAILABLE:
110
+ case ErrorCode.ItemUnavailable:
84
111
  return 'This item is not available for purchase';
85
- case ErrorCode.E_ITEM_NOT_OWNED:
112
+ case ErrorCode.ItemNotOwned:
86
113
  return "You don't own this item";
87
- case ErrorCode.E_ALREADY_OWNED:
114
+ case ErrorCode.AlreadyOwned:
88
115
  return 'You already own this item';
89
- case ErrorCode.E_SKU_NOT_FOUND:
116
+ case ErrorCode.SkuNotFound:
90
117
  return 'Requested product could not be found';
91
- case ErrorCode.E_SKU_OFFER_MISMATCH:
118
+ case ErrorCode.SkuOfferMismatch:
92
119
  return 'Selected offer does not match the SKU';
93
- case ErrorCode.E_DEFERRED_PAYMENT:
120
+ case ErrorCode.DeferredPayment:
94
121
  return 'Payment is pending approval';
95
- case ErrorCode.E_NOT_PREPARED:
122
+ case ErrorCode.NotPrepared:
96
123
  return 'In-app purchase is not ready. Please try again later.';
97
- case ErrorCode.E_SERVICE_ERROR:
124
+ case ErrorCode.ServiceError:
98
125
  return 'Store service error. Please try again later.';
99
- case ErrorCode.E_FEATURE_NOT_SUPPORTED:
126
+ case ErrorCode.FeatureNotSupported:
100
127
  return 'This feature is not supported on this device.';
101
- case ErrorCode.E_TRANSACTION_VALIDATION_FAILED:
128
+ case ErrorCode.TransactionValidationFailed:
102
129
  return 'Transaction could not be verified';
103
- case ErrorCode.E_RECEIPT_FAILED:
130
+ case ErrorCode.ReceiptFailed:
104
131
  return 'Receipt processing failed';
105
- case ErrorCode.E_EMPTY_SKU_LIST:
132
+ case ErrorCode.EmptySkuList:
106
133
  return 'No product IDs provided';
107
- case ErrorCode.E_INIT_CONNECTION:
134
+ case ErrorCode.InitConnection:
108
135
  return 'Failed to initialize billing connection';
109
- case ErrorCode.E_QUERY_PRODUCT:
136
+ case ErrorCode.QueryProduct:
110
137
  return 'Failed to query products. Please try again later.';
111
- default:
112
- return error?.message || 'An unexpected error occurred';
138
+ default: {
139
+ if (error && typeof error === 'object' && 'message' in error) {
140
+ return (
141
+ (error as {message?: string}).message ??
142
+ 'An unexpected error occurred'
143
+ );
144
+ }
145
+ return 'An unexpected error occurred';
146
+ }
113
147
  }
114
148
  }
@@ -1,294 +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 type ProductCommon = {
8
- id: string;
9
- title: string;
10
- description: string;
11
- type: ProductType;
12
- displayName?: string;
13
- displayPrice: string;
14
- currency: string;
15
- price?: number;
16
- debugDescription?: string;
17
- platform?: string;
18
- };
19
- export type PurchaseCommon = {
20
- id: string;
21
- productId: string;
22
- ids?: string[];
23
- transactionDate: number;
24
- transactionReceipt: string;
25
- purchaseToken?: string;
26
- platform?: string;
27
- };
28
- export type ProductSubscriptionCommon = ProductCommon & {
29
- type: 'subs';
30
- };
31
- export type IosPlatform = {
32
- platform: 'ios';
33
- };
34
- export type AndroidPlatform = {
35
- platform: 'android';
36
- };
37
- export type Product = (ProductAndroid & AndroidPlatform) | (ProductIOS & IosPlatform);
38
- export type SubscriptionProduct = (ProductSubscriptionAndroid & AndroidPlatform) | (ProductSubscriptionIOS & IosPlatform);
39
- export * from './types/ExpoIapAndroid.types';
40
- export * from './types/ExpoIapIOS.types';
41
- export type Purchase = (PurchaseAndroid & AndroidPlatform) | (PurchaseIOS & IosPlatform);
42
- export type PurchaseResult = {
43
- responseCode?: number;
44
- debugMessage?: string;
45
- code?: string;
46
- message?: string;
47
- purchaseToken?: string;
48
- };
49
- /**
50
- * Centralized error codes for expo-iap
51
- * These are mapped to platform-specific error codes and provide consistent error handling
52
- */
53
- export declare enum ErrorCode {
54
- E_UNKNOWN = "E_UNKNOWN",
55
- E_USER_CANCELLED = "E_USER_CANCELLED",
56
- E_USER_ERROR = "E_USER_ERROR",
57
- E_ITEM_UNAVAILABLE = "E_ITEM_UNAVAILABLE",
58
- E_REMOTE_ERROR = "E_REMOTE_ERROR",
59
- E_NETWORK_ERROR = "E_NETWORK_ERROR",
60
- E_SERVICE_ERROR = "E_SERVICE_ERROR",
61
- E_RECEIPT_FAILED = "E_RECEIPT_FAILED",
62
- E_RECEIPT_FINISHED = "E_RECEIPT_FINISHED",
63
- E_RECEIPT_FINISHED_FAILED = "E_RECEIPT_FINISHED_FAILED",
64
- E_NOT_PREPARED = "E_NOT_PREPARED",
65
- E_NOT_ENDED = "E_NOT_ENDED",
66
- E_ALREADY_OWNED = "E_ALREADY_OWNED",
67
- E_DEVELOPER_ERROR = "E_DEVELOPER_ERROR",
68
- E_BILLING_RESPONSE_JSON_PARSE_ERROR = "E_BILLING_RESPONSE_JSON_PARSE_ERROR",
69
- E_DEFERRED_PAYMENT = "E_DEFERRED_PAYMENT",
70
- E_INTERRUPTED = "E_INTERRUPTED",
71
- E_IAP_NOT_AVAILABLE = "E_IAP_NOT_AVAILABLE",
72
- E_PURCHASE_ERROR = "E_PURCHASE_ERROR",
73
- E_SYNC_ERROR = "E_SYNC_ERROR",
74
- E_TRANSACTION_VALIDATION_FAILED = "E_TRANSACTION_VALIDATION_FAILED",
75
- E_ACTIVITY_UNAVAILABLE = "E_ACTIVITY_UNAVAILABLE",
76
- E_ALREADY_PREPARED = "E_ALREADY_PREPARED",
77
- E_PENDING = "E_PENDING",
78
- E_CONNECTION_CLOSED = "E_CONNECTION_CLOSED",
79
- E_INIT_CONNECTION = "E_INIT_CONNECTION",
80
- E_SERVICE_DISCONNECTED = "E_SERVICE_DISCONNECTED",
81
- E_QUERY_PRODUCT = "E_QUERY_PRODUCT",
82
- E_SKU_NOT_FOUND = "E_SKU_NOT_FOUND",
83
- E_SKU_OFFER_MISMATCH = "E_SKU_OFFER_MISMATCH",
84
- E_ITEM_NOT_OWNED = "E_ITEM_NOT_OWNED",
85
- E_BILLING_UNAVAILABLE = "E_BILLING_UNAVAILABLE",
86
- E_FEATURE_NOT_SUPPORTED = "E_FEATURE_NOT_SUPPORTED",
87
- E_EMPTY_SKU_LIST = "E_EMPTY_SKU_LIST"
88
- }
89
- export declare const ErrorCodeMapping: {
90
- readonly ios: {
91
- readonly E_UNKNOWN: "E_UNKNOWN";
92
- readonly E_USER_CANCELLED: "E_USER_CANCELLED";
93
- readonly E_USER_ERROR: "E_USER_ERROR";
94
- readonly E_ITEM_UNAVAILABLE: "E_ITEM_UNAVAILABLE";
95
- readonly E_REMOTE_ERROR: "E_REMOTE_ERROR";
96
- readonly E_NETWORK_ERROR: "E_NETWORK_ERROR";
97
- readonly E_SERVICE_ERROR: "E_SERVICE_ERROR";
98
- readonly E_RECEIPT_FAILED: "E_RECEIPT_FAILED";
99
- readonly E_RECEIPT_FINISHED: "E_RECEIPT_FINISHED";
100
- readonly E_RECEIPT_FINISHED_FAILED: "E_RECEIPT_FINISHED_FAILED";
101
- readonly E_NOT_PREPARED: "E_NOT_PREPARED";
102
- readonly E_NOT_ENDED: "E_NOT_ENDED";
103
- readonly E_ALREADY_OWNED: "E_ALREADY_OWNED";
104
- readonly E_DEVELOPER_ERROR: "E_DEVELOPER_ERROR";
105
- readonly E_BILLING_RESPONSE_JSON_PARSE_ERROR: "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
106
- readonly E_DEFERRED_PAYMENT: "E_DEFERRED_PAYMENT";
107
- readonly E_INTERRUPTED: "E_INTERRUPTED";
108
- readonly E_IAP_NOT_AVAILABLE: "E_IAP_NOT_AVAILABLE";
109
- readonly E_PURCHASE_ERROR: "E_PURCHASE_ERROR";
110
- readonly E_SYNC_ERROR: "E_SYNC_ERROR";
111
- readonly E_TRANSACTION_VALIDATION_FAILED: "E_TRANSACTION_VALIDATION_FAILED";
112
- readonly E_ACTIVITY_UNAVAILABLE: "E_ACTIVITY_UNAVAILABLE";
113
- readonly E_ALREADY_PREPARED: "E_ALREADY_PREPARED";
114
- readonly E_PENDING: "E_PENDING";
115
- readonly E_CONNECTION_CLOSED: "E_CONNECTION_CLOSED";
116
- readonly E_INIT_CONNECTION: "E_INIT_CONNECTION";
117
- readonly E_SERVICE_DISCONNECTED: "E_SERVICE_DISCONNECTED";
118
- readonly E_QUERY_PRODUCT: "E_QUERY_PRODUCT";
119
- readonly E_SKU_NOT_FOUND: "E_SKU_NOT_FOUND";
120
- readonly E_SKU_OFFER_MISMATCH: "E_SKU_OFFER_MISMATCH";
121
- readonly E_ITEM_NOT_OWNED: "E_ITEM_NOT_OWNED";
122
- readonly E_BILLING_UNAVAILABLE: "E_BILLING_UNAVAILABLE";
123
- readonly E_FEATURE_NOT_SUPPORTED: "E_FEATURE_NOT_SUPPORTED";
124
- readonly E_EMPTY_SKU_LIST: "E_EMPTY_SKU_LIST";
125
- };
126
- readonly android: {
127
- readonly E_UNKNOWN: "E_UNKNOWN";
128
- readonly E_USER_CANCELLED: "E_USER_CANCELLED";
129
- readonly E_USER_ERROR: "E_USER_ERROR";
130
- readonly E_ITEM_UNAVAILABLE: "E_ITEM_UNAVAILABLE";
131
- readonly E_REMOTE_ERROR: "E_REMOTE_ERROR";
132
- readonly E_NETWORK_ERROR: "E_NETWORK_ERROR";
133
- readonly E_SERVICE_ERROR: "E_SERVICE_ERROR";
134
- readonly E_RECEIPT_FAILED: "E_RECEIPT_FAILED";
135
- readonly E_RECEIPT_FINISHED: "E_RECEIPT_FINISHED";
136
- readonly E_RECEIPT_FINISHED_FAILED: "E_RECEIPT_FINISHED_FAILED";
137
- readonly E_NOT_PREPARED: "E_NOT_PREPARED";
138
- readonly E_NOT_ENDED: "E_NOT_ENDED";
139
- readonly E_ALREADY_OWNED: "E_ALREADY_OWNED";
140
- readonly E_DEVELOPER_ERROR: "E_DEVELOPER_ERROR";
141
- readonly E_BILLING_RESPONSE_JSON_PARSE_ERROR: "E_BILLING_RESPONSE_JSON_PARSE_ERROR";
142
- readonly E_DEFERRED_PAYMENT: "E_DEFERRED_PAYMENT";
143
- readonly E_INTERRUPTED: "E_INTERRUPTED";
144
- readonly E_IAP_NOT_AVAILABLE: "E_IAP_NOT_AVAILABLE";
145
- readonly E_PURCHASE_ERROR: "E_PURCHASE_ERROR";
146
- readonly E_SYNC_ERROR: "E_SYNC_ERROR";
147
- readonly E_TRANSACTION_VALIDATION_FAILED: "E_TRANSACTION_VALIDATION_FAILED";
148
- readonly E_ACTIVITY_UNAVAILABLE: "E_ACTIVITY_UNAVAILABLE";
149
- readonly E_ALREADY_PREPARED: "E_ALREADY_PREPARED";
150
- readonly E_PENDING: "E_PENDING";
151
- readonly E_CONNECTION_CLOSED: "E_CONNECTION_CLOSED";
152
- readonly E_INIT_CONNECTION: "E_INIT_CONNECTION";
153
- readonly E_SERVICE_DISCONNECTED: "E_SERVICE_DISCONNECTED";
154
- readonly E_QUERY_PRODUCT: "E_QUERY_PRODUCT";
155
- readonly E_SKU_NOT_FOUND: "E_SKU_NOT_FOUND";
156
- readonly E_SKU_OFFER_MISMATCH: "E_SKU_OFFER_MISMATCH";
157
- readonly E_ITEM_NOT_OWNED: "E_ITEM_NOT_OWNED";
158
- readonly E_BILLING_UNAVAILABLE: "E_BILLING_UNAVAILABLE";
159
- readonly E_FEATURE_NOT_SUPPORTED: "E_FEATURE_NOT_SUPPORTED";
160
- readonly E_EMPTY_SKU_LIST: "E_EMPTY_SKU_LIST";
161
- };
162
- };
163
- export type PurchaseErrorProps = {
164
- message: string;
165
- responseCode?: number;
166
- debugMessage?: string;
167
- code?: ErrorCode;
168
- productId?: string;
169
- platform?: 'ios' | 'android';
170
- };
171
- export declare class PurchaseError implements Error {
172
- name: string;
173
- message: string;
174
- responseCode?: number;
175
- debugMessage?: string;
176
- code?: ErrorCode;
177
- productId?: string;
178
- platform?: 'ios' | 'android';
179
- constructor(messageOrProps: string | PurchaseErrorProps, ...rest: any[]);
180
- /**
181
- * Creates a PurchaseError from platform-specific error data
182
- * @param errorData Raw error data from native modules
183
- * @param platform Platform where the error occurred
184
- * @returns Properly typed PurchaseError instance
185
- */
186
- static fromPlatformError(errorData: any, platform: 'ios' | 'android'): PurchaseError;
187
- /**
188
- * Gets the platform-specific error code for this error
189
- * @returns Platform-specific error code
190
- */
191
- getPlatformCode(): string | number | undefined;
192
- }
193
- /**
194
- * Utility functions for error code mapping and validation
195
- */
196
- export declare const ErrorCodeUtils: {
197
- /**
198
- * Gets the native error code for the current platform
199
- * @param errorCode ErrorCode enum value
200
- * @returns Platform-specific error code from native constants
201
- */
202
- getNativeErrorCode: (errorCode: ErrorCode) => string;
203
- /**
204
- * Maps a platform-specific error code back to the standardized ErrorCode enum
205
- * @param platformCode Platform-specific error code (string for Android, number for iOS)
206
- * @param platform Target platform
207
- * @returns Corresponding ErrorCode enum value or E_UNKNOWN if not found
208
- */
209
- fromPlatformCode: (platformCode: string | number, platform: "ios" | "android") => ErrorCode;
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: ErrorCode, platform: "ios" | "android") => string | number;
217
- /**
218
- * Checks if an error code is valid for the specified platform
219
- * @param errorCode ErrorCode enum value
220
- * @param platform Target platform
221
- * @returns True if the error code is supported on the platform
222
- */
223
- isValidForPlatform: (errorCode: ErrorCode, platform: "ios" | "android") => boolean;
224
- };
225
- /**
226
- * Unified request props that work on both iOS and Android platforms
227
- * iOS will use 'sku', Android will use 'skus' (or convert sku to skus array)
228
- */
229
- export interface UnifiedRequestPurchaseProps {
230
- readonly sku?: string;
231
- readonly skus?: string[];
232
- readonly andDangerouslyFinishTransactionAutomatically?: boolean;
233
- readonly appAccountToken?: string;
234
- readonly quantity?: number;
235
- readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;
236
- readonly obfuscatedAccountIdAndroid?: string;
237
- readonly obfuscatedProfileIdAndroid?: string;
238
- readonly isOfferPersonalized?: boolean;
239
- }
240
- /**
241
- * iOS-specific purchase request parameters
242
- */
243
- export interface RequestPurchaseIosProps {
244
- readonly sku: string;
245
- readonly andDangerouslyFinishTransactionAutomatically?: boolean;
246
- readonly appAccountToken?: string;
247
- readonly quantity?: number;
248
- readonly withOffer?: import('./types/ExpoIapIOS.types').PaymentDiscount;
249
- }
250
- /**
251
- * Android-specific purchase request parameters
252
- */
253
- export interface RequestPurchaseAndroidProps {
254
- readonly skus: string[];
255
- readonly obfuscatedAccountIdAndroid?: string;
256
- readonly obfuscatedProfileIdAndroid?: string;
257
- readonly isOfferPersonalized?: boolean;
258
- }
259
- /**
260
- * Android-specific subscription request parameters
261
- */
262
- export interface RequestSubscriptionAndroidProps extends RequestPurchaseAndroidProps {
263
- readonly replacementModeAndroid?: number;
264
- readonly subscriptionOffers: {
265
- sku: string;
266
- offerToken: string;
267
- }[];
268
- }
269
- /**
270
- * Modern platform-specific request structure (v2.7.0+)
271
- * Allows clear separation of iOS and Android parameters
272
- */
273
- export interface RequestPurchasePropsByPlatforms {
274
- readonly ios?: RequestPurchaseIosProps;
275
- readonly android?: RequestPurchaseAndroidProps;
276
- }
277
- /**
278
- * Modern platform-specific subscription request structure (v2.7.0+)
279
- */
280
- export interface RequestSubscriptionPropsByPlatforms {
281
- readonly ios?: RequestPurchaseIosProps;
282
- readonly android?: RequestSubscriptionAndroidProps;
283
- }
284
- /**
285
- * Modern request purchase parameters (v2.7.0+)
286
- * This is the recommended API moving forward
287
- */
288
- export type RequestPurchaseProps = RequestPurchasePropsByPlatforms;
289
- /**
290
- * Modern request subscription parameters (v2.7.0+)
291
- * This is the recommended API moving forward
292
- */
293
- export type RequestSubscriptionProps = RequestSubscriptionPropsByPlatforms;
294
- //# 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,eAAe,EACf,0BAA0B,EAC3B,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,M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