glitch-javascript-sdk 3.10.8 → 4.0.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/README.md +7 -1
- package/dist/browser/hosting-runtime.js +13 -3
- package/dist/browser/hosting-runtime.js.map +1 -1
- package/dist/cjs/index.js +8348 -8
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/api/FestivalNetworking.d.ts +286 -0
- package/dist/esm/api/Messages.d.ts +4 -1
- package/dist/esm/api/Microtransactions.d.ts +776 -0
- package/dist/esm/api/index.d.ts +2 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +8272 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/routes/FestivalNetworkingRoute.d.ts +7 -0
- package/dist/esm/routes/MicrotransactionsRoute.d.ts +8 -0
- package/dist/esm/util/MicrotransactionBridge.d.ts +93 -0
- package/dist/esm/util/MicrotransactionOverlay.d.ts +59 -0
- package/dist/esm/util/Requests.d.ts +7 -3
- package/dist/index.d.ts +1227 -5
- package/guides/commerce-delivery-receiver.mjs +117 -0
- package/guides/microtransactions.md +466 -0
- package/package.json +7 -4
- package/src/api/FestivalNetworking.ts +216 -0
- package/src/api/Messages.ts +4 -1
- package/src/api/Microtransactions.ts +699 -0
- package/src/api/index.ts +2 -0
- package/src/index.ts +8 -0
- package/src/routes/FestivalNetworkingRoute.ts +33 -0
- package/src/routes/MicrotransactionsRoute.ts +57 -0
- package/src/util/MicrotransactionBridge.ts +193 -0
- package/src/util/MicrotransactionOverlay.ts +302 -0
- package/src/util/Requests.ts +15 -3
- package/src/util/Session.ts +3 -2
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import { AxiosProgressEvent, AxiosPromise, AxiosRequestConfig } from 'axios';
|
|
2
|
+
import MicrotransactionsRoute from '../routes/MicrotransactionsRoute';
|
|
3
|
+
import Requests from '../util/Requests';
|
|
4
|
+
|
|
5
|
+
export type MicrotransactionEnvironment = 'sandbox' | 'live';
|
|
6
|
+
export type MicrotransactionProviderName = 'stripe' | 'xsolla';
|
|
7
|
+
export type MicrotransactionProductType = 'durable' | 'consumable' | 'currency' | 'bundle' | 'pass';
|
|
8
|
+
export type MicrotransactionCurrency = 'USD' | 'EUR' | 'GBP' | 'CAD' | 'AUD' | 'JPY' | 'BRL' | 'INR' | 'KRW';
|
|
9
|
+
export type MicrotransactionProductStatus = 'draft' | 'active' | 'archived';
|
|
10
|
+
export type MicrotransactionPaymentStatus = 'created' | 'action_required' | 'pending' | 'unknown' | 'paid' | 'failed' | 'canceled' | 'refund_pending' | 'partially_refunded' | 'refunded' | 'disputed' | 'quarantined' | 'refund_review';
|
|
11
|
+
export type MicrotransactionRefundStatus = 'requested' | 'linked' | 'unknown' | 'pending' | 'submitted' | 'succeeded' | 'failed' | 'canceled';
|
|
12
|
+
export type MicrotransactionDeliveryStatus = 'pending' | 'retrying' | 'processing' | 'acknowledged' | 'failed' | 'superseded';
|
|
13
|
+
export type MicrotransactionPayoutStatus = 'pending' | 'transferred' | 'bank_paid' | 'bank_pending' | 'bank_failed' | 'transfer_reversed';
|
|
14
|
+
export type MicrotransactionFulfillmentStatus = 'not_ready' | 'pending' | 'delivered' | 'retrying' | 'failed' | 'revoked' | 'partially_recovered';
|
|
15
|
+
export type MicrotransactionAbility = 'commerce:read' | 'commerce:write' | 'commerce:finance' | 'commerce:fulfill';
|
|
16
|
+
export type MicrotransactionErrorCode = 'authentication_required' | 'permission_denied' | 'not_found' | 'not_eligible' | 'quote_expired' | 'already_owned' | 'idempotency_conflict' | 'payment_unknown' | 'rate_limited' | 'invalid_revenue_configuration' | 'fulfillment_pending' | 'provider_unavailable';
|
|
17
|
+
|
|
18
|
+
/** The backend's JSON envelope; Axios returns this envelope in response.data. */
|
|
19
|
+
export interface MicrotransactionResponse<T> { data: T; message?: string; success?: boolean; }
|
|
20
|
+
export interface MicrotransactionError { message: string; code?: MicrotransactionErrorCode | string; errors?: Record<string, string[]>; }
|
|
21
|
+
|
|
22
|
+
export interface MicrotransactionRequestOptions extends Pick<AxiosRequestConfig, 'signal' | 'timeout'> {
|
|
23
|
+
/** Optional short-lived commerce-only player token. Never a shipped developer/title token. */
|
|
24
|
+
playerToken?: string;
|
|
25
|
+
}
|
|
26
|
+
export interface MicrotransactionSessionOptions extends MicrotransactionRequestOptions {
|
|
27
|
+
/** Required limited checkout capability; sent only in X-Checkout-Token, never a query. */
|
|
28
|
+
checkoutToken: string;
|
|
29
|
+
}
|
|
30
|
+
export interface MicrotransactionEnvironmentFilter { environment?: MicrotransactionEnvironment; }
|
|
31
|
+
/** Catalog discovery defaults to 200 records per page; absence on page one is not proof a SKU is unused. */
|
|
32
|
+
export interface MicrotransactionProductListFilters {
|
|
33
|
+
page?: number;
|
|
34
|
+
per_page?: number;
|
|
35
|
+
status?: MicrotransactionProductStatus;
|
|
36
|
+
/** Exact SKU, not a substring search. */
|
|
37
|
+
sku?: string;
|
|
38
|
+
}
|
|
39
|
+
/** Administrative lists default to page 1 / 25 records and are scoped to the authorized title. */
|
|
40
|
+
export interface MicrotransactionManagementListFilters extends MicrotransactionEnvironmentFilter {
|
|
41
|
+
page?: number;
|
|
42
|
+
per_page?: number;
|
|
43
|
+
status?: string;
|
|
44
|
+
}
|
|
45
|
+
export interface MicrotransactionOrderListFilters extends MicrotransactionManagementListFilters { product_id?: string; status?: MicrotransactionPaymentStatus; payment_status?: MicrotransactionPaymentStatus; }
|
|
46
|
+
export interface MicrotransactionRelatedListFilters extends MicrotransactionManagementListFilters { order_id?: string; }
|
|
47
|
+
export interface MicrotransactionRefundListFilters extends MicrotransactionRelatedListFilters { status?: MicrotransactionRefundStatus; }
|
|
48
|
+
export interface MicrotransactionDeliveryListFilters extends MicrotransactionRelatedListFilters { status?: MicrotransactionDeliveryStatus; }
|
|
49
|
+
export interface MicrotransactionPayoutListFilters extends MicrotransactionRelatedListFilters { status?: MicrotransactionPayoutStatus; }
|
|
50
|
+
/** @deprecated Optional compatibility field only; no confirmation or human-approval gate is enforced. */
|
|
51
|
+
export interface MicrotransactionLegacyConfirmation { confirm?: boolean; }
|
|
52
|
+
/** Self-only purchase-history filters. Identity comes from authentication, never a user_id argument. */
|
|
53
|
+
export interface MicrotransactionMyPurchasesFilters extends MicrotransactionEnvironmentFilter {
|
|
54
|
+
/** Page number, integer 1–10000. Defaults to 1; ordering is created_at DESC, id DESC. */
|
|
55
|
+
page?: number;
|
|
56
|
+
/** Integer 1–100. Defaults to 20. No cursor or product filter is supported. */
|
|
57
|
+
per_page?: number;
|
|
58
|
+
}
|
|
59
|
+
export interface MicrotransactionCatalogFilter extends MicrotransactionEnvironmentFilter {
|
|
60
|
+
country?: string;
|
|
61
|
+
currency?: string;
|
|
62
|
+
channel?: 'web';
|
|
63
|
+
}
|
|
64
|
+
export interface MicrotransactionMedia {
|
|
65
|
+
id: string;
|
|
66
|
+
url: string;
|
|
67
|
+
mime_type: string;
|
|
68
|
+
poster?: string | null;
|
|
69
|
+
}
|
|
70
|
+
export interface MicrotransactionBranding {
|
|
71
|
+
display_name?: string | null;
|
|
72
|
+
accent_color?: string | null;
|
|
73
|
+
/** Existing authorized title Media ID, not an external URL or UserMedia ID. */
|
|
74
|
+
logo_media_id?: string | null;
|
|
75
|
+
/** Resolved public Media returned for display; not a writable branding input. */
|
|
76
|
+
logo_media?: MicrotransactionMedia | null;
|
|
77
|
+
}
|
|
78
|
+
export interface MicrotransactionPrice {
|
|
79
|
+
/** Uppercase ISO 4217 currency. Not all currencies have two decimal places. */
|
|
80
|
+
currency: MicrotransactionCurrency;
|
|
81
|
+
/** Uppercase ISO 3166-1 alpha-2 buyer country, or '*' default. */
|
|
82
|
+
country: string;
|
|
83
|
+
/** Integer 1–100000 in currency minor units: USD 499 means $4.99; JPY 499 means ¥499. Provider minima apply separately. */
|
|
84
|
+
amount_minor: number;
|
|
85
|
+
}
|
|
86
|
+
export interface MicrotransactionGrant {
|
|
87
|
+
/** Stable per-title inventory key; never a client-supplied grant at checkout. */
|
|
88
|
+
key: string;
|
|
89
|
+
quantity: number;
|
|
90
|
+
kind: 'durable' | 'consumable' | 'pass';
|
|
91
|
+
/** Required for pass grants; 60–31536000 seconds. Durable quantity must be one. */
|
|
92
|
+
duration_seconds?: number | null;
|
|
93
|
+
}
|
|
94
|
+
export interface MicrotransactionProductInput {
|
|
95
|
+
sku: string;
|
|
96
|
+
name: string;
|
|
97
|
+
description?: string;
|
|
98
|
+
type: MicrotransactionProductType;
|
|
99
|
+
status?: MicrotransactionProductStatus;
|
|
100
|
+
/** Attach IDs from the existing title-authorized Media pipeline. No arbitrary media URLs. */
|
|
101
|
+
media_ids?: string[];
|
|
102
|
+
prices: MicrotransactionPrice[];
|
|
103
|
+
grants: MicrotransactionGrant[];
|
|
104
|
+
localizations?: Record<string, { name: string; description?: string | null }>;
|
|
105
|
+
starts_at?: string | null;
|
|
106
|
+
ends_at?: string | null;
|
|
107
|
+
max_per_order?: number;
|
|
108
|
+
/** @deprecated Ignored compatibility field. Title authorization and immutable-data validation remain required. */
|
|
109
|
+
confirm?: boolean;
|
|
110
|
+
}
|
|
111
|
+
export interface MicrotransactionProduct extends Omit<MicrotransactionProductInput, 'confirm' | 'status' | 'media_ids'> {
|
|
112
|
+
id: string;
|
|
113
|
+
title_id: string;
|
|
114
|
+
status: MicrotransactionProductStatus;
|
|
115
|
+
version: number;
|
|
116
|
+
media_ids: string[];
|
|
117
|
+
media: MicrotransactionMedia[];
|
|
118
|
+
created_at: string;
|
|
119
|
+
updated_at: string;
|
|
120
|
+
}
|
|
121
|
+
export interface MicrotransactionProvider {
|
|
122
|
+
provider: MicrotransactionProviderName;
|
|
123
|
+
environment: MicrotransactionEnvironment;
|
|
124
|
+
configured: boolean;
|
|
125
|
+
/** Actual external provider/account capability, not a manual approval flag. */
|
|
126
|
+
available: boolean;
|
|
127
|
+
enabled: boolean;
|
|
128
|
+
priority: number;
|
|
129
|
+
countries: string[];
|
|
130
|
+
currencies: string[];
|
|
131
|
+
minimum_amounts: Record<string, number>;
|
|
132
|
+
channels: string[];
|
|
133
|
+
payment_methods: string[];
|
|
134
|
+
configuration: MicrotransactionProviderConfiguration;
|
|
135
|
+
account: { id: string; country: string | null; charges_enabled: boolean; payouts_enabled: boolean; requirements_due: string[] } | null;
|
|
136
|
+
/** The game's payout target. Do not substitute the platform processing account's payouts_enabled. */
|
|
137
|
+
payout_account: { source: 'platform' | 'user' | 'community' | 'managed'; id: string | null; available: boolean; country: string | null; transfers_active: boolean; payouts_enabled: boolean; requirements_due: string[]; reasons: string[] };
|
|
138
|
+
tax: { status: string; missing_fields: string[] };
|
|
139
|
+
reasons: string[];
|
|
140
|
+
checked_at: string | null;
|
|
141
|
+
revision?: number;
|
|
142
|
+
}
|
|
143
|
+
export interface MicrotransactionProviderSku {
|
|
144
|
+
/** Provider SKU, 1–100 characters. */
|
|
145
|
+
sku: string;
|
|
146
|
+
currency: MicrotransactionCurrency;
|
|
147
|
+
amount_minor: number;
|
|
148
|
+
}
|
|
149
|
+
export interface MicrotransactionProviderConfiguration {
|
|
150
|
+
tax_mode: 'automatic' | 'disabled';
|
|
151
|
+
/** Stripe tax code txcd_ followed by exactly eight digits. */
|
|
152
|
+
tax_code: string | null;
|
|
153
|
+
payout_source: 'platform' | 'user' | 'community' | 'managed';
|
|
154
|
+
/** Xsolla public project ID, 1–20 decimal digits. */
|
|
155
|
+
project_id: string | null;
|
|
156
|
+
/** Maximum 200 mappings. */
|
|
157
|
+
sku_map: Record<string, MicrotransactionProviderSku>;
|
|
158
|
+
}
|
|
159
|
+
/** Developer preferences and an optional new owned Xsolla webhook secret only; never platform credentials, arbitrary payees, or availability facts. */
|
|
160
|
+
export interface MicrotransactionProviderInput extends Partial<MicrotransactionProviderConfiguration>, MicrotransactionLegacyConfirmation {
|
|
161
|
+
environment: MicrotransactionEnvironment;
|
|
162
|
+
enabled?: boolean;
|
|
163
|
+
priority?: number;
|
|
164
|
+
countries?: string[];
|
|
165
|
+
currencies?: MicrotransactionCurrency[];
|
|
166
|
+
minimum_amounts?: Record<string, number>;
|
|
167
|
+
/** Write-only NEW owned Xsolla project secret, 16–512 chars, finance scope. Never a platform API key or MCP token; never returned/logged or put in game code. Existing platform/historical bindings cannot be overwritten. */
|
|
168
|
+
webhook_secret?: string;
|
|
169
|
+
}
|
|
170
|
+
export interface MicrotransactionProviderOnboardingInput extends MicrotransactionLegacyConfirmation {
|
|
171
|
+
environment: MicrotransactionEnvironment;
|
|
172
|
+
country: string;
|
|
173
|
+
/** Stable caller-created key. Reuse with identical input after uncertain retries; never generate inside a retry. */
|
|
174
|
+
idempotency_key: string;
|
|
175
|
+
}
|
|
176
|
+
export interface MicrotransactionProviderOnboarding {
|
|
177
|
+
title_id: string;
|
|
178
|
+
provider: 'stripe';
|
|
179
|
+
environment: MicrotransactionEnvironment;
|
|
180
|
+
account_id: string;
|
|
181
|
+
/** Single-use provider onboarding URL on connect.stripe.com; do not log or persist it. */
|
|
182
|
+
onboarding_url: string;
|
|
183
|
+
expires_at: string;
|
|
184
|
+
status: 'requires_provider_onboarding';
|
|
185
|
+
reused: boolean;
|
|
186
|
+
}
|
|
187
|
+
export interface MicrotransactionDeliverySettings {
|
|
188
|
+
title_id: string;
|
|
189
|
+
environment: MicrotransactionEnvironment;
|
|
190
|
+
enabled: boolean;
|
|
191
|
+
url: string | null;
|
|
192
|
+
signature_algorithm: 'ed25519' | 'hmac-sha256';
|
|
193
|
+
/** Public verification material only. The private signing key never leaves the server. */
|
|
194
|
+
verification_public_key: string | null;
|
|
195
|
+
key_id: string | null;
|
|
196
|
+
revision: number;
|
|
197
|
+
configured: boolean;
|
|
198
|
+
}
|
|
199
|
+
export interface MicrotransactionDeliverySettingsInput extends MicrotransactionLegacyConfirmation {
|
|
200
|
+
environment: MicrotransactionEnvironment;
|
|
201
|
+
enabled?: boolean;
|
|
202
|
+
url?: string | null;
|
|
203
|
+
}
|
|
204
|
+
export interface MicrotransactionDelivery {
|
|
205
|
+
id: string;
|
|
206
|
+
order_id: string;
|
|
207
|
+
event_type: string;
|
|
208
|
+
status: MicrotransactionDeliveryStatus;
|
|
209
|
+
attempts: number;
|
|
210
|
+
next_attempt_at: string | null;
|
|
211
|
+
acknowledged_at: string | null;
|
|
212
|
+
created_at: string;
|
|
213
|
+
updated_at: string;
|
|
214
|
+
}
|
|
215
|
+
/** Replay/acknowledgement return only this safe subset, not the list's timestamps. */
|
|
216
|
+
export type MicrotransactionDeliveryResult = Pick<MicrotransactionDelivery, 'id' | 'order_id' | 'status' | 'event_type' | 'attempts' | 'acknowledged_at'>;
|
|
217
|
+
export interface MicrotransactionRefundRecord {
|
|
218
|
+
id: string;
|
|
219
|
+
order_id: string;
|
|
220
|
+
status: MicrotransactionRefundStatus;
|
|
221
|
+
amount_minor: number;
|
|
222
|
+
reason: string;
|
|
223
|
+
idempotency_key: string | null;
|
|
224
|
+
record_type: 'request' | 'execution';
|
|
225
|
+
execution_refund_id: string | null;
|
|
226
|
+
execution_status: MicrotransactionRefundStatus | null;
|
|
227
|
+
request_resolution: 'linked_to_execution' | 'not_executed' | null;
|
|
228
|
+
order_refunded_minor: number | null;
|
|
229
|
+
failure_code: string | null;
|
|
230
|
+
created_at: string;
|
|
231
|
+
updated_at: string;
|
|
232
|
+
}
|
|
233
|
+
export interface MicrotransactionPayout {
|
|
234
|
+
id: string;
|
|
235
|
+
order_id: string;
|
|
236
|
+
status: MicrotransactionPayoutStatus;
|
|
237
|
+
amount_minor: number;
|
|
238
|
+
provider_reference: string | null;
|
|
239
|
+
created_at: string;
|
|
240
|
+
updated_at: string;
|
|
241
|
+
}
|
|
242
|
+
export interface MicrotransactionRefundInput extends MicrotransactionLegacyConfirmation {
|
|
243
|
+
reason: string;
|
|
244
|
+
amount_minor?: number;
|
|
245
|
+
/** REQUIRED stable operation key, scoped to title/order. Reuse identical input on retry; changes conflict. */
|
|
246
|
+
idempotency_key: string;
|
|
247
|
+
}
|
|
248
|
+
export interface MicrotransactionReadiness {
|
|
249
|
+
status: 'disabled' | 'draft' | 'sandbox' | 'ready' | 'live' | 'degraded' | 'suspended';
|
|
250
|
+
ready: boolean;
|
|
251
|
+
blockers: string[];
|
|
252
|
+
providers: MicrotransactionProvider[];
|
|
253
|
+
commission_basis_points: 1200;
|
|
254
|
+
}
|
|
255
|
+
export interface MicrotransactionFramePolicy { frame_ancestors: string[]; expires_at: string | null; }
|
|
256
|
+
export interface MicrotransactionSettingsInput {
|
|
257
|
+
enabled?: boolean;
|
|
258
|
+
environment?: MicrotransactionEnvironment;
|
|
259
|
+
/** Actual title-wide ad-delivery policy, distinct from ad revenue sharing. */
|
|
260
|
+
ads_enabled?: boolean;
|
|
261
|
+
fulfillment_mode?: 'glitch' | 'server';
|
|
262
|
+
allowed_origins?: string[];
|
|
263
|
+
countries?: string[];
|
|
264
|
+
currencies?: MicrotransactionCurrency[];
|
|
265
|
+
branding?: Omit<MicrotransactionBranding, 'logo_media'>;
|
|
266
|
+
support_email?: string | null;
|
|
267
|
+
/** @deprecated Legacy delivery alias requiring BOTH commerce:write and commerce:fulfill; prefer updateDeliverySettings/getDeliverySettings. */
|
|
268
|
+
webhook_url?: string | null;
|
|
269
|
+
/** @deprecated Ignored compatibility field. Authorized title editors save directly; actual provider/sales restrictions remain. */
|
|
270
|
+
confirm?: boolean;
|
|
271
|
+
}
|
|
272
|
+
export interface MicrotransactionSettings extends Omit<Required<MicrotransactionSettingsInput>, 'confirm'> {
|
|
273
|
+
title_id: string;
|
|
274
|
+
branding: MicrotransactionBranding;
|
|
275
|
+
integration_verified: boolean;
|
|
276
|
+
/** 12% of discounted pre-tax subtotal; no second commission for in-game currency spending. */
|
|
277
|
+
commission_basis_points: 1200;
|
|
278
|
+
fee_policy: 'developer_pays_provider_costs';
|
|
279
|
+
readiness: MicrotransactionReadiness;
|
|
280
|
+
}
|
|
281
|
+
export interface MicrotransactionCatalog {
|
|
282
|
+
title: { id: string; name: string };
|
|
283
|
+
branding: MicrotransactionBranding;
|
|
284
|
+
products: MicrotransactionProduct[];
|
|
285
|
+
environment: MicrotransactionEnvironment;
|
|
286
|
+
available: boolean;
|
|
287
|
+
blockers: string[];
|
|
288
|
+
}
|
|
289
|
+
export interface MicrotransactionPurchaseInput {
|
|
290
|
+
product_id: string;
|
|
291
|
+
quantity: number;
|
|
292
|
+
country: string;
|
|
293
|
+
currency: string;
|
|
294
|
+
environment: MicrotransactionEnvironment;
|
|
295
|
+
channel: 'web';
|
|
296
|
+
}
|
|
297
|
+
export interface MicrotransactionCheckoutSessionInput extends MicrotransactionPurchaseInput {
|
|
298
|
+
/** Exact game origin previously allowlisted by its owner. */
|
|
299
|
+
return_origin: string;
|
|
300
|
+
/** Random per-purchase state; retain locally and compare before claiming a handoff. */
|
|
301
|
+
nonce: string;
|
|
302
|
+
}
|
|
303
|
+
export interface MicrotransactionQuote extends Omit<MicrotransactionPurchaseInput, 'channel'> {
|
|
304
|
+
id: string;
|
|
305
|
+
product_version: number;
|
|
306
|
+
subtotal_minor: number;
|
|
307
|
+
tax_minor: number;
|
|
308
|
+
total_minor: number;
|
|
309
|
+
commission_minor: number;
|
|
310
|
+
commission_basis_points: 1200;
|
|
311
|
+
expires_at: string;
|
|
312
|
+
}
|
|
313
|
+
export interface MicrotransactionEntitlement {
|
|
314
|
+
key: string;
|
|
315
|
+
kind: 'durable' | 'consumable' | 'pass';
|
|
316
|
+
balance: number;
|
|
317
|
+
environment: MicrotransactionEnvironment;
|
|
318
|
+
updated_at: string;
|
|
319
|
+
expires_at?: string | null;
|
|
320
|
+
}
|
|
321
|
+
export interface MicrotransactionOrder {
|
|
322
|
+
id: string;
|
|
323
|
+
/** Opaque owning Glitch player ID; no email or billing identity is exposed. */
|
|
324
|
+
player_id?: string;
|
|
325
|
+
checkout_session_id: string | null;
|
|
326
|
+
title_id: string;
|
|
327
|
+
product_id: string;
|
|
328
|
+
quantity: number;
|
|
329
|
+
environment: MicrotransactionEnvironment;
|
|
330
|
+
currency: string;
|
|
331
|
+
country: string;
|
|
332
|
+
subtotal_minor: number;
|
|
333
|
+
tax_minor: number;
|
|
334
|
+
total_minor: number;
|
|
335
|
+
commission_minor: number;
|
|
336
|
+
/** Null until actual costs are reconciled; never confuse an estimate with a payout. */
|
|
337
|
+
provider_fee_minor: number | null;
|
|
338
|
+
payment_status: MicrotransactionPaymentStatus;
|
|
339
|
+
fulfillment_status: MicrotransactionFulfillmentStatus;
|
|
340
|
+
provider: 'stripe' | 'xsolla' | null;
|
|
341
|
+
created_at: string;
|
|
342
|
+
paid_at: string | null;
|
|
343
|
+
refunded_minor: number;
|
|
344
|
+
items: MicrotransactionGrant[];
|
|
345
|
+
entitlements?: MicrotransactionEntitlement[];
|
|
346
|
+
}
|
|
347
|
+
export interface MicrotransactionOrderDetail extends MicrotransactionOrder {
|
|
348
|
+
/** Optional, permission-scoped management relationships. Omission is not proof no records exist. */
|
|
349
|
+
refunds?: Array<Pick<MicrotransactionRefundRecord, 'id' | 'order_id' | 'status'> & Partial<MicrotransactionRefundRecord>>;
|
|
350
|
+
deliveries?: MicrotransactionDelivery[];
|
|
351
|
+
payouts?: Array<Pick<MicrotransactionPayout, 'id' | 'order_id' | 'status'> & Partial<MicrotransactionPayout>>;
|
|
352
|
+
financial_details_included?: boolean;
|
|
353
|
+
}
|
|
354
|
+
export type MicrotransactionGrantUsageStatus = 'unused' | 'partially_used' | 'used_up' | 'owned' | 'expired' | 'revoked' | 'not_delivered' | 'unavailable';
|
|
355
|
+
|
|
356
|
+
/** One purchase's server-calculated grant lot, not the player's aggregate inventory balance. */
|
|
357
|
+
export interface MicrotransactionGrantUsage {
|
|
358
|
+
/** Null when the captured purchase has not produced an actual grant lot. */
|
|
359
|
+
grant_id: string | null;
|
|
360
|
+
key: string;
|
|
361
|
+
kind: 'durable' | 'consumable' | 'pass';
|
|
362
|
+
/** Promised units from the frozen grant quantity multiplied by order quantity, not money. */
|
|
363
|
+
purchased_quantity: number;
|
|
364
|
+
/** Actual granted units; zero when no lot exists, even if promised units are positive. */
|
|
365
|
+
granted_quantity: number;
|
|
366
|
+
/** Alias of actual granted_quantity, not the promised purchased_quantity. */
|
|
367
|
+
acquired_quantity: number;
|
|
368
|
+
/** Units remaining in the lot; expired/unavailable lots may still have raw remaining units. */
|
|
369
|
+
remaining_quantity: number;
|
|
370
|
+
/** acquired_quantity - remaining_quantity - revoked_quantity. Includes unrecoverable consumed units. */
|
|
371
|
+
consumed_quantity: number;
|
|
372
|
+
/** Units actually recovered/revoked by a refund; not gameplay consumption. */
|
|
373
|
+
revoked_quantity: number;
|
|
374
|
+
/** Bounded revoked_quantity + unrecoverable_quantity. This overlaps consumed quantity; do not subtract twice. */
|
|
375
|
+
refunded_quantity: number;
|
|
376
|
+
/** Refunded units that could not be recovered because already consumed. Overlaps consumed_quantity. */
|
|
377
|
+
unrecoverable_quantity: number;
|
|
378
|
+
expires_at: string | null;
|
|
379
|
+
expired: boolean;
|
|
380
|
+
/** Server-calculated usable units after expiry and payment/fulfillment restrictions. */
|
|
381
|
+
usable_quantity: number;
|
|
382
|
+
/** Consumable usage only. Durable/pass grants return null; ownership is not proof of gameplay use. */
|
|
383
|
+
is_used: boolean | null;
|
|
384
|
+
usage_status: MicrotransactionGrantUsageStatus;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface MicrotransactionPlayerPurchase extends MicrotransactionOrder {
|
|
388
|
+
/** Always present on authenticated self-history, unlike older generic order DTOs. */
|
|
389
|
+
player_id: string;
|
|
390
|
+
/** Product snapshot for this purchase, not a replacement for the current catalog. */
|
|
391
|
+
product: { id: string; sku: string | null; name: string | null; type: MicrotransactionProductType | null; version: number | null };
|
|
392
|
+
grant_usage: MicrotransactionGrantUsage[];
|
|
393
|
+
has_consumed_grants: boolean;
|
|
394
|
+
has_usable_grants: boolean;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface MicrotransactionPurchasePagination {
|
|
398
|
+
page: number;
|
|
399
|
+
per_page: number;
|
|
400
|
+
total: number;
|
|
401
|
+
last_page: number;
|
|
402
|
+
has_more_pages: boolean;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** Captured own-player purchases, including later refunds/disputes/quarantine; unpaid attempts are excluded. */
|
|
406
|
+
export interface MicrotransactionMyPurchases {
|
|
407
|
+
title_id: string;
|
|
408
|
+
player_id: string;
|
|
409
|
+
environment: MicrotransactionEnvironment;
|
|
410
|
+
purchases: MicrotransactionPlayerPurchase[];
|
|
411
|
+
pagination: MicrotransactionPurchasePagination;
|
|
412
|
+
}
|
|
413
|
+
export interface MicrotransactionCreatedCheckoutSession {
|
|
414
|
+
id: string;
|
|
415
|
+
checkout_session_id: string;
|
|
416
|
+
intent: 'purchase' | 'restore';
|
|
417
|
+
/** Short-lived capability: never log, send to analytics, or put in a URL query. */
|
|
418
|
+
session_token: string;
|
|
419
|
+
hosted_url: string;
|
|
420
|
+
expires_at: string;
|
|
421
|
+
status: 'authentication_required' | 'ready';
|
|
422
|
+
nonce: string;
|
|
423
|
+
}
|
|
424
|
+
export interface MicrotransactionCheckoutSession {
|
|
425
|
+
id: string;
|
|
426
|
+
checkout_session_id: string;
|
|
427
|
+
title_id: string;
|
|
428
|
+
intent: 'purchase' | 'restore';
|
|
429
|
+
title: { id: string; name: string };
|
|
430
|
+
branding: MicrotransactionBranding;
|
|
431
|
+
product: MicrotransactionProduct | null;
|
|
432
|
+
quantity: number;
|
|
433
|
+
country: string;
|
|
434
|
+
currency: string;
|
|
435
|
+
environment: MicrotransactionEnvironment;
|
|
436
|
+
status: string;
|
|
437
|
+
expires_at: string;
|
|
438
|
+
authenticated: boolean;
|
|
439
|
+
order: MicrotransactionOrder | null;
|
|
440
|
+
return_origin: string;
|
|
441
|
+
nonce: string;
|
|
442
|
+
support_email: string | null;
|
|
443
|
+
}
|
|
444
|
+
export interface MicrotransactionCheckoutInput {
|
|
445
|
+
/** UUID retained for retries of the same purchase, never reused for different goods. */
|
|
446
|
+
idempotency_key: string;
|
|
447
|
+
accept_terms: true;
|
|
448
|
+
}
|
|
449
|
+
export interface MicrotransactionCheckoutResult {
|
|
450
|
+
order: MicrotransactionOrder;
|
|
451
|
+
checkout_url: string | null;
|
|
452
|
+
status: MicrotransactionPaymentStatus;
|
|
453
|
+
provider: 'stripe' | 'xsolla';
|
|
454
|
+
quote: MicrotransactionQuote;
|
|
455
|
+
/** Provider's limited embedded-checkout secret if this route supports embedded checkout. */
|
|
456
|
+
client_secret?: string | null;
|
|
457
|
+
/** Public provider key only. Never a Stripe secret key. */
|
|
458
|
+
publishable_key?: string | null;
|
|
459
|
+
ui_mode: 'embedded' | 'xsolla';
|
|
460
|
+
}
|
|
461
|
+
export interface MicrotransactionHandoff {
|
|
462
|
+
event: {
|
|
463
|
+
type: 'glitch.microtransaction.updated';
|
|
464
|
+
version: 1;
|
|
465
|
+
title_id: string;
|
|
466
|
+
checkout_session_id: string;
|
|
467
|
+
order_id: string;
|
|
468
|
+
nonce: string;
|
|
469
|
+
/** One-time claim only; never an account JWT. */
|
|
470
|
+
claim_code: string;
|
|
471
|
+
};
|
|
472
|
+
target_origin: string;
|
|
473
|
+
expires_at: string;
|
|
474
|
+
}
|
|
475
|
+
export interface MicrotransactionHandoffClaimInput { claim_code: string; nonce: string; return_origin: string; checkout_session_id: string; }
|
|
476
|
+
export interface MicrotransactionHandoffClaim {
|
|
477
|
+
title_id: string;
|
|
478
|
+
checkout_session_id: string;
|
|
479
|
+
order_id: string;
|
|
480
|
+
player_id: string;
|
|
481
|
+
entitlements: MicrotransactionEntitlement[];
|
|
482
|
+
/** 15-minute title/player/environment-scoped token, stored in memory only. */
|
|
483
|
+
player_token: string;
|
|
484
|
+
expires_at: string;
|
|
485
|
+
}
|
|
486
|
+
export interface MicrotransactionConsumeInput {
|
|
487
|
+
key: string;
|
|
488
|
+
quantity: number;
|
|
489
|
+
action_id: string;
|
|
490
|
+
environment: MicrotransactionEnvironment;
|
|
491
|
+
}
|
|
492
|
+
export interface MicrotransactionRefund { refund_id: string; status: MicrotransactionRefundStatus; order_id: string; idempotency_key: string; failure_code: string | null; refund_allocation?: 'pro_rata_all_grants'; }
|
|
493
|
+
export interface MicrotransactionRefundRequest { id: string; order_id: string; status: 'requested'; }
|
|
494
|
+
export interface MicrotransactionEarnings {
|
|
495
|
+
currency_balances: Array<{
|
|
496
|
+
currency: string; pending_minor: number; available_minor: number; paid_minor: number;
|
|
497
|
+
commission_minor: number; provider_fees_minor: number;
|
|
498
|
+
/** Transfer to a connected provider balance is NOT a confirmed bank payout. */
|
|
499
|
+
transferred_minor?: number;
|
|
500
|
+
bank_payout_status?: 'provider_managed_not_reconciled';
|
|
501
|
+
}>;
|
|
502
|
+
payouts_enabled: boolean;
|
|
503
|
+
reserve_days?: number;
|
|
504
|
+
}
|
|
505
|
+
export type MicrotransactionOperation = 'settings.get' | 'settings.update' | 'products.list' | 'products.create' | 'products.update' | 'products.archive' | 'providers.list' | 'providers.update' | 'providers.refresh' | 'providers.onboarding' | 'readiness.get' | 'orders.list' | 'orders.get' | 'orders.reconcile' | 'earnings.get' | 'refunds.list' | 'refunds.get' | 'refunds.create' | 'refunds.request' | 'refunds.reconcile' | 'delivery.settings.get' | 'delivery.settings.update' | 'deliveries.list' | 'deliveries.replay' | 'deliveries.acknowledge' | 'payouts.list' | 'integration.get' | 'integration.verify';
|
|
506
|
+
export interface MicrotransactionOperationCapability {
|
|
507
|
+
operation: MicrotransactionOperation;
|
|
508
|
+
description: string;
|
|
509
|
+
ability: MicrotransactionAbility;
|
|
510
|
+
input_schema: Record<string, unknown>;
|
|
511
|
+
http_method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
512
|
+
mutates: boolean;
|
|
513
|
+
requires_confirmation: false;
|
|
514
|
+
requires_human_approval: false;
|
|
515
|
+
examples: Array<Record<string, unknown>>;
|
|
516
|
+
output_description: string;
|
|
517
|
+
}
|
|
518
|
+
export interface MicrotransactionCapabilities {
|
|
519
|
+
schema_version: number;
|
|
520
|
+
title_id: string;
|
|
521
|
+
operations: MicrotransactionOperationCapability[];
|
|
522
|
+
[key: string]: unknown;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Provider-neutral, title-scoped commerce. Configure with user JWT; purchases
|
|
527
|
+
* use a recoverable user account and limited checkout capability. Install/title
|
|
528
|
+
* tokens cannot authorize money, ownership, refunds, or catalog changes.
|
|
529
|
+
*
|
|
530
|
+
* Each result preserves payment versus fulfillment versus settlement. Redirects
|
|
531
|
+
* and postMessage events only trigger an authoritative refresh. A timeout is
|
|
532
|
+
* unknown; reconcile the original attempt instead of charging another provider.
|
|
533
|
+
*/
|
|
534
|
+
class Microtransactions {
|
|
535
|
+
/**
|
|
536
|
+
* Upload an image/video through existing Glitch Media processing with title
|
|
537
|
+
* and actor ownership. Attach its returned Media ID to products/branding.
|
|
538
|
+
* Does not create a social-library post, scheduler, or new payment product.
|
|
539
|
+
*/
|
|
540
|
+
static uploadMedia(title_id: string, media: File | Blob, onUploadProgress?: (event: AxiosProgressEvent) => void, options?: Pick<AxiosRequestConfig, 'signal' | 'timeout'>): AxiosPromise<MicrotransactionResponse<MicrotransactionMedia>> {
|
|
541
|
+
if (!/^[A-Za-z0-9_:-]+$/.test(title_id)) throw new Error('Invalid commerce title identifier.');
|
|
542
|
+
return Requests.uploadFile<MicrotransactionMedia>(MicrotransactionsRoute.routes.uploadMedia.url.replace('{title_id}', encodeURIComponent(title_id)), 'media', media, {}, undefined, onUploadProgress, { ...options, excludeCommunityContext: true });
|
|
543
|
+
}
|
|
544
|
+
/** Same title-authorized Media pipeline using the caller's MCP credential and commerce:write ability. */
|
|
545
|
+
static mcpUploadMedia(title_id: string, media: File | Blob, onUploadProgress?: (event: AxiosProgressEvent) => void, options?: Pick<AxiosRequestConfig, 'signal' | 'timeout'>): AxiosPromise<MicrotransactionResponse<MicrotransactionMedia>> {
|
|
546
|
+
if (!/^[A-Za-z0-9_:-]+$/.test(title_id)) throw new Error('Invalid commerce title identifier.');
|
|
547
|
+
return Requests.uploadFile<MicrotransactionMedia>(MicrotransactionsRoute.routes.mcpUploadMedia.url.replace('{title_id}', encodeURIComponent(title_id)), 'media', media, {}, undefined, onUploadProgress, { ...options, excludeCommunityContext: true });
|
|
548
|
+
}
|
|
549
|
+
/** Admin settings, including immutable 1200bp commission and readiness blockers. */
|
|
550
|
+
static settings(title_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionSettings>('settings', title_id, undefined, {}, undefined, options); }
|
|
551
|
+
/** Atomic policy update. Sandbox/off by default. Cannot disable the final working revenue model. */
|
|
552
|
+
static updateSettings(title_id: string, data: MicrotransactionSettingsInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionSettings>('updateSettings', title_id, data, {}, undefined, options); }
|
|
553
|
+
/** Read-only current country/provider capability and revenue readiness; never fabricates availability. */
|
|
554
|
+
static readiness(title_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionReadiness>('readiness', title_id, undefined, {}, undefined, options); }
|
|
555
|
+
/** Paginated admin catalog including drafts/archives. Default 200, per_page 1–200/page 1–10000. Use exact sku to resolve uncertain creates. */
|
|
556
|
+
static listProducts(title_id: string, params?: MicrotransactionProductListFilters, options?: MicrotransactionRequestOptions): AxiosPromise<MicrotransactionResponse<{ products: MicrotransactionProduct[]; pagination: MicrotransactionPurchasePagination }>>;
|
|
557
|
+
/** @deprecated Compatibility overload for the earlier second-argument request options. */
|
|
558
|
+
static listProducts(title_id: string, options?: MicrotransactionRequestOptions): AxiosPromise<MicrotransactionResponse<{ products: MicrotransactionProduct[]; pagination: MicrotransactionPurchasePagination }>>;
|
|
559
|
+
static listProducts(title_id: string, paramsOrOptions?: MicrotransactionProductListFilters | MicrotransactionRequestOptions, options?: MicrotransactionRequestOptions) {
|
|
560
|
+
const legacy = paramsOrOptions && ('playerToken' in paramsOrOptions || 'signal' in paramsOrOptions || 'timeout' in paramsOrOptions);
|
|
561
|
+
return this.call<{ products: MicrotransactionProduct[]; pagination: MicrotransactionPurchasePagination }>('products', title_id, undefined, {}, legacy ? undefined : paramsOrOptions, legacy ? paramsOrOptions as MicrotransactionRequestOptions : options);
|
|
562
|
+
}
|
|
563
|
+
/** Save a catalog product. Prices use integer minor units and attached media must belong to the title. */
|
|
564
|
+
static createProduct(title_id: string, data: MicrotransactionProductInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProduct>('createProduct', title_id, data, {}, undefined, options); }
|
|
565
|
+
/** Update a product version. Existing order snapshots remain unchanged. */
|
|
566
|
+
static updateProduct(title_id: string, product_id: string, data: Partial<MicrotransactionProductInput>, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProduct>('updateProduct', title_id, data, { product_id }, undefined, options); }
|
|
567
|
+
/** Direct authorized archive. Never deletes financial history or bypasses the last-revenue-model rule. */
|
|
568
|
+
static archiveProduct(title_id: string, product_id: string, data: MicrotransactionLegacyConfirmation = {}, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProduct>('archiveProduct', title_id, data, { product_id }, undefined, options); }
|
|
569
|
+
/** Actual provider configuration/capability facts; no credentials or manual approval flag. */
|
|
570
|
+
static providers(title_id: string, params?: MicrotransactionEnvironmentFilter, options?: MicrotransactionRequestOptions): AxiosPromise<MicrotransactionResponse<{ providers: MicrotransactionProvider[] }>>;
|
|
571
|
+
/** @deprecated Compatibility overload for the earlier second-argument request options. */
|
|
572
|
+
static providers(title_id: string, options?: MicrotransactionRequestOptions): AxiosPromise<MicrotransactionResponse<{ providers: MicrotransactionProvider[] }>>;
|
|
573
|
+
static providers(title_id: string, paramsOrOptions?: MicrotransactionEnvironmentFilter | MicrotransactionRequestOptions, options?: MicrotransactionRequestOptions) {
|
|
574
|
+
const legacy = paramsOrOptions && !('environment' in paramsOrOptions) && ('playerToken' in paramsOrOptions || 'signal' in paramsOrOptions || 'timeout' in paramsOrOptions);
|
|
575
|
+
return this.call<{ providers: MicrotransactionProvider[] }>('providers', title_id, undefined, {}, legacy ? undefined : paramsOrOptions, legacy ? paramsOrOptions as MicrotransactionRequestOptions : options);
|
|
576
|
+
}
|
|
577
|
+
/** Direct commerce:finance configuration. Saving preferences does not fabricate external capability; inspect available/reasons. */
|
|
578
|
+
static updateProvider(title_id: string, provider: MicrotransactionProviderName, data: MicrotransactionProviderInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProvider>('updateProvider', title_id, data, { provider }, undefined, options); }
|
|
579
|
+
/** Refresh authenticated external provider facts. May update cached state; never creates a payment or invents eligibility. */
|
|
580
|
+
static refreshProvider(title_id: string, provider: MicrotransactionProviderName, data: { environment: MicrotransactionEnvironment }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProvider>('refreshProvider', title_id, data, { provider }, undefined, options); }
|
|
581
|
+
/** Start/reuse owned Stripe Connect onboarding with one stable key. Provider KYC is factual setup, not a Glitch approval workflow. */
|
|
582
|
+
static createProviderOnboarding(title_id: string, data: MicrotransactionProviderOnboardingInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionProviderOnboarding>('createProviderOnboarding', title_id, data, {}, undefined, options); }
|
|
583
|
+
/** Read title/environment delivery settings and the Ed25519 PUBLIC verification key. */
|
|
584
|
+
static getDeliverySettings(title_id: string, params?: MicrotransactionEnvironmentFilter, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionDeliverySettings>('deliverySettings', title_id, undefined, {}, params, options); }
|
|
585
|
+
/** Direct commerce:fulfill setup. Private/metadata network targets and private-key inputs remain forbidden. */
|
|
586
|
+
static updateDeliverySettings(title_id: string, data: MicrotransactionDeliverySettingsInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionDeliverySettings>('updateDeliverySettings', title_id, data, {}, undefined, options); }
|
|
587
|
+
/** Discover safe event IDs/statuses before replay or acknowledge. Page 1–10000, per_page 1–100, default 25. */
|
|
588
|
+
static listDeliveries(title_id: string, params?: MicrotransactionDeliveryListFilters, options?: MicrotransactionRequestOptions) { return this.call<{ deliveries: MicrotransactionDelivery[]; pagination: MicrotransactionPurchasePagination }>('deliveries', title_id, undefined, {}, params, options); }
|
|
589
|
+
/** Financially scoped refund operation discovery; pending/unknown is not completed. */
|
|
590
|
+
static listRefunds(title_id: string, params?: MicrotransactionRefundListFilters, options?: MicrotransactionRequestOptions) { return this.call<{ refunds: MicrotransactionRefundRecord[]; pagination: MicrotransactionPurchasePagination }>('refunds', title_id, undefined, {}, params, options); }
|
|
591
|
+
/** Inspect one same-title refund operation. */
|
|
592
|
+
static getRefund(title_id: string, refund_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionRefundRecord>('refundDetail', title_id, undefined, { refund_id }, undefined, options); }
|
|
593
|
+
/** Query/retry the original persisted refund with its existing identity, never generate a new refund key. */
|
|
594
|
+
static reconcileRefund(title_id: string, refund_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionRefundRecord>('reconcileRefund', title_id, {}, { refund_id }, undefined, options); }
|
|
595
|
+
/** Discover provider transfer/payout records; transferred funds are not automatically a verified bank payout. */
|
|
596
|
+
static listPayouts(title_id: string, params?: MicrotransactionPayoutListFilters, options?: MicrotransactionRequestOptions) { return this.call<{ payouts: MicrotransactionPayout[]; pagination: MicrotransactionPurchasePagination }>('payouts', title_id, undefined, {}, params, options); }
|
|
597
|
+
/** Admin read of separate-currency balances; pending is not withdrawable revenue. */
|
|
598
|
+
static earnings(title_id: string, params?: MicrotransactionEnvironmentFilter, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionEarnings>('earnings', title_id, undefined, {}, params, options); }
|
|
599
|
+
/** Admin paginated redacted orders. Page 1–10000/per_page 1–100 (default 25); own-player history is separate. */
|
|
600
|
+
static listOrders(title_id: string, params?: MicrotransactionOrderListFilters, options?: MicrotransactionRequestOptions) { return this.call<{ orders: MicrotransactionOrder[]; pagination: MicrotransactionPurchasePagination }>('orders', title_id, undefined, {}, params, options); }
|
|
601
|
+
/** Owner JWT/scoped player token or title admin. An arbitrary order UUID grants no access. */
|
|
602
|
+
static getOrder(title_id: string, order_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionOrderDetail>('order', title_id, undefined, { order_id }, undefined, options); }
|
|
603
|
+
/** Financially scoped original-provider reconciliation. Does not reroute or start a different purchase. */
|
|
604
|
+
static reconcileOrder(title_id: string, order_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionOrderDetail>('reconcileOrder', title_id, {}, { order_id }, undefined, options); }
|
|
605
|
+
/** Direct commerce:finance refund. REQUIRED stable idempotency_key; omission is an error, never auto-filled. Same-key changed input conflicts. */
|
|
606
|
+
static refundOrder(title_id: string, order_id: string, data: MicrotransactionRefundInput, options?: MicrotransactionRequestOptions) {
|
|
607
|
+
if (typeof data.idempotency_key !== 'string' || data.idempotency_key.length < 16 || data.idempotency_key.length > 128) throw new Error('A stable 16–128 character refund idempotency_key is required. Reuse it on retry.');
|
|
608
|
+
return this.call<MicrotransactionRefund>('refund', title_id, data, { order_id }, undefined, options);
|
|
609
|
+
}
|
|
610
|
+
/** Replay the same immutable event. Receiver must deduplicate event_id. This cannot mint goods. */
|
|
611
|
+
static replayDelivery(title_id: string, delivery_id: string, data: MicrotransactionLegacyConfirmation = {}, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionDeliveryResult>('replayDelivery', title_id, data, { delivery_id }, undefined, options); }
|
|
612
|
+
/** Public eligible catalog. Sandbox is restricted by backend environment/admin policy. */
|
|
613
|
+
static catalog(title_id: string, params?: MicrotransactionCatalogFilter, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionCatalog>('catalog', title_id, undefined, {}, params, options); }
|
|
614
|
+
/** User-authenticated quote. Clients select product/quantity, never monetary values or seller accounts. */
|
|
615
|
+
static createQuote(title_id: string, data: MicrotransactionPurchaseInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionQuote>('createQuote', title_id, data, {}, undefined, options); }
|
|
616
|
+
/** Anonymous-safe opening step only. The hosted UI creates/logs into an account before payment. */
|
|
617
|
+
static createCheckoutSession(title_id: string, data: MicrotransactionCheckoutSessionInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionCreatedCheckoutSession>('createCheckoutSession', title_id, data, {}, undefined, options); }
|
|
618
|
+
/** Anonymous-safe inventory recovery. Opens an in-game hosted sign-in overlay, never creates a charge or requires the game's account JWT. */
|
|
619
|
+
static createRestoreSession(title_id: string, data: { return_origin: string; nonce: string; environment: MicrotransactionEnvironment }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionCreatedCheckoutSession>('createRestoreSession', title_id, data, {}, undefined, options); }
|
|
620
|
+
/** Read the session using its limited capability. Cannot mutate user identity or declare payment. */
|
|
621
|
+
static getCheckoutSession(title_id: string, session_id: string, options: MicrotransactionSessionOptions) { return this.call<MicrotransactionCheckoutSession>('checkoutSession', title_id, undefined, { session_id }, undefined, options); }
|
|
622
|
+
/** Anonymous, read-only embedding policy: server-approved frame ancestors only, no player/session capability data. */
|
|
623
|
+
static getCheckoutFramePolicy(title_id: string, session_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionFramePolicy>('checkoutFramePolicy', title_id, undefined, { session_id }, undefined, options); }
|
|
624
|
+
/** Anonymous title-wide approved embedding policy for trusted hosted account pages; no player data. */
|
|
625
|
+
static getFramePolicy(title_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionFramePolicy>('framePolicy', title_id, undefined, {}, undefined, options); }
|
|
626
|
+
/** Bind once to the existing authenticated account. Cannot reassign another player's purchase. */
|
|
627
|
+
static authenticateCheckoutSession(title_id: string, session_id: string, options: MicrotransactionSessionOptions) { return this.call<MicrotransactionCheckoutSession>('authenticateCheckoutSession', title_id, {}, { session_id }, undefined, options); }
|
|
628
|
+
/** Bound-user JWT + session capability. Reuse the idempotency key after a network timeout. */
|
|
629
|
+
static checkout(title_id: string, session_id: string, data: MicrotransactionCheckoutInput, options: MicrotransactionSessionOptions) { return this.call<MicrotransactionCheckoutResult>('checkout', title_id, data, { session_id }, undefined, options); }
|
|
630
|
+
/** Query original provider; never creates another charge. Pending/unknown remains non-terminal. */
|
|
631
|
+
static reconcileCheckoutSession(title_id: string, session_id: string, options: MicrotransactionSessionOptions) { return this.call<MicrotransactionOrder>('reconcileCheckout', title_id, {}, { session_id }, undefined, options); }
|
|
632
|
+
/** Hosted checkout only. Server issues an expiring one-time game handoff after verified fulfillment. */
|
|
633
|
+
static createHandoff(title_id: string, session_id: string, options: MicrotransactionSessionOptions) { return this.call<MicrotransactionHandoff>('createHandoff', title_id, {}, { session_id }, undefined, options); }
|
|
634
|
+
/** Game exchanges a verified popup code. Browser Origin must match return_origin; code is consumed once. */
|
|
635
|
+
static claimHandoff(title_id: string, data: MicrotransactionHandoffClaimInput, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionHandoffClaim>('claimHandoff', title_id, data, {}, undefined, options); }
|
|
636
|
+
/**
|
|
637
|
+
* Authenticated hosted Glitch account only: restore a previous purchase into a
|
|
638
|
+
* NEW nonce-bound session/handoff after the game's 15-minute token expires or
|
|
639
|
+
* storage is cleared. Does not create another payment. Return to the game via
|
|
640
|
+
* verified source/origin and a new bridge bound to event.checkout_session_id.
|
|
641
|
+
*/
|
|
642
|
+
static restoreHandoff(title_id: string, data: { order_id: string; return_origin: string; nonce: string }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionHandoff>('restoreHandoff', title_id, data, {}, undefined, options); }
|
|
643
|
+
/** Record integration proof from a genuinely paid, fulfilled sandbox order with a claimed game handoff. */
|
|
644
|
+
static verifyIntegration(title_id: string, data: { order_id: string; confirm?: boolean }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionReadiness>('verifyIntegration', title_id, data, {}, undefined, options); }
|
|
645
|
+
/** Restore authoritative durable ownership/current consumable balances, never mutable cloud-save balances. */
|
|
646
|
+
static listEntitlements(title_id: string, params?: MicrotransactionEnvironmentFilter, options?: MicrotransactionRequestOptions) { return this.call<{ entitlements: MicrotransactionEntitlement[] }>('entitlements', title_id, undefined, {}, params, options); }
|
|
647
|
+
/**
|
|
648
|
+
* Optional self-only purchase/usage history. A user JWT selects that user; a
|
|
649
|
+
* scoped playerToken selects its bound title/player/environment and requires
|
|
650
|
+
* the exact approved game Origin. No MCP/install token or caller-selected
|
|
651
|
+
* user_id/player_id is accepted. JWT environment defaults to live; scoped
|
|
652
|
+
* tokens default to their bound environment. Admin listOrders stays separate.
|
|
653
|
+
*
|
|
654
|
+
* Read response.data.data.purchases and .pagination. Use grant_usage for lot
|
|
655
|
+
* consumption/refund/expiry status, listEntitlements for current aggregate
|
|
656
|
+
* inventory, and consume for explicit gameplay spending. History never grants
|
|
657
|
+
* inventory and durable/pass is_used is null rather than a guessed boolean.
|
|
658
|
+
*/
|
|
659
|
+
static listMyPurchases(title_id: string, filters: MicrotransactionMyPurchasesFilters = {}, options?: MicrotransactionRequestOptions) {
|
|
660
|
+
const allowed = ['environment', 'page', 'per_page'];
|
|
661
|
+
if (Object.keys(filters).some(key => !allowed.includes(key))) throw new Error('Own purchase history supports only environment, page and per_page; identity cannot be selected.');
|
|
662
|
+
if (filters.environment !== undefined && !['sandbox', 'live'].includes(filters.environment)) throw new Error('Invalid purchase-history environment.');
|
|
663
|
+
if (filters.page !== undefined && (!Number.isInteger(filters.page) || filters.page < 1 || filters.page > 10000)) throw new Error('Purchase-history page must be an integer from 1 to 10000.');
|
|
664
|
+
if (filters.per_page !== undefined && (!Number.isInteger(filters.per_page) || filters.per_page < 1 || filters.per_page > 100)) throw new Error('Purchase-history per_page must be an integer from 1 to 100.');
|
|
665
|
+
return this.call<MicrotransactionMyPurchases>('myPurchases', title_id, undefined, {}, filters, options);
|
|
666
|
+
}
|
|
667
|
+
/** Atomic tracked spending. Reuse action_id for retries; a new gameplay action needs a new ID. */
|
|
668
|
+
static consume(title_id: string, data: MicrotransactionConsumeInput, options?: MicrotransactionRequestOptions) { return this.call<{ entitlement: MicrotransactionEntitlement; replayed: boolean }>('consume', title_id, data, {}, undefined, options); }
|
|
669
|
+
/** Owning user asks support to review a refund. This does not execute payment reversal. */
|
|
670
|
+
static requestRefund(title_id: string, data: { order_id: string; reason: string }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionRefundRequest>('requestRefund', title_id, data, {}, undefined, options); }
|
|
671
|
+
/** Trusted title server with commerce:fulfill or admin JWT acknowledges the immutable event. */
|
|
672
|
+
static acknowledgeDelivery(title_id: string, delivery_id: string, data: { event_id: string }, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionDeliveryResult>('acknowledgeDelivery', title_id, data, { delivery_id }, undefined, options); }
|
|
673
|
+
/** Title MCP token, never a runtime install token. Describes arguments, abilities, mutation semantics and provider facts. */
|
|
674
|
+
static mcpCapabilities(title_id: string, options?: MicrotransactionRequestOptions) { return this.call<MicrotransactionCapabilities>('mcpCapabilities', title_id, undefined, {}, undefined, options); }
|
|
675
|
+
/** Execute a discovered authorized operation directly. Legacy confirm is ignored and not forwarded. */
|
|
676
|
+
static mcpOperation<T = Record<string, unknown>>(title_id: string, operation: MicrotransactionOperation, data: { arguments: Record<string, unknown>; confirm?: boolean }, options?: MicrotransactionRequestOptions) { return this.call<{ operation: MicrotransactionOperation; result: T }>('mcpOperation', title_id, { arguments: data.arguments }, { operation }, undefined, options); }
|
|
677
|
+
|
|
678
|
+
private static call<T>(route: string, title_id: string, data?: object, ids: Record<string, string> = {}, params?: object, options?: MicrotransactionRequestOptions | MicrotransactionSessionOptions): AxiosPromise<MicrotransactionResponse<T>> {
|
|
679
|
+
const replacements: Record<string, string> = {};
|
|
680
|
+
for (const [key, value] of Object.entries({ title_id, ...ids })) {
|
|
681
|
+
if (!value || !/^[A-Za-z0-9_.:-]+$/.test(value) || value === '.' || value === '..') throw new Error(`Invalid commerce route identifier: ${key}`);
|
|
682
|
+
replacements[key] = encodeURIComponent(value);
|
|
683
|
+
}
|
|
684
|
+
const headers: Record<string, string> = {};
|
|
685
|
+
if (options?.playerToken) headers.Authorization = `Bearer ${options.playerToken}`;
|
|
686
|
+
if (options && 'checkoutToken' in options) {
|
|
687
|
+
if (!options.checkoutToken) throw new Error('A checkout capability is required.');
|
|
688
|
+
headers['X-Checkout-Token'] = options.checkoutToken;
|
|
689
|
+
}
|
|
690
|
+
return Requests.processRoute<T>(MicrotransactionsRoute.routes[route], data, replacements, params, {
|
|
691
|
+
signal: options?.signal, timeout: options?.timeout, headers,
|
|
692
|
+
// Every commerce route is title/environment-scoped. Never inject unrelated
|
|
693
|
+
// global community context into strict management/player route inputs.
|
|
694
|
+
excludeCommunityContext: true,
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
export default Microtransactions;
|