@checkoutpage/sdk 0.1.21 → 0.1.31

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/dist/index.js CHANGED
@@ -55,16 +55,68 @@ var APIError = class _APIError extends CheckoutPageError {
55
55
  }
56
56
  };
57
57
 
58
+ // src/resources/invoices/invoices.ts
59
+ var InvoiceResource = class {
60
+ constructor(client) {
61
+ this.client = client;
62
+ }
63
+ /**
64
+ * Retrieve a single invoice by ID. The returned `invoiceUrl` is a freshly
65
+ * signed link to the hosted PDF and expires an hour later — re-fetch to
66
+ * mint a new one.
67
+ *
68
+ * @example
69
+ * const { data: invoice } = await client.invoices.get(invoiceId);
70
+ */
71
+ async get(id) {
72
+ if (!id) {
73
+ throw new Error("Invoice ID is required");
74
+ }
75
+ return this.client.request({
76
+ method: "GET",
77
+ path: `/v1/invoices/${id}`
78
+ });
79
+ }
80
+ async list(args = {}) {
81
+ const query = {
82
+ limit: args.limit?.toString(),
83
+ starting_after: args.starting_after,
84
+ ending_before: args.ending_before,
85
+ search: args.search,
86
+ status: args.status,
87
+ customerId: args.customerId,
88
+ chargeId: args.chargeId,
89
+ poNumber: args.poNumber,
90
+ createdAfter: args.createdAfter,
91
+ createdBefore: args.createdBefore
92
+ };
93
+ return this.client.request({
94
+ method: "GET",
95
+ path: "/v1/invoices/",
96
+ query
97
+ });
98
+ }
99
+ async regenerate(id) {
100
+ const response = await this.client.request({
101
+ method: "POST",
102
+ path: `/v1/invoices/${id}/regenerate`
103
+ });
104
+ return response.data;
105
+ }
106
+ };
107
+
58
108
  // src/client.ts
59
109
  var CheckoutPageApiClient = class {
60
110
  apiKey;
61
111
  baseUrl;
112
+ invoices;
62
113
  constructor(options) {
63
114
  if (!options.apiKey) {
64
115
  throw new Error("API key is required");
65
116
  }
66
117
  this.apiKey = options.apiKey;
67
118
  this.baseUrl = options.baseUrl || "https://api.checkoutpage.com";
119
+ this.invoices = new InvoiceResource(this);
68
120
  }
69
121
  async request(options) {
70
122
  const url = this.buildUrl(options.path, options.query);
@@ -87,6 +139,25 @@ var CheckoutPageApiClient = class {
87
139
  const response = await fetch(url, fetchOptions);
88
140
  return await this.handleResponse(response);
89
141
  }
142
+ /**
143
+ * Perform a request whose successful response is a binary file rather than
144
+ * JSON (e.g. a ticket PDF). Errors are parsed and thrown the same way as
145
+ * request().
146
+ */
147
+ async requestRaw(options) {
148
+ const url = this.buildUrl(options.path, options.query);
149
+ const response = await fetch(url, {
150
+ method: options.method,
151
+ headers: {
152
+ Authorization: `Bearer ${this.apiKey}`,
153
+ "User-Agent": "@checkoutpage/sdk/0.1.0"
154
+ }
155
+ });
156
+ if (!response.ok) {
157
+ await this.handleResponse(response);
158
+ }
159
+ return await response.arrayBuffer();
160
+ }
90
161
  buildUrl(path, query) {
91
162
  const url = new URL(path, this.baseUrl);
92
163
  if (query) {
@@ -141,6 +212,27 @@ var CheckoutPageApiClient = class {
141
212
  }
142
213
  };
143
214
 
215
+ // src/resources/accounts/accounts.ts
216
+ var AccountResource = class {
217
+ constructor(client) {
218
+ this.client = client;
219
+ }
220
+ /**
221
+ * Retrieve the seller account the API key belongs to: store slug, display
222
+ * name and logo.
223
+ *
224
+ * The endpoint wraps the account in a `data` envelope (the OpenAPI spec
225
+ * documents the bare object); this unwraps it so callers get the account.
226
+ */
227
+ async get() {
228
+ const response = await this.client.request({
229
+ method: "GET",
230
+ path: "/v1/account/"
231
+ });
232
+ return response.data;
233
+ }
234
+ };
235
+
144
236
  // src/resources/customers/customers.ts
145
237
  var CustomerResource = class {
146
238
  constructor(client) {
@@ -168,6 +260,38 @@ var CustomerResource = class {
168
260
  path: "/v1/customers/"
169
261
  });
170
262
  }
263
+ async update(customerId, params) {
264
+ if (!customerId) {
265
+ throw new Error("Customer ID is required");
266
+ }
267
+ const body = {};
268
+ if (params.name !== void 0) {
269
+ body.name = params.name;
270
+ }
271
+ if (params.companyName !== void 0) {
272
+ body.companyName = params.companyName;
273
+ }
274
+ if (params.email !== void 0) {
275
+ body.email = params.email;
276
+ }
277
+ if (params.phone !== void 0) {
278
+ body.phone = params.phone;
279
+ }
280
+ if (params.billingEmail !== void 0) {
281
+ body.billingEmail = params.billingEmail;
282
+ }
283
+ if (params.address !== void 0) {
284
+ body.address = params.address;
285
+ }
286
+ if (params.shipping !== void 0) {
287
+ body.shipping = params.shipping;
288
+ }
289
+ return this.client.request({
290
+ method: "PATCH",
291
+ path: `/v1/customers/${customerId}`,
292
+ body
293
+ });
294
+ }
171
295
  };
172
296
 
173
297
  // src/resources/coupons/coupons.ts
@@ -188,6 +312,29 @@ var CouponResource = class {
188
312
  path: "/v1/coupons/"
189
313
  });
190
314
  }
315
+ /**
316
+ * Update an existing coupon. Only the fields you supply are changed.
317
+ *
318
+ * `pageIds` and `ticketTypeIds` replace the existing lists rather than
319
+ * merging — pass an empty array to clear one.
320
+ *
321
+ * The discount itself (`code`, `amountOff`, `percentOff`, `currency`,
322
+ * `duration`) is fixed once the coupon is mirrored into Stripe. To change a
323
+ * discount, soft delete this coupon and create a replacement.
324
+ *
325
+ * @example
326
+ * const { data: coupon } = await client.coupons.update(couponId, { deleted: true });
327
+ */
328
+ async update(couponId, params) {
329
+ if (!couponId) {
330
+ throw new Error("Coupon ID is required");
331
+ }
332
+ return this.client.request({
333
+ method: "PATCH",
334
+ path: `/v1/coupons/${couponId}`,
335
+ body: params
336
+ });
337
+ }
191
338
  async create(params) {
192
339
  const body = {
193
340
  label: params.label,
@@ -231,6 +378,22 @@ var PaymentResource = class {
231
378
  constructor(client) {
232
379
  this.client = client;
233
380
  }
381
+ /**
382
+ * Retrieve a single payment by ID. Only checkout payments are returned —
383
+ * an event charge is a booking, and 404s here.
384
+ *
385
+ * @example
386
+ * const { data: payment } = await client.payments.get(paymentId);
387
+ */
388
+ async get(paymentId) {
389
+ if (!paymentId) {
390
+ throw new Error("Payment ID is required");
391
+ }
392
+ return this.client.request({
393
+ method: "GET",
394
+ path: `/v1/payments/${paymentId}`
395
+ });
396
+ }
234
397
  async list(args = {}) {
235
398
  const query = {
236
399
  search: args.search,
@@ -260,6 +423,21 @@ var SubscriptionResource = class {
260
423
  constructor(client) {
261
424
  this.client = client;
262
425
  }
426
+ /**
427
+ * Retrieve a single subscription by ID.
428
+ *
429
+ * @example
430
+ * const { data: subscription } = await client.subscriptions.get(subscriptionId);
431
+ */
432
+ async get(subscriptionId) {
433
+ if (!subscriptionId) {
434
+ throw new Error("Subscription ID is required");
435
+ }
436
+ return this.client.request({
437
+ method: "GET",
438
+ path: `/v1/subscriptions/${subscriptionId}`
439
+ });
440
+ }
263
441
  async list(args = {}) {
264
442
  const query = {
265
443
  search: args.search,
@@ -275,6 +453,71 @@ var SubscriptionResource = class {
275
453
  path: "/v1/subscriptions/"
276
454
  });
277
455
  }
456
+ /**
457
+ * Cancel a subscription. Provide exactly one of `cancelImmediately`,
458
+ * `cancelAtPeriodEnd`, or `cancelAt` — timing is explicit at the API
459
+ * boundary. Enforced both at the type level via the
460
+ * {@link SubscriptionCancelParams} discriminated union and at the server
461
+ * via zod. Cancellation is one-way; a canceled Stripe subscription cannot
462
+ * be un-canceled.
463
+ *
464
+ * @example
465
+ * await client.subscriptions.cancel(id, { cancelImmediately: true });
466
+ * await client.subscriptions.cancel(id, { cancelAtPeriodEnd: true, sendCancellationEmail: true });
467
+ * await client.subscriptions.cancel(id, { cancelAt: '2026-12-31T23:59:59.000Z' });
468
+ */
469
+ async cancel(subscriptionId, params) {
470
+ return this.client.request({
471
+ method: "POST",
472
+ path: `/v1/subscriptions/${subscriptionId}/cancel`,
473
+ body: params
474
+ });
475
+ }
476
+ };
477
+
478
+ // src/resources/subscription-payments/subscription-payments.ts
479
+ var SubscriptionPaymentResource = class {
480
+ constructor(client) {
481
+ this.client = client;
482
+ }
483
+ /**
484
+ * Retrieve a single subscription payment by ID — one charge within a
485
+ * subscription's billing cycle, not the subscription itself. For every
486
+ * payment on a subscription, use `list({ subscriptionId })`.
487
+ *
488
+ * @example
489
+ * const { data: payment } = await client.subscriptionPayments.get(paymentId);
490
+ */
491
+ async get(subscriptionPaymentId) {
492
+ if (!subscriptionPaymentId) {
493
+ throw new Error("Subscription payment ID is required");
494
+ }
495
+ return this.client.request({
496
+ method: "GET",
497
+ path: `/v1/subscription-payments/${subscriptionPaymentId}`
498
+ });
499
+ }
500
+ async list(args = {}) {
501
+ const query = {
502
+ limit: args.limit?.toString(),
503
+ starting_after: args.starting_after,
504
+ ending_before: args.ending_before,
505
+ subscriptionId: args.subscriptionId,
506
+ customerId: args.customerId,
507
+ pageId: args.pageId,
508
+ paymentStatus: args.paymentStatus,
509
+ paid: args.paid,
510
+ refunded: args.refunded,
511
+ billingReason: args.billingReason,
512
+ createdAfter: args.createdAfter,
513
+ createdBefore: args.createdBefore
514
+ };
515
+ return this.client.request({
516
+ method: "GET",
517
+ query,
518
+ path: "/v1/subscription-payments/"
519
+ });
520
+ }
278
521
  };
279
522
 
280
523
  // src/resources/bookings/bookings.ts
@@ -282,6 +525,41 @@ var BookingResource = class {
282
525
  constructor(client) {
283
526
  this.client = client;
284
527
  }
528
+ /**
529
+ * Retrieve a single booking by ID. Only event bookings are returned —
530
+ * a checkout charge is a payment, and 404s here.
531
+ *
532
+ * @example
533
+ * const { data: booking } = await client.bookings.get(bookingId);
534
+ */
535
+ async get(bookingId) {
536
+ if (!bookingId) {
537
+ throw new Error("Booking ID is required");
538
+ }
539
+ return this.client.request({
540
+ method: "GET",
541
+ path: `/v1/bookings/${bookingId}`
542
+ });
543
+ }
544
+ /**
545
+ * Download the booking's ticket PDF (every ticket in the booking) as raw
546
+ * bytes. The response reflects the current tickets, so attendee updates
547
+ * appear on the next download. Throws NotFoundError when no PDF exists,
548
+ * e.g. for unpaid or abandoned bookings.
549
+ *
550
+ * @example
551
+ * const pdf = await client.bookings.downloadTicketPdf(bookingId);
552
+ * fs.writeFileSync('tickets.pdf', Buffer.from(pdf));
553
+ */
554
+ async downloadTicketPdf(bookingId) {
555
+ if (!bookingId) {
556
+ throw new Error("Booking ID is required");
557
+ }
558
+ return this.client.requestRaw({
559
+ method: "GET",
560
+ path: `/v1/bookings/${bookingId}/ticket-pdf`
561
+ });
562
+ }
285
563
  async list(args = {}) {
286
564
  const query = {
287
565
  search: args.search,
@@ -310,6 +588,48 @@ var TicketResource = class {
310
588
  constructor(client) {
311
589
  this.client = client;
312
590
  }
591
+ async list(args = {}) {
592
+ const query = {
593
+ pageId: args.pageId,
594
+ bookingId: args.bookingId,
595
+ orderId: args.orderId,
596
+ customerId: args.customerId,
597
+ ticketTypeId: args.ticketTypeId,
598
+ status: args.status,
599
+ checkInStatus: args.checkInStatus,
600
+ createdAfter: args.createdAfter,
601
+ createdBefore: args.createdBefore,
602
+ search: args.search,
603
+ limit: args.limit?.toString(),
604
+ starting_after: args.starting_after,
605
+ ending_before: args.ending_before
606
+ };
607
+ return this.client.request({
608
+ method: "GET",
609
+ query,
610
+ path: "/v1/tickets/"
611
+ });
612
+ }
613
+ async update(ticketId, params) {
614
+ if (!ticketId) {
615
+ throw new Error("Ticket ID is required");
616
+ }
617
+ const body = {};
618
+ if (params.attendeeName !== void 0) {
619
+ body.attendeeName = params.attendeeName;
620
+ }
621
+ if (params.attendeeEmail !== void 0) {
622
+ body.attendeeEmail = params.attendeeEmail;
623
+ }
624
+ if (params.metadata !== void 0) {
625
+ body.metadata = params.metadata;
626
+ }
627
+ return this.client.request({
628
+ method: "PATCH",
629
+ path: `/v1/tickets/${ticketId}`,
630
+ body
631
+ });
632
+ }
313
633
  async validate(qrCode, params) {
314
634
  const body = params || {};
315
635
  const response = await this.client.request({
@@ -382,9 +702,21 @@ var ProductResource = class {
382
702
  if (params.limitSubscriptions !== void 0) {
383
703
  body.limitSubscriptions = params.limitSubscriptions;
384
704
  }
705
+ if (params.enableFileAccessForInactiveSubscriptions !== void 0) {
706
+ body.enableFileAccessForInactiveSubscriptions = params.enableFileAccessForInactiveSubscriptions;
707
+ }
385
708
  if (params.generateLicenseKeys !== void 0) {
386
709
  body.generateLicenseKeys = params.generateLicenseKeys;
387
710
  }
711
+ if (params.fixedTaxRateIds !== void 0) {
712
+ body.fixedTaxRateIds = params.fixedTaxRateIds;
713
+ }
714
+ if (params.prices !== void 0) {
715
+ body.prices = params.prices;
716
+ }
717
+ if (params.defaultPriceId !== void 0) {
718
+ body.defaultPriceId = params.defaultPriceId;
719
+ }
388
720
  return this.client.request({
389
721
  method: "PATCH",
390
722
  path: `/v1/products/${productId}`,
@@ -490,11 +822,10 @@ var CheckoutPageFieldsResource = class {
490
822
  if (!fieldId) {
491
823
  throw new Error("Field ID is required");
492
824
  }
493
- const response = await this.client.request({
825
+ return this.client.request({
494
826
  method: "DELETE",
495
827
  path: `/v1/checkout-pages/${pageId}/fields/${fieldId}`
496
828
  });
497
- return response;
498
829
  }
499
830
  };
500
831
  var CheckoutPagesResource = class {
@@ -1013,12 +1344,76 @@ var TaxRateResource = class {
1013
1344
  }
1014
1345
  };
1015
1346
 
1347
+ // src/resources/webhooks/webhooks.ts
1348
+ var WebhookResource = class {
1349
+ constructor(client) {
1350
+ this.client = client;
1351
+ }
1352
+ /**
1353
+ * List webhook endpoints, newest first. Secrets are never returned.
1354
+ *
1355
+ * @example
1356
+ * const { data, has_more } = await client.webhooks.list({ event: 'payment.paid' });
1357
+ */
1358
+ async list(args = {}) {
1359
+ const query = {
1360
+ status: args.status,
1361
+ event: args.event,
1362
+ limit: args.limit?.toString(),
1363
+ starting_after: args.starting_after,
1364
+ ending_before: args.ending_before
1365
+ };
1366
+ return this.client.request({
1367
+ method: "GET",
1368
+ path: "/v1/webhooks/",
1369
+ query
1370
+ });
1371
+ }
1372
+ /**
1373
+ * Create a webhook endpoint. The `url` must use https.
1374
+ *
1375
+ * The response is the only place the signing `secret` is ever returned —
1376
+ * store it immediately. Omit `secret` to have one generated.
1377
+ *
1378
+ * @example
1379
+ * const { data: webhook } = await client.webhooks.create({
1380
+ * name: 'CRM sync',
1381
+ * url: 'https://example.com/hooks/checkoutpage',
1382
+ * events: ['payment.paid', 'subscription.created'],
1383
+ * });
1384
+ * saveSecret(webhook.secret);
1385
+ */
1386
+ async create(params) {
1387
+ return this.client.request({
1388
+ method: "POST",
1389
+ path: "/v1/webhooks/",
1390
+ body: params
1391
+ });
1392
+ }
1393
+ /**
1394
+ * Delete a webhook endpoint. Deliveries stop immediately; the returned
1395
+ * object is its final state. The webhook no longer appears in `list()`,
1396
+ * and deleting the same id again returns 404.
1397
+ */
1398
+ async delete(webhookId) {
1399
+ if (!webhookId) {
1400
+ throw new Error("Webhook ID is required");
1401
+ }
1402
+ return this.client.request({
1403
+ method: "DELETE",
1404
+ path: `/v1/webhooks/${encodeURIComponent(webhookId)}`
1405
+ });
1406
+ }
1407
+ };
1408
+
1016
1409
  // src/index.ts
1017
1410
  var CheckoutPageClient = class {
1411
+ accounts;
1018
1412
  customers;
1019
1413
  coupons;
1020
1414
  payments;
1021
1415
  subscriptions;
1416
+ subscriptionPayments;
1022
1417
  bookings;
1023
1418
  tickets;
1024
1419
  products;
@@ -1028,13 +1423,17 @@ var CheckoutPageClient = class {
1028
1423
  forms;
1029
1424
  submissions;
1030
1425
  taxRates;
1426
+ invoices;
1427
+ webhooks;
1031
1428
  client;
1032
1429
  constructor(options) {
1033
1430
  this.client = new CheckoutPageApiClient(options);
1431
+ this.accounts = new AccountResource(this.client);
1034
1432
  this.customers = new CustomerResource(this.client);
1035
1433
  this.coupons = new CouponResource(this.client);
1036
1434
  this.payments = new PaymentResource(this.client);
1037
1435
  this.subscriptions = new SubscriptionResource(this.client);
1436
+ this.subscriptionPayments = new SubscriptionPaymentResource(this.client);
1038
1437
  this.bookings = new BookingResource(this.client);
1039
1438
  this.tickets = new TicketResource(this.client);
1040
1439
  this.products = new ProductResource(this.client);
@@ -1044,6 +1443,8 @@ var CheckoutPageClient = class {
1044
1443
  this.forms = new FormsResource(this.client);
1045
1444
  this.submissions = new SubmissionResource(this.client);
1046
1445
  this.taxRates = new TaxRateResource(this.client);
1446
+ this.invoices = new InvoiceResource(this.client);
1447
+ this.webhooks = new WebhookResource(this.client);
1047
1448
  }
1048
1449
  };
1049
1450
  var createCheckoutPageClient = (options) => {