@chipmobilesdk/rn-payment 0.1.0 → 0.2.1
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 +113 -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/persistence/mmkv-store.ts +16 -8
- package/src/react/hooks.ts +274 -238
- package/src/testing/fakeStore.ts +33 -0
package/src/adapter/port.ts
CHANGED
|
@@ -172,6 +172,18 @@ export interface ProviderPort {
|
|
|
172
172
|
/** Store-initiated updates, including a pending purchase settling later (FR-039). */
|
|
173
173
|
observePurchases(listener: (purchase: ProviderPurchase) => void): Unsubscribe;
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Why a pending purchase the store has stopped reporting ended, if the store
|
|
177
|
+
* says (FR-102). Optional, and synchronous because it is asked about a
|
|
178
|
+
* transaction the store already dropped, not fetched.
|
|
179
|
+
*
|
|
180
|
+
* Play gives no reason — a declined or abandoned pending purchase simply
|
|
181
|
+
* vanishes from `queryOwned` — so the Android adapter leaves this out and the
|
|
182
|
+
* engine reports `cancelled`. It is never inferred from age: guessing the
|
|
183
|
+
* store's pending window would be inventing a fact.
|
|
184
|
+
*/
|
|
185
|
+
pendingEndReason?(transactionId: string): 'cancelled' | 'expired' | undefined;
|
|
186
|
+
|
|
175
187
|
/** Must be safe to call for an already-finalized transaction (FR-044). */
|
|
176
188
|
acknowledge(token: ProviderToken): Promise<void>;
|
|
177
189
|
/** Must be safe to call twice; the item is granted once (FR-044). */
|
package/src/config/types.ts
CHANGED
|
@@ -198,6 +198,46 @@ export type PurchaseResult =
|
|
|
198
198
|
| { kind: 'network_error'; productKey: ProductKey }
|
|
199
199
|
| { kind: 'store_error'; productKey: ProductKey; code: string };
|
|
200
200
|
|
|
201
|
+
/**
|
|
202
|
+
* A purchase whose money has not arrived yet (FR-101), added in 0.2.0.
|
|
203
|
+
*
|
|
204
|
+
* One entry per product key, whatever number of pending transactions the store
|
|
205
|
+
* reports for it. Carries no transaction id, token, or store object (FR-051) —
|
|
206
|
+
* enough to render "payment pending" and to withhold Buy, nothing to act on.
|
|
207
|
+
*/
|
|
208
|
+
export interface PendingPurchase {
|
|
209
|
+
readonly productKey: ProductKey;
|
|
210
|
+
/** When the store reports the purchase was made, in epoch milliseconds. Earliest if several. */
|
|
211
|
+
readonly since: number;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The pending set, with how far it can be trusted (FR-101, FR-103).
|
|
216
|
+
*
|
|
217
|
+
* Read `status` first. `unknown` follows the entitlement rule exactly: never
|
|
218
|
+
* synced, or synced longer ago than `staleAfterMs`. Under `unknown`, `purchases`
|
|
219
|
+
* still lists what the last good sync saw, but an empty list there does **not**
|
|
220
|
+
* mean "nothing is pending" — the same reason an `unknown` entitlement is not
|
|
221
|
+
* `not_entitled`.
|
|
222
|
+
*/
|
|
223
|
+
export interface PendingPurchasesState {
|
|
224
|
+
readonly status: 'known' | 'unknown';
|
|
225
|
+
readonly purchases: readonly PendingPurchase[];
|
|
226
|
+
/** True once the snapshot is older than `staleAfterMs`; `status` is then `unknown`. */
|
|
227
|
+
readonly isStale: boolean;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* How a pending purchase ended (FR-102).
|
|
232
|
+
*
|
|
233
|
+
* `settled` — the money arrived; an entitlement grant, if the product confers one,
|
|
234
|
+
* follows. `expired` — the store reported that the pending window ran out.
|
|
235
|
+
* `cancelled` — it ended without payment for any other reason, **including when
|
|
236
|
+
* the store gives none**: Play simply stops reporting a declined or abandoned
|
|
237
|
+
* pending purchase, so on Android every unpaid end is `cancelled`.
|
|
238
|
+
*/
|
|
239
|
+
export type PendingResolution = 'settled' | 'cancelled' | 'expired';
|
|
240
|
+
|
|
201
241
|
/** Outcome of finalizing or consuming a transaction (FR-044). */
|
|
202
242
|
export type FinalizeResult =
|
|
203
243
|
| { kind: 'finalized' }
|
|
@@ -14,6 +14,7 @@ import { redact, type PaymentErrorCode, type PaymentOperation } from './errors';
|
|
|
14
14
|
import type {
|
|
15
15
|
EntitlementKey,
|
|
16
16
|
Environment,
|
|
17
|
+
PendingResolution,
|
|
17
18
|
ProductKey,
|
|
18
19
|
Unsubscribe,
|
|
19
20
|
UnavailableReason,
|
|
@@ -28,6 +29,9 @@ export type PaymentEventType =
|
|
|
28
29
|
| 'purchase_succeeded'
|
|
29
30
|
| 'purchase_cancelled'
|
|
30
31
|
| 'purchase_pending'
|
|
32
|
+
// How a pending purchase ended, once per transaction. `settled` precedes the
|
|
33
|
+
// `entitlement_granted` it leads to (FR-102), added in 0.2.0.
|
|
34
|
+
| 'purchase_pending_resolved'
|
|
31
35
|
| 'purchase_failed'
|
|
32
36
|
| 'transaction_finalized'
|
|
33
37
|
| 'transaction_consumed'
|
|
@@ -74,6 +78,11 @@ export type PaymentEvent = BaseEvent &
|
|
|
74
78
|
| { type: 'purchase_succeeded'; productKey: ProductKey }
|
|
75
79
|
| { type: 'purchase_cancelled'; productKey: ProductKey }
|
|
76
80
|
| { type: 'purchase_pending'; productKey: ProductKey }
|
|
81
|
+
| {
|
|
82
|
+
type: 'purchase_pending_resolved';
|
|
83
|
+
productKey: ProductKey;
|
|
84
|
+
outcome: PendingResolution;
|
|
85
|
+
}
|
|
77
86
|
| {
|
|
78
87
|
type: 'purchase_failed';
|
|
79
88
|
productKey: ProductKey;
|