expo-iap 3.0.2 → 3.0.3
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 +5 -0
- package/build/ExpoIap.types.d.ts +49 -36
- package/build/ExpoIap.types.d.ts.map +1 -1
- package/build/ExpoIap.types.js +79 -70
- package/build/ExpoIap.types.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/types/ExpoIapAndroid.types.d.ts +2 -3
- package/build/types/ExpoIapAndroid.types.d.ts.map +1 -1
- package/build/types/ExpoIapAndroid.types.js.map +1 -1
- package/build/types/ExpoIapIOS.types.d.ts +7 -1
- package/build/types/ExpoIapIOS.types.d.ts.map +1 -1
- package/build/types/ExpoIapIOS.types.js +7 -1
- package/build/types/ExpoIapIOS.types.js.map +1 -1
- package/build/useIAP.d.ts +2 -2
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +1 -2
- package/build/useIAP.js.map +1 -1
- package/build/utils/errorMapping.d.ts +10 -4
- package/build/utils/errorMapping.d.ts.map +1 -1
- package/build/utils/errorMapping.js +54 -46
- package/build/utils/errorMapping.js.map +1 -1
- package/package.json +1 -1
- package/src/ExpoIap.types.ts +89 -74
- package/src/index.ts +6 -6
- package/src/types/ExpoIapAndroid.types.ts +2 -5
- package/src/types/ExpoIapIOS.types.ts +8 -3
- package/src/useIAP.ts +7 -10
- package/src/utils/errorMapping.ts +67 -54
|
@@ -5,21 +5,27 @@
|
|
|
5
5
|
|
|
6
6
|
import {ErrorCode} from '../ExpoIap.types';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
function extractCode(error: unknown): string | undefined {
|
|
14
11
|
if (typeof error === 'string') {
|
|
15
|
-
return error
|
|
12
|
+
return error;
|
|
16
13
|
}
|
|
17
14
|
|
|
18
|
-
if (error && error
|
|
19
|
-
return error
|
|
15
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
16
|
+
return (error as {code?: string}).code;
|
|
20
17
|
}
|
|
21
18
|
|
|
22
|
-
return
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Checks if an error is a user cancellation
|
|
24
|
+
* @param error Error object or error code
|
|
25
|
+
* @returns True if the error represents user cancellation
|
|
26
|
+
*/
|
|
27
|
+
export function isUserCancelledError(error: unknown): boolean {
|
|
28
|
+
return extractCode(error) === ErrorCode.UserCancelled;
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
/**
|
|
@@ -27,17 +33,17 @@ export function isUserCancelledError(error: any): boolean {
|
|
|
27
33
|
* @param error Error object or error code
|
|
28
34
|
* @returns True if the error is network-related
|
|
29
35
|
*/
|
|
30
|
-
export function isNetworkError(error:
|
|
31
|
-
const networkErrors = [
|
|
32
|
-
ErrorCode.
|
|
33
|
-
ErrorCode.
|
|
34
|
-
ErrorCode.
|
|
35
|
-
ErrorCode.
|
|
36
|
-
ErrorCode.
|
|
36
|
+
export function isNetworkError(error: unknown): boolean {
|
|
37
|
+
const networkErrors: ErrorCode[] = [
|
|
38
|
+
ErrorCode.NetworkError,
|
|
39
|
+
ErrorCode.RemoteError,
|
|
40
|
+
ErrorCode.ServiceError,
|
|
41
|
+
ErrorCode.ServiceDisconnected,
|
|
42
|
+
ErrorCode.BillingUnavailable,
|
|
37
43
|
];
|
|
38
44
|
|
|
39
|
-
const
|
|
40
|
-
return networkErrors.includes(
|
|
45
|
+
const code = extractCode(error);
|
|
46
|
+
return !!code && (networkErrors as string[]).includes(code);
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
/**
|
|
@@ -45,20 +51,20 @@ export function isNetworkError(error: any): boolean {
|
|
|
45
51
|
* @param error Error object or error code
|
|
46
52
|
* @returns True if the error is potentially recoverable
|
|
47
53
|
*/
|
|
48
|
-
export function isRecoverableError(error:
|
|
49
|
-
const recoverableErrors = [
|
|
50
|
-
ErrorCode.
|
|
51
|
-
ErrorCode.
|
|
52
|
-
ErrorCode.
|
|
53
|
-
ErrorCode.
|
|
54
|
-
ErrorCode.
|
|
55
|
-
ErrorCode.
|
|
56
|
-
ErrorCode.
|
|
57
|
-
ErrorCode.
|
|
54
|
+
export function isRecoverableError(error: unknown): boolean {
|
|
55
|
+
const recoverableErrors: ErrorCode[] = [
|
|
56
|
+
ErrorCode.NetworkError,
|
|
57
|
+
ErrorCode.RemoteError,
|
|
58
|
+
ErrorCode.ServiceError,
|
|
59
|
+
ErrorCode.Interrupted,
|
|
60
|
+
ErrorCode.ServiceDisconnected,
|
|
61
|
+
ErrorCode.BillingUnavailable,
|
|
62
|
+
ErrorCode.QueryProduct,
|
|
63
|
+
ErrorCode.InitConnection,
|
|
58
64
|
];
|
|
59
65
|
|
|
60
|
-
const
|
|
61
|
-
return recoverableErrors.includes(
|
|
66
|
+
const code = extractCode(error);
|
|
67
|
+
return !!code && (recoverableErrors as string[]).includes(code);
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
/**
|
|
@@ -66,49 +72,56 @@ export function isRecoverableError(error: any): boolean {
|
|
|
66
72
|
* @param error Error object or error code
|
|
67
73
|
* @returns User-friendly error message
|
|
68
74
|
*/
|
|
69
|
-
export function getUserFriendlyErrorMessage(error:
|
|
70
|
-
const errorCode =
|
|
75
|
+
export function getUserFriendlyErrorMessage(error: ErrorLike): string {
|
|
76
|
+
const errorCode = extractCode(error);
|
|
71
77
|
|
|
72
78
|
switch (errorCode) {
|
|
73
|
-
case ErrorCode.
|
|
79
|
+
case ErrorCode.UserCancelled:
|
|
74
80
|
return 'Purchase was cancelled by user';
|
|
75
|
-
case ErrorCode.
|
|
81
|
+
case ErrorCode.NetworkError:
|
|
76
82
|
return 'Network connection error. Please check your internet connection and try again.';
|
|
77
|
-
case ErrorCode.
|
|
83
|
+
case ErrorCode.ReceiptFinished:
|
|
78
84
|
return 'Receipt already finished';
|
|
79
|
-
case ErrorCode.
|
|
85
|
+
case ErrorCode.ServiceDisconnected:
|
|
80
86
|
return 'Billing service disconnected. Please try again.';
|
|
81
|
-
case ErrorCode.
|
|
87
|
+
case ErrorCode.BillingUnavailable:
|
|
82
88
|
return 'Billing is unavailable on this device or account.';
|
|
83
|
-
case ErrorCode.
|
|
89
|
+
case ErrorCode.ItemUnavailable:
|
|
84
90
|
return 'This item is not available for purchase';
|
|
85
|
-
case ErrorCode.
|
|
91
|
+
case ErrorCode.ItemNotOwned:
|
|
86
92
|
return "You don't own this item";
|
|
87
|
-
case ErrorCode.
|
|
93
|
+
case ErrorCode.AlreadyOwned:
|
|
88
94
|
return 'You already own this item';
|
|
89
|
-
case ErrorCode.
|
|
95
|
+
case ErrorCode.SkuNotFound:
|
|
90
96
|
return 'Requested product could not be found';
|
|
91
|
-
case ErrorCode.
|
|
97
|
+
case ErrorCode.SkuOfferMismatch:
|
|
92
98
|
return 'Selected offer does not match the SKU';
|
|
93
|
-
case ErrorCode.
|
|
99
|
+
case ErrorCode.DeferredPayment:
|
|
94
100
|
return 'Payment is pending approval';
|
|
95
|
-
case ErrorCode.
|
|
101
|
+
case ErrorCode.NotPrepared:
|
|
96
102
|
return 'In-app purchase is not ready. Please try again later.';
|
|
97
|
-
case ErrorCode.
|
|
103
|
+
case ErrorCode.ServiceError:
|
|
98
104
|
return 'Store service error. Please try again later.';
|
|
99
|
-
case ErrorCode.
|
|
105
|
+
case ErrorCode.FeatureNotSupported:
|
|
100
106
|
return 'This feature is not supported on this device.';
|
|
101
|
-
case ErrorCode.
|
|
107
|
+
case ErrorCode.TransactionValidationFailed:
|
|
102
108
|
return 'Transaction could not be verified';
|
|
103
|
-
case ErrorCode.
|
|
109
|
+
case ErrorCode.ReceiptFailed:
|
|
104
110
|
return 'Receipt processing failed';
|
|
105
|
-
case ErrorCode.
|
|
111
|
+
case ErrorCode.EmptySkuList:
|
|
106
112
|
return 'No product IDs provided';
|
|
107
|
-
case ErrorCode.
|
|
113
|
+
case ErrorCode.InitConnection:
|
|
108
114
|
return 'Failed to initialize billing connection';
|
|
109
|
-
case ErrorCode.
|
|
115
|
+
case ErrorCode.QueryProduct:
|
|
110
116
|
return 'Failed to query products. Please try again later.';
|
|
111
|
-
default:
|
|
112
|
-
|
|
117
|
+
default: {
|
|
118
|
+
if (error && typeof error === 'object' && 'message' in error) {
|
|
119
|
+
return (
|
|
120
|
+
(error as {message?: string}).message ??
|
|
121
|
+
'An unexpected error occurred'
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
return 'An unexpected error occurred';
|
|
125
|
+
}
|
|
113
126
|
}
|
|
114
127
|
}
|