This repository was archived by the owner on Apr 18, 2026. It is now read-only.
Commit 2882e58
fix(ios): emit error on duplicate purchase instead of silent hang (#3177)
## Summary
- Fixes duplicate purchase detection silently dropping events, causing
the app to hang indefinitely
- Adds `ErrorCode.DuplicatePurchase` (`'duplicate-purchase'`) so apps
can detect and recover from this scenario
- Adds `isDuplicatePurchaseError()` public helper for convenient error
checking
Closes #3176
## Changes
### iOS Native (`ios/HybridRnIap.swift`)
- When a duplicate purchase event is detected in `sendPurchaseUpdate`,
now calls `sendPurchaseError` with code `duplicate-purchase` instead of
silently returning
- The `onPurchaseError` callback now fires, allowing apps to respond
(e.g., trigger `restorePurchases`)
### TypeScript Types (`src/types.ts`)
- Added `DuplicatePurchase = 'duplicate-purchase'` to `ErrorCode` enum
### Error Utilities (`src/utils/error.ts`)
- Added `isDuplicatePurchaseError()` public helper (exported via
`react-native-iap`)
### Error Mapping (`src/utils/errorMapping.ts`)
- Added `DuplicatePurchase` to `COMMON_ERROR_CODE_MAP`
- Added user-friendly message: `"This purchase has already been
processed. Try restoring purchases."`
- Added `DuplicatePurchase` to `isRecoverableError` list (recoverable
via `restorePurchases`)
- Added internal `isDuplicatePurchaseError()` helper
## Usage
```typescript
import { useIAP, isDuplicatePurchaseError } from 'react-native-iap';
const { requestPurchase, restorePurchases } = useIAP({
onPurchaseError: (error) => {
if (isDuplicatePurchaseError(error)) {
restorePurchases();
return;
}
// handle other errors
},
});
```
## Test plan
- [x] `yarn typecheck` passes
- [x] `yarn lint` passes
- [x] `yarn test` passes (260 tests, 12 suites)
🤖 Generated with [Claude Code](https://claude.ai/code)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Duplicate purchase attempts are now detected and reported as a
distinct, recoverable error and surface a clear, user-friendly message
guiding recovery (restore purchases or review options).
* **New Features**
* Exposed utilities to detect duplicate-purchase errors so UI can handle
them consistently and provide targeted recovery guidance.
* **Tests**
* Added tests verifying duplicate-purchase detection, recoverability,
and the user-facing message.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 642ba92 commit 2882e58
6 files changed
Lines changed: 132 additions & 0 deletions
File tree
- ios
- src
- __tests__/utils
- utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
1042 | 1043 | | |
1043 | 1044 | | |
1044 | 1045 | | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
1045 | 1054 | | |
1046 | 1055 | | |
1047 | 1056 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
140 | 142 | | |
141 | 143 | | |
142 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
143 | 184 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
48 | 91 | | |
49 | 92 | | |
50 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
150 | 152 | | |
151 | 153 | | |
152 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
153 | 168 | | |
154 | 169 | | |
155 | 170 | | |
| |||
175 | 190 | | |
176 | 191 | | |
177 | 192 | | |
| 193 | + | |
178 | 194 | | |
179 | 195 | | |
180 | 196 | | |
| |||
193 | 209 | | |
194 | 210 | | |
195 | 211 | | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
196 | 215 | | |
197 | 216 | | |
198 | 217 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
271 | 278 | | |
272 | 279 | | |
273 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
274 | 285 | | |
275 | 286 | | |
276 | 287 | | |
| |||
296 | 307 | | |
297 | 308 | | |
298 | 309 | | |
| 310 | + | |
299 | 311 | | |
300 | 312 | | |
301 | 313 | | |
| |||
326 | 338 | | |
327 | 339 | | |
328 | 340 | | |
| 341 | + | |
| 342 | + | |
329 | 343 | | |
330 | 344 | | |
331 | 345 | | |
| |||
0 commit comments