@chipmobilesdk/rn-payment 0.4.0 → 0.5.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 +482 -334
- package/README.md +925 -897
- package/package.json +52 -54
- package/skills/sdk-rn-payment/SKILL.md +175 -174
- package/src/adapter/createStoreProvider.ts +116 -118
- package/src/adapter/iap-adapter.ts +627 -660
- package/src/adapter/port.ts +209 -215
- package/src/config/types.ts +298 -310
- package/src/config/validate.ts +224 -232
- package/src/core/mutex.ts +25 -128
- package/src/core/retry.ts +95 -133
- package/src/core/timers.ts +272 -267
- package/src/diagnostics/errors.ts +124 -117
- package/src/diagnostics/events.ts +282 -266
- package/src/diagnostics/messageKeys.ts +93 -95
- package/src/engine/engine.ts +921 -999
- package/src/engine/finalize.ts +343 -346
- package/src/engine/foreground.ts +29 -0
- package/src/engine/products.ts +259 -259
- package/src/engine/purchase.ts +589 -614
- package/src/engine/subscriptions.ts +146 -157
- package/src/entitlements/aggregate.ts +261 -242
- package/src/entitlements/mapping.ts +67 -67
- package/src/entitlements/policy.ts +121 -129
- package/src/index.ts +5 -9
- package/src/persistence/mmkv-store.ts +158 -158
- package/src/persistence/snapshot.ts +220 -247
- package/src/react/PaymentProvider.tsx +90 -79
- package/src/react/hooks.ts +236 -274
- package/src/testing/conformance.ts +169 -0
- package/src/testing/fakeStore.ts +360 -393
- package/src/testing/index.ts +19 -10
package/src/config/types.ts
CHANGED
|
@@ -1,310 +1,298 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public configuration and catalog types.
|
|
3
|
-
*
|
|
4
|
-
* Nothing here names Google Play Billing, `react-native-iap`, or any store
|
|
5
|
-
* concept (FR-002). Apps speak in **product keys** and **entitlement keys** they
|
|
6
|
-
* chose themselves; store product identifiers appear only inside catalog
|
|
7
|
-
* configuration, never in app logic (FR-003).
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** An app-chosen logical entitlement, e.g. `no_ads`. What business logic asks about. */
|
|
11
|
-
export type EntitlementKey = string;
|
|
12
|
-
|
|
13
|
-
/** An app-chosen logical product, e.g. `premium_yearly`. Never a store identifier. */
|
|
14
|
-
export type ProductKey = string;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* How a product behaves once bought.
|
|
18
|
-
*
|
|
19
|
-
* `one_time_permanent` — bought once, kept forever.
|
|
20
|
-
* `one_time_consumable` — bought, used up by the app, buyable again (FR-043).
|
|
21
|
-
* `subscription` — recurring, with its own lifecycle (FR-048).
|
|
22
|
-
*/
|
|
23
|
-
export type ProductType =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
*/
|
|
52
|
-
export type
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
export type
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
export
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
export interface
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
| { kind: '
|
|
195
|
-
|
|
196
|
-
| { kind: '
|
|
197
|
-
/**
|
|
198
|
-
| { kind: '
|
|
199
|
-
| { kind: '
|
|
200
|
-
| { kind: '
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
| { kind: '
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
| { kind: '
|
|
208
|
-
|
|
209
|
-
| { kind: '
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
| { kind: '
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
export
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
at: number;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
export interface PaymentStatus {
|
|
303
|
-
kind: PaymentStatusKind;
|
|
304
|
-
unavailableReason?: UnavailableReason;
|
|
305
|
-
/** Whether retrying initialization could plausibly help (FR-024). */
|
|
306
|
-
retryable?: boolean;
|
|
307
|
-
/** Reconnect attempts made in this session, so a retry storm is visible (FR-020). */
|
|
308
|
-
reconnectAttempts?: number;
|
|
309
|
-
blockedOperations: BlockedOperation[];
|
|
310
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Public configuration and catalog types.
|
|
3
|
+
*
|
|
4
|
+
* Nothing here names Google Play Billing, `react-native-iap`, or any store
|
|
5
|
+
* concept (FR-002). Apps speak in **product keys** and **entitlement keys** they
|
|
6
|
+
* chose themselves; store product identifiers appear only inside catalog
|
|
7
|
+
* configuration, never in app logic (FR-003).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** An app-chosen logical entitlement, e.g. `no_ads`. What business logic asks about. */
|
|
11
|
+
export type EntitlementKey = string;
|
|
12
|
+
|
|
13
|
+
/** An app-chosen logical product, e.g. `premium_yearly`. Never a store identifier. */
|
|
14
|
+
export type ProductKey = string;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* How a product behaves once bought.
|
|
18
|
+
*
|
|
19
|
+
* `one_time_permanent` — bought once, kept forever.
|
|
20
|
+
* `one_time_consumable` — bought, used up by the app, buyable again (FR-043).
|
|
21
|
+
* `subscription` — recurring, with its own lifecycle (FR-048).
|
|
22
|
+
*/
|
|
23
|
+
export type ProductType = 'one_time_permanent' | 'one_time_consumable' | 'subscription';
|
|
24
|
+
|
|
25
|
+
/** Store identifiers per platform. iOS is optional and additive (FR-007). */
|
|
26
|
+
export interface StoreProductIds {
|
|
27
|
+
android?: string;
|
|
28
|
+
ios?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** One product the app sells, and what it unlocks. */
|
|
32
|
+
export interface CatalogEntry {
|
|
33
|
+
productKey: ProductKey;
|
|
34
|
+
productType: ProductType;
|
|
35
|
+
storeProductIds: StoreProductIds;
|
|
36
|
+
/** Entitlement keys this product confers. Many-to-many is supported (FR-010). */
|
|
37
|
+
grants: EntitlementKey[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Separately configurable, and the basis of the production-transaction guard. */
|
|
41
|
+
export type Environment = 'development' | 'test' | 'production';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Entitlement policy for a subscription whose renewal payment failed.
|
|
45
|
+
*
|
|
46
|
+
* Kept configurable because it is a business decision, not a technical constant
|
|
47
|
+
* (FR-049). See `entitlements/policy.ts` for the defaults and why.
|
|
48
|
+
*/
|
|
49
|
+
export type LapsePolicy = 'grant' | 'withhold';
|
|
50
|
+
|
|
51
|
+
/** What to do when a configured validation hook cannot be reached (FR-072). */
|
|
52
|
+
export type ValidationUnavailablePolicy = 'grant_and_queue' | 'withhold';
|
|
53
|
+
|
|
54
|
+
/** Returned by every subscribe call. Idempotent and safe to call twice (FR-006). */
|
|
55
|
+
export type Unsubscribe = () => void;
|
|
56
|
+
|
|
57
|
+
export interface TimeoutConfig {
|
|
58
|
+
connectMs?: number;
|
|
59
|
+
productQueryMs?: number;
|
|
60
|
+
syncMs?: number;
|
|
61
|
+
/** Covers opening the store surface only. Time the user spends in it is not counted (FR-035). */
|
|
62
|
+
purchaseLaunchMs?: number;
|
|
63
|
+
/** Bounds each acknowledge or consume call; a timed-out attempt is retried. */
|
|
64
|
+
finalizeAttemptMs?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Bounds the app's `validateTransaction` hook. A hook that does not answer in
|
|
67
|
+
* time is treated as unavailable, exactly like one that throws (FR-072b).
|
|
68
|
+
* Added in 0.3.2.
|
|
69
|
+
*/
|
|
70
|
+
validateMs?: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface RetryConfig {
|
|
74
|
+
reconnect?: BackoffConfig;
|
|
75
|
+
finalize?: BackoffConfig;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface BackoffConfig {
|
|
79
|
+
initialDelayMs?: number;
|
|
80
|
+
maxDelayMs?: number;
|
|
81
|
+
factor?: number;
|
|
82
|
+
/** Attempts per session. Finalize is resumed next session rather than abandoned (FR-045). */
|
|
83
|
+
maxAttempts?: number;
|
|
84
|
+
jitter?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** What the app's backend is asked to decide about (FR-069). */
|
|
88
|
+
export interface ValidationCandidate {
|
|
89
|
+
productKey: ProductKey;
|
|
90
|
+
productType: ProductType;
|
|
91
|
+
/** Opaque verification material for the backend. Never logged (FR-074). */
|
|
92
|
+
verificationPayload: string;
|
|
93
|
+
/** Ties this decision to one purchase cycle in the event stream (FR-076). */
|
|
94
|
+
correlationId: string;
|
|
95
|
+
/**
|
|
96
|
+
* The store's identifier for this transaction (Play's order id). Not a secret,
|
|
97
|
+
* and the only handle a backend has on re-validation, where
|
|
98
|
+
* `verificationPayload` is empty because it is never persisted. Added in 0.3.2.
|
|
99
|
+
*/
|
|
100
|
+
transactionId: string;
|
|
101
|
+
/** Which store issued the transaction, so a backend picks the right API. Added in 0.3.2. */
|
|
102
|
+
platform: 'android' | 'ios';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface ValidationDecision {
|
|
106
|
+
approved: boolean;
|
|
107
|
+
/** Optional app-supplied reason, surfaced as a distinguishable outcome (FR-071). */
|
|
108
|
+
reason?: string;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type ValidationHook = (candidate: ValidationCandidate) => Promise<ValidationDecision>;
|
|
112
|
+
|
|
113
|
+
/** Diagnostics sink. Deliberately not tied to any analytics vendor (FR-080). */
|
|
114
|
+
export interface LoggerAdapter {
|
|
115
|
+
debug?(message: string, meta?: Record<string, unknown>): void;
|
|
116
|
+
warn?(message: string, meta?: Record<string, unknown>): void;
|
|
117
|
+
error?(message: string, meta?: Record<string, unknown>): void;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export interface PaymentConfig {
|
|
121
|
+
catalog: CatalogEntry[];
|
|
122
|
+
/** Entitlement keys the app intends to query. Used for orphan detection (FR-011). */
|
|
123
|
+
entitlements: EntitlementKey[];
|
|
124
|
+
environment: Environment;
|
|
125
|
+
/**
|
|
126
|
+
* Whether the running binary is a production build.
|
|
127
|
+
*
|
|
128
|
+
* Supplied by the app because only the app knows how it was built. Drives the
|
|
129
|
+
* fail-closed guard: a non-production build declaring `production` must not
|
|
130
|
+
* proceed (FR-015).
|
|
131
|
+
*/
|
|
132
|
+
isProductionBuild: boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Global sell switch. When false, purchases report `disabled` but entitlements
|
|
135
|
+
* already held stay readable — turning off selling is not the same as taking
|
|
136
|
+
* away what someone bought (FR-012).
|
|
137
|
+
*/
|
|
138
|
+
enabled?: boolean;
|
|
139
|
+
gracePolicy?: LapsePolicy;
|
|
140
|
+
holdPolicy?: LapsePolicy;
|
|
141
|
+
staleAfterMs?: number;
|
|
142
|
+
productCacheTtlMs?: number;
|
|
143
|
+
foregroundSyncMinIntervalMs?: number;
|
|
144
|
+
timeouts?: TimeoutConfig;
|
|
145
|
+
retry?: RetryConfig;
|
|
146
|
+
/**
|
|
147
|
+
* Opaque cache-partition key (FR-057a).
|
|
148
|
+
*
|
|
149
|
+
* Not a user identifier: the package never interprets it, transmits it, or
|
|
150
|
+
* attaches it to a transaction. Changing it makes the previous snapshot
|
|
151
|
+
* unreadable, so a second app-account user cannot inherit the first one's
|
|
152
|
+
* entitlements even if the app forgets to call `clearLocalData`.
|
|
153
|
+
*/
|
|
154
|
+
scopeToken?: string;
|
|
155
|
+
validateTransaction?: ValidationHook;
|
|
156
|
+
onValidationUnavailable?: ValidationUnavailablePolicy;
|
|
157
|
+
logger?: LoggerAdapter;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Opaque handle for a transaction. Exposes no raw store record (FR-051). */
|
|
161
|
+
export interface TransactionRef {
|
|
162
|
+
readonly transactionId: string;
|
|
163
|
+
readonly productKey: ProductKey;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface PurchaseOptions {
|
|
167
|
+
/**
|
|
168
|
+
* The app's obfuscated account identifier, passed straight through to the
|
|
169
|
+
* store for fraud prevention. Never generated, inferred, or persisted by the
|
|
170
|
+
* package (FR-034), and distinct from `scopeToken`.
|
|
171
|
+
*/
|
|
172
|
+
obfuscatedAccountId?: string;
|
|
173
|
+
/** Which pricing option to buy, for a subscription with several offers. */
|
|
174
|
+
offerKey?: string;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Every way a purchase can end (FR-005).
|
|
179
|
+
*
|
|
180
|
+
* A discriminated union rather than a boolean plus an error, because the app has
|
|
181
|
+
* to tell these apart: `user_cancelled` is a normal outcome to stay quiet about,
|
|
182
|
+
* `pending` means wait, `already_owned` means re-sync, and `store_error` means
|
|
183
|
+
* show something. Collapsing them is how apps end up reporting a cancellation as
|
|
184
|
+
* a failure.
|
|
185
|
+
*/
|
|
186
|
+
export type PurchaseResult =
|
|
187
|
+
| { kind: 'success'; productKey: ProductKey; transaction: TransactionRef }
|
|
188
|
+
/** Money has not arrived. No entitlement is granted (FR-037). */
|
|
189
|
+
| { kind: 'pending'; productKey: ProductKey; transaction: TransactionRef }
|
|
190
|
+
/** Normal, not an error. Must never be recorded as a technical failure (FR-032). */
|
|
191
|
+
| { kind: 'user_cancelled'; productKey: ProductKey }
|
|
192
|
+
/** Triggers a re-sync: this is how a reinstall repairs itself (FR-033). */
|
|
193
|
+
| { kind: 'already_owned'; productKey: ProductKey }
|
|
194
|
+
| { kind: 'ineligible'; productKey: ProductKey }
|
|
195
|
+
| { kind: 'unknown_product'; productKey: ProductKey }
|
|
196
|
+
| { kind: 'product_unavailable_in_region'; productKey: ProductKey }
|
|
197
|
+
/** Global sell switch is off (FR-012). */
|
|
198
|
+
| { kind: 'disabled' }
|
|
199
|
+
| { kind: 'not_ready'; status: PaymentStatusKind }
|
|
200
|
+
| { kind: 'unsupported' }
|
|
201
|
+
/** A second purchase while one is open. Refused, never queued (FR-031). */
|
|
202
|
+
| { kind: 'purchase_in_progress' }
|
|
203
|
+
/** Refused because this build may not create a production transaction (FR-014). */
|
|
204
|
+
| { kind: 'environment_blocked'; productKey: ProductKey; environment: Environment }
|
|
205
|
+
/** The app's backend said no (FR-071). Distinguishable from a network failure. */
|
|
206
|
+
| { kind: 'validation_rejected'; productKey: ProductKey; reason?: string }
|
|
207
|
+
| { kind: 'timeout'; productKey: ProductKey }
|
|
208
|
+
| { kind: 'network_error'; productKey: ProductKey }
|
|
209
|
+
| { kind: 'store_error'; productKey: ProductKey; code: string };
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* A purchase whose money has not arrived yet (FR-101), added in 0.2.0.
|
|
213
|
+
*
|
|
214
|
+
* One entry per product key, whatever number of pending transactions the store
|
|
215
|
+
* reports for it. Carries no transaction id, token, or store object (FR-051) —
|
|
216
|
+
* enough to render "payment pending" and to withhold Buy, nothing to act on.
|
|
217
|
+
*/
|
|
218
|
+
export interface PendingPurchase {
|
|
219
|
+
readonly productKey: ProductKey;
|
|
220
|
+
/** When the store reports the purchase was made, in epoch milliseconds. Earliest if several. */
|
|
221
|
+
readonly since: number;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The pending set, with how far it can be trusted (FR-101, FR-103).
|
|
226
|
+
*
|
|
227
|
+
* Read `status` first. `unknown` follows the entitlement rule exactly: never
|
|
228
|
+
* synced, or synced longer ago than `staleAfterMs`. Under `unknown`, `purchases`
|
|
229
|
+
* still lists what the last good sync saw, but an empty list there does **not**
|
|
230
|
+
* mean "nothing is pending" — the same reason an `unknown` entitlement is not
|
|
231
|
+
* `not_entitled`.
|
|
232
|
+
*/
|
|
233
|
+
export interface PendingPurchasesState {
|
|
234
|
+
readonly status: 'known' | 'unknown';
|
|
235
|
+
readonly purchases: readonly PendingPurchase[];
|
|
236
|
+
/** True once the snapshot is older than `staleAfterMs`; `status` is then `unknown`. */
|
|
237
|
+
readonly isStale: boolean;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* How a pending purchase ended (FR-102).
|
|
242
|
+
*
|
|
243
|
+
* `settled` — the money arrived; an entitlement grant, if the product confers one,
|
|
244
|
+
* follows. `expired` — the store reported that the pending window ran out.
|
|
245
|
+
* `cancelled` — it ended without payment for any other reason, **including when
|
|
246
|
+
* the store gives none**: Play simply stops reporting a declined or abandoned
|
|
247
|
+
* pending purchase, so on Android every unpaid end is `cancelled`.
|
|
248
|
+
*/
|
|
249
|
+
export type PendingResolution = 'settled' | 'cancelled' | 'expired';
|
|
250
|
+
|
|
251
|
+
/** Outcome of finalizing or consuming a transaction (FR-044). */
|
|
252
|
+
export type FinalizeResult =
|
|
253
|
+
| { kind: 'finalized' }
|
|
254
|
+
/** Already done. Idempotent by design, so this is a success, not an error. */
|
|
255
|
+
| { kind: 'already_finalized' }
|
|
256
|
+
| { kind: 'unknown_transaction' }
|
|
257
|
+
/** Queued for bounded retry; the condition stays observable (FR-045). */
|
|
258
|
+
| { kind: 'retry_scheduled'; attempts: number }
|
|
259
|
+
| { kind: 'failed'; code: string };
|
|
260
|
+
|
|
261
|
+
/** A paid transaction not yet settled with the store, surfaced so it is not swallowed. */
|
|
262
|
+
export interface UnfinalizedSummary {
|
|
263
|
+
productKey: ProductKey;
|
|
264
|
+
transactionId: string;
|
|
265
|
+
attempts: number;
|
|
266
|
+
purchasedAt: number;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** Observable package status (FR-019). */
|
|
270
|
+
export type PaymentStatusKind =
|
|
271
|
+
'not_started' | 'connecting' | 'ready' | 'disabled' | 'unavailable' | 'failed';
|
|
272
|
+
|
|
273
|
+
/** Why selling is impossible here, kept distinguishable so apps can tell users why (FR-021). */
|
|
274
|
+
export type UnavailableReason =
|
|
275
|
+
'no_billing_service' | 'billing_service_outdated' | 'platform_unsupported';
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* A purchase the package refused because it could have been a real charge
|
|
279
|
+
* outside production (FR-014).
|
|
280
|
+
*
|
|
281
|
+
* Exposed in status rather than only logged so an automated test can assert the
|
|
282
|
+
* block happened, which is the difference between a guarantee and a hope.
|
|
283
|
+
*/
|
|
284
|
+
export interface BlockedOperation {
|
|
285
|
+
productKey: ProductKey;
|
|
286
|
+
environment: Environment;
|
|
287
|
+
at: number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface PaymentStatus {
|
|
291
|
+
kind: PaymentStatusKind;
|
|
292
|
+
unavailableReason?: UnavailableReason;
|
|
293
|
+
/** Whether retrying initialization could plausibly help (FR-024). */
|
|
294
|
+
retryable?: boolean;
|
|
295
|
+
/** Reconnect attempts made in this session, so a retry storm is visible (FR-020). */
|
|
296
|
+
reconnectAttempts?: number;
|
|
297
|
+
blockedOperations: BlockedOperation[];
|
|
298
|
+
}
|