@commet/node 7.1.0 → 7.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/dist/index.js CHANGED
@@ -246,6 +246,35 @@ var InvoicesResource = class {
246
246
  }
247
247
  };
248
248
 
249
+ // src/resources/payments.ts
250
+ var PaymentsResource = class {
251
+ constructor(httpClient) {
252
+ this.httpClient = httpClient;
253
+ }
254
+ /** List payments with cursor-based pagination. Filter by customer. */
255
+ async list(params, options) {
256
+ return this.httpClient.get("/payments", params, options);
257
+ }
258
+ /** Create a hosted payment link. Returns a url the customer opens to pay with any card. Calculates tax, generates an invoice, and vaults the payment method on confirmation. No subscription or plan required. */
259
+ async create(params, options) {
260
+ return this.httpClient.post("/payments", params, options);
261
+ }
262
+ /** Charge a customer's vaulted payment method off-session. Calculates tax, generates an invoice, and sends a receipt. No subscription or plan required. */
263
+ async charge(params, options) {
264
+ return this.httpClient.post("/payments/charge", params, options);
265
+ }
266
+ /** Retrieve a payment by its public ID. */
267
+ async get(params, options) {
268
+ const { id } = params;
269
+ return this.httpClient.get(`/payments/${id}`, void 0, options);
270
+ }
271
+ /** Cancel a pending payment link so it can no longer be paid. Only a link that has not been paid or started processing can be canceled; canceling an already canceled link is a no-op. Charges cannot be canceled. */
272
+ async cancel(params, options) {
273
+ const { id } = params;
274
+ return this.httpClient.post(`/payments/${id}/cancel`, {}, options);
275
+ }
276
+ };
277
+
249
278
  // src/resources/payouts.ts
250
279
  var PayoutsResource = class {
251
280
  constructor(httpClient) {
@@ -553,6 +582,29 @@ var SubscriptionsResource = class {
553
582
  const { id } = params;
554
583
  return this.httpClient.post(`/subscriptions/${id}/uncancel`, {}, options);
555
584
  }
585
+ /** Retries the outstanding renewal charge for a past_due subscription. On a successful charge the subscription recovers to active and a payment.recovered webhook is delivered; a declined charge returns an error and the subscription stays past_due. */
586
+ async reactivate(params, options) {
587
+ const { id } = params;
588
+ return this.httpClient.post(`/subscriptions/${id}/reactivate`, {}, options);
589
+ }
590
+ /** Generates a hosted, signed recovery link that lets the customer pay the outstanding renewal charge for a past_due subscription. Unlike reactivate, which charges server-to-server, this returns a link the merchant can deliver through their own email, SMS, or dashboard. The link carries a self-contained signed token and stays valid until the charge is paid or the subscription is no longer past due. */
591
+ async createRecoveryLink(params, options) {
592
+ const { id } = params;
593
+ return this.httpClient.post(
594
+ `/subscriptions/${id}/recovery-link`,
595
+ {},
596
+ options
597
+ );
598
+ }
599
+ /** Creates a hosted checkout session for the customer to update the subscription's default payment method. */
600
+ async updatePaymentMethod(params, options) {
601
+ const { id, ...rest } = params;
602
+ return this.httpClient.post(
603
+ `/subscriptions/${id}/payment-method/update`,
604
+ rest,
605
+ options
606
+ );
607
+ }
556
608
  /** Upgrade, downgrade, or change billing interval. */
557
609
  async changePlan(params, options) {
558
610
  const { id, ...rest } = params;
@@ -648,7 +700,7 @@ var TransactionsResource = class {
648
700
  const { id } = params;
649
701
  return this.httpClient.post(`/transactions/${id}/refund`, {}, options);
650
702
  }
651
- /** Retry a failed payment transaction. Creates a new invoice and initiates a new payment attempt. */
703
+ /** Retry a failed subscription renewal. Re-charges the outstanding renewal invoice through the recovery engine. */
652
704
  async retry(params, options) {
653
705
  const { id } = params;
654
706
  return this.httpClient.post(`/transactions/${id}/retry`, {}, options);
@@ -665,6 +717,7 @@ var GeneratedResources = class {
665
717
  this.featureAccess = new FeatureAccessResource(http);
666
718
  this.features = new FeaturesResource(http);
667
719
  this.invoices = new InvoicesResource(http);
720
+ this.payments = new PaymentsResource(http);
668
721
  this.payouts = new PayoutsResource(http);
669
722
  this.planGroups = new PlanGroupsResource(http);
670
723
  this.plans = new PlansResource(http);
@@ -721,8 +774,8 @@ var import_node_crypto = __toESM(require("crypto"));
721
774
  var Webhooks = class {
722
775
  constructor(httpClient) {
723
776
  this.httpClient = httpClient;
777
+ this.eventHandlers = /* @__PURE__ */ new Map();
724
778
  }
725
- /** HMAC-SHA256 verification. Payload must be the raw request body string, not parsed JSON. */
726
779
  verify(params) {
727
780
  const { payload, signature, secret } = params;
728
781
  if (!signature || !secret || !payload) {
@@ -742,7 +795,6 @@ var Webhooks = class {
742
795
  const { payload, secret } = params;
743
796
  return import_node_crypto.default.createHmac("sha256", secret).update(payload).digest("hex");
744
797
  }
745
- /** Verifies signature and parses JSON in one step. Returns null if invalid. */
746
798
  verifyAndParse(params) {
747
799
  const { rawBody, signature, secret } = params;
748
800
  if (!this.verify({ payload: rawBody, signature, secret })) {
@@ -754,6 +806,20 @@ var Webhooks = class {
754
806
  return null;
755
807
  }
756
808
  }
809
+ on(event, handler) {
810
+ this.eventHandlers.set(
811
+ event,
812
+ handler
813
+ );
814
+ return this;
815
+ }
816
+ async process(params) {
817
+ const payload = this.verifyAndParse(params);
818
+ if (!payload) return null;
819
+ const handler = this.eventHandlers.get(payload.event);
820
+ if (handler) await handler(payload.data, payload);
821
+ return payload;
822
+ }
757
823
  async list(params, options) {
758
824
  return this.httpClient.get("/webhooks", params, options);
759
825
  }
@@ -810,7 +876,7 @@ var CommetValidationError = class extends CommetError {
810
876
 
811
877
  // src/version.ts
812
878
  var API_VERSION = "2026-06-10";
813
- var SDK_VERSION = "7.1.0";
879
+ var SDK_VERSION = "7.3.0";
814
880
 
815
881
  // src/utils/telemetry.ts
816
882
  var registeredIntegrations = /* @__PURE__ */ new Set();