expo-iap 2.4.5-rc.1 → 2.4.5
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/README.md +12 -11
- package/docs/ERROR_CODES.md +17 -9
- package/package.json +4 -1
- package/plugin/tsconfig.tsbuildinfo +1 -1
package/README.md
CHANGED
|
@@ -20,34 +20,34 @@ expo-iap now provides a centralized error code system that works consistently ac
|
|
|
20
20
|
### Error Codes
|
|
21
21
|
|
|
22
22
|
```typescript
|
|
23
|
-
import {
|
|
23
|
+
import {ErrorCode} from 'expo-iap';
|
|
24
24
|
|
|
25
25
|
// Standardized error codes
|
|
26
|
-
ErrorCode.E_USER_CANCELLED
|
|
27
|
-
ErrorCode.E_NETWORK_ERROR
|
|
28
|
-
ErrorCode.E_ITEM_UNAVAILABLE
|
|
29
|
-
ErrorCode.E_SERVICE_ERROR
|
|
26
|
+
ErrorCode.E_USER_CANCELLED; // User cancelled the purchase
|
|
27
|
+
ErrorCode.E_NETWORK_ERROR; // Network connectivity issue
|
|
28
|
+
ErrorCode.E_ITEM_UNAVAILABLE; // Product not available
|
|
29
|
+
ErrorCode.E_SERVICE_ERROR; // Store service error
|
|
30
30
|
// ... and more
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
### Error Utilities
|
|
34
34
|
|
|
35
35
|
```typescript
|
|
36
|
-
import {
|
|
37
|
-
mapPlatformError,
|
|
38
|
-
isUserCancelledError,
|
|
39
|
-
getUserFriendlyErrorMessage
|
|
36
|
+
import {
|
|
37
|
+
mapPlatformError,
|
|
38
|
+
isUserCancelledError,
|
|
39
|
+
getUserFriendlyErrorMessage,
|
|
40
40
|
} from 'expo-iap';
|
|
41
41
|
|
|
42
42
|
// Handle purchase errors
|
|
43
43
|
try {
|
|
44
|
-
await requestPurchase({
|
|
44
|
+
await requestPurchase({sku: 'product_id'});
|
|
45
45
|
} catch (error) {
|
|
46
46
|
if (isUserCancelledError(error)) {
|
|
47
47
|
// User cancelled - don't show error
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
|
|
51
51
|
// Show user-friendly message
|
|
52
52
|
const message = getUserFriendlyErrorMessage(error);
|
|
53
53
|
Alert.alert('Purchase Failed', message);
|
|
@@ -57,6 +57,7 @@ try {
|
|
|
57
57
|
### Platform-Specific Error Mapping
|
|
58
58
|
|
|
59
59
|
The system automatically maps platform codes:
|
|
60
|
+
|
|
60
61
|
- **iOS**: Integer codes (0, 1, 2, etc.) → ErrorCode enum
|
|
61
62
|
- **Android**: String codes ("E_USER_CANCELLED", etc.) → ErrorCode enum
|
|
62
63
|
|
package/docs/ERROR_CODES.md
CHANGED
|
@@ -7,6 +7,7 @@ expo-iap now provides a centralized error code management system that ensures co
|
|
|
7
7
|
## Problem Solved
|
|
8
8
|
|
|
9
9
|
Previously, users experienced inconsistent error codes:
|
|
10
|
+
|
|
10
11
|
- iOS returned numeric error codes (e.g., "2" for user cancellation)
|
|
11
12
|
- Android returned string error codes (e.g., "E_USER_CANCELLED" for user cancellation)
|
|
12
13
|
- The TypeScript enum didn't align with platform-specific implementations
|
|
@@ -54,7 +55,7 @@ export const ErrorCodeMapping = {
|
|
|
54
55
|
### Basic Error Handling
|
|
55
56
|
|
|
56
57
|
```typescript
|
|
57
|
-
import {
|
|
58
|
+
import {ErrorCode, PurchaseError} from 'expo-iap';
|
|
58
59
|
|
|
59
60
|
// Handle purchase errors consistently
|
|
60
61
|
const handleError = (error: PurchaseError) => {
|
|
@@ -74,7 +75,7 @@ const handleError = (error: PurchaseError) => {
|
|
|
74
75
|
### Creating Errors from Platform Data
|
|
75
76
|
|
|
76
77
|
```typescript
|
|
77
|
-
import {
|
|
78
|
+
import {PurchaseError} from 'expo-iap';
|
|
78
79
|
|
|
79
80
|
// Create properly typed errors from platform-specific data
|
|
80
81
|
const error = PurchaseError.fromPlatformError(rawErrorData, 'ios');
|
|
@@ -83,18 +84,24 @@ const error = PurchaseError.fromPlatformError(rawErrorData, 'ios');
|
|
|
83
84
|
### Error Code Utilities
|
|
84
85
|
|
|
85
86
|
```typescript
|
|
86
|
-
import {
|
|
87
|
+
import {ErrorCodeUtils, ErrorCode} from 'expo-iap';
|
|
87
88
|
|
|
88
89
|
// Convert platform-specific codes to standard enum
|
|
89
|
-
const errorCode = ErrorCodeUtils.fromPlatformCode(2, 'ios');
|
|
90
|
+
const errorCode = ErrorCodeUtils.fromPlatformCode(2, 'ios');
|
|
90
91
|
// Returns ErrorCode.E_USER_CANCELLED
|
|
91
92
|
|
|
92
|
-
// Convert standard enum to platform-specific code
|
|
93
|
-
const iosCode = ErrorCodeUtils.toPlatformCode(
|
|
93
|
+
// Convert standard enum to platform-specific code
|
|
94
|
+
const iosCode = ErrorCodeUtils.toPlatformCode(
|
|
95
|
+
ErrorCode.E_USER_CANCELLED,
|
|
96
|
+
'ios',
|
|
97
|
+
);
|
|
94
98
|
// Returns 2
|
|
95
99
|
|
|
96
100
|
// Check platform support
|
|
97
|
-
const isSupported = ErrorCodeUtils.isValidForPlatform(
|
|
101
|
+
const isSupported = ErrorCodeUtils.isValidForPlatform(
|
|
102
|
+
ErrorCode.E_USER_CANCELLED,
|
|
103
|
+
'ios',
|
|
104
|
+
);
|
|
98
105
|
// Returns true
|
|
99
106
|
```
|
|
100
107
|
|
|
@@ -108,7 +115,7 @@ if (error.code === '2') {
|
|
|
108
115
|
// Handle user cancellation
|
|
109
116
|
}
|
|
110
117
|
|
|
111
|
-
// Android would return string codes
|
|
118
|
+
// Android would return string codes
|
|
112
119
|
if (error.code === 'E_USER_CANCELLED') {
|
|
113
120
|
// Handle user cancellation
|
|
114
121
|
}
|
|
@@ -117,7 +124,7 @@ if (error.code === 'E_USER_CANCELLED') {
|
|
|
117
124
|
### After (Consistent)
|
|
118
125
|
|
|
119
126
|
```typescript
|
|
120
|
-
import {
|
|
127
|
+
import {ErrorCode} from 'expo-iap';
|
|
121
128
|
|
|
122
129
|
// Works consistently across platforms
|
|
123
130
|
if (error.code === ErrorCode.E_USER_CANCELLED) {
|
|
@@ -157,6 +164,7 @@ if (error.code === ErrorCode.E_USER_CANCELLED) {
|
|
|
157
164
|
## Breaking Changes
|
|
158
165
|
|
|
159
166
|
This is a **non-breaking change** for most users:
|
|
167
|
+
|
|
160
168
|
- Existing error handling will continue to work
|
|
161
169
|
- New error code system provides additional functionality
|
|
162
170
|
- Users can migrate gradually to the new system
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-iap",
|
|
3
|
-
"version": "2.4.5
|
|
3
|
+
"version": "2.4.5",
|
|
4
4
|
"description": "In App Purchase module in Expo",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -49,5 +49,8 @@
|
|
|
49
49
|
"expo": "*",
|
|
50
50
|
"react": "*",
|
|
51
51
|
"react-native": "*"
|
|
52
|
+
},
|
|
53
|
+
"expo": {
|
|
54
|
+
"plugin": "./app.plugin.js"
|
|
52
55
|
}
|
|
53
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["./src/
|
|
1
|
+
{"root":["./src/withIAP.ts"],"version":"5.8.3"}
|