@checkoutpage/sdk 0.1.14 → 0.1.30
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 +174 -0
- package/dist/index.d.mts +21402 -1343
- package/dist/index.d.ts +21402 -1343
- package/dist/index.js +1151 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1151 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -55,6 +55,18 @@ const checkoutpage = createCheckoutPageClient({
|
|
|
55
55
|
|
|
56
56
|
## Usage
|
|
57
57
|
|
|
58
|
+
### Account
|
|
59
|
+
|
|
60
|
+
#### Get the account your API key belongs to
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const account = await checkoutpage.accounts.get();
|
|
64
|
+
|
|
65
|
+
console.log(account.name); // 'mystore' — store slug, the default checkout subdomain
|
|
66
|
+
console.log(account.displayName); // 'My Store' — shown to customers
|
|
67
|
+
console.log(account.logo?.url); // store logo, or null when none is set
|
|
68
|
+
```
|
|
69
|
+
|
|
58
70
|
### Customers
|
|
59
71
|
|
|
60
72
|
#### Get a customer
|
|
@@ -150,6 +162,36 @@ const previousPage = await checkoutpage.subscriptions.list({
|
|
|
150
162
|
});
|
|
151
163
|
```
|
|
152
164
|
|
|
165
|
+
### Subscription Payments
|
|
166
|
+
|
|
167
|
+
Per-payment records for subscriptions — one record per Stripe invoice charge. Use this for billing history, refund inspection, and "when was I charged?" questions.
|
|
168
|
+
|
|
169
|
+
#### List subscription payments
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
const result = await checkoutpage.subscriptionPayments.list({
|
|
173
|
+
limit: 10,
|
|
174
|
+
});
|
|
175
|
+
console.log(`Total: ${result.total}, has more: ${result.has_more}`);
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### List payments for a single subscription
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const result = await checkoutpage.subscriptionPayments.list({
|
|
182
|
+
subscriptionId: 'sub_id',
|
|
183
|
+
});
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
#### Filter failed/unpaid payments
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
const failed = await checkoutpage.subscriptionPayments.list({
|
|
190
|
+
paymentStatus: 'failed',
|
|
191
|
+
});
|
|
192
|
+
const unpaid = await checkoutpage.subscriptionPayments.list({ paid: 'false' });
|
|
193
|
+
```
|
|
194
|
+
|
|
153
195
|
### Payments
|
|
154
196
|
|
|
155
197
|
#### List payments
|
|
@@ -199,6 +241,138 @@ const pageBookings = await checkoutpage.bookings.list({
|
|
|
199
241
|
});
|
|
200
242
|
```
|
|
201
243
|
|
|
244
|
+
### Products
|
|
245
|
+
|
|
246
|
+
#### Get a product
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const product = await checkoutpage.products.get('product_id');
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
#### Update a product
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const updated = await checkoutpage.products.update('product_id', {
|
|
256
|
+
title: 'Updated Product Title',
|
|
257
|
+
description: 'Updated description',
|
|
258
|
+
price: 5900, // $59.00 in cents
|
|
259
|
+
stock: 100,
|
|
260
|
+
hasUnlimitedStock: false,
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
#### Subscription limits and file access
|
|
265
|
+
|
|
266
|
+
These settings live on the product, so a product reused across several checkout
|
|
267
|
+
pages behaves consistently everywhere.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
await checkoutpage.products.update('product_id', {
|
|
271
|
+
// Cap each customer to one active subscription for this product
|
|
272
|
+
limitSubscriptions: {
|
|
273
|
+
enabled: true,
|
|
274
|
+
// Also check active subscriptions in Stripe
|
|
275
|
+
limitSubscriptionsStripe: { enabled: true },
|
|
276
|
+
},
|
|
277
|
+
// Let customers keep downloading files after their subscription lapses
|
|
278
|
+
enableFileAccessForInactiveSubscriptions: true,
|
|
279
|
+
});
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Both are also accepted when creating a page, under `productData`:
|
|
283
|
+
|
|
284
|
+
```typescript
|
|
285
|
+
await checkoutpage.checkoutPages.create({
|
|
286
|
+
name: 'Membership',
|
|
287
|
+
productData: {
|
|
288
|
+
title: 'Membership',
|
|
289
|
+
price: { amount: 4900, currency: 'usd', recurring: { interval: 'month' } },
|
|
290
|
+
limitSubscriptions: { enabled: true },
|
|
291
|
+
enableFileAccessForInactiveSubscriptions: true,
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
> The page-level `limitSubscriptions`, `limitSubscriptionsStripe`, and
|
|
297
|
+
> `enableFileAccessForInactiveSubscriptions` fields are **deprecated**. They are
|
|
298
|
+
> still accepted and are applied to the page's product, and page responses still
|
|
299
|
+
> report them by mirroring the product — but new integrations should set them
|
|
300
|
+
> under `productData` or via `products.update()`.
|
|
301
|
+
|
|
302
|
+
### Files
|
|
303
|
+
|
|
304
|
+
#### Upload an image
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
const imageFile = new File([blob], 'product-image.jpg', { type: 'image/jpeg' });
|
|
308
|
+
|
|
309
|
+
const result = await checkoutpage.files.upload({
|
|
310
|
+
file: imageFile,
|
|
311
|
+
purpose: 'image',
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
console.log('Image uploaded:', result.data.id, result.data.location);
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
#### Upload a file
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
const pdfFile = new File([blob], 'ebook.pdf', { type: 'application/pdf' });
|
|
321
|
+
|
|
322
|
+
const result = await checkoutpage.files.upload({
|
|
323
|
+
file: pdfFile,
|
|
324
|
+
purpose: 'file',
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
console.log('File uploaded:', result.data.id);
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Webhooks
|
|
331
|
+
|
|
332
|
+
#### List webhook endpoints
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
const { data: webhooks, has_more } = await checkoutpage.webhooks.list();
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
#### Filter by event and status
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
const active = await checkoutpage.webhooks.list({
|
|
342
|
+
event: 'payment.paid',
|
|
343
|
+
status: 'active',
|
|
344
|
+
limit: 25,
|
|
345
|
+
});
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
#### Create a webhook endpoint
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
const { data: webhook } = await checkoutpage.webhooks.create({
|
|
352
|
+
name: 'CRM sync',
|
|
353
|
+
url: 'https://example.com/hooks/checkoutpage',
|
|
354
|
+
events: ['payment.paid', 'subscription.created'],
|
|
355
|
+
customHeaders: { Authorization: 'Bearer receiver-token' },
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
saveSecret(webhook.secret);
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
> The `url` must use **https** — an `http` URL is rejected with a `ValidationError`,
|
|
362
|
+
> and a URL already registered on the account is rejected with a `ConflictError`.
|
|
363
|
+
|
|
364
|
+
> The create response is the **only** place the signing `secret` is ever returned.
|
|
365
|
+
> It is not included in `list()` responses and cannot be retrieved later — store it
|
|
366
|
+
> when you create the endpoint. Omit `secret` to have one generated for you.
|
|
367
|
+
|
|
368
|
+
#### Delete a webhook endpoint
|
|
369
|
+
|
|
370
|
+
```typescript
|
|
371
|
+
const { data: deleted } = await checkoutpage.webhooks.delete(webhook.id);
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
Deliveries stop immediately and the endpoint no longer appears in `list()`.
|
|
375
|
+
|
|
202
376
|
## Error Handling
|
|
203
377
|
|
|
204
378
|
The SDK provides typed error classes for different error scenarios:
|