-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathguest-wallets.ts
More file actions
343 lines (279 loc) · 8.67 KB
/
Copy pathguest-wallets.ts
File metadata and controls
343 lines (279 loc) · 8.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
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
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// SPDX-FileCopyrightText: 2026 Xquik contributors
//
// SPDX-License-Identifier: Apache-2.0
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import * as GuestWalletsAPI from './guest-wallets';
import { APIPromise } from '../core/api-promise';
import { buildHeaders } from '../internal/headers';
import { RequestOptions } from '../internal/request-options';
/**
* Accountless prepaid access for paid read endpoints
*/
export class GuestWallets extends APIResource {
/**
* Create a one-use hosted checkout after the user confirms $10-$250 USD. The
* request creates no charge. It returns a paid-read API key without an Xquik
* account. Idempotent replays return the same key.
*
* @example
* ```ts
* const guestWallet = await client.guestWallets.create({
* amount_minor: 1000,
* currency: 'usd',
* 'Idempotency-Key': 'e1cb97D8-dDF3-4AaA-ad0a-49E4A0d1CfAa',
* });
* ```
*/
create(params: GuestWalletCreateParams, options?: RequestOptions): APIPromise<GuestWalletCreateResponse> {
const { 'Idempotency-Key': idempotencyKey, ...body } = params;
return this._client.post('/guest-wallets', {
body,
...options,
headers: buildHeaders([{ 'Idempotency-Key': idempotencyKey }, options?.headers]),
__security: {},
});
}
/**
* Poll after payment. Use usable to decide whether paid reads can run. An active
* wallet can remain usable while a top-up is pending. A new wallet becomes usable
* only after payment is verified. Send the guest key as Authorization: Bearer.
*
* @example
* ```ts
* const response = await client.guestWallets.retrieveStatus();
* ```
*/
retrieveStatus(options?: RequestOptions): APIPromise<GuestWalletRetrieveStatusResponse> {
return this._client.get('/guest-wallets/status', {
...options,
__security: { apiKeyAuth: true, oauthBearerAuth: true },
});
}
/**
* Create a one-use hosted checkout after the user confirms a $10-$250 USD amount
* for an existing paid-read guest key. The key remains the same. This request
* creates no charge and never redirects through Xquik.
*
* @example
* ```ts
* const response = await client.guestWallets.topup({
* amount_minor: 1000,
* currency: 'usd',
* 'Idempotency-Key': 'e1cb97D8-dDF3-4AaA-ad0a-49E4A0d1CfAa',
* });
* ```
*/
topup(params: GuestWalletTopupParams, options?: RequestOptions): APIPromise<GuestWalletTopupResponse> {
const { 'Idempotency-Key': idempotencyKey, ...body } = params;
return this._client.post('/guest-wallets/topups', {
body,
...options,
headers: buildHeaders([{ 'Idempotency-Key': idempotencyKey }, options?.headers]),
__security: { apiKeyAuth: true, oauthBearerAuth: true },
});
}
}
/**
* Confirmed USD amount for a guest wallet purchase.
*/
export interface GuestWalletAmount {
/**
* USD amount in cents. Accepted range is $10-$250.
*/
amount_minor: number;
currency: 'usd';
}
/**
* Initial guest wallet response containing the one-time key.
*/
export interface GuestWalletCreateResponse {
account_required: false;
/**
* Confirmed USD amount for a guest wallet purchase.
*/
amount: GuestWalletAmount;
/**
* Paid-read bearer credential returned only by initial creation. Store it as a
* secret. Never place it in a URL or log.
*/
api_key: string;
authorization: GuestWalletCreateResponse.Authorization;
/**
* Hosted checkout URL for user interaction.
*/
checkout_url: string;
credential_notice: 'Store api_key and the Idempotency-Key securely before sharing checkout_url. No email recovery is available.';
/**
* Usage granted after verified payment.
*/
credits: string;
/**
* Time when the pending checkout expires.
*/
expires_at: string;
/**
* Hosted checkout and status polling instructions.
*/
instructions: string;
/**
* Wait at least this long before polling status_url.
*/
poll_after_seconds: 2;
purchase_id: string;
requires_user_interaction: true;
status: 'creating' | 'pending' | 'paid' | 'expired' | 'failed' | 'refunded' | 'disputed';
status_url: 'https://xquik.com/api/v1/guest-wallets/status';
wallet_id: string;
}
export namespace GuestWalletCreateResponse {
export interface Authorization {
header: 'Authorization';
scheme: 'Bearer';
}
}
/**
* Current balance, usability, and latest guest purchase state.
*/
export interface GuestWalletRetrieveStatusResponse {
balance: string;
/**
* Latest guest wallet purchase fulfillment state.
*/
latest_purchase: GuestWalletRetrieveStatusResponse.LatestPurchase | null;
/**
* Polling delay while payment is pending. Null means stop.
*/
poll_after_seconds: 2 | null;
scope: 'paid_reads';
/**
* Combined wallet and pending-checkout state. A pending top-up can coexist with
* usable true. Terminal expired or failed states require a new guest wallet.
*/
status: 'active' | 'pending' | 'expired' | 'failed' | 'frozen' | 'closed';
/**
* Top-up action when usable and no checkout is pending.
*/
top_up: GuestWalletRetrieveStatusResponse.TopUp | null;
/**
* Authoritative paid-read readiness. Use instead of status.
*/
usable: boolean;
wallet_id: string;
}
export namespace GuestWalletRetrieveStatusResponse {
/**
* Latest guest wallet purchase fulfillment state.
*/
export interface LatestPurchase {
/**
* Confirmed USD amount for a guest wallet purchase.
*/
amount: GuestWalletsAPI.GuestWalletAmount;
/**
* Present only while the purchase is pending.
*/
checkout_url: string | null;
credits: string;
expires_at: string;
purchase_id: string;
status: 'creating' | 'pending' | 'paid' | 'expired' | 'failed' | 'refunded' | 'disputed';
}
/**
* Top-up action when usable and no checkout is pending.
*/
export interface TopUp {
method: 'POST';
path: '/api/v1/guest-wallets/topups';
}
}
/**
* Pending hosted checkout and guest wallet purchase details.
*/
export interface GuestWalletTopupResponse {
account_required: false;
/**
* Confirmed USD amount for a guest wallet purchase.
*/
amount: GuestWalletAmount;
/**
* Hosted checkout URL for user interaction.
*/
checkout_url: string;
/**
* Usage granted after verified payment.
*/
credits: string;
/**
* Time when the pending checkout expires.
*/
expires_at: string;
/**
* Hosted checkout and status polling instructions.
*/
instructions: string;
/**
* Wait at least this long before polling status_url.
*/
poll_after_seconds: 2;
purchase_id: string;
requires_user_interaction: true;
status: 'creating' | 'pending' | 'paid' | 'expired' | 'failed' | 'refunded' | 'disputed';
status_url: 'https://xquik.com/api/v1/guest-wallets/status';
wallet_id: string;
/**
* Paid-read bearer credential returned only by initial creation. Store it as a
* secret. Never place it in a URL or log.
*/
api_key?: string;
authorization?: GuestWalletTopupResponse.Authorization;
credential_notice?: 'Store api_key and the Idempotency-Key securely before sharing checkout_url. No email recovery is available.';
}
export namespace GuestWalletTopupResponse {
export interface Authorization {
header: 'Authorization';
scheme: 'Bearer';
}
}
export interface GuestWalletCreateParams {
/**
* Body param: USD cents accepted for this checkout.
*/
amount_minor: number;
/**
* Body param
*/
currency: 'usd';
/**
* Header param: Generate a cryptographically random UUID v4. Reuse it only to
* retry the same wallet and amount request. Initial wallet creation can recover
* the API key from this value, so store it as a secret and never log it.
*/
'Idempotency-Key': string;
}
export interface GuestWalletTopupParams {
/**
* Body param: USD cents accepted for this checkout.
*/
amount_minor: number;
/**
* Body param
*/
currency: 'usd';
/**
* Header param: Generate a cryptographically random UUID v4. Reuse it only to
* retry the same wallet and amount request. Initial wallet creation can recover
* the API key from this value, so store it as a secret and never log it.
*/
'Idempotency-Key': string;
}
export declare namespace GuestWallets {
export {
type GuestWalletAmount as GuestWalletAmount,
type GuestWalletCreateResponse as GuestWalletCreateResponse,
type GuestWalletRetrieveStatusResponse as GuestWalletRetrieveStatusResponse,
type GuestWalletTopupResponse as GuestWalletTopupResponse,
type GuestWalletCreateParams as GuestWalletCreateParams,
type GuestWalletTopupParams as GuestWalletTopupParams,
};
}