@checkoutpage/sdk 0.1.21 → 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 +126 -0
- package/dist/index.d.mts +15524 -9974
- package/dist/index.d.ts +15524 -9974
- package/dist/index.js +402 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +402 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
@@ -219,6 +261,44 @@ const updated = await checkoutpage.products.update('product_id', {
|
|
|
219
261
|
});
|
|
220
262
|
```
|
|
221
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
|
+
|
|
222
302
|
### Files
|
|
223
303
|
|
|
224
304
|
#### Upload an image
|
|
@@ -247,6 +327,52 @@ const result = await checkoutpage.files.upload({
|
|
|
247
327
|
console.log('File uploaded:', result.data.id);
|
|
248
328
|
```
|
|
249
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
|
+
|
|
250
376
|
## Error Handling
|
|
251
377
|
|
|
252
378
|
The SDK provides typed error classes for different error scenarios:
|