chargebee 3.17.0-beta.2 → 3.17.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 CHANGED
@@ -1,14 +1,37 @@
1
- ### v3.17.0-beta.2 (2025-12-16)
1
+ ### v3.17.0 (2025-12-30)
2
+ * * *
2
3
 
3
- ### Enhancements
4
- * `WebhookEventType` is now a runtime enum that can be used for event type comparisons at runtime.
5
- * `WebhookEventType` and `WebhookContentType` are now exported from the main entry points.
4
+ ### New Attributes:
5
+ * retry_engine has been added to Invoice#DunningAttempt.
6
+
7
+ ### New Endpoint:
8
+ * move action has been added to ItemPrice.
6
9
 
7
- ### v3.17.0-beta.1 (2025-12-10)
10
+ ### New Parameters:
11
+ * exclude_tax_type has been added to Estimate#RenewalEstimateInputParam.
12
+ * variant_id has been added to ItemPrice#MoveInputParam.
13
+ * custom has been added to PricingPageSession#CreateForNewSubscriptionInputParam.
14
+ * custom has been added to PricingPageSession#CreateForExistingSubscriptionInputParam.
8
15
 
9
- ### Enhancements
10
- * Add webhook event handler to process chargebee-events.
11
- * Deprecated `WebhookContentType` class, added `WebhookEventType` class.
16
+ ### New Enums:
17
+ * ELECTRONIC_PAYMENT_STANDARD has been added to PaymentMethodTypeEnum.
18
+ * KBC_PAYMENT_BUTTON has been added to PaymentMethodTypeEnum.
19
+ * PAY_BY_BANK has been added to PaymentMethodTypeEnum.
20
+ * TRUSTLY has been added to PaymentMethodTypeEnum.
21
+ * STABLECOIN has been added to PaymentMethodTypeEnum.
22
+
23
+ ### v3.16.2 (2025-12-17)
24
+ * * *
25
+
26
+ ### Improvements:
27
+ * `WebhookContentType` is now deprecated but still available for backward compatibility.
28
+
29
+ ### v3.16.1 (2025-12-17)
30
+ * * *
31
+
32
+ ### Improvements:
33
+ * Renamed `WebhookContentType` to `WebhookEventType` for better clarity. `WebhookContentType` is now deprecated but still available for backward compatibility.
34
+ * Added runtime export of `WebhookEventType` enum.
12
35
 
13
36
  ### v3.16.0 (2025-12-01)
14
37
  * * *
package/README.md CHANGED
@@ -148,174 +148,6 @@ const chargebeeSiteEU = new Chargebee({
148
148
  });
149
149
  ```
150
150
 
151
- ### Handle webhooks
152
-
153
- Use the webhook handlers to parse and route webhook payloads from Chargebee with full TypeScript support.
154
-
155
- #### Quick Start: Using the default `webhook` instance
156
-
157
- The simplest way to handle webhooks is using the pre-configured `webhook` instance:
158
-
159
- ```typescript
160
- import express from 'express';
161
- import { webhook, type WebhookEvent } from 'chargebee';
162
-
163
- const app = express();
164
- app.use(express.json());
165
-
166
- webhook.on('subscription_created', async (event: WebhookEvent) => {
167
- console.log(`Subscription created: ${event.id}`);
168
- const subscription = event.content.subscription;
169
- console.log(`Customer: ${subscription.customer_id}`);
170
- });
171
-
172
- webhook.on('error', (err: Error) => {
173
- console.error('Webhook error:', err.message);
174
- });
175
-
176
- app.post('/chargebee/webhooks', (req, res) => {
177
- webhook.handle(req.body, req.headers);
178
- res.status(200).send('OK');
179
- });
180
-
181
- app.listen(8080);
182
- ```
183
-
184
- **Auto-configured Basic Auth:** The default `webhook` instance automatically configures Basic Auth validation if the following environment variables are set:
185
-
186
- - `CHARGEBEE_WEBHOOK_USERNAME` - The expected username
187
- - `CHARGEBEE_WEBHOOK_PASSWORD` - The expected password
188
-
189
- When both are present, incoming webhook requests will be validated against these credentials. If not set, no authentication is applied.
190
-
191
- #### Creating custom `WebhookHandler` instances
192
-
193
- For more control or multiple webhook endpoints, create your own instances:
194
-
195
- ```typescript
196
- import express from 'express';
197
- import { WebhookHandler, basicAuthValidator } from 'chargebee';
198
-
199
- const app = express();
200
- app.use(express.json());
201
-
202
- const handler = new WebhookHandler();
203
-
204
- // Register event listeners using .on() - events are fully typed
205
- handler.on('subscription_created', async (event) => {
206
- console.log(`Subscription created: ${event.id}`);
207
- const subscription = event.content.subscription;
208
- console.log(`Customer: ${subscription.customer_id}`);
209
- console.log(`Plan: ${subscription.plan_id}`);
210
- });
211
-
212
- handler.on('payment_succeeded', async (event) => {
213
- console.log(`Payment succeeded: ${event.id}`);
214
- const transaction = event.content.transaction;
215
- const customer = event.content.customer;
216
- console.log(`Amount: ${transaction.amount}, Customer: ${customer.email}`);
217
- });
218
-
219
- // Optional: Add request validator (e.g., Basic Auth)
220
- handler.requestValidator = basicAuthValidator((username, password) => {
221
- return username === 'admin' && password === 'secret';
222
- });
223
-
224
- app.post('/chargebee/webhooks', (req, res) => {
225
- handler.handle(req.body, req.headers);
226
- res.status(200).send('OK');
227
- });
228
-
229
- app.listen(8080);
230
- ```
231
-
232
- #### Low-level: Parse and handle events manually
233
-
234
- For more control, you can parse webhook events manually:
235
-
236
- ```typescript
237
- import express from 'express';
238
- import Chargebee, { type WebhookEvent } from 'chargebee';
239
-
240
- const app = express();
241
- app.use(express.json());
242
-
243
- app.post('/chargebee/webhooks', async (req, res) => {
244
- try {
245
- const event = req.body as WebhookEvent;
246
-
247
- switch (event.event_type) {
248
- case 'subscription_created':
249
- // Access event content with proper typing
250
- const subscription = event.content.subscription;
251
- console.log('Subscription created:', subscription.id);
252
- break;
253
-
254
- case 'payment_succeeded':
255
- const transaction = event.content.transaction;
256
- console.log('Payment succeeded:', transaction.amount);
257
- break;
258
-
259
- default:
260
- console.log('Unhandled event type:', event.event_type);
261
- }
262
-
263
- res.status(200).send('OK');
264
- } catch (err) {
265
- console.error('Error processing webhook:', err);
266
- res.status(500).send('Error processing webhook');
267
- }
268
- });
269
-
270
- app.listen(8080);
271
- ```
272
-
273
- #### Handling Unhandled Events
274
-
275
- By default, if an incoming webhook event type is not recognized or you haven't registered a corresponding callback handler, the SDK provides flexible options to handle these scenarios:
276
-
277
- **Using the `unhandled_event` listener:**
278
-
279
- ```typescript
280
- import { WebhookHandler } from 'chargebee';
281
-
282
- const handler = new WebhookHandler();
283
-
284
- handler.on('subscription_created', async (event) => {
285
- // Handle subscription created
286
- });
287
-
288
- // Gracefully handle events without registered listeners
289
- handler.on('unhandled_event', async (event) => {
290
- console.log(`Received unhandled event: ${event.event_type}`);
291
- // Log for monitoring or store for later processing
292
- });
293
- ```
294
-
295
- **Using the `error` listener for error handling:**
296
-
297
- If an error occurs during webhook processing (e.g., invalid JSON, validator failure), the SDK will emit an `error` event:
298
-
299
- ```typescript
300
- const handler = new WebhookHandler();
301
-
302
- handler.on('subscription_created', async (event) => {
303
- // Handle subscription created
304
- });
305
-
306
- // Catch any errors during webhook processing
307
- handler.on('error', (err) => {
308
- console.error('Webhook processing error:', err);
309
- // Log to monitoring service, alert team, etc.
310
- });
311
- ```
312
-
313
- **Best Practices:**
314
-
315
- - Use `unhandled_event` listener to acknowledge unknown events (return 200 OK) and log them
316
- - Use `error` listener to catch and handle exceptions thrown during event processing
317
- - Both listeners help ensure your webhook endpoint remains stable even when new event types are introduced by Chargebee
318
-
319
151
  ### Processing Webhooks - API Version Check
320
152
 
321
153
  An attribute `api_version` is added to the [Event](https://apidocs.chargebee.com/docs/api/events) resource, which indicates the API version based on which the event content is structured. In your webhook servers, ensure this `api_version` is the same as the [API version](https://apidocs.chargebee.com/docs/api#versions) used by your webhook server's client library.
@@ -392,18 +224,38 @@ To improve type safety and gain better autocompletion when working with webhooks
392
224
  #### Example
393
225
 
394
226
  ```ts
395
- import Chargebee, { type WebhookContentType, WebhookEvent } from "chargebee";
227
+ import Chargebee, { WebhookEventType, WebhookEvent } from "chargebee";
396
228
 
397
229
  const result = await chargebeeInstance.event.retrieve("{event-id}");
398
- const subscripitonActivatedEvent: WebhookEvent<WebhookContentType.SubscriptionActivated> = result.event;
399
- const subscription = subscripitonActivatedEvent.content.subscription;
230
+ const subscriptionActivatedEvent: WebhookEvent<typeof WebhookEventType.SubscriptionActivated> = result.event;
231
+ const subscription = subscriptionActivatedEvent.content.subscription;
232
+ ```
233
+
234
+ You can also use `WebhookEventType` in switch statements for runtime event handling:
235
+
236
+ ```ts
237
+ import { WebhookEventType, WebhookEvent } from "chargebee";
238
+
239
+ function handleWebhook(event: WebhookEvent) {
240
+ switch (event.event_type) {
241
+ case WebhookEventType.SubscriptionCreated:
242
+ console.log("Subscription created:", event.content.subscription?.id);
243
+ break;
244
+ case WebhookEventType.PaymentSucceeded:
245
+ console.log("Payment succeeded:", event.content.transaction?.id);
246
+ break;
247
+ default:
248
+ console.log("Unhandled event:", event.event_type);
249
+ }
250
+ }
400
251
  ```
401
252
 
402
253
  #### Notes
403
254
 
404
255
  * `WebhookEvent<T>` provides type hinting for the event payload, making it easier to work with specific event structures.
405
- * Use the `WebhookContentType` to specify the exact event type (e.g., `SubscriptionCreated`, `InvoiceGenerated`, etc.).
406
- * This approach ensures you get proper IntelliSense and compile-time checks when accessing event fields.
256
+ * Use `WebhookEventType` to specify the exact event type (e.g., `SubscriptionCreated`, `InvoiceGenerated`, etc.).
257
+ * `WebhookEventType` is available at runtime, so you can use it in switch statements and comparisons.
258
+ * `WebhookContentType` is deprecated but still available for backward compatibility.
407
259
 
408
260
  ### Custom HTTP Client
409
261
 
@@ -2,17 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const createChargebee_js_1 = require("./createChargebee.js");
4
4
  const FetchClient_js_1 = require("./net/FetchClient.js");
5
- const handler_js_1 = require("./resources/webhook/handler.js");
6
- const handler_js_2 = require("./resources/webhook/handler.js");
7
- const auth_js_1 = require("./resources/webhook/auth.js");
5
+ const eventType_js_1 = require("./resources/webhook/eventType.js");
8
6
  const httpClient = new FetchClient_js_1.FetchHttpClient();
9
7
  const Chargebee = (0, createChargebee_js_1.CreateChargebee)(httpClient);
10
8
  module.exports = Chargebee;
11
9
  module.exports.Chargebee = Chargebee;
12
10
  module.exports.default = Chargebee;
13
- // Export webhook modules
14
- module.exports.WebhookHandler = handler_js_1.WebhookHandler;
15
- module.exports.WebhookEventType = handler_js_1.WebhookEventType;
16
- module.exports.WebhookContentType = handler_js_1.WebhookContentType;
17
- module.exports.webhook = handler_js_2.default;
18
- module.exports.basicAuthValidator = auth_js_1.basicAuthValidator;
11
+ // Export webhook event types
12
+ module.exports.WebhookEventType = eventType_js_1.WebhookEventType;
13
+ module.exports.WebhookContentType = eventType_js_1.WebhookContentType;
@@ -11,7 +11,7 @@ exports.Environment = {
11
11
  hostSuffix: '.chargebee.com',
12
12
  apiPath: '/api/v2',
13
13
  timeout: DEFAULT_TIME_OUT,
14
- clientVersion: '3.17.0-beta.2',
14
+ clientVersion: 'v3.17.0',
15
15
  port: DEFAULT_PORT,
16
16
  timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
17
17
  exportWaitInMillis: DEFAULT_EXPORT_WAIT,
@@ -4608,7 +4608,9 @@ exports.Endpoints = {
4608
4608
  false,
4609
4609
  null,
4610
4610
  false,
4611
- {},
4611
+ {
4612
+ custom: 0,
4613
+ },
4612
4614
  {
4613
4615
  isIdempotent: true,
4614
4616
  },
@@ -4621,7 +4623,9 @@ exports.Endpoints = {
4621
4623
  false,
4622
4624
  null,
4623
4625
  false,
4624
- {},
4626
+ {
4627
+ custom: 0,
4628
+ },
4625
4629
  {
4626
4630
  isIdempotent: true,
4627
4631
  },
@@ -3,7 +3,5 @@ import { FetchHttpClient } from './net/FetchClient.js';
3
3
  const httpClient = new FetchHttpClient();
4
4
  const Chargebee = CreateChargebee(httpClient);
5
5
  export default Chargebee;
6
- // Export webhook modules
7
- export { WebhookHandler, WebhookEventType, WebhookContentType, } from './resources/webhook/handler.js';
8
- export { default as webhook } from './resources/webhook/handler.js';
9
- export { basicAuthValidator } from './resources/webhook/auth.js';
6
+ // Export webhook event types
7
+ export { WebhookEventType, WebhookContentType, } from './resources/webhook/eventType.js';
@@ -8,7 +8,7 @@ export const Environment = {
8
8
  hostSuffix: '.chargebee.com',
9
9
  apiPath: '/api/v2',
10
10
  timeout: DEFAULT_TIME_OUT,
11
- clientVersion: '3.17.0-beta.2',
11
+ clientVersion: 'v3.17.0',
12
12
  port: DEFAULT_PORT,
13
13
  timemachineWaitInMillis: DEFAULT_TIME_MACHINE_WAIT,
14
14
  exportWaitInMillis: DEFAULT_EXPORT_WAIT,
@@ -4605,7 +4605,9 @@ export const Endpoints = {
4605
4605
  false,
4606
4606
  null,
4607
4607
  false,
4608
- {},
4608
+ {
4609
+ custom: 0,
4610
+ },
4609
4611
  {
4610
4612
  isIdempotent: true,
4611
4613
  },
@@ -4618,7 +4620,9 @@ export const Endpoints = {
4618
4620
  false,
4619
4621
  null,
4620
4622
  false,
4621
- {},
4623
+ {
4624
+ custom: 0,
4625
+ },
4622
4626
  {
4623
4627
  isIdempotent: true,
4624
4628
  },
package/package.json CHANGED
@@ -1,10 +1,9 @@
1
1
  {
2
2
  "name": "chargebee",
3
- "version": "3.17.0-beta.2",
3
+ "version": "3.17.0",
4
4
  "description": "A library for integrating with Chargebee.",
5
5
  "scripts": {
6
6
  "prepack": "npm install && npm run build",
7
- "test": "mocha -r ts-node/register 'test/**/*.test.ts'",
8
7
  "build": "npm run build-esm && npm run build-cjs",
9
8
  "build-esm": "rm -rf esm && mkdir -p esm && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > esm/package.json",
10
9
  "build-cjs": "rm -rf cjs && mkdir -p cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
@@ -33,6 +32,8 @@
33
32
  "url": "http://github.com/chargebee/chargebee-node/blob/master/LICENSE"
34
33
  }
35
34
  ],
35
+ "dependencies": {
36
+ },
36
37
  "exports": {
37
38
  "types": "./types/index.d.ts",
38
39
  "browser": {
@@ -61,19 +62,13 @@
61
62
  }
62
63
  },
63
64
  "devDependencies": {
64
- "@types/chai": "^4.3.5",
65
- "@types/mocha": "^10.0.10",
66
- "@types/node": "20.12.0",
67
- "chai": "^4.3.7",
68
- "mocha": "^10.2.0",
65
+ "@types/node": "20.0.0",
69
66
  "prettier": "^3.3.3",
70
- "ts-node": "^10.9.1",
71
- "typescript": "^5.5.4",
72
- "undici-types": "^7.16.0"
67
+ "typescript": "^5.5.4"
73
68
  },
74
69
  "prettier": {
75
70
  "semi": true,
76
71
  "singleQuote": true,
77
72
  "parser": "typescript"
78
73
  }
79
- }
74
+ }
package/types/core.d.ts CHANGED
@@ -369,6 +369,7 @@ declare module 'chargebee' {
369
369
  | 'addon_created'
370
370
  | 'addon_updated'
371
371
  | 'addon_deleted';
372
+ type ExcludeTaxTypeEnum = 'exclusive' | 'none';
372
373
  type ExportTypeEnum = 'data' | 'import_friendly_data';
373
374
  type FreePeriodUnitEnum = 'day' | 'week' | 'month' | 'year';
374
375
  type FriendOfferTypeEnum = 'none' | 'coupon' | 'coupon_code';
@@ -502,7 +503,12 @@ declare module 'chargebee' {
502
503
  | 'automated_bank_transfer'
503
504
  | 'klarna_pay_now'
504
505
  | 'online_banking_poland'
505
- | 'payconiq_by_bancontact';
506
+ | 'payconiq_by_bancontact'
507
+ | 'electronic_payment_standard'
508
+ | 'kbc_payment_button'
509
+ | 'pay_by_bank'
510
+ | 'trustly'
511
+ | 'stablecoin';
506
512
  type PaymentMethodTypeEnum =
507
513
  | 'card'
508
514
  | 'paypal_express_checkout'
@@ -528,7 +534,12 @@ declare module 'chargebee' {
528
534
  | 'automated_bank_transfer'
529
535
  | 'klarna_pay_now'
530
536
  | 'online_banking_poland'
531
- | 'payconiq_by_bancontact';
537
+ | 'payconiq_by_bancontact'
538
+ | 'electronic_payment_standard'
539
+ | 'kbc_payment_button'
540
+ | 'pay_by_bank'
541
+ | 'trustly'
542
+ | 'stablecoin';
532
543
  type PaymentVoucherTypeEnum = 'boleto';
533
544
  type PeriodUnitEnum = 'day' | 'week' | 'month' | 'year';
534
545
  type PriceTypeEnum = 'tax_exclusive' | 'tax_inclusive';
@@ -553,6 +564,7 @@ declare module 'chargebee' {
553
564
  type RefundableCreditsHandlingEnum = 'no_action' | 'schedule_refund';
554
565
  type ReportByEnum = 'customer' | 'invoice' | 'product' | 'subscription';
555
566
  type ResumeOptionEnum = 'immediately' | 'specific_date';
567
+ type RetryEngineEnum = 'chargebee' | 'flexpay' | 'successplus';
556
568
  type RoleEnum = 'primary' | 'backup' | 'none';
557
569
  type ScheduleTypeEnum = 'immediate' | 'specific_dates' | 'fixed_intervals';
558
570
  type SourceEnum =
@@ -621,6 +633,11 @@ declare module 'chargebee' {
621
633
  | 'klarna_pay_now'
622
634
  | 'online_banking_poland'
623
635
  | 'payconiq_by_bancontact'
636
+ | 'electronic_payment_standard'
637
+ | 'kbc_payment_button'
638
+ | 'pay_by_bank'
639
+ | 'trustly'
640
+ | 'stablecoin'
624
641
  | 'free_trial'
625
642
  | 'pay_up_front'
626
643
  | 'pay_as_you_go';
package/types/index.d.ts CHANGED
@@ -250,69 +250,4 @@ declare module 'chargebee' {
250
250
  virtualBankAccount: VirtualBankAccount.VirtualBankAccountResource;
251
251
  webhookEndpoint: WebhookEndpoint.WebhookEndpointResource;
252
252
  }
253
-
254
- // Webhook Handler
255
- export type WebhookEventName = EventTypeEnum | 'unhandled_event';
256
- export type WebhookEventTypeValue = `${WebhookEventType}`;
257
- /** @deprecated Use WebhookEventTypeValue instead */
258
- export type WebhookContentTypeValue = WebhookEventTypeValue;
259
-
260
- export type WebhookEventListener<
261
- T extends WebhookEventType = WebhookEventType,
262
- > = (event: WebhookEvent<T>) => Promise<void> | void;
263
- export type WebhookErrorListener = (error: Error) => Promise<void> | void;
264
-
265
- // Helper type to map string literal to enum member
266
- type StringToWebhookEventType<S extends WebhookEventTypeValue> = {
267
- [K in WebhookEventType]: `${K}` extends S ? K : never;
268
- }[WebhookEventType];
269
-
270
- export class WebhookHandler {
271
- on<T extends WebhookEventType>(
272
- eventName: T,
273
- listener: WebhookEventListener<T>,
274
- ): this;
275
- on<S extends WebhookEventTypeValue>(
276
- eventName: S,
277
- listener: WebhookEventListener<StringToWebhookEventType<S>>,
278
- ): this;
279
- on(eventName: 'unhandled_event', listener: WebhookEventListener): this;
280
- on(eventName: 'error', listener: WebhookErrorListener): this;
281
- once<T extends WebhookEventType>(
282
- eventName: T,
283
- listener: WebhookEventListener<T>,
284
- ): this;
285
- once<S extends WebhookEventTypeValue>(
286
- eventName: S,
287
- listener: WebhookEventListener<StringToWebhookEventType<S>>,
288
- ): this;
289
- once(eventName: 'unhandled_event', listener: WebhookEventListener): this;
290
- once(eventName: 'error', listener: WebhookErrorListener): this;
291
- off<T extends WebhookEventType>(
292
- eventName: T,
293
- listener: WebhookEventListener<T>,
294
- ): this;
295
- off<S extends WebhookEventTypeValue>(
296
- eventName: S,
297
- listener: WebhookEventListener<StringToWebhookEventType<S>>,
298
- ): this;
299
- off(eventName: 'unhandled_event', listener: WebhookEventListener): this;
300
- off(eventName: 'error', listener: WebhookErrorListener): this;
301
- handle(
302
- body: string | object,
303
- headers?: Record<string, string | string[] | undefined>,
304
- ): void;
305
- onError?: (error: any) => void;
306
- requestValidator?: (
307
- headers: Record<string, string | string[] | undefined>,
308
- ) => void;
309
- }
310
-
311
- // Webhook Auth
312
- export function basicAuthValidator(
313
- validateCredentials: (username: string, password: string) => boolean,
314
- ): (headers: Record<string, string | string[] | undefined>) => void;
315
-
316
- // Default webhook handler instance
317
- export const webhook: WebhookHandler;
318
253
  }
@@ -12,6 +12,10 @@ declare module 'chargebee' {
12
12
 
13
13
  export namespace CouponCode {
14
14
  export class CouponCodeResource {
15
+ /**
16
+ * @deprecated This method is deprecated and will be removed in a future version.
17
+ */
18
+
15
19
  create(
16
20
  input: CreateInputParam,
17
21
  headers?: ChargebeeRequestHeader,
@@ -113,6 +113,10 @@ declare module 'chargebee' {
113
113
  headers?: ChargebeeRequestHeader,
114
114
  ): Promise<ChargebeeResponse<ListResponse>>;
115
115
 
116
+ /**
117
+ * @deprecated This method is deprecated and will be removed in a future version.
118
+ */
119
+
116
120
  creditNotesForCustomer(
117
121
  customer_id: string,
118
122
  input?: CreditNotesForCustomerInputParam,
@@ -150,18 +150,30 @@ declare module 'chargebee' {
150
150
  headers?: ChargebeeRequestHeader,
151
151
  ): Promise<ChargebeeResponse<DeleteContactResponse>>;
152
152
 
153
+ /**
154
+ * @deprecated This method is deprecated and will be removed in a future version.
155
+ */
156
+
153
157
  addPromotionalCredits(
154
158
  customer_id: string,
155
159
  input: AddPromotionalCreditsInputParam,
156
160
  headers?: ChargebeeRequestHeader,
157
161
  ): Promise<ChargebeeResponse<AddPromotionalCreditsResponse>>;
158
162
 
163
+ /**
164
+ * @deprecated This method is deprecated and will be removed in a future version.
165
+ */
166
+
159
167
  deductPromotionalCredits(
160
168
  customer_id: string,
161
169
  input: DeductPromotionalCreditsInputParam,
162
170
  headers?: ChargebeeRequestHeader,
163
171
  ): Promise<ChargebeeResponse<DeductPromotionalCreditsResponse>>;
164
172
 
173
+ /**
174
+ * @deprecated This method is deprecated and will be removed in a future version.
175
+ */
176
+
165
177
  setPromotionalCredits(
166
178
  customer_id: string,
167
179
  input: SetPromotionalCreditsInputParam,
@@ -738,7 +750,12 @@ declare module 'chargebee' {
738
750
  | 'sepa_instant_transfer'
739
751
  | 'klarna_pay_now'
740
752
  | 'online_banking_poland'
741
- | 'payconiq_by_bancontact';
753
+ | 'payconiq_by_bancontact'
754
+ | 'electronic_payment_standard'
755
+ | 'kbc_payment_button'
756
+ | 'pay_by_bank'
757
+ | 'trustly'
758
+ | 'stablecoin';
742
759
  reference_id?: string;
743
760
  /**
744
761
  * @deprecated Please refer API docs to use other attributes
@@ -911,7 +928,12 @@ declare module 'chargebee' {
911
928
  | 'sepa_instant_transfer'
912
929
  | 'klarna_pay_now'
913
930
  | 'online_banking_poland'
914
- | 'payconiq_by_bancontact';
931
+ | 'payconiq_by_bancontact'
932
+ | 'electronic_payment_standard'
933
+ | 'kbc_payment_button'
934
+ | 'pay_by_bank'
935
+ | 'trustly'
936
+ | 'stablecoin';
915
937
  /**
916
938
  * @deprecated Please refer API docs to use other attributes
917
939
  */
@@ -340,6 +340,7 @@ declare module 'chargebee' {
340
340
  use_existing_balances?: boolean;
341
341
  ignore_scheduled_cancellation?: boolean;
342
342
  ignore_scheduled_changes?: boolean;
343
+ exclude_tax_type?: 'exclusive' | 'none';
343
344
  }
344
345
  export interface AdvanceInvoiceEstimateInputParam {
345
346
  terms_to_charge?: number;
@@ -1041,7 +1042,12 @@ declare module 'chargebee' {
1041
1042
  | 'sepa_instant_transfer'
1042
1043
  | 'klarna_pay_now'
1043
1044
  | 'online_banking_poland'
1044
- | 'payconiq_by_bancontact';
1045
+ | 'payconiq_by_bancontact'
1046
+ | 'electronic_payment_standard'
1047
+ | 'kbc_payment_button'
1048
+ | 'pay_by_bank'
1049
+ | 'trustly'
1050
+ | 'stablecoin';
1045
1051
  reference_id?: string;
1046
1052
  /**
1047
1053
  * @deprecated Please refer API docs to use other attributes
@@ -1119,7 +1125,12 @@ declare module 'chargebee' {
1119
1125
  | 'sepa_instant_transfer'
1120
1126
  | 'klarna_pay_now'
1121
1127
  | 'online_banking_poland'
1122
- | 'payconiq_by_bancontact';
1128
+ | 'payconiq_by_bancontact'
1129
+ | 'electronic_payment_standard'
1130
+ | 'kbc_payment_button'
1131
+ | 'pay_by_bank'
1132
+ | 'trustly'
1133
+ | 'stablecoin';
1123
1134
  reference_id?: string;
1124
1135
  /**
1125
1136
  * @deprecated Please refer API docs to use other attributes
@@ -203,7 +203,12 @@ declare module 'chargebee' {
203
203
  | 'sepa_instant_transfer'
204
204
  | 'klarna_pay_now'
205
205
  | 'online_banking_poland'
206
- | 'payconiq_by_bancontact';
206
+ | 'payconiq_by_bancontact'
207
+ | 'electronic_payment_standard'
208
+ | 'kbc_payment_button'
209
+ | 'pay_by_bank'
210
+ | 'trustly'
211
+ | 'stablecoin';
207
212
  reference_id?: string;
208
213
  /**
209
214
  * @deprecated Please refer API docs to use other attributes
@@ -275,7 +280,12 @@ declare module 'chargebee' {
275
280
  | 'sepa_instant_transfer'
276
281
  | 'klarna_pay_now'
277
282
  | 'online_banking_poland'
278
- | 'payconiq_by_bancontact';
283
+ | 'payconiq_by_bancontact'
284
+ | 'electronic_payment_standard'
285
+ | 'kbc_payment_button'
286
+ | 'pay_by_bank'
287
+ | 'trustly'
288
+ | 'stablecoin';
279
289
  reference_id?: string;
280
290
  /**
281
291
  * @deprecated Please refer API docs to use other attributes
@@ -68,6 +68,10 @@ declare module 'chargebee' {
68
68
  headers?: ChargebeeRequestHeader,
69
69
  ): Promise<ChargebeeResponse<CheckoutExistingForItemsResponse>>;
70
70
 
71
+ /**
72
+ * @deprecated This method is deprecated and will be removed in a future version.
73
+ */
74
+
71
75
  updateCard(
72
76
  input: UpdateCardInputParam,
73
77
  headers?: ChargebeeRequestHeader,
@@ -104,6 +104,10 @@ declare module 'chargebee' {
104
104
  headers?: ChargebeeRequestHeader,
105
105
  ): Promise<ChargebeeResponse<ChargeAddonResponse>>;
106
106
 
107
+ /**
108
+ * @deprecated This method is deprecated and will be removed in a future version.
109
+ */
110
+
107
111
  createForChargeItem(
108
112
  input: CreateForChargeItemInputParam,
109
113
  headers?: ChargebeeRequestHeader,
@@ -160,12 +164,20 @@ declare module 'chargebee' {
160
164
  headers?: ChargebeeRequestHeader,
161
165
  ): Promise<ChargebeeResponse<ListResponse>>;
162
166
 
167
+ /**
168
+ * @deprecated This method is deprecated and will be removed in a future version.
169
+ */
170
+
163
171
  invoicesForCustomer(
164
172
  customer_id: string,
165
173
  input?: InvoicesForCustomerInputParam,
166
174
  headers?: ChargebeeRequestHeader,
167
175
  ): Promise<ChargebeeResponse<InvoicesForCustomerResponse>>;
168
176
 
177
+ /**
178
+ * @deprecated This method is deprecated and will be removed in a future version.
179
+ */
180
+
169
181
  invoicesForSubscription(
170
182
  subscription_id: string,
171
183
  input?: InvoicesForSubscriptionInputParam,
@@ -687,6 +699,7 @@ declare module 'chargebee' {
687
699
  | 'needs_attention'
688
700
  | 'late_failure';
689
701
  txn_amount?: number;
702
+ retry_engine?: 'chargebee' | 'flexpay' | 'successplus';
690
703
  }
691
704
  export interface AppliedCredit {
692
705
  cn_id: string;
@@ -1247,7 +1260,12 @@ declare module 'chargebee' {
1247
1260
  | 'sepa_instant_transfer'
1248
1261
  | 'klarna_pay_now'
1249
1262
  | 'online_banking_poland'
1250
- | 'payconiq_by_bancontact';
1263
+ | 'payconiq_by_bancontact'
1264
+ | 'electronic_payment_standard'
1265
+ | 'kbc_payment_button'
1266
+ | 'pay_by_bank'
1267
+ | 'trustly'
1268
+ | 'stablecoin';
1251
1269
  reference_id?: string;
1252
1270
  /**
1253
1271
  * @deprecated Please refer API docs to use other attributes
@@ -1394,7 +1412,12 @@ declare module 'chargebee' {
1394
1412
  | 'sepa_instant_transfer'
1395
1413
  | 'klarna_pay_now'
1396
1414
  | 'online_banking_poland'
1397
- | 'payconiq_by_bancontact';
1415
+ | 'payconiq_by_bancontact'
1416
+ | 'electronic_payment_standard'
1417
+ | 'kbc_payment_button'
1418
+ | 'pay_by_bank'
1419
+ | 'trustly'
1420
+ | 'stablecoin';
1398
1421
  reference_id?: string;
1399
1422
  /**
1400
1423
  * @deprecated Please refer API docs to use other attributes
@@ -92,6 +92,10 @@ declare module 'chargebee' {
92
92
  headers?: ChargebeeRequestHeader,
93
93
  ): Promise<ChargebeeResponse<FindApplicableItemPricesResponse>>;
94
94
 
95
+ /**
96
+ * @deprecated This method is deprecated and will be removed in a future version.
97
+ */
98
+
95
99
  moveItemPrice(
96
100
  item_price_id: string,
97
101
  input: MoveItemPriceInputParam,
@@ -281,6 +285,7 @@ declare module 'chargebee' {
281
285
  }
282
286
  export interface MoveItemPriceInputParam {
283
287
  destination_item_id: string;
288
+ variant_id?: string;
284
289
  }
285
290
  export interface TaxDetailCreateInputParam {
286
291
  tax_profile_id?: string;
@@ -143,6 +143,10 @@ declare module 'chargebee' {
143
143
  headers?: ChargebeeRequestHeader,
144
144
  ): Promise<ChargebeeResponse<ListResponse>>;
145
145
 
146
+ /**
147
+ * @deprecated This method is deprecated and will be removed in a future version.
148
+ */
149
+
146
150
  ordersForInvoice(
147
151
  invoice_id: string,
148
152
  input?: OrdersForInvoiceInputParam,
@@ -31,7 +31,12 @@ declare module 'chargebee' {
31
31
  | 'sepa_instant_transfer'
32
32
  | 'klarna_pay_now'
33
33
  | 'online_banking_poland'
34
- | 'payconiq_by_bancontact';
34
+ | 'payconiq_by_bancontact'
35
+ | 'electronic_payment_standard'
36
+ | 'kbc_payment_button'
37
+ | 'pay_by_bank'
38
+ | 'trustly'
39
+ | 'stablecoin';
35
40
  success_url?: string;
36
41
  failure_url?: string;
37
42
  created_at: number;
@@ -107,7 +112,12 @@ declare module 'chargebee' {
107
112
  | 'sepa_instant_transfer'
108
113
  | 'klarna_pay_now'
109
114
  | 'online_banking_poland'
110
- | 'payconiq_by_bancontact';
115
+ | 'payconiq_by_bancontact'
116
+ | 'electronic_payment_standard'
117
+ | 'kbc_payment_button'
118
+ | 'pay_by_bank'
119
+ | 'trustly'
120
+ | 'stablecoin';
111
121
  id_at_gateway?: string;
112
122
  error_code?: string;
113
123
  error_text?: string;
@@ -147,7 +157,12 @@ declare module 'chargebee' {
147
157
  | 'sepa_instant_transfer'
148
158
  | 'klarna_pay_now'
149
159
  | 'online_banking_poland'
150
- | 'payconiq_by_bancontact';
160
+ | 'payconiq_by_bancontact'
161
+ | 'electronic_payment_standard'
162
+ | 'kbc_payment_button'
163
+ | 'pay_by_bank'
164
+ | 'trustly'
165
+ | 'stablecoin';
151
166
  id_at_gateway?: string;
152
167
  error_code?: string;
153
168
  error_text?: string;
@@ -187,7 +202,12 @@ declare module 'chargebee' {
187
202
  | 'sepa_instant_transfer'
188
203
  | 'klarna_pay_now'
189
204
  | 'online_banking_poland'
190
- | 'payconiq_by_bancontact';
205
+ | 'payconiq_by_bancontact'
206
+ | 'electronic_payment_standard'
207
+ | 'kbc_payment_button'
208
+ | 'pay_by_bank'
209
+ | 'trustly'
210
+ | 'stablecoin';
191
211
  success_url?: string;
192
212
  failure_url?: string;
193
213
  }
@@ -216,7 +236,12 @@ declare module 'chargebee' {
216
236
  | 'sepa_instant_transfer'
217
237
  | 'klarna_pay_now'
218
238
  | 'online_banking_poland'
219
- | 'payconiq_by_bancontact';
239
+ | 'payconiq_by_bancontact'
240
+ | 'electronic_payment_standard'
241
+ | 'kbc_payment_button'
242
+ | 'pay_by_bank'
243
+ | 'trustly'
244
+ | 'stablecoin';
220
245
  success_url?: string;
221
246
  failure_url?: string;
222
247
  }
@@ -453,7 +453,12 @@ declare module 'chargebee' {
453
453
  | 'sepa_instant_transfer'
454
454
  | 'klarna_pay_now'
455
455
  | 'online_banking_poland'
456
- | 'payconiq_by_bancontact';
456
+ | 'payconiq_by_bancontact'
457
+ | 'electronic_payment_standard'
458
+ | 'kbc_payment_button'
459
+ | 'pay_by_bank'
460
+ | 'trustly'
461
+ | 'stablecoin';
457
462
  reference_id?: string;
458
463
  /**
459
464
  * @deprecated Please refer API docs to use other attributes
@@ -37,6 +37,7 @@ declare module 'chargebee' {
37
37
  redirect_url?: string;
38
38
  business_entity_id?: string;
39
39
  auto_select_local_currency?: boolean;
40
+ custom?: any;
40
41
  pricing_page?: PricingPageCreateForNewSubscriptionInputParam;
41
42
  subscription?: SubscriptionCreateForNewSubscriptionInputParam;
42
43
  customer?: CustomerCreateForNewSubscriptionInputParam;
@@ -46,6 +47,7 @@ declare module 'chargebee' {
46
47
  }
47
48
  export interface CreateForExistingSubscriptionInputParam {
48
49
  redirect_url?: string;
50
+ custom?: any;
49
51
  pricing_page?: PricingPageCreateForExistingSubscriptionInputParam;
50
52
  subscription?: SubscriptionCreateForExistingSubscriptionInputParam;
51
53
  discounts?: DiscountsCreateForExistingSubscriptionInputParam[];
@@ -98,7 +98,12 @@ declare module 'chargebee' {
98
98
  | 'sepa_instant_transfer'
99
99
  | 'klarna_pay_now'
100
100
  | 'online_banking_poland'
101
- | 'payconiq_by_bancontact';
101
+ | 'payconiq_by_bancontact'
102
+ | 'electronic_payment_standard'
103
+ | 'kbc_payment_button'
104
+ | 'pay_by_bank'
105
+ | 'trustly'
106
+ | 'stablecoin';
102
107
  reference_id?: string;
103
108
  /**
104
109
  * @deprecated Please refer API docs to use other attributes
@@ -122,6 +122,10 @@ declare module 'chargebee' {
122
122
  headers?: ChargebeeRequestHeader,
123
123
  ): Promise<ChargebeeResponse<ListResponse>>;
124
124
 
125
+ /**
126
+ * @deprecated This method is deprecated and will be removed in a future version.
127
+ */
128
+
125
129
  subscriptionsForCustomer(
126
130
  customer_id: string,
127
131
  input?: SubscriptionsForCustomerInputParam,
@@ -1401,7 +1405,12 @@ declare module 'chargebee' {
1401
1405
  | 'sepa_instant_transfer'
1402
1406
  | 'klarna_pay_now'
1403
1407
  | 'online_banking_poland'
1404
- | 'payconiq_by_bancontact';
1408
+ | 'payconiq_by_bancontact'
1409
+ | 'electronic_payment_standard'
1410
+ | 'kbc_payment_button'
1411
+ | 'pay_by_bank'
1412
+ | 'trustly'
1413
+ | 'stablecoin';
1405
1414
  reference_id?: string;
1406
1415
  /**
1407
1416
  * @deprecated Please refer API docs to use other attributes
@@ -1529,7 +1538,12 @@ declare module 'chargebee' {
1529
1538
  | 'sepa_instant_transfer'
1530
1539
  | 'klarna_pay_now'
1531
1540
  | 'online_banking_poland'
1532
- | 'payconiq_by_bancontact';
1541
+ | 'payconiq_by_bancontact'
1542
+ | 'electronic_payment_standard'
1543
+ | 'kbc_payment_button'
1544
+ | 'pay_by_bank'
1545
+ | 'trustly'
1546
+ | 'stablecoin';
1533
1547
  reference_id?: string;
1534
1548
  /**
1535
1549
  * @deprecated Please refer API docs to use other attributes
@@ -1624,7 +1638,12 @@ declare module 'chargebee' {
1624
1638
  | 'sepa_instant_transfer'
1625
1639
  | 'klarna_pay_now'
1626
1640
  | 'online_banking_poland'
1627
- | 'payconiq_by_bancontact';
1641
+ | 'payconiq_by_bancontact'
1642
+ | 'electronic_payment_standard'
1643
+ | 'kbc_payment_button'
1644
+ | 'pay_by_bank'
1645
+ | 'trustly'
1646
+ | 'stablecoin';
1628
1647
  reference_id?: string;
1629
1648
  /**
1630
1649
  * @deprecated Please refer API docs to use other attributes
@@ -1774,7 +1793,12 @@ declare module 'chargebee' {
1774
1793
  | 'sepa_instant_transfer'
1775
1794
  | 'klarna_pay_now'
1776
1795
  | 'online_banking_poland'
1777
- | 'payconiq_by_bancontact';
1796
+ | 'payconiq_by_bancontact'
1797
+ | 'electronic_payment_standard'
1798
+ | 'kbc_payment_button'
1799
+ | 'pay_by_bank'
1800
+ | 'trustly'
1801
+ | 'stablecoin';
1778
1802
  reference_id?: string;
1779
1803
  /**
1780
1804
  * @deprecated Please refer API docs to use other attributes
@@ -1938,7 +1962,12 @@ declare module 'chargebee' {
1938
1962
  | 'sepa_instant_transfer'
1939
1963
  | 'klarna_pay_now'
1940
1964
  | 'online_banking_poland'
1941
- | 'payconiq_by_bancontact';
1965
+ | 'payconiq_by_bancontact'
1966
+ | 'electronic_payment_standard'
1967
+ | 'kbc_payment_button'
1968
+ | 'pay_by_bank'
1969
+ | 'trustly'
1970
+ | 'stablecoin';
1942
1971
  reference_id?: string;
1943
1972
  /**
1944
1973
  * @deprecated Please refer API docs to use other attributes
@@ -2058,7 +2087,12 @@ declare module 'chargebee' {
2058
2087
  | 'sepa_instant_transfer'
2059
2088
  | 'klarna_pay_now'
2060
2089
  | 'online_banking_poland'
2061
- | 'payconiq_by_bancontact';
2090
+ | 'payconiq_by_bancontact'
2091
+ | 'electronic_payment_standard'
2092
+ | 'kbc_payment_button'
2093
+ | 'pay_by_bank'
2094
+ | 'trustly'
2095
+ | 'stablecoin';
2062
2096
  reference_id?: string;
2063
2097
  /**
2064
2098
  * @deprecated Please refer API docs to use other attributes
@@ -2484,7 +2518,12 @@ declare module 'chargebee' {
2484
2518
  | 'sepa_instant_transfer'
2485
2519
  | 'klarna_pay_now'
2486
2520
  | 'online_banking_poland'
2487
- | 'payconiq_by_bancontact';
2521
+ | 'payconiq_by_bancontact'
2522
+ | 'electronic_payment_standard'
2523
+ | 'kbc_payment_button'
2524
+ | 'pay_by_bank'
2525
+ | 'trustly'
2526
+ | 'stablecoin';
2488
2527
  reference_id?: string;
2489
2528
  /**
2490
2529
  * @deprecated Please refer API docs to use other attributes
@@ -96,12 +96,20 @@ declare module 'chargebee' {
96
96
  headers?: ChargebeeRequestHeader,
97
97
  ): Promise<ChargebeeResponse<ListResponse>>;
98
98
 
99
+ /**
100
+ * @deprecated This method is deprecated and will be removed in a future version.
101
+ */
102
+
99
103
  transactionsForCustomer(
100
104
  customer_id: string,
101
105
  input?: TransactionsForCustomerInputParam,
102
106
  headers?: ChargebeeRequestHeader,
103
107
  ): Promise<ChargebeeResponse<TransactionsForCustomerResponse>>;
104
108
 
109
+ /**
110
+ * @deprecated This method is deprecated and will be removed in a future version.
111
+ */
112
+
105
113
  transactionsForSubscription(
106
114
  subscription_id: string,
107
115
  input?: TransactionsForSubscriptionInputParam,
@@ -220,6 +220,7 @@ declare module 'chargebee' {
220
220
  PlanCreated = 'plan_created',
221
221
  PlanUpdated = 'plan_updated',
222
222
  }
223
+
223
224
  /**
224
225
  * @deprecated Use WebhookEventType instead.
225
226
  */
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.basicAuthValidator = void 0;
4
- const basicAuthValidator = (validateCredentials) => {
5
- return (headers) => {
6
- const authHeader = headers['authorization'] || headers['Authorization'];
7
- if (!authHeader) {
8
- throw new Error('Invalid authorization header');
9
- }
10
- const authStr = Array.isArray(authHeader) ? authHeader[0] : authHeader;
11
- if (!authStr) {
12
- throw new Error('Invalid authorization header');
13
- }
14
- const parts = authStr.split(' ');
15
- if (parts.length !== 2 || parts[0] !== 'Basic') {
16
- throw new Error('Invalid authorization header');
17
- }
18
- const credentials = Buffer.from(parts[1], 'base64').toString().split(':');
19
- if (credentials.length !== 2) {
20
- throw new Error('Invalid credentials');
21
- }
22
- if (!validateCredentials(credentials[0], credentials[1])) {
23
- throw new Error('Invalid credentials');
24
- }
25
- };
26
- };
27
- exports.basicAuthValidator = basicAuthValidator;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- ///<reference path='../../../types/index.d.ts'/>
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WebhookHandler = exports.WebhookContentType = exports.WebhookEventType = void 0;
4
- const node_events_1 = require("node:events");
5
- const auth_js_1 = require("./auth.js");
6
- const eventType_js_1 = require("./eventType.js");
7
- Object.defineProperty(exports, "WebhookEventType", { enumerable: true, get: function () { return eventType_js_1.WebhookEventType; } });
8
- Object.defineProperty(exports, "WebhookContentType", { enumerable: true, get: function () { return eventType_js_1.WebhookContentType; } });
9
- class WebhookHandler extends node_events_1.EventEmitter {
10
- constructor() {
11
- super({ captureRejections: true });
12
- }
13
- handle(body, headers) {
14
- try {
15
- if (this.requestValidator && headers) {
16
- this.requestValidator(headers);
17
- }
18
- const event = typeof body === 'string' ? JSON.parse(body) : body;
19
- const eventType = event.event_type;
20
- if (this.listenerCount(eventType) > 0) {
21
- this.emit(eventType, event);
22
- }
23
- else {
24
- this.emit('unhandled_event', event);
25
- }
26
- }
27
- catch (err) {
28
- this.emit('error', err instanceof Error ? err : new Error(String(err)));
29
- }
30
- }
31
- }
32
- exports.WebhookHandler = WebhookHandler;
33
- const webhook = new WebhookHandler();
34
- // Auto-configure basic auth if env vars are present
35
- const username = process.env.CHARGEBEE_WEBHOOK_USERNAME;
36
- const password = process.env.CHARGEBEE_WEBHOOK_PASSWORD;
37
- if (username && password) {
38
- webhook.requestValidator = (0, auth_js_1.basicAuthValidator)((u, p) => u === username && p === password);
39
- }
40
- exports.default = webhook;
@@ -1,23 +0,0 @@
1
- export const basicAuthValidator = (validateCredentials) => {
2
- return (headers) => {
3
- const authHeader = headers['authorization'] || headers['Authorization'];
4
- if (!authHeader) {
5
- throw new Error('Invalid authorization header');
6
- }
7
- const authStr = Array.isArray(authHeader) ? authHeader[0] : authHeader;
8
- if (!authStr) {
9
- throw new Error('Invalid authorization header');
10
- }
11
- const parts = authStr.split(' ');
12
- if (parts.length !== 2 || parts[0] !== 'Basic') {
13
- throw new Error('Invalid authorization header');
14
- }
15
- const credentials = Buffer.from(parts[1], 'base64').toString().split(':');
16
- if (credentials.length !== 2) {
17
- throw new Error('Invalid credentials');
18
- }
19
- if (!validateCredentials(credentials[0], credentials[1])) {
20
- throw new Error('Invalid credentials');
21
- }
22
- };
23
- };
@@ -1,2 +0,0 @@
1
- ///<reference path='../../../types/index.d.ts'/>
2
- export {};
@@ -1,35 +0,0 @@
1
- import { EventEmitter } from 'node:events';
2
- import { basicAuthValidator } from './auth.js';
3
- import { WebhookEventType, WebhookContentType } from './eventType.js';
4
- export { WebhookEventType, WebhookContentType };
5
- export class WebhookHandler extends EventEmitter {
6
- constructor() {
7
- super({ captureRejections: true });
8
- }
9
- handle(body, headers) {
10
- try {
11
- if (this.requestValidator && headers) {
12
- this.requestValidator(headers);
13
- }
14
- const event = typeof body === 'string' ? JSON.parse(body) : body;
15
- const eventType = event.event_type;
16
- if (this.listenerCount(eventType) > 0) {
17
- this.emit(eventType, event);
18
- }
19
- else {
20
- this.emit('unhandled_event', event);
21
- }
22
- }
23
- catch (err) {
24
- this.emit('error', err instanceof Error ? err : new Error(String(err)));
25
- }
26
- }
27
- }
28
- const webhook = new WebhookHandler();
29
- // Auto-configure basic auth if env vars are present
30
- const username = process.env.CHARGEBEE_WEBHOOK_USERNAME;
31
- const password = process.env.CHARGEBEE_WEBHOOK_PASSWORD;
32
- if (username && password) {
33
- webhook.requestValidator = basicAuthValidator((u, p) => u === username && p === password);
34
- }
35
- export default webhook;