Commit bca1999
authored
Refactor Core APIs - Platform-Specific Request Structure (#109)
## Summary
This PR introduces a cleaner, more intuitive API for handling
platform-specific purchase requests in expo-iap v2.7.0. The new API
eliminates the need for `Platform.OS` checks in userland code by
providing explicit platform parameters.
## Motivation
Previously, developers had to write conditional logic to handle platform
differences:
```tsx
// Old approach - requires platform checks
if (Platform.OS === 'ios') {
await requestPurchase({ request: { sku: productId } });
} else {
await requestPurchase({ request: { skus: [productId] } });
}
```
This approach had several issues:
- Required manual platform checks
- Easy to miss platform-specific parameters
- TypeScript couldn't provide proper platform-specific type hints
## Changes
### 1. New Platform-Specific API
```tsx
// New approach - clear platform separation
await requestPurchase({
request: {
ios: {
sku: productId,
appAccountToken: 'user-123',
},
android: {
skus: [productId],
obfuscatedAccountIdAndroid: 'user-123',
}
}
});
```
### 2. New requestProducts API
- Added `requestProducts` to replace deprecated `getProducts` and
`getSubscriptions`
- Supports both platform-specific and unified parameter structure
- When parameters are identical, can use simplified API:
```tsx
// Simplified API when parameters are the same
await requestProducts({
skus: ['product1', 'product2'],
type: 'inapp'
});
```
### 3. requestSubscription Deprecation
- `requestSubscription` is now deprecated
- Use `requestPurchase({ type: 'subs' })` instead
- Unifies the API for both products and subscriptions
### 4. Platform-Specific Method Improvements
- Changed platform-specific methods to show warnings instead of throwing
errors
- Methods like `getStorefrontIOS()` now return empty values with console
warnings on Android
- Prevents app crashes when accidentally calling wrong platform methods
### 5. Type System Improvements
- Separated modern and legacy request types for future migration
- Added discriminated unions for better type safety
- Improved TypeScript autocompletion
### 6. Documentation Updates
- Added versioning support (2.6 and 2.7)
- Updated all examples to use new API
- Added comprehensive migration guide
- Fixed anti-pattern of using useEffect with currentPurchase
### 7. Google Play Billing Library v8.0.0
- Updated to latest Google Play Billing Library
- Removed deprecated getPurchaseHistory method on Android
- Improved error handling and type safety
## Benefits
- ✅ **Better Type Safety**: TypeScript provides accurate autocompletion
- ✅ **Cleaner Code**: No more Platform.OS checks in purchase logic
- ✅ **Backward Compatible**: Old API still works for gradual migration
- ✅ **Unified API**: Same function for both products and subscriptions
- ✅ **Safer Cross-Platform**: Platform methods warn instead of crash
## Migration
The old API continues to work, allowing gradual migration:
```tsx
// Both approaches work in v2.7.0
// Old way (still supported)
if (Platform.OS === 'ios') {
await requestPurchase({ request: { sku: productId } });
}
// New way (recommended)
await requestPurchase({
request: {
ios: { sku: productId },
android: { skus: [productId] }
}
});
```
## Testing
- [x] Tested on iOS device
- [x] Tested on Android device
- [x] Updated unit tests
- [x] Documentation builds successfully
- [x] Examples run without errors
- [x] TypeScript compilation passes
- [x] Lint checks pass
## Related Issues
Addresses feedback from the community about API complexity and platform
handling.
## Commits
1. `feat(types)`: Add platform-specific request types for v2.7.0
2. `feat(api)`: Implement new platform-specific requestPurchase API
3. `feat(api)`: Add requestProducts API and improve platform-specific
error handling
4. `refactor(ios)`: Remove redundant Platform.OS checks
5. `refactor(android)`: Update to Google Play Billing Library v8.0.0
6. `refactor(types)`: Separate modern and legacy request types
7. `refactor(api)`: Simplify requestProducts API for unified parameters
8. `refactor(examples)`: Update examples to use new platform-specific
API
9. `docs`: Update documentation for v2.7.0 platform-specific API
10. `docs`: Setup documentation versioning for v2.6 and v2.7
11. `docs(blog)`: Add comprehensive v2.7.0 release notes
12. `fix`: Update all documentation to avoid currentPurchase
anti-pattern1 parent 9336a44 commit bca1999
File tree
52 files changed
+9930
-452
lines changed- .vscode
- docs
- blog
- docs
- api
- methods
- examples
- guides
- versioned_docs/version-2.6
- api
- methods
- examples
- getting-started
- guides
- versioned_sidebars
- example
- __tests__
- app
- src
- modules
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
52 files changed
+9930
-452
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
72 | 95 | | |
73 | 96 | | |
74 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
101 | | - | |
| 101 | + | |
102 | 102 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | 103 | | |
| 104 | + | |
107 | 105 | | |
108 | 106 | | |
109 | 107 | | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | 108 | | |
114 | 109 | | |
115 | 110 | | |
116 | | - | |
| 111 | + | |
117 | 112 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | 113 | | |
| 114 | + | |
122 | 115 | | |
123 | 116 | | |
124 | 117 | | |
| 118 | + | |
| 119 | + | |
125 | 120 | | |
126 | 121 | | |
127 | 122 | | |
| |||
133 | 128 | | |
134 | 129 | | |
135 | 130 | | |
136 | | - | |
137 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
192 | 197 | | |
193 | 198 | | |
194 | 199 | | |
195 | | - | |
196 | | - | |
197 | | - | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
198 | 207 | | |
199 | 208 | | |
200 | | - | |
201 | | - | |
202 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
203 | 214 | | |
204 | 215 | | |
205 | 216 | | |
206 | | - | |
| 217 | + | |
207 | 218 | | |
208 | 219 | | |
209 | | - | |
210 | | - | |
211 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
212 | 223 | | |
213 | | - | |
214 | | - | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
215 | 228 | | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | 229 | | |
220 | | - | |
| 230 | + | |
221 | 231 | | |
222 | | - | |
223 | | - | |
| 232 | + | |
| 233 | + | |
224 | 234 | | |
225 | 235 | | |
226 | 236 | | |
| |||
388 | 398 | | |
389 | 399 | | |
390 | 400 | | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | 401 | | |
395 | 402 | | |
396 | 403 | | |
| |||
404 | 411 | | |
405 | 412 | | |
406 | 413 | | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
407 | 477 | | |
408 | 478 | | |
409 | 479 | | |
| |||
413 | 483 | | |
414 | 484 | | |
415 | 485 | | |
416 | | - | |
| 486 | + | |
| 487 | + | |
0 commit comments