@chipmobilesdk/rn-payment 0.1.0 → 0.2.0
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 +90 -1
- package/README.md +885 -761
- package/package.json +54 -54
- package/skills/sdk-rn-payment/SKILL.md +33 -6
- package/src/adapter/createStoreProvider.ts +117 -117
- package/src/adapter/iap-adapter.ts +547 -516
- package/src/adapter/port.ts +12 -0
- package/src/config/types.ts +40 -0
- package/src/diagnostics/events.ts +9 -0
- package/src/engine/engine.ts +951 -854
- package/src/engine/finalize.ts +298 -298
- package/src/engine/pending.ts +118 -0
- package/src/engine/products.ts +259 -259
- package/src/engine/purchase.ts +526 -495
- package/src/engine/subscriptions.ts +157 -157
- package/src/entitlements/aggregate.ts +21 -4
- package/src/index.ts +4 -0
- package/src/react/hooks.ts +274 -238
- package/src/testing/fakeStore.ts +33 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,96 @@ product keys, error codes, event names, state values, message keys, and the
|
|
|
7
7
|
public API shape are this package's contract: renaming any of them is a breaking
|
|
8
8
|
change.
|
|
9
9
|
|
|
10
|
-
## [0.
|
|
10
|
+
## [0.2.0] — 2026-10-12
|
|
11
|
+
|
|
12
|
+
Additive minor release closing one gap that surfaced when `0.1.0` met an app that
|
|
13
|
+
must show a pending payment after a restart. It is a **capability** gap: `0.1.0`'s
|
|
14
|
+
engine refused to grant a pending purchase, but an app could only *see* one in the
|
|
15
|
+
session that started it. Reconstructing the pending set meant importing the billing
|
|
16
|
+
library, which this package exists to prevent.
|
|
17
|
+
|
|
18
|
+
It also fixes a **serious defect on Android devices**: a pending purchase was
|
|
19
|
+
granted. See [Fixed](#fixed). **Upgrade from `0.1.0` before shipping.**
|
|
20
|
+
|
|
21
|
+
**Upgrading requires one change, compile-time only:** `PaymentEventType` gained a
|
|
22
|
+
member. See [Migration](#migration).
|
|
23
|
+
|
|
24
|
+
### Added
|
|
25
|
+
|
|
26
|
+
**Pending purchases, visible across sessions**
|
|
27
|
+
|
|
28
|
+
- `getPendingPurchases()` and `subscribePendingPurchases(listener)` on the engine,
|
|
29
|
+
and `usePendingPurchases(productKeys?)` in React. They return a
|
|
30
|
+
`PendingPurchasesState`: a `status` (`known` | `unknown`), an `isStale` flag, and
|
|
31
|
+
`purchases`, one `{ productKey, since }` per product. No transaction id, token or
|
|
32
|
+
store object.
|
|
33
|
+
- Read from the persisted snapshot, so the set survives an app kill and an offline
|
|
34
|
+
restart. It is judged by the **same staleness rule as entitlements**, now shared
|
|
35
|
+
code rather than a parallel copy: never synced, or older than `staleAfterMs`,
|
|
36
|
+
reports `unknown`, never an empty "nothing pending".
|
|
37
|
+
- Pushed only when the set, its status, or its staleness changes. A sync that finds
|
|
38
|
+
nothing new re-renders nothing.
|
|
39
|
+
|
|
40
|
+
**How a pending purchase ended**
|
|
41
|
+
|
|
42
|
+
- `purchase_pending_resolved` event, `{ productKey, outcome }`, with `outcome`
|
|
43
|
+
`settled` | `cancelled` | `expired`, emitted once per pending transaction.
|
|
44
|
+
`settled` precedes the `entitlement_granted` it leads to.
|
|
45
|
+
- Detected from the snapshot commit itself, so it is exactly-once by construction:
|
|
46
|
+
a store push and a sync racing on one settlement emit one event, a sync that
|
|
47
|
+
changed nothing emits none, and `clearLocalData()` emits none, because discarding
|
|
48
|
+
a record locally is not the store ending it.
|
|
49
|
+
- **On Android every unpaid end is `cancelled`.** Play does not say whether a pending
|
|
50
|
+
purchase was declined or expired; it stops reporting it. The package does not
|
|
51
|
+
guess from elapsed time. `expired` is reported only by a store that says so,
|
|
52
|
+
through a new optional `pendingEndReason` on the internal provider port.
|
|
53
|
+
|
|
54
|
+
**Testing**
|
|
55
|
+
|
|
56
|
+
- Fake store: `settlePending`, `cancelPending` and `expirePending` change store-side
|
|
57
|
+
state the way the real store does, so the engine sees the change at its next sync,
|
|
58
|
+
in the same session or after a simulated app kill.
|
|
59
|
+
|
|
60
|
+
### Fixed
|
|
61
|
+
|
|
62
|
+
- **On a device, a pending purchase was granted.** The Android adapter read only
|
|
63
|
+
Play's numeric purchase state and treated anything else as purchased. The
|
|
64
|
+
`react-native-iap` 16.x binding hands JavaScript the state as a **string**
|
|
65
|
+
(`'pending' | 'purchased' | 'unknown'`) and does not carry the numeric one across,
|
|
66
|
+
so every pending purchase fell through to "purchased": entitlement granted, and an
|
|
67
|
+
acknowledgement attempted, for money that had not arrived. The engine's own
|
|
68
|
+
"pending never grants" rule was intact; the adapter fed it the wrong state. No
|
|
69
|
+
test could see it, because tests drive the fake store, which bypasses the adapter.
|
|
70
|
+
The adapter now reads either form, and anything it does not recognize is
|
|
71
|
+
`unspecified`, never purchased. Checked against the installed 16.7.3 declarations
|
|
72
|
+
and its JavaScript bridge.
|
|
73
|
+
- **An `unspecified` purchase state is never treated as paid.** `0.1.0` persisted
|
|
74
|
+
Play's unknown state as `purchased`, granting it and queuing an acknowledgement.
|
|
75
|
+
Now a new transaction in that state is left out until the store says what it is,
|
|
76
|
+
a known one keeps what the package already knew (uncertainty is neither a grant nor
|
|
77
|
+
a refund), a store push in that state is ignored, and `purchase()` returning one
|
|
78
|
+
answers `store_error`, retryable: if the money did move, a retry gets
|
|
79
|
+
`already_owned`, which re-syncs and grants.
|
|
80
|
+
|
|
81
|
+
### Unchanged, deliberately
|
|
82
|
+
|
|
83
|
+
- **Pending never grants**, under any configuration. The new surface is read-only.
|
|
84
|
+
- **No storage migration.** The schema stays at version 1. `0.1.0` already persisted
|
|
85
|
+
pending records; `0.2.0` only reads them.
|
|
86
|
+
- `purchase()` still returns `pending`, and `purchase_pending` still fires, exactly
|
|
87
|
+
as before.
|
|
88
|
+
|
|
89
|
+
### Migration
|
|
90
|
+
|
|
91
|
+
| Union | New member |
|
|
92
|
+
|---|---|
|
|
93
|
+
| `PaymentEventType` / `PaymentEvent` | `'purchase_pending_resolved'` |
|
|
94
|
+
|
|
95
|
+
An exhaustive `switch` over either needs the new case or a `default`. A
|
|
96
|
+
hand-written `PaymentEngine`, typically a test mock, needs `getPendingPurchases` and
|
|
97
|
+
`subscribePendingPurchases`. Nothing else changes.
|
|
98
|
+
|
|
99
|
+
## [0.1.0] — 2026-10-06
|
|
11
100
|
|
|
12
101
|
First version. Android only, via Google Play Billing.
|
|
13
102
|
|