checkout-intents 0.1.0 → 0.3.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 +49 -0
- package/LICENSE +4 -198
- package/README.md +155 -21
- package/client.d.mts +21 -7
- package/client.d.mts.map +1 -1
- package/client.d.ts +21 -7
- package/client.d.ts.map +1 -1
- package/client.js +37 -10
- package/client.js.map +1 -1
- package/client.mjs +37 -10
- package/client.mjs.map +1 -1
- package/internal/to-file.d.mts +1 -1
- package/internal/to-file.d.ts +1 -1
- package/internal/to-file.js +1 -1
- package/internal/to-file.mjs +1 -1
- package/internal/tslib.js +17 -17
- package/internal/utils/values.js +3 -3
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +3 -3
- package/internal/utils/values.mjs.map +1 -1
- package/package.json +3 -3
- package/resources/brands.d.mts +31 -0
- package/resources/brands.d.mts.map +1 -0
- package/resources/brands.d.ts +31 -0
- package/resources/brands.d.ts.map +1 -0
- package/resources/{api/v1/brands.js → brands.js} +5 -5
- package/resources/brands.js.map +1 -0
- package/resources/brands.mjs +15 -0
- package/resources/brands.mjs.map +1 -0
- package/resources/checkout-intents.d.mts +320 -0
- package/resources/checkout-intents.d.mts.map +1 -0
- package/resources/checkout-intents.d.ts +320 -0
- package/resources/checkout-intents.d.ts.map +1 -0
- package/resources/checkout-intents.js +248 -0
- package/resources/checkout-intents.js.map +1 -0
- package/resources/checkout-intents.mjs +244 -0
- package/resources/checkout-intents.mjs.map +1 -0
- package/resources/index.d.mts +2 -2
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +2 -2
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +5 -5
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -2
- package/resources/index.mjs.map +1 -1
- package/src/client.ts +84 -14
- package/src/internal/to-file.ts +1 -1
- package/src/internal/utils/values.ts +3 -3
- package/src/resources/{api/v1/brands.ts → brands.ts} +9 -9
- package/src/resources/checkout-intents.ts +531 -0
- package/src/resources/index.ts +14 -2
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/api/api.d.mts +0 -10
- package/resources/api/api.d.mts.map +0 -1
- package/resources/api/api.d.ts +0 -10
- package/resources/api/api.d.ts.map +0 -1
- package/resources/api/api.js +0 -17
- package/resources/api/api.js.map +0 -1
- package/resources/api/api.mjs +0 -12
- package/resources/api/api.mjs.map +0 -1
- package/resources/api/index.d.mts +0 -3
- package/resources/api/index.d.mts.map +0 -1
- package/resources/api/index.d.ts +0 -3
- package/resources/api/index.d.ts.map +0 -1
- package/resources/api/index.js +0 -9
- package/resources/api/index.js.map +0 -1
- package/resources/api/index.mjs +0 -4
- package/resources/api/index.mjs.map +0 -1
- package/resources/api/v1/brands.d.mts +0 -31
- package/resources/api/v1/brands.d.mts.map +0 -1
- package/resources/api/v1/brands.d.ts +0 -31
- package/resources/api/v1/brands.d.ts.map +0 -1
- package/resources/api/v1/brands.js.map +0 -1
- package/resources/api/v1/brands.mjs +0 -15
- package/resources/api/v1/brands.mjs.map +0 -1
- package/resources/api/v1/checkout-intents.d.mts +0 -117
- package/resources/api/v1/checkout-intents.d.mts.map +0 -1
- package/resources/api/v1/checkout-intents.d.ts +0 -117
- package/resources/api/v1/checkout-intents.d.ts.map +0 -1
- package/resources/api/v1/checkout-intents.js +0 -33
- package/resources/api/v1/checkout-intents.js.map +0 -1
- package/resources/api/v1/checkout-intents.mjs +0 -29
- package/resources/api/v1/checkout-intents.mjs.map +0 -1
- package/resources/api/v1/index.d.mts +0 -4
- package/resources/api/v1/index.d.mts.map +0 -1
- package/resources/api/v1/index.d.ts +0 -4
- package/resources/api/v1/index.d.ts.map +0 -1
- package/resources/api/v1/index.js +0 -11
- package/resources/api/v1/index.js.map +0 -1
- package/resources/api/v1/index.mjs +0 -5
- package/resources/api/v1/index.mjs.map +0 -1
- package/resources/api/v1/v1.d.mts +0 -14
- package/resources/api/v1/v1.d.mts.map +0 -1
- package/resources/api/v1/v1.d.ts +0 -14
- package/resources/api/v1/v1.d.ts.map +0 -1
- package/resources/api/v1/v1.js +0 -21
- package/resources/api/v1/v1.js.map +0 -1
- package/resources/api/v1/v1.mjs +0 -16
- package/resources/api/v1/v1.mjs.map +0 -1
- package/resources/api/v1.d.mts +0 -2
- package/resources/api/v1.d.mts.map +0 -1
- package/resources/api/v1.d.ts +0 -2
- package/resources/api/v1.d.ts.map +0 -1
- package/resources/api/v1.js +0 -6
- package/resources/api/v1.js.map +0 -1
- package/resources/api/v1.mjs +0 -3
- package/resources/api/v1.mjs.map +0 -1
- package/resources/api.d.mts +0 -2
- package/resources/api.d.mts.map +0 -1
- package/resources/api.d.ts +0 -2
- package/resources/api.d.ts.map +0 -1
- package/resources/api.js +0 -6
- package/resources/api.js.map +0 -1
- package/resources/api.mjs +0 -3
- package/resources/api.mjs.map +0 -1
- package/resources/health.d.mts +0 -17
- package/resources/health.d.mts.map +0 -1
- package/resources/health.d.ts +0 -17
- package/resources/health.d.ts.map +0 -1
- package/resources/health.js +0 -15
- package/resources/health.js.map +0 -1
- package/resources/health.mjs +0 -11
- package/resources/health.mjs.map +0 -1
- package/src/resources/api/api.ts +0 -15
- package/src/resources/api/index.ts +0 -4
- package/src/resources/api/v1/checkout-intents.ts +0 -207
- package/src/resources/api/v1/index.ts +0 -15
- package/src/resources/api/v1/v1.ts +0 -41
- package/src/resources/api/v1.ts +0 -3
- package/src/resources/api.ts +0 -3
- package/src/resources/health.ts +0 -24
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
import { APIResource } from "../core/resource.js";
|
|
2
|
+
import * as CheckoutIntentsAPI from "./checkout-intents.js";
|
|
3
|
+
import { APIPromise } from "../core/api-promise.js";
|
|
4
|
+
import { RequestOptions } from "../internal/request-options.js";
|
|
5
|
+
/**
|
|
6
|
+
* Options for polling operations.
|
|
7
|
+
*/
|
|
8
|
+
export interface PollOptions {
|
|
9
|
+
/**
|
|
10
|
+
* The interval in milliseconds between polling attempts.
|
|
11
|
+
*/
|
|
12
|
+
pollIntervalMs?: number;
|
|
13
|
+
/**
|
|
14
|
+
* The maximum number of polling attempts before timing out.
|
|
15
|
+
*/
|
|
16
|
+
maxAttempts?: number;
|
|
17
|
+
}
|
|
18
|
+
export declare class CheckoutIntentsResource extends APIResource {
|
|
19
|
+
/**
|
|
20
|
+
* Create a checkout intent with the given request body.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* const checkoutIntent = await client.checkoutIntents.create({
|
|
25
|
+
* buyer: {
|
|
26
|
+
* address1: '123 Main St',
|
|
27
|
+
* city: 'New York',
|
|
28
|
+
* country: 'United States',
|
|
29
|
+
* email: 'john.doe@example.com',
|
|
30
|
+
* firstName: 'John',
|
|
31
|
+
* lastName: 'Doe',
|
|
32
|
+
* phone: '+1234567890',
|
|
33
|
+
* postalCode: '10001',
|
|
34
|
+
* province: 'NY',
|
|
35
|
+
* },
|
|
36
|
+
* productUrl: 'productUrl',
|
|
37
|
+
* quantity: 1,
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
create(body: CheckoutIntentCreateParams, options?: RequestOptions): APIPromise<CheckoutIntent>;
|
|
42
|
+
/**
|
|
43
|
+
* Retrieve a checkout intent by id
|
|
44
|
+
*
|
|
45
|
+
* Returns checkout intent information if the lookup succeeds.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const checkoutIntent =
|
|
50
|
+
* await client.checkoutIntents.retrieve('id');
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
retrieve(id: string, options?: RequestOptions): APIPromise<CheckoutIntent>;
|
|
54
|
+
/**
|
|
55
|
+
* Add payment details to a checkout intent
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const checkoutIntent =
|
|
60
|
+
* await client.checkoutIntents.addPayment('id', {
|
|
61
|
+
* paymentMethod: {
|
|
62
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
63
|
+
* type: 'stripe_token',
|
|
64
|
+
* },
|
|
65
|
+
* });
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
addPayment(id: string, body: CheckoutIntentAddPaymentParams, options?: RequestOptions): APIPromise<CheckoutIntent>;
|
|
69
|
+
/**
|
|
70
|
+
* Confirm a checkout intent with provided payment information
|
|
71
|
+
*
|
|
72
|
+
* Confirm means we have buyer's name, address and payment info, so we can move
|
|
73
|
+
* forward to place the order.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const checkoutIntent = await client.checkoutIntents.confirm(
|
|
78
|
+
* 'id',
|
|
79
|
+
* {
|
|
80
|
+
* paymentMethod: {
|
|
81
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
82
|
+
* type: 'stripe_token',
|
|
83
|
+
* },
|
|
84
|
+
* },
|
|
85
|
+
* );
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
confirm(id: string, body: CheckoutIntentConfirmParams, options?: RequestOptions): APIPromise<CheckoutIntent>;
|
|
89
|
+
/**
|
|
90
|
+
* A helper to poll a checkout intent until a specific condition is met.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* // Poll until completed or failed
|
|
95
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntil(
|
|
96
|
+
* 'id',
|
|
97
|
+
* (intent) => intent.state === 'completed' || intent.state === 'failed'
|
|
98
|
+
* );
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
private pollUntil;
|
|
102
|
+
/**
|
|
103
|
+
* A helper to poll a checkout intent until it reaches a completed state
|
|
104
|
+
* (completed or failed).
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntilCompleted('id');
|
|
109
|
+
* if (checkoutIntent.state === 'completed') {
|
|
110
|
+
* console.log('Order placed successfully!');
|
|
111
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
112
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
pollUntilCompleted(id: string, options?: RequestOptions & PollOptions): Promise<CheckoutIntent.CompletedCheckoutIntent | CheckoutIntent.FailedCheckoutIntent>;
|
|
117
|
+
/**
|
|
118
|
+
* A helper to poll a checkout intent until it's ready for confirmation
|
|
119
|
+
* (awaiting_confirmation state) or has failed. This is typically used after
|
|
120
|
+
* creating a checkout intent to wait for the offer to be retrieved from the merchant.
|
|
121
|
+
*
|
|
122
|
+
* The intent can reach awaiting_confirmation (success - ready to confirm) or failed
|
|
123
|
+
* (offer retrieval failed). Always check the state after polling.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const intent = await client.checkoutIntents.pollUntilAwaitingConfirmation('id');
|
|
128
|
+
*
|
|
129
|
+
* if (intent.state === 'awaiting_confirmation') {
|
|
130
|
+
* // Review the offer before confirming
|
|
131
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
132
|
+
* } else if (intent.state === 'failed') {
|
|
133
|
+
* // Handle failure (e.g., offer retrieval failed, product out of stock)
|
|
134
|
+
* console.log('Failed:', intent.failureReason);
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
pollUntilAwaitingConfirmation(id: string, options?: RequestOptions & PollOptions): Promise<CheckoutIntent.AwaitingConfirmationCheckoutIntent | CheckoutIntent.FailedCheckoutIntent>;
|
|
139
|
+
/**
|
|
140
|
+
* A helper to create a checkout intent and poll until it's ready for confirmation.
|
|
141
|
+
* This follows the Rye documented flow: create → poll until awaiting_confirmation.
|
|
142
|
+
*
|
|
143
|
+
* After this method completes, you should review the offer (pricing, shipping, taxes)
|
|
144
|
+
* with the user before calling confirm().
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```ts
|
|
148
|
+
* // Phase 1: Create and wait for offer
|
|
149
|
+
* const intent = await client.checkoutIntents.createAndPoll({
|
|
150
|
+
* buyer: {
|
|
151
|
+
* address1: '123 Main St',
|
|
152
|
+
* city: 'New York',
|
|
153
|
+
* country: 'United States',
|
|
154
|
+
* email: 'john.doe@example.com',
|
|
155
|
+
* firstName: 'John',
|
|
156
|
+
* lastName: 'Doe',
|
|
157
|
+
* phone: '+1234567890',
|
|
158
|
+
* postalCode: '10001',
|
|
159
|
+
* province: 'NY',
|
|
160
|
+
* },
|
|
161
|
+
* productUrl: 'https://example.com/product',
|
|
162
|
+
* quantity: 1,
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Review the offer with the user
|
|
166
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
167
|
+
*
|
|
168
|
+
* // Phase 2: Confirm with payment
|
|
169
|
+
* const completed = await client.checkoutIntents.confirmAndPoll(intent.id, {
|
|
170
|
+
* paymentMethod: { type: 'stripe_token', stripeToken: 'tok_visa' }
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
createAndPoll(body: CheckoutIntentCreateParams, options?: RequestOptions & PollOptions): Promise<CheckoutIntent.AwaitingConfirmationCheckoutIntent | CheckoutIntent.FailedCheckoutIntent>;
|
|
175
|
+
/**
|
|
176
|
+
* A helper to confirm a checkout intent and poll until it reaches a completed state
|
|
177
|
+
* (completed or failed).
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* const checkoutIntent = await client.checkoutIntents.confirmAndPoll(
|
|
182
|
+
* 'id',
|
|
183
|
+
* {
|
|
184
|
+
* paymentMethod: {
|
|
185
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
186
|
+
* type: 'stripe_token',
|
|
187
|
+
* },
|
|
188
|
+
* }
|
|
189
|
+
* );
|
|
190
|
+
*
|
|
191
|
+
* if (checkoutIntent.state === 'completed') {
|
|
192
|
+
* console.log('Order placed successfully!');
|
|
193
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
194
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
confirmAndPoll(id: string, body: CheckoutIntentConfirmParams, options?: RequestOptions & PollOptions): Promise<CheckoutIntent.CompletedCheckoutIntent | CheckoutIntent.FailedCheckoutIntent>;
|
|
199
|
+
}
|
|
200
|
+
export interface BaseCheckoutIntent {
|
|
201
|
+
id: string;
|
|
202
|
+
buyer: Buyer;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
productUrl: string;
|
|
205
|
+
quantity: number;
|
|
206
|
+
variantSelections?: Array<VariantSelection>;
|
|
207
|
+
}
|
|
208
|
+
export interface Buyer {
|
|
209
|
+
address1: string;
|
|
210
|
+
city: string;
|
|
211
|
+
country: string;
|
|
212
|
+
email: string;
|
|
213
|
+
firstName: string;
|
|
214
|
+
lastName: string;
|
|
215
|
+
phone: string;
|
|
216
|
+
postalCode: string;
|
|
217
|
+
province: string;
|
|
218
|
+
address2?: string;
|
|
219
|
+
}
|
|
220
|
+
export type CheckoutIntent = CheckoutIntent.RetrievingOfferCheckoutIntent | CheckoutIntent.AwaitingConfirmationCheckoutIntent | CheckoutIntent.PlacingOrderCheckoutIntent | CheckoutIntent.CompletedCheckoutIntent | CheckoutIntent.FailedCheckoutIntent;
|
|
221
|
+
export declare namespace CheckoutIntent {
|
|
222
|
+
interface RetrievingOfferCheckoutIntent extends CheckoutIntentsAPI.BaseCheckoutIntent {
|
|
223
|
+
state: 'retrieving_offer';
|
|
224
|
+
}
|
|
225
|
+
interface AwaitingConfirmationCheckoutIntent extends CheckoutIntentsAPI.BaseCheckoutIntent {
|
|
226
|
+
offer: CheckoutIntentsAPI.Offer;
|
|
227
|
+
state: 'awaiting_confirmation';
|
|
228
|
+
paymentMethod?: CheckoutIntentsAPI.PaymentMethod;
|
|
229
|
+
}
|
|
230
|
+
interface PlacingOrderCheckoutIntent extends CheckoutIntentsAPI.BaseCheckoutIntent {
|
|
231
|
+
offer: CheckoutIntentsAPI.Offer;
|
|
232
|
+
paymentMethod: CheckoutIntentsAPI.PaymentMethod;
|
|
233
|
+
state: 'placing_order';
|
|
234
|
+
}
|
|
235
|
+
interface CompletedCheckoutIntent extends CheckoutIntentsAPI.BaseCheckoutIntent {
|
|
236
|
+
offer: CheckoutIntentsAPI.Offer;
|
|
237
|
+
paymentMethod: CheckoutIntentsAPI.PaymentMethod;
|
|
238
|
+
state: 'completed';
|
|
239
|
+
}
|
|
240
|
+
interface FailedCheckoutIntent extends CheckoutIntentsAPI.BaseCheckoutIntent {
|
|
241
|
+
failureReason: FailedCheckoutIntent.FailureReason;
|
|
242
|
+
state: 'failed';
|
|
243
|
+
offer?: CheckoutIntentsAPI.Offer;
|
|
244
|
+
paymentMethod?: CheckoutIntentsAPI.PaymentMethod;
|
|
245
|
+
}
|
|
246
|
+
namespace FailedCheckoutIntent {
|
|
247
|
+
interface FailureReason {
|
|
248
|
+
code: 'checkout_intent_expired' | 'payment_failed' | 'insufficient_stock' | 'product_out_of_stock' | 'offer_retrieval_failed' | 'order_placement_failed' | 'developer_not_found' | 'missing_shipping_method' | 'unsupported_currency' | 'unsupported_store_no_guest_checkout';
|
|
249
|
+
message: string;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
export interface Money {
|
|
254
|
+
amountSubunits: number;
|
|
255
|
+
currencyCode: string;
|
|
256
|
+
}
|
|
257
|
+
export interface Offer {
|
|
258
|
+
cost: Offer.Cost;
|
|
259
|
+
shipping: Offer.Shipping;
|
|
260
|
+
}
|
|
261
|
+
export declare namespace Offer {
|
|
262
|
+
interface Cost {
|
|
263
|
+
subtotal: CheckoutIntentsAPI.Money;
|
|
264
|
+
total: CheckoutIntentsAPI.Money;
|
|
265
|
+
discount?: CheckoutIntentsAPI.Money;
|
|
266
|
+
shipping?: CheckoutIntentsAPI.Money;
|
|
267
|
+
tax?: CheckoutIntentsAPI.Money;
|
|
268
|
+
}
|
|
269
|
+
interface Shipping {
|
|
270
|
+
availableOptions: Array<Shipping.AvailableOption>;
|
|
271
|
+
selectedOptionId?: string;
|
|
272
|
+
}
|
|
273
|
+
namespace Shipping {
|
|
274
|
+
interface AvailableOption {
|
|
275
|
+
id: string;
|
|
276
|
+
cost: CheckoutIntentsAPI.Money;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
export type PaymentMethod = PaymentMethod.StripeTokenPaymentMethod | PaymentMethod.BasisTheoryPaymentMethod | PaymentMethod.NekudaPaymentMethod;
|
|
281
|
+
export declare namespace PaymentMethod {
|
|
282
|
+
interface StripeTokenPaymentMethod {
|
|
283
|
+
stripeToken: string;
|
|
284
|
+
type: 'stripe_token';
|
|
285
|
+
}
|
|
286
|
+
interface BasisTheoryPaymentMethod {
|
|
287
|
+
basisTheoryToken: string;
|
|
288
|
+
type: 'basis_theory_token';
|
|
289
|
+
}
|
|
290
|
+
interface NekudaPaymentMethod {
|
|
291
|
+
nekudaUserId: string;
|
|
292
|
+
type: 'nekuda_token';
|
|
293
|
+
/**
|
|
294
|
+
* Construct a type with a set of properties K of type T
|
|
295
|
+
*/
|
|
296
|
+
nekudaMandateData?: {
|
|
297
|
+
[key: string]: string | number;
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export interface VariantSelection {
|
|
302
|
+
label: string;
|
|
303
|
+
value: string | number;
|
|
304
|
+
}
|
|
305
|
+
export interface CheckoutIntentCreateParams {
|
|
306
|
+
buyer: Buyer;
|
|
307
|
+
productUrl: string;
|
|
308
|
+
quantity: number;
|
|
309
|
+
variantSelections?: Array<VariantSelection>;
|
|
310
|
+
}
|
|
311
|
+
export interface CheckoutIntentAddPaymentParams {
|
|
312
|
+
paymentMethod: PaymentMethod;
|
|
313
|
+
}
|
|
314
|
+
export interface CheckoutIntentConfirmParams {
|
|
315
|
+
paymentMethod: PaymentMethod;
|
|
316
|
+
}
|
|
317
|
+
export declare namespace CheckoutIntentsResource {
|
|
318
|
+
export { type BaseCheckoutIntent as BaseCheckoutIntent, type Buyer as Buyer, type CheckoutIntent as CheckoutIntent, type Money as Money, type Offer as Offer, type PaymentMethod as PaymentMethod, type PollOptions as PollOptions, type VariantSelection as VariantSelection, type CheckoutIntentCreateParams as CheckoutIntentCreateParams, type CheckoutIntentAddPaymentParams as CheckoutIntentAddPaymentParams, type CheckoutIntentConfirmParams as CheckoutIntentConfirmParams, };
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=checkout-intents.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-intents.d.ts","sourceRoot":"","sources":["../src/resources/checkout-intents.ts"],"names":[],"mappings":"OAEO,EAAE,WAAW,EAAE;OACf,KAAK,kBAAkB;OACvB,EAAE,UAAU,EAAE;OACd,EAAE,cAAc,EAAE;AAKzB;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,uBAAwB,SAAQ,WAAW;IACtD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAI,EAAE,0BAA0B,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;IAI9F;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;IAI1E;;;;;;;;;;;;;OAaG;IACH,UAAU,CACR,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,8BAA8B,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AW,EAC/B,KAAK,gBAAgB,IAAI,gBAAgB,EACzC,KAAK,0BAA0B,IAAI,0BAA0B,EAC7D,KAAK,8BAA8B,IAAI,8BAA8B,EACrE,KAAK,2BAA2B,IAAI,2BAA2B,GAChE,CAAC;CACH"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.CheckoutIntentsResource = void 0;
|
|
5
|
+
const resource_1 = require("../core/resource.js");
|
|
6
|
+
const path_1 = require("../internal/utils/path.js");
|
|
7
|
+
const sleep_1 = require("../internal/utils/sleep.js");
|
|
8
|
+
const headers_1 = require("../internal/headers.js");
|
|
9
|
+
class CheckoutIntentsResource extends resource_1.APIResource {
|
|
10
|
+
/**
|
|
11
|
+
* Create a checkout intent with the given request body.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const checkoutIntent = await client.checkoutIntents.create({
|
|
16
|
+
* buyer: {
|
|
17
|
+
* address1: '123 Main St',
|
|
18
|
+
* city: 'New York',
|
|
19
|
+
* country: 'United States',
|
|
20
|
+
* email: 'john.doe@example.com',
|
|
21
|
+
* firstName: 'John',
|
|
22
|
+
* lastName: 'Doe',
|
|
23
|
+
* phone: '+1234567890',
|
|
24
|
+
* postalCode: '10001',
|
|
25
|
+
* province: 'NY',
|
|
26
|
+
* },
|
|
27
|
+
* productUrl: 'productUrl',
|
|
28
|
+
* quantity: 1,
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
create(body, options) {
|
|
33
|
+
return this._client.post('/api/v1/checkout-intents', { body, ...options });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Retrieve a checkout intent by id
|
|
37
|
+
*
|
|
38
|
+
* Returns checkout intent information if the lookup succeeds.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* const checkoutIntent =
|
|
43
|
+
* await client.checkoutIntents.retrieve('id');
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
retrieve(id, options) {
|
|
47
|
+
return this._client.get((0, path_1.path) `/api/v1/checkout-intents/${id}`, options);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Add payment details to a checkout intent
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* const checkoutIntent =
|
|
55
|
+
* await client.checkoutIntents.addPayment('id', {
|
|
56
|
+
* paymentMethod: {
|
|
57
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
58
|
+
* type: 'stripe_token',
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
addPayment(id, body, options) {
|
|
64
|
+
return this._client.post((0, path_1.path) `/api/v1/checkout-intents/${id}/payment`, { body, ...options });
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Confirm a checkout intent with provided payment information
|
|
68
|
+
*
|
|
69
|
+
* Confirm means we have buyer's name, address and payment info, so we can move
|
|
70
|
+
* forward to place the order.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const checkoutIntent = await client.checkoutIntents.confirm(
|
|
75
|
+
* 'id',
|
|
76
|
+
* {
|
|
77
|
+
* paymentMethod: {
|
|
78
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
79
|
+
* type: 'stripe_token',
|
|
80
|
+
* },
|
|
81
|
+
* },
|
|
82
|
+
* );
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
confirm(id, body, options) {
|
|
86
|
+
return this._client.post((0, path_1.path) `/api/v1/checkout-intents/${id}/confirm`, { body, ...options });
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A helper to poll a checkout intent until a specific condition is met.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // Poll until completed or failed
|
|
94
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntil(
|
|
95
|
+
* 'id',
|
|
96
|
+
* (intent) => intent.state === 'completed' || intent.state === 'failed'
|
|
97
|
+
* );
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
async pollUntil(id, condition, options) {
|
|
101
|
+
const maxAttempts = options?.maxAttempts ?? 120; // Default: 120 attempts
|
|
102
|
+
const pollIntervalMs = options?.pollIntervalMs ?? 5000; // Default: 5 seconds
|
|
103
|
+
let attempts = 0;
|
|
104
|
+
const headers = (0, headers_1.buildHeaders)([
|
|
105
|
+
options?.headers,
|
|
106
|
+
{
|
|
107
|
+
'X-Stainless-Poll-Helper': 'true',
|
|
108
|
+
'X-Stainless-Custom-Poll-Interval': pollIntervalMs.toString(),
|
|
109
|
+
},
|
|
110
|
+
]);
|
|
111
|
+
while (attempts < maxAttempts) {
|
|
112
|
+
const { data: intent, response } = await this.retrieve(id, {
|
|
113
|
+
...options,
|
|
114
|
+
headers: { ...options?.headers, ...headers.values },
|
|
115
|
+
}).withResponse();
|
|
116
|
+
// Check if condition is met
|
|
117
|
+
if (condition(intent)) {
|
|
118
|
+
return intent;
|
|
119
|
+
}
|
|
120
|
+
attempts++;
|
|
121
|
+
// If we've reached max attempts, throw an error
|
|
122
|
+
if (attempts >= maxAttempts) {
|
|
123
|
+
throw new Error(`Polling timeout: condition not met after ${maxAttempts} attempts (${(maxAttempts * pollIntervalMs) / 1000}s)`);
|
|
124
|
+
}
|
|
125
|
+
// Check if server suggests a polling interval
|
|
126
|
+
let sleepInterval = pollIntervalMs;
|
|
127
|
+
const headerInterval = response.headers.get('retry-after-ms');
|
|
128
|
+
if (headerInterval) {
|
|
129
|
+
const headerIntervalMs = parseInt(headerInterval);
|
|
130
|
+
if (!isNaN(headerIntervalMs)) {
|
|
131
|
+
sleepInterval = headerIntervalMs;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
await (0, sleep_1.sleep)(sleepInterval);
|
|
135
|
+
}
|
|
136
|
+
// This should never be reached due to the throw above, but TypeScript needs it
|
|
137
|
+
throw new Error(`Polling timeout: condition not met after ${maxAttempts} attempts`);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A helper to poll a checkout intent until it reaches a completed state
|
|
141
|
+
* (completed or failed).
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const checkoutIntent = await client.checkoutIntents.pollUntilCompleted('id');
|
|
146
|
+
* if (checkoutIntent.state === 'completed') {
|
|
147
|
+
* console.log('Order placed successfully!');
|
|
148
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
149
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
150
|
+
* }
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
async pollUntilCompleted(id, options) {
|
|
154
|
+
return this.pollUntil(id, (intent) => intent.state === 'completed' || intent.state === 'failed', options);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* A helper to poll a checkout intent until it's ready for confirmation
|
|
158
|
+
* (awaiting_confirmation state) or has failed. This is typically used after
|
|
159
|
+
* creating a checkout intent to wait for the offer to be retrieved from the merchant.
|
|
160
|
+
*
|
|
161
|
+
* The intent can reach awaiting_confirmation (success - ready to confirm) or failed
|
|
162
|
+
* (offer retrieval failed). Always check the state after polling.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* const intent = await client.checkoutIntents.pollUntilAwaitingConfirmation('id');
|
|
167
|
+
*
|
|
168
|
+
* if (intent.state === 'awaiting_confirmation') {
|
|
169
|
+
* // Review the offer before confirming
|
|
170
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
171
|
+
* } else if (intent.state === 'failed') {
|
|
172
|
+
* // Handle failure (e.g., offer retrieval failed, product out of stock)
|
|
173
|
+
* console.log('Failed:', intent.failureReason);
|
|
174
|
+
* }
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
async pollUntilAwaitingConfirmation(id, options) {
|
|
178
|
+
return this.pollUntil(id, (intent) => intent.state === 'awaiting_confirmation' || intent.state === 'failed', options);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* A helper to create a checkout intent and poll until it's ready for confirmation.
|
|
182
|
+
* This follows the Rye documented flow: create → poll until awaiting_confirmation.
|
|
183
|
+
*
|
|
184
|
+
* After this method completes, you should review the offer (pricing, shipping, taxes)
|
|
185
|
+
* with the user before calling confirm().
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```ts
|
|
189
|
+
* // Phase 1: Create and wait for offer
|
|
190
|
+
* const intent = await client.checkoutIntents.createAndPoll({
|
|
191
|
+
* buyer: {
|
|
192
|
+
* address1: '123 Main St',
|
|
193
|
+
* city: 'New York',
|
|
194
|
+
* country: 'United States',
|
|
195
|
+
* email: 'john.doe@example.com',
|
|
196
|
+
* firstName: 'John',
|
|
197
|
+
* lastName: 'Doe',
|
|
198
|
+
* phone: '+1234567890',
|
|
199
|
+
* postalCode: '10001',
|
|
200
|
+
* province: 'NY',
|
|
201
|
+
* },
|
|
202
|
+
* productUrl: 'https://example.com/product',
|
|
203
|
+
* quantity: 1,
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* // Review the offer with the user
|
|
207
|
+
* console.log('Total:', intent.offer.cost.total);
|
|
208
|
+
*
|
|
209
|
+
* // Phase 2: Confirm with payment
|
|
210
|
+
* const completed = await client.checkoutIntents.confirmAndPoll(intent.id, {
|
|
211
|
+
* paymentMethod: { type: 'stripe_token', stripeToken: 'tok_visa' }
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
async createAndPoll(body, options) {
|
|
216
|
+
const intent = await this.create(body, options);
|
|
217
|
+
return this.pollUntilAwaitingConfirmation(intent.id, options);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* A helper to confirm a checkout intent and poll until it reaches a completed state
|
|
221
|
+
* (completed or failed).
|
|
222
|
+
*
|
|
223
|
+
* @example
|
|
224
|
+
* ```ts
|
|
225
|
+
* const checkoutIntent = await client.checkoutIntents.confirmAndPoll(
|
|
226
|
+
* 'id',
|
|
227
|
+
* {
|
|
228
|
+
* paymentMethod: {
|
|
229
|
+
* stripeToken: 'tok_1RkrWWHGDlstla3f1Fc7ZrhH',
|
|
230
|
+
* type: 'stripe_token',
|
|
231
|
+
* },
|
|
232
|
+
* }
|
|
233
|
+
* );
|
|
234
|
+
*
|
|
235
|
+
* if (checkoutIntent.state === 'completed') {
|
|
236
|
+
* console.log('Order placed successfully!');
|
|
237
|
+
* } else if (checkoutIntent.state === 'failed') {
|
|
238
|
+
* console.log('Order failed:', checkoutIntent.failureReason);
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
async confirmAndPoll(id, body, options) {
|
|
243
|
+
const intent = await this.confirm(id, body, options);
|
|
244
|
+
return this.pollUntilCompleted(intent.id, options);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
exports.CheckoutIntentsResource = CheckoutIntentsResource;
|
|
248
|
+
//# sourceMappingURL=checkout-intents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout-intents.js","sourceRoot":"","sources":["../src/resources/checkout-intents.ts"],"names":[],"mappings":";AAAA,sFAAsF;;;AAEtF,kDAA+C;AAI/C,oDAA8C;AAC9C,sDAAgD;AAChD,oDAAmD;AAiBnD,MAAa,uBAAwB,SAAQ,sBAAW;IACtD;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,IAAgC,EAAE,OAAwB;QAC/D,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,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