This is page 8 of 10. Use http://codebase.md/dodopayments/dodopayments-node?lines=true&page={x} to view the full context.
# Directory Structure
```
├── .devcontainer
│ └── devcontainer.json
├── .github
│ └── workflows
│ ├── ci.yml
│ ├── docker-mcp.yml
│ ├── publish-npm.yml
│ └── release-doctor.yml
├── .gitignore
├── .prettierignore
├── .prettierrc.json
├── .release-please-manifest.json
├── .stats.yml
├── api.md
├── bin
│ ├── check-release-environment
│ ├── cli
│ ├── docker-tags
│ ├── migration-config.json
│ └── publish-npm
├── Brewfile
├── CHANGELOG.md
├── CONTRIBUTING.md
├── eslint.config.mjs
├── examples
│ └── .keep
├── jest.config.ts
├── LICENSE
├── MIGRATION.md
├── package.json
├── packages
│ └── mcp-server
│ ├── .dockerignore
│ ├── build
│ ├── cloudflare-worker
│ │ ├── .gitignore
│ │ ├── biome.json
│ │ ├── package.json
│ │ ├── README.md
│ │ ├── src
│ │ │ ├── app.ts
│ │ │ ├── index.ts
│ │ │ └── utils.ts
│ │ ├── static
│ │ │ └── home.md
│ │ ├── tsconfig.json
│ │ ├── worker-configuration.d.ts
│ │ └── wrangler.jsonc
│ ├── Dockerfile
│ ├── jest.config.ts
│ ├── manifest.json
│ ├── package.json
│ ├── README.md
│ ├── scripts
│ │ ├── copy-bundle-files.cjs
│ │ └── postprocess-dist-package-json.cjs
│ ├── src
│ │ ├── code-tool-paths.cts
│ │ ├── code-tool-types.ts
│ │ ├── code-tool-worker.ts
│ │ ├── code-tool.ts
│ │ ├── compat.ts
│ │ ├── docs-search-tool.ts
│ │ ├── dynamic-tools.ts
│ │ ├── filtering.ts
│ │ ├── headers.ts
│ │ ├── http.ts
│ │ ├── index.ts
│ │ ├── options.ts
│ │ ├── server.ts
│ │ ├── stdio.ts
│ │ ├── tools
│ │ │ ├── addons
│ │ │ │ ├── create-addons.ts
│ │ │ │ ├── list-addons.ts
│ │ │ │ ├── retrieve-addons.ts
│ │ │ │ ├── update-addons.ts
│ │ │ │ └── update-images-addons.ts
│ │ │ ├── brands
│ │ │ │ ├── create-brands.ts
│ │ │ │ ├── list-brands.ts
│ │ │ │ ├── retrieve-brands.ts
│ │ │ │ ├── update-brands.ts
│ │ │ │ └── update-images-brands.ts
│ │ │ ├── checkout-sessions
│ │ │ │ ├── create-checkout-sessions.ts
│ │ │ │ └── retrieve-checkout-sessions.ts
│ │ │ ├── customers
│ │ │ │ ├── create-customers.ts
│ │ │ │ ├── customer-portal
│ │ │ │ │ └── create-customers-customer-portal.ts
│ │ │ │ ├── list-customers.ts
│ │ │ │ ├── retrieve-customers.ts
│ │ │ │ ├── update-customers.ts
│ │ │ │ └── wallets
│ │ │ │ ├── ledger-entries
│ │ │ │ │ ├── create-wallets-customers-ledger-entries.ts
│ │ │ │ │ └── list-wallets-customers-ledger-entries.ts
│ │ │ │ └── list-customers-wallets.ts
│ │ │ ├── discounts
│ │ │ │ ├── create-discounts.ts
│ │ │ │ ├── delete-discounts.ts
│ │ │ │ ├── list-discounts.ts
│ │ │ │ ├── retrieve-discounts.ts
│ │ │ │ └── update-discounts.ts
│ │ │ ├── disputes
│ │ │ │ ├── list-disputes.ts
│ │ │ │ └── retrieve-disputes.ts
│ │ │ ├── index.ts
│ │ │ ├── invoices
│ │ │ │ └── payments
│ │ │ │ ├── retrieve-invoices-payments.ts
│ │ │ │ └── retrieve-refund-invoices-payments.ts
│ │ │ ├── license-key-instances
│ │ │ │ ├── list-license-key-instances.ts
│ │ │ │ ├── retrieve-license-key-instances.ts
│ │ │ │ └── update-license-key-instances.ts
│ │ │ ├── license-keys
│ │ │ │ ├── list-license-keys.ts
│ │ │ │ ├── retrieve-license-keys.ts
│ │ │ │ └── update-license-keys.ts
│ │ │ ├── licenses
│ │ │ │ ├── activate-licenses.ts
│ │ │ │ ├── deactivate-licenses.ts
│ │ │ │ └── validate-licenses.ts
│ │ │ ├── meters
│ │ │ │ ├── archive-meters.ts
│ │ │ │ ├── create-meters.ts
│ │ │ │ ├── list-meters.ts
│ │ │ │ ├── retrieve-meters.ts
│ │ │ │ └── unarchive-meters.ts
│ │ │ ├── misc
│ │ │ │ └── list-supported-countries-misc.ts
│ │ │ ├── payments
│ │ │ │ ├── create-payments.ts
│ │ │ │ ├── list-payments.ts
│ │ │ │ ├── retrieve-line-items-payments.ts
│ │ │ │ └── retrieve-payments.ts
│ │ │ ├── payouts
│ │ │ │ └── list-payouts.ts
│ │ │ ├── products
│ │ │ │ ├── archive-products.ts
│ │ │ │ ├── create-products.ts
│ │ │ │ ├── images
│ │ │ │ │ └── update-products-images.ts
│ │ │ │ ├── list-products.ts
│ │ │ │ ├── retrieve-products.ts
│ │ │ │ ├── unarchive-products.ts
│ │ │ │ ├── update-files-products.ts
│ │ │ │ └── update-products.ts
│ │ │ ├── refunds
│ │ │ │ ├── create-refunds.ts
│ │ │ │ ├── list-refunds.ts
│ │ │ │ └── retrieve-refunds.ts
│ │ │ ├── subscriptions
│ │ │ │ ├── change-plan-subscriptions.ts
│ │ │ │ ├── charge-subscriptions.ts
│ │ │ │ ├── create-subscriptions.ts
│ │ │ │ ├── list-subscriptions.ts
│ │ │ │ ├── retrieve-subscriptions.ts
│ │ │ │ ├── retrieve-usage-history-subscriptions.ts
│ │ │ │ └── update-subscriptions.ts
│ │ │ ├── types.ts
│ │ │ ├── usage-events
│ │ │ │ ├── ingest-usage-events.ts
│ │ │ │ ├── list-usage-events.ts
│ │ │ │ └── retrieve-usage-events.ts
│ │ │ └── webhooks
│ │ │ ├── create-webhooks.ts
│ │ │ ├── delete-webhooks.ts
│ │ │ ├── headers
│ │ │ │ ├── retrieve-webhooks-headers.ts
│ │ │ │ └── update-webhooks-headers.ts
│ │ │ ├── list-webhooks.ts
│ │ │ ├── retrieve-secret-webhooks.ts
│ │ │ ├── retrieve-webhooks.ts
│ │ │ └── update-webhooks.ts
│ │ └── tools.ts
│ ├── tests
│ │ ├── compat.test.ts
│ │ ├── dynamic-tools.test.ts
│ │ ├── options.test.ts
│ │ └── tools.test.ts
│ ├── tsc-multi.json
│ ├── tsconfig.build.json
│ ├── tsconfig.dist-src.json
│ ├── tsconfig.json
│ └── yarn.lock
├── README.md
├── release-please-config.json
├── scripts
│ ├── bootstrap
│ ├── build
│ ├── build-all
│ ├── fast-format
│ ├── format
│ ├── lint
│ ├── mock
│ ├── publish-packages.ts
│ ├── test
│ └── utils
│ ├── attw-report.cjs
│ ├── check-is-in-git-install.sh
│ ├── check-version.cjs
│ ├── fix-index-exports.cjs
│ ├── git-swap.sh
│ ├── make-dist-package-json.cjs
│ ├── postprocess-files.cjs
│ └── upload-artifact.sh
├── SECURITY.md
├── src
│ ├── api-promise.ts
│ ├── client.ts
│ ├── core
│ │ ├── api-promise.ts
│ │ ├── error.ts
│ │ ├── pagination.ts
│ │ ├── README.md
│ │ ├── resource.ts
│ │ └── uploads.ts
│ ├── error.ts
│ ├── index.ts
│ ├── internal
│ │ ├── builtin-types.ts
│ │ ├── detect-platform.ts
│ │ ├── errors.ts
│ │ ├── headers.ts
│ │ ├── parse.ts
│ │ ├── README.md
│ │ ├── request-options.ts
│ │ ├── shim-types.ts
│ │ ├── shims.ts
│ │ ├── to-file.ts
│ │ ├── types.ts
│ │ ├── uploads.ts
│ │ ├── utils
│ │ │ ├── base64.ts
│ │ │ ├── bytes.ts
│ │ │ ├── env.ts
│ │ │ ├── log.ts
│ │ │ ├── path.ts
│ │ │ ├── sleep.ts
│ │ │ ├── uuid.ts
│ │ │ └── values.ts
│ │ └── utils.ts
│ ├── lib
│ │ └── .keep
│ ├── pagination.ts
│ ├── resource.ts
│ ├── resources
│ │ ├── addons.ts
│ │ ├── brands.ts
│ │ ├── checkout-sessions.ts
│ │ ├── customers
│ │ │ ├── customer-portal.ts
│ │ │ ├── customers.ts
│ │ │ ├── index.ts
│ │ │ ├── wallets
│ │ │ │ ├── index.ts
│ │ │ │ ├── ledger-entries.ts
│ │ │ │ └── wallets.ts
│ │ │ └── wallets.ts
│ │ ├── customers.ts
│ │ ├── discounts.ts
│ │ ├── disputes.ts
│ │ ├── index.ts
│ │ ├── invoices
│ │ │ ├── index.ts
│ │ │ ├── invoices.ts
│ │ │ └── payments.ts
│ │ ├── invoices.ts
│ │ ├── license-key-instances.ts
│ │ ├── license-keys.ts
│ │ ├── licenses.ts
│ │ ├── meters.ts
│ │ ├── misc.ts
│ │ ├── payments.ts
│ │ ├── payouts.ts
│ │ ├── products
│ │ │ ├── images.ts
│ │ │ ├── index.ts
│ │ │ └── products.ts
│ │ ├── products.ts
│ │ ├── refunds.ts
│ │ ├── subscriptions.ts
│ │ ├── usage-events.ts
│ │ ├── webhook-events.ts
│ │ ├── webhooks
│ │ │ ├── headers.ts
│ │ │ ├── index.ts
│ │ │ └── webhooks.ts
│ │ └── webhooks.ts
│ ├── resources.ts
│ ├── uploads.ts
│ └── version.ts
├── tests
│ ├── api-resources
│ │ ├── addons.test.ts
│ │ ├── brands.test.ts
│ │ ├── checkout-sessions.test.ts
│ │ ├── customers
│ │ │ ├── customer-portal.test.ts
│ │ │ ├── customers.test.ts
│ │ │ └── wallets
│ │ │ ├── ledger-entries.test.ts
│ │ │ └── wallets.test.ts
│ │ ├── discounts.test.ts
│ │ ├── disputes.test.ts
│ │ ├── license-key-instances.test.ts
│ │ ├── license-keys.test.ts
│ │ ├── licenses.test.ts
│ │ ├── meters.test.ts
│ │ ├── misc.test.ts
│ │ ├── payments.test.ts
│ │ ├── payouts.test.ts
│ │ ├── products
│ │ │ ├── images.test.ts
│ │ │ └── products.test.ts
│ │ ├── refunds.test.ts
│ │ ├── subscriptions.test.ts
│ │ ├── usage-events.test.ts
│ │ └── webhooks
│ │ ├── headers.test.ts
│ │ └── webhooks.test.ts
│ ├── base64.test.ts
│ ├── buildHeaders.test.ts
│ ├── form.test.ts
│ ├── index.test.ts
│ ├── path.test.ts
│ ├── stringifyQuery.test.ts
│ └── uploads.test.ts
├── tsc-multi.json
├── tsconfig.build.json
├── tsconfig.deno.json
├── tsconfig.dist-src.json
├── tsconfig.json
└── yarn.lock
```
# Files
--------------------------------------------------------------------------------
/src/resources/webhooks/webhooks.ts:
--------------------------------------------------------------------------------
```typescript
1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2 |
3 | import { APIResource } from '../../core/resource';
4 | import * as DisputesAPI from '../disputes';
5 | import * as LicenseKeysAPI from '../license-keys';
6 | import * as PaymentsAPI from '../payments';
7 | import * as RefundsAPI from '../refunds';
8 | import * as SubscriptionsAPI from '../subscriptions';
9 | import * as WebhookEventsAPI from '../webhook-events';
10 | import * as HeadersAPI from './headers';
11 | import { HeaderRetrieveResponse, HeaderUpdateParams, Headers } from './headers';
12 | import { Webhook } from 'standardwebhooks';
13 | import { APIPromise } from '../../core/api-promise';
14 | import { CursorPagePagination, type CursorPagePaginationParams, PagePromise } from '../../core/pagination';
15 | import { buildHeaders } from '../../internal/headers';
16 | import { RequestOptions } from '../../internal/request-options';
17 | import { path } from '../../internal/utils/path';
18 |
19 | export class Webhooks extends APIResource {
20 | headers: HeadersAPI.Headers = new HeadersAPI.Headers(this._client);
21 |
22 | /**
23 | * Create a new webhook
24 | */
25 | create(body: WebhookCreateParams, options?: RequestOptions): APIPromise<WebhookDetails> {
26 | return this._client.post('/webhooks', { body, ...options });
27 | }
28 |
29 | /**
30 | * Get a webhook by id
31 | */
32 | retrieve(webhookID: string, options?: RequestOptions): APIPromise<WebhookDetails> {
33 | return this._client.get(path`/webhooks/${webhookID}`, options);
34 | }
35 |
36 | /**
37 | * Patch a webhook by id
38 | */
39 | update(webhookID: string, body: WebhookUpdateParams, options?: RequestOptions): APIPromise<WebhookDetails> {
40 | return this._client.patch(path`/webhooks/${webhookID}`, { body, ...options });
41 | }
42 |
43 | /**
44 | * List all webhooks
45 | */
46 | list(
47 | query: WebhookListParams | null | undefined = {},
48 | options?: RequestOptions,
49 | ): PagePromise<WebhookDetailsCursorPagePagination, WebhookDetails> {
50 | return this._client.getAPIList('/webhooks', CursorPagePagination<WebhookDetails>, { query, ...options });
51 | }
52 |
53 | /**
54 | * Delete a webhook by id
55 | */
56 | delete(webhookID: string, options?: RequestOptions): APIPromise<void> {
57 | return this._client.delete(path`/webhooks/${webhookID}`, {
58 | ...options,
59 | headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
60 | });
61 | }
62 |
63 | /**
64 | * Get webhook secret by id
65 | */
66 | retrieveSecret(webhookID: string, options?: RequestOptions): APIPromise<WebhookRetrieveSecretResponse> {
67 | return this._client.get(path`/webhooks/${webhookID}/secret`, options);
68 | }
69 |
70 | unsafeUnwrap(body: string): UnsafeUnwrapWebhookEvent {
71 | return JSON.parse(body) as UnsafeUnwrapWebhookEvent;
72 | }
73 |
74 | unwrap(
75 | body: string,
76 | { headers, key }: { headers: Record<string, string>; key?: string },
77 | ): UnwrapWebhookEvent {
78 | if (headers !== undefined) {
79 | const keyStr: string | null = key === undefined ? this._client.webhookKey : key;
80 | if (keyStr === null) throw new Error('Webhook key must not be null in order to unwrap');
81 | const wh = new Webhook(keyStr);
82 | wh.verify(body, headers);
83 | }
84 | return JSON.parse(body) as UnwrapWebhookEvent;
85 | }
86 | }
87 |
88 | export type WebhookDetailsCursorPagePagination = CursorPagePagination<WebhookDetails>;
89 |
90 | export interface WebhookDetails {
91 | /**
92 | * The webhook's ID.
93 | */
94 | id: string;
95 |
96 | /**
97 | * Created at timestamp
98 | */
99 | created_at: string;
100 |
101 | /**
102 | * An example webhook name.
103 | */
104 | description: string;
105 |
106 | /**
107 | * Metadata of the webhook
108 | */
109 | metadata: { [key: string]: string };
110 |
111 | /**
112 | * Updated at timestamp
113 | */
114 | updated_at: string;
115 |
116 | /**
117 | * Url endpoint of the webhook
118 | */
119 | url: string;
120 |
121 | /**
122 | * Status of the webhook.
123 | *
124 | * If true, events are not sent
125 | */
126 | disabled?: boolean | null;
127 |
128 | /**
129 | * Filter events to the webhook.
130 | *
131 | * Webhook event will only be sent for events in the list.
132 | */
133 | filter_types?: Array<string> | null;
134 |
135 | /**
136 | * Configured rate limit
137 | */
138 | rate_limit?: number | null;
139 | }
140 |
141 | export interface WebhookRetrieveSecretResponse {
142 | secret: string;
143 | }
144 |
145 | export interface DisputeAcceptedWebhookEvent {
146 | /**
147 | * The business identifier
148 | */
149 | business_id: string;
150 |
151 | /**
152 | * Event-specific data
153 | */
154 | data: DisputeAcceptedWebhookEvent.Data;
155 |
156 | /**
157 | * The timestamp of when the event occurred
158 | */
159 | timestamp: string;
160 |
161 | /**
162 | * The event type
163 | */
164 | type: 'dispute.accepted';
165 | }
166 |
167 | export namespace DisputeAcceptedWebhookEvent {
168 | /**
169 | * Event-specific data
170 | */
171 | export interface Data extends DisputesAPI.Dispute {
172 | /**
173 | * The type of payload in the data field
174 | */
175 | payload_type?: 'Dispute';
176 | }
177 | }
178 |
179 | export interface DisputeCancelledWebhookEvent {
180 | /**
181 | * The business identifier
182 | */
183 | business_id: string;
184 |
185 | /**
186 | * Event-specific data
187 | */
188 | data: DisputeCancelledWebhookEvent.Data;
189 |
190 | /**
191 | * The timestamp of when the event occurred
192 | */
193 | timestamp: string;
194 |
195 | /**
196 | * The event type
197 | */
198 | type: 'dispute.cancelled';
199 | }
200 |
201 | export namespace DisputeCancelledWebhookEvent {
202 | /**
203 | * Event-specific data
204 | */
205 | export interface Data extends DisputesAPI.Dispute {
206 | /**
207 | * The type of payload in the data field
208 | */
209 | payload_type?: 'Dispute';
210 | }
211 | }
212 |
213 | export interface DisputeChallengedWebhookEvent {
214 | /**
215 | * The business identifier
216 | */
217 | business_id: string;
218 |
219 | /**
220 | * Event-specific data
221 | */
222 | data: DisputeChallengedWebhookEvent.Data;
223 |
224 | /**
225 | * The timestamp of when the event occurred
226 | */
227 | timestamp: string;
228 |
229 | /**
230 | * The event type
231 | */
232 | type: 'dispute.challenged';
233 | }
234 |
235 | export namespace DisputeChallengedWebhookEvent {
236 | /**
237 | * Event-specific data
238 | */
239 | export interface Data extends DisputesAPI.Dispute {
240 | /**
241 | * The type of payload in the data field
242 | */
243 | payload_type?: 'Dispute';
244 | }
245 | }
246 |
247 | export interface DisputeExpiredWebhookEvent {
248 | /**
249 | * The business identifier
250 | */
251 | business_id: string;
252 |
253 | /**
254 | * Event-specific data
255 | */
256 | data: DisputeExpiredWebhookEvent.Data;
257 |
258 | /**
259 | * The timestamp of when the event occurred
260 | */
261 | timestamp: string;
262 |
263 | /**
264 | * The event type
265 | */
266 | type: 'dispute.expired';
267 | }
268 |
269 | export namespace DisputeExpiredWebhookEvent {
270 | /**
271 | * Event-specific data
272 | */
273 | export interface Data extends DisputesAPI.Dispute {
274 | /**
275 | * The type of payload in the data field
276 | */
277 | payload_type?: 'Dispute';
278 | }
279 | }
280 |
281 | export interface DisputeLostWebhookEvent {
282 | /**
283 | * The business identifier
284 | */
285 | business_id: string;
286 |
287 | /**
288 | * Event-specific data
289 | */
290 | data: DisputeLostWebhookEvent.Data;
291 |
292 | /**
293 | * The timestamp of when the event occurred
294 | */
295 | timestamp: string;
296 |
297 | /**
298 | * The event type
299 | */
300 | type: 'dispute.lost';
301 | }
302 |
303 | export namespace DisputeLostWebhookEvent {
304 | /**
305 | * Event-specific data
306 | */
307 | export interface Data extends DisputesAPI.Dispute {
308 | /**
309 | * The type of payload in the data field
310 | */
311 | payload_type?: 'Dispute';
312 | }
313 | }
314 |
315 | export interface DisputeOpenedWebhookEvent {
316 | /**
317 | * The business identifier
318 | */
319 | business_id: string;
320 |
321 | /**
322 | * Event-specific data
323 | */
324 | data: DisputeOpenedWebhookEvent.Data;
325 |
326 | /**
327 | * The timestamp of when the event occurred
328 | */
329 | timestamp: string;
330 |
331 | /**
332 | * The event type
333 | */
334 | type: 'dispute.opened';
335 | }
336 |
337 | export namespace DisputeOpenedWebhookEvent {
338 | /**
339 | * Event-specific data
340 | */
341 | export interface Data extends DisputesAPI.Dispute {
342 | /**
343 | * The type of payload in the data field
344 | */
345 | payload_type?: 'Dispute';
346 | }
347 | }
348 |
349 | export interface DisputeWonWebhookEvent {
350 | /**
351 | * The business identifier
352 | */
353 | business_id: string;
354 |
355 | /**
356 | * Event-specific data
357 | */
358 | data: DisputeWonWebhookEvent.Data;
359 |
360 | /**
361 | * The timestamp of when the event occurred
362 | */
363 | timestamp: string;
364 |
365 | /**
366 | * The event type
367 | */
368 | type: 'dispute.won';
369 | }
370 |
371 | export namespace DisputeWonWebhookEvent {
372 | /**
373 | * Event-specific data
374 | */
375 | export interface Data extends DisputesAPI.Dispute {
376 | /**
377 | * The type of payload in the data field
378 | */
379 | payload_type?: 'Dispute';
380 | }
381 | }
382 |
383 | export interface LicenseKeyCreatedWebhookEvent {
384 | /**
385 | * The business identifier
386 | */
387 | business_id: string;
388 |
389 | /**
390 | * Event-specific data
391 | */
392 | data: LicenseKeyCreatedWebhookEvent.Data;
393 |
394 | /**
395 | * The timestamp of when the event occurred
396 | */
397 | timestamp: string;
398 |
399 | /**
400 | * The event type
401 | */
402 | type: 'license_key.created';
403 | }
404 |
405 | export namespace LicenseKeyCreatedWebhookEvent {
406 | /**
407 | * Event-specific data
408 | */
409 | export interface Data extends LicenseKeysAPI.LicenseKey {
410 | /**
411 | * The type of payload in the data field
412 | */
413 | payload_type?: 'LicenseKey';
414 | }
415 | }
416 |
417 | export interface PaymentCancelledWebhookEvent {
418 | /**
419 | * The business identifier
420 | */
421 | business_id: string;
422 |
423 | /**
424 | * Event-specific data
425 | */
426 | data: PaymentCancelledWebhookEvent.Data;
427 |
428 | /**
429 | * The timestamp of when the event occurred
430 | */
431 | timestamp: string;
432 |
433 | /**
434 | * The event type
435 | */
436 | type: 'payment.cancelled';
437 | }
438 |
439 | export namespace PaymentCancelledWebhookEvent {
440 | /**
441 | * Event-specific data
442 | */
443 | export interface Data extends PaymentsAPI.Payment {
444 | /**
445 | * The type of payload in the data field
446 | */
447 | payload_type?: 'Payment';
448 | }
449 | }
450 |
451 | export interface PaymentFailedWebhookEvent {
452 | /**
453 | * The business identifier
454 | */
455 | business_id: string;
456 |
457 | /**
458 | * Event-specific data
459 | */
460 | data: PaymentFailedWebhookEvent.Data;
461 |
462 | /**
463 | * The timestamp of when the event occurred
464 | */
465 | timestamp: string;
466 |
467 | /**
468 | * The event type
469 | */
470 | type: 'payment.failed';
471 | }
472 |
473 | export namespace PaymentFailedWebhookEvent {
474 | /**
475 | * Event-specific data
476 | */
477 | export interface Data extends PaymentsAPI.Payment {
478 | /**
479 | * The type of payload in the data field
480 | */
481 | payload_type?: 'Payment';
482 | }
483 | }
484 |
485 | export interface PaymentProcessingWebhookEvent {
486 | /**
487 | * The business identifier
488 | */
489 | business_id: string;
490 |
491 | /**
492 | * Event-specific data
493 | */
494 | data: PaymentProcessingWebhookEvent.Data;
495 |
496 | /**
497 | * The timestamp of when the event occurred
498 | */
499 | timestamp: string;
500 |
501 | /**
502 | * The event type
503 | */
504 | type: 'payment.processing';
505 | }
506 |
507 | export namespace PaymentProcessingWebhookEvent {
508 | /**
509 | * Event-specific data
510 | */
511 | export interface Data extends PaymentsAPI.Payment {
512 | /**
513 | * The type of payload in the data field
514 | */
515 | payload_type?: 'Payment';
516 | }
517 | }
518 |
519 | export interface PaymentSucceededWebhookEvent {
520 | /**
521 | * The business identifier
522 | */
523 | business_id: string;
524 |
525 | /**
526 | * Event-specific data
527 | */
528 | data: PaymentSucceededWebhookEvent.Data;
529 |
530 | /**
531 | * The timestamp of when the event occurred
532 | */
533 | timestamp: string;
534 |
535 | /**
536 | * The event type
537 | */
538 | type: 'payment.succeeded';
539 | }
540 |
541 | export namespace PaymentSucceededWebhookEvent {
542 | /**
543 | * Event-specific data
544 | */
545 | export interface Data extends PaymentsAPI.Payment {
546 | /**
547 | * The type of payload in the data field
548 | */
549 | payload_type?: 'Payment';
550 | }
551 | }
552 |
553 | export interface RefundFailedWebhookEvent {
554 | /**
555 | * The business identifier
556 | */
557 | business_id: string;
558 |
559 | /**
560 | * Event-specific data
561 | */
562 | data: RefundFailedWebhookEvent.Data;
563 |
564 | /**
565 | * The timestamp of when the event occurred
566 | */
567 | timestamp: string;
568 |
569 | /**
570 | * The event type
571 | */
572 | type: 'refund.failed';
573 | }
574 |
575 | export namespace RefundFailedWebhookEvent {
576 | /**
577 | * Event-specific data
578 | */
579 | export interface Data extends RefundsAPI.Refund {
580 | /**
581 | * The type of payload in the data field
582 | */
583 | payload_type?: 'Refund';
584 | }
585 | }
586 |
587 | export interface RefundSucceededWebhookEvent {
588 | /**
589 | * The business identifier
590 | */
591 | business_id: string;
592 |
593 | /**
594 | * Event-specific data
595 | */
596 | data: RefundSucceededWebhookEvent.Data;
597 |
598 | /**
599 | * The timestamp of when the event occurred
600 | */
601 | timestamp: string;
602 |
603 | /**
604 | * The event type
605 | */
606 | type: 'refund.succeeded';
607 | }
608 |
609 | export namespace RefundSucceededWebhookEvent {
610 | /**
611 | * Event-specific data
612 | */
613 | export interface Data extends RefundsAPI.Refund {
614 | /**
615 | * The type of payload in the data field
616 | */
617 | payload_type?: 'Refund';
618 | }
619 | }
620 |
621 | export interface SubscriptionActiveWebhookEvent {
622 | /**
623 | * The business identifier
624 | */
625 | business_id: string;
626 |
627 | /**
628 | * Event-specific data
629 | */
630 | data: SubscriptionActiveWebhookEvent.Data;
631 |
632 | /**
633 | * The timestamp of when the event occurred
634 | */
635 | timestamp: string;
636 |
637 | /**
638 | * The event type
639 | */
640 | type: 'subscription.active';
641 | }
642 |
643 | export namespace SubscriptionActiveWebhookEvent {
644 | /**
645 | * Event-specific data
646 | */
647 | export interface Data extends SubscriptionsAPI.Subscription {
648 | /**
649 | * The type of payload in the data field
650 | */
651 | payload_type?: 'Subscription';
652 | }
653 | }
654 |
655 | export interface SubscriptionCancelledWebhookEvent {
656 | /**
657 | * The business identifier
658 | */
659 | business_id: string;
660 |
661 | /**
662 | * Event-specific data
663 | */
664 | data: SubscriptionCancelledWebhookEvent.Data;
665 |
666 | /**
667 | * The timestamp of when the event occurred
668 | */
669 | timestamp: string;
670 |
671 | /**
672 | * The event type
673 | */
674 | type: 'subscription.cancelled';
675 | }
676 |
677 | export namespace SubscriptionCancelledWebhookEvent {
678 | /**
679 | * Event-specific data
680 | */
681 | export interface Data extends SubscriptionsAPI.Subscription {
682 | /**
683 | * The type of payload in the data field
684 | */
685 | payload_type?: 'Subscription';
686 | }
687 | }
688 |
689 | export interface SubscriptionExpiredWebhookEvent {
690 | /**
691 | * The business identifier
692 | */
693 | business_id: string;
694 |
695 | /**
696 | * Event-specific data
697 | */
698 | data: SubscriptionExpiredWebhookEvent.Data;
699 |
700 | /**
701 | * The timestamp of when the event occurred
702 | */
703 | timestamp: string;
704 |
705 | /**
706 | * The event type
707 | */
708 | type: 'subscription.expired';
709 | }
710 |
711 | export namespace SubscriptionExpiredWebhookEvent {
712 | /**
713 | * Event-specific data
714 | */
715 | export interface Data extends SubscriptionsAPI.Subscription {
716 | /**
717 | * The type of payload in the data field
718 | */
719 | payload_type?: 'Subscription';
720 | }
721 | }
722 |
723 | export interface SubscriptionFailedWebhookEvent {
724 | /**
725 | * The business identifier
726 | */
727 | business_id: string;
728 |
729 | /**
730 | * Event-specific data
731 | */
732 | data: SubscriptionFailedWebhookEvent.Data;
733 |
734 | /**
735 | * The timestamp of when the event occurred
736 | */
737 | timestamp: string;
738 |
739 | /**
740 | * The event type
741 | */
742 | type: 'subscription.failed';
743 | }
744 |
745 | export namespace SubscriptionFailedWebhookEvent {
746 | /**
747 | * Event-specific data
748 | */
749 | export interface Data extends SubscriptionsAPI.Subscription {
750 | /**
751 | * The type of payload in the data field
752 | */
753 | payload_type?: 'Subscription';
754 | }
755 | }
756 |
757 | export interface SubscriptionOnHoldWebhookEvent {
758 | /**
759 | * The business identifier
760 | */
761 | business_id: string;
762 |
763 | /**
764 | * Event-specific data
765 | */
766 | data: SubscriptionOnHoldWebhookEvent.Data;
767 |
768 | /**
769 | * The timestamp of when the event occurred
770 | */
771 | timestamp: string;
772 |
773 | /**
774 | * The event type
775 | */
776 | type: 'subscription.on_hold';
777 | }
778 |
779 | export namespace SubscriptionOnHoldWebhookEvent {
780 | /**
781 | * Event-specific data
782 | */
783 | export interface Data extends SubscriptionsAPI.Subscription {
784 | /**
785 | * The type of payload in the data field
786 | */
787 | payload_type?: 'Subscription';
788 | }
789 | }
790 |
791 | export interface SubscriptionPlanChangedWebhookEvent {
792 | /**
793 | * The business identifier
794 | */
795 | business_id: string;
796 |
797 | /**
798 | * Event-specific data
799 | */
800 | data: SubscriptionPlanChangedWebhookEvent.Data;
801 |
802 | /**
803 | * The timestamp of when the event occurred
804 | */
805 | timestamp: string;
806 |
807 | /**
808 | * The event type
809 | */
810 | type: 'subscription.plan_changed';
811 | }
812 |
813 | export namespace SubscriptionPlanChangedWebhookEvent {
814 | /**
815 | * Event-specific data
816 | */
817 | export interface Data extends SubscriptionsAPI.Subscription {
818 | /**
819 | * The type of payload in the data field
820 | */
821 | payload_type?: 'Subscription';
822 | }
823 | }
824 |
825 | export interface SubscriptionRenewedWebhookEvent {
826 | /**
827 | * The business identifier
828 | */
829 | business_id: string;
830 |
831 | /**
832 | * Event-specific data
833 | */
834 | data: SubscriptionRenewedWebhookEvent.Data;
835 |
836 | /**
837 | * The timestamp of when the event occurred
838 | */
839 | timestamp: string;
840 |
841 | /**
842 | * The event type
843 | */
844 | type: 'subscription.renewed';
845 | }
846 |
847 | export namespace SubscriptionRenewedWebhookEvent {
848 | /**
849 | * Event-specific data
850 | */
851 | export interface Data extends SubscriptionsAPI.Subscription {
852 | /**
853 | * The type of payload in the data field
854 | */
855 | payload_type?: 'Subscription';
856 | }
857 | }
858 |
859 | export interface DisputeAcceptedWebhookEvent {
860 | /**
861 | * The business identifier
862 | */
863 | business_id: string;
864 |
865 | /**
866 | * Event-specific data
867 | */
868 | data: DisputeAcceptedWebhookEvent.Data;
869 |
870 | /**
871 | * The timestamp of when the event occurred
872 | */
873 | timestamp: string;
874 |
875 | /**
876 | * The event type
877 | */
878 | type: 'dispute.accepted';
879 | }
880 |
881 | export namespace DisputeAcceptedWebhookEvent {
882 | /**
883 | * Event-specific data
884 | */
885 | export interface Data extends DisputesAPI.Dispute {
886 | /**
887 | * The type of payload in the data field
888 | */
889 | payload_type?: 'Dispute';
890 | }
891 | }
892 |
893 | export interface DisputeCancelledWebhookEvent {
894 | /**
895 | * The business identifier
896 | */
897 | business_id: string;
898 |
899 | /**
900 | * Event-specific data
901 | */
902 | data: DisputeCancelledWebhookEvent.Data;
903 |
904 | /**
905 | * The timestamp of when the event occurred
906 | */
907 | timestamp: string;
908 |
909 | /**
910 | * The event type
911 | */
912 | type: 'dispute.cancelled';
913 | }
914 |
915 | export namespace DisputeCancelledWebhookEvent {
916 | /**
917 | * Event-specific data
918 | */
919 | export interface Data extends DisputesAPI.Dispute {
920 | /**
921 | * The type of payload in the data field
922 | */
923 | payload_type?: 'Dispute';
924 | }
925 | }
926 |
927 | export interface DisputeChallengedWebhookEvent {
928 | /**
929 | * The business identifier
930 | */
931 | business_id: string;
932 |
933 | /**
934 | * Event-specific data
935 | */
936 | data: DisputeChallengedWebhookEvent.Data;
937 |
938 | /**
939 | * The timestamp of when the event occurred
940 | */
941 | timestamp: string;
942 |
943 | /**
944 | * The event type
945 | */
946 | type: 'dispute.challenged';
947 | }
948 |
949 | export namespace DisputeChallengedWebhookEvent {
950 | /**
951 | * Event-specific data
952 | */
953 | export interface Data extends DisputesAPI.Dispute {
954 | /**
955 | * The type of payload in the data field
956 | */
957 | payload_type?: 'Dispute';
958 | }
959 | }
960 |
961 | export interface DisputeExpiredWebhookEvent {
962 | /**
963 | * The business identifier
964 | */
965 | business_id: string;
966 |
967 | /**
968 | * Event-specific data
969 | */
970 | data: DisputeExpiredWebhookEvent.Data;
971 |
972 | /**
973 | * The timestamp of when the event occurred
974 | */
975 | timestamp: string;
976 |
977 | /**
978 | * The event type
979 | */
980 | type: 'dispute.expired';
981 | }
982 |
983 | export namespace DisputeExpiredWebhookEvent {
984 | /**
985 | * Event-specific data
986 | */
987 | export interface Data extends DisputesAPI.Dispute {
988 | /**
989 | * The type of payload in the data field
990 | */
991 | payload_type?: 'Dispute';
992 | }
993 | }
994 |
995 | export interface DisputeLostWebhookEvent {
996 | /**
997 | * The business identifier
998 | */
999 | business_id: string;
1000 |
1001 | /**
1002 | * Event-specific data
1003 | */
1004 | data: DisputeLostWebhookEvent.Data;
1005 |
1006 | /**
1007 | * The timestamp of when the event occurred
1008 | */
1009 | timestamp: string;
1010 |
1011 | /**
1012 | * The event type
1013 | */
1014 | type: 'dispute.lost';
1015 | }
1016 |
1017 | export namespace DisputeLostWebhookEvent {
1018 | /**
1019 | * Event-specific data
1020 | */
1021 | export interface Data extends DisputesAPI.Dispute {
1022 | /**
1023 | * The type of payload in the data field
1024 | */
1025 | payload_type?: 'Dispute';
1026 | }
1027 | }
1028 |
1029 | export interface DisputeOpenedWebhookEvent {
1030 | /**
1031 | * The business identifier
1032 | */
1033 | business_id: string;
1034 |
1035 | /**
1036 | * Event-specific data
1037 | */
1038 | data: DisputeOpenedWebhookEvent.Data;
1039 |
1040 | /**
1041 | * The timestamp of when the event occurred
1042 | */
1043 | timestamp: string;
1044 |
1045 | /**
1046 | * The event type
1047 | */
1048 | type: 'dispute.opened';
1049 | }
1050 |
1051 | export namespace DisputeOpenedWebhookEvent {
1052 | /**
1053 | * Event-specific data
1054 | */
1055 | export interface Data extends DisputesAPI.Dispute {
1056 | /**
1057 | * The type of payload in the data field
1058 | */
1059 | payload_type?: 'Dispute';
1060 | }
1061 | }
1062 |
1063 | export interface DisputeWonWebhookEvent {
1064 | /**
1065 | * The business identifier
1066 | */
1067 | business_id: string;
1068 |
1069 | /**
1070 | * Event-specific data
1071 | */
1072 | data: DisputeWonWebhookEvent.Data;
1073 |
1074 | /**
1075 | * The timestamp of when the event occurred
1076 | */
1077 | timestamp: string;
1078 |
1079 | /**
1080 | * The event type
1081 | */
1082 | type: 'dispute.won';
1083 | }
1084 |
1085 | export namespace DisputeWonWebhookEvent {
1086 | /**
1087 | * Event-specific data
1088 | */
1089 | export interface Data extends DisputesAPI.Dispute {
1090 | /**
1091 | * The type of payload in the data field
1092 | */
1093 | payload_type?: 'Dispute';
1094 | }
1095 | }
1096 |
1097 | export interface LicenseKeyCreatedWebhookEvent {
1098 | /**
1099 | * The business identifier
1100 | */
1101 | business_id: string;
1102 |
1103 | /**
1104 | * Event-specific data
1105 | */
1106 | data: LicenseKeyCreatedWebhookEvent.Data;
1107 |
1108 | /**
1109 | * The timestamp of when the event occurred
1110 | */
1111 | timestamp: string;
1112 |
1113 | /**
1114 | * The event type
1115 | */
1116 | type: 'license_key.created';
1117 | }
1118 |
1119 | export namespace LicenseKeyCreatedWebhookEvent {
1120 | /**
1121 | * Event-specific data
1122 | */
1123 | export interface Data extends LicenseKeysAPI.LicenseKey {
1124 | /**
1125 | * The type of payload in the data field
1126 | */
1127 | payload_type?: 'LicenseKey';
1128 | }
1129 | }
1130 |
1131 | export interface PaymentCancelledWebhookEvent {
1132 | /**
1133 | * The business identifier
1134 | */
1135 | business_id: string;
1136 |
1137 | /**
1138 | * Event-specific data
1139 | */
1140 | data: PaymentCancelledWebhookEvent.Data;
1141 |
1142 | /**
1143 | * The timestamp of when the event occurred
1144 | */
1145 | timestamp: string;
1146 |
1147 | /**
1148 | * The event type
1149 | */
1150 | type: 'payment.cancelled';
1151 | }
1152 |
1153 | export namespace PaymentCancelledWebhookEvent {
1154 | /**
1155 | * Event-specific data
1156 | */
1157 | export interface Data extends PaymentsAPI.Payment {
1158 | /**
1159 | * The type of payload in the data field
1160 | */
1161 | payload_type?: 'Payment';
1162 | }
1163 | }
1164 |
1165 | export interface PaymentFailedWebhookEvent {
1166 | /**
1167 | * The business identifier
1168 | */
1169 | business_id: string;
1170 |
1171 | /**
1172 | * Event-specific data
1173 | */
1174 | data: PaymentFailedWebhookEvent.Data;
1175 |
1176 | /**
1177 | * The timestamp of when the event occurred
1178 | */
1179 | timestamp: string;
1180 |
1181 | /**
1182 | * The event type
1183 | */
1184 | type: 'payment.failed';
1185 | }
1186 |
1187 | export namespace PaymentFailedWebhookEvent {
1188 | /**
1189 | * Event-specific data
1190 | */
1191 | export interface Data extends PaymentsAPI.Payment {
1192 | /**
1193 | * The type of payload in the data field
1194 | */
1195 | payload_type?: 'Payment';
1196 | }
1197 | }
1198 |
1199 | export interface PaymentProcessingWebhookEvent {
1200 | /**
1201 | * The business identifier
1202 | */
1203 | business_id: string;
1204 |
1205 | /**
1206 | * Event-specific data
1207 | */
1208 | data: PaymentProcessingWebhookEvent.Data;
1209 |
1210 | /**
1211 | * The timestamp of when the event occurred
1212 | */
1213 | timestamp: string;
1214 |
1215 | /**
1216 | * The event type
1217 | */
1218 | type: 'payment.processing';
1219 | }
1220 |
1221 | export namespace PaymentProcessingWebhookEvent {
1222 | /**
1223 | * Event-specific data
1224 | */
1225 | export interface Data extends PaymentsAPI.Payment {
1226 | /**
1227 | * The type of payload in the data field
1228 | */
1229 | payload_type?: 'Payment';
1230 | }
1231 | }
1232 |
1233 | export interface PaymentSucceededWebhookEvent {
1234 | /**
1235 | * The business identifier
1236 | */
1237 | business_id: string;
1238 |
1239 | /**
1240 | * Event-specific data
1241 | */
1242 | data: PaymentSucceededWebhookEvent.Data;
1243 |
1244 | /**
1245 | * The timestamp of when the event occurred
1246 | */
1247 | timestamp: string;
1248 |
1249 | /**
1250 | * The event type
1251 | */
1252 | type: 'payment.succeeded';
1253 | }
1254 |
1255 | export namespace PaymentSucceededWebhookEvent {
1256 | /**
1257 | * Event-specific data
1258 | */
1259 | export interface Data extends PaymentsAPI.Payment {
1260 | /**
1261 | * The type of payload in the data field
1262 | */
1263 | payload_type?: 'Payment';
1264 | }
1265 | }
1266 |
1267 | export interface RefundFailedWebhookEvent {
1268 | /**
1269 | * The business identifier
1270 | */
1271 | business_id: string;
1272 |
1273 | /**
1274 | * Event-specific data
1275 | */
1276 | data: RefundFailedWebhookEvent.Data;
1277 |
1278 | /**
1279 | * The timestamp of when the event occurred
1280 | */
1281 | timestamp: string;
1282 |
1283 | /**
1284 | * The event type
1285 | */
1286 | type: 'refund.failed';
1287 | }
1288 |
1289 | export namespace RefundFailedWebhookEvent {
1290 | /**
1291 | * Event-specific data
1292 | */
1293 | export interface Data extends RefundsAPI.Refund {
1294 | /**
1295 | * The type of payload in the data field
1296 | */
1297 | payload_type?: 'Refund';
1298 | }
1299 | }
1300 |
1301 | export interface RefundSucceededWebhookEvent {
1302 | /**
1303 | * The business identifier
1304 | */
1305 | business_id: string;
1306 |
1307 | /**
1308 | * Event-specific data
1309 | */
1310 | data: RefundSucceededWebhookEvent.Data;
1311 |
1312 | /**
1313 | * The timestamp of when the event occurred
1314 | */
1315 | timestamp: string;
1316 |
1317 | /**
1318 | * The event type
1319 | */
1320 | type: 'refund.succeeded';
1321 | }
1322 |
1323 | export namespace RefundSucceededWebhookEvent {
1324 | /**
1325 | * Event-specific data
1326 | */
1327 | export interface Data extends RefundsAPI.Refund {
1328 | /**
1329 | * The type of payload in the data field
1330 | */
1331 | payload_type?: 'Refund';
1332 | }
1333 | }
1334 |
1335 | export interface SubscriptionActiveWebhookEvent {
1336 | /**
1337 | * The business identifier
1338 | */
1339 | business_id: string;
1340 |
1341 | /**
1342 | * Event-specific data
1343 | */
1344 | data: SubscriptionActiveWebhookEvent.Data;
1345 |
1346 | /**
1347 | * The timestamp of when the event occurred
1348 | */
1349 | timestamp: string;
1350 |
1351 | /**
1352 | * The event type
1353 | */
1354 | type: 'subscription.active';
1355 | }
1356 |
1357 | export namespace SubscriptionActiveWebhookEvent {
1358 | /**
1359 | * Event-specific data
1360 | */
1361 | export interface Data extends SubscriptionsAPI.Subscription {
1362 | /**
1363 | * The type of payload in the data field
1364 | */
1365 | payload_type?: 'Subscription';
1366 | }
1367 | }
1368 |
1369 | export interface SubscriptionCancelledWebhookEvent {
1370 | /**
1371 | * The business identifier
1372 | */
1373 | business_id: string;
1374 |
1375 | /**
1376 | * Event-specific data
1377 | */
1378 | data: SubscriptionCancelledWebhookEvent.Data;
1379 |
1380 | /**
1381 | * The timestamp of when the event occurred
1382 | */
1383 | timestamp: string;
1384 |
1385 | /**
1386 | * The event type
1387 | */
1388 | type: 'subscription.cancelled';
1389 | }
1390 |
1391 | export namespace SubscriptionCancelledWebhookEvent {
1392 | /**
1393 | * Event-specific data
1394 | */
1395 | export interface Data extends SubscriptionsAPI.Subscription {
1396 | /**
1397 | * The type of payload in the data field
1398 | */
1399 | payload_type?: 'Subscription';
1400 | }
1401 | }
1402 |
1403 | export interface SubscriptionExpiredWebhookEvent {
1404 | /**
1405 | * The business identifier
1406 | */
1407 | business_id: string;
1408 |
1409 | /**
1410 | * Event-specific data
1411 | */
1412 | data: SubscriptionExpiredWebhookEvent.Data;
1413 |
1414 | /**
1415 | * The timestamp of when the event occurred
1416 | */
1417 | timestamp: string;
1418 |
1419 | /**
1420 | * The event type
1421 | */
1422 | type: 'subscription.expired';
1423 | }
1424 |
1425 | export namespace SubscriptionExpiredWebhookEvent {
1426 | /**
1427 | * Event-specific data
1428 | */
1429 | export interface Data extends SubscriptionsAPI.Subscription {
1430 | /**
1431 | * The type of payload in the data field
1432 | */
1433 | payload_type?: 'Subscription';
1434 | }
1435 | }
1436 |
1437 | export interface SubscriptionFailedWebhookEvent {
1438 | /**
1439 | * The business identifier
1440 | */
1441 | business_id: string;
1442 |
1443 | /**
1444 | * Event-specific data
1445 | */
1446 | data: SubscriptionFailedWebhookEvent.Data;
1447 |
1448 | /**
1449 | * The timestamp of when the event occurred
1450 | */
1451 | timestamp: string;
1452 |
1453 | /**
1454 | * The event type
1455 | */
1456 | type: 'subscription.failed';
1457 | }
1458 |
1459 | export namespace SubscriptionFailedWebhookEvent {
1460 | /**
1461 | * Event-specific data
1462 | */
1463 | export interface Data extends SubscriptionsAPI.Subscription {
1464 | /**
1465 | * The type of payload in the data field
1466 | */
1467 | payload_type?: 'Subscription';
1468 | }
1469 | }
1470 |
1471 | export interface SubscriptionOnHoldWebhookEvent {
1472 | /**
1473 | * The business identifier
1474 | */
1475 | business_id: string;
1476 |
1477 | /**
1478 | * Event-specific data
1479 | */
1480 | data: SubscriptionOnHoldWebhookEvent.Data;
1481 |
1482 | /**
1483 | * The timestamp of when the event occurred
1484 | */
1485 | timestamp: string;
1486 |
1487 | /**
1488 | * The event type
1489 | */
1490 | type: 'subscription.on_hold';
1491 | }
1492 |
1493 | export namespace SubscriptionOnHoldWebhookEvent {
1494 | /**
1495 | * Event-specific data
1496 | */
1497 | export interface Data extends SubscriptionsAPI.Subscription {
1498 | /**
1499 | * The type of payload in the data field
1500 | */
1501 | payload_type?: 'Subscription';
1502 | }
1503 | }
1504 |
1505 | export interface SubscriptionPlanChangedWebhookEvent {
1506 | /**
1507 | * The business identifier
1508 | */
1509 | business_id: string;
1510 |
1511 | /**
1512 | * Event-specific data
1513 | */
1514 | data: SubscriptionPlanChangedWebhookEvent.Data;
1515 |
1516 | /**
1517 | * The timestamp of when the event occurred
1518 | */
1519 | timestamp: string;
1520 |
1521 | /**
1522 | * The event type
1523 | */
1524 | type: 'subscription.plan_changed';
1525 | }
1526 |
1527 | export namespace SubscriptionPlanChangedWebhookEvent {
1528 | /**
1529 | * Event-specific data
1530 | */
1531 | export interface Data extends SubscriptionsAPI.Subscription {
1532 | /**
1533 | * The type of payload in the data field
1534 | */
1535 | payload_type?: 'Subscription';
1536 | }
1537 | }
1538 |
1539 | export interface SubscriptionRenewedWebhookEvent {
1540 | /**
1541 | * The business identifier
1542 | */
1543 | business_id: string;
1544 |
1545 | /**
1546 | * Event-specific data
1547 | */
1548 | data: SubscriptionRenewedWebhookEvent.Data;
1549 |
1550 | /**
1551 | * The timestamp of when the event occurred
1552 | */
1553 | timestamp: string;
1554 |
1555 | /**
1556 | * The event type
1557 | */
1558 | type: 'subscription.renewed';
1559 | }
1560 |
1561 | export namespace SubscriptionRenewedWebhookEvent {
1562 | /**
1563 | * Event-specific data
1564 | */
1565 | export interface Data extends SubscriptionsAPI.Subscription {
1566 | /**
1567 | * The type of payload in the data field
1568 | */
1569 | payload_type?: 'Subscription';
1570 | }
1571 | }
1572 |
1573 | export type UnsafeUnwrapWebhookEvent =
1574 | | DisputeAcceptedWebhookEvent
1575 | | DisputeCancelledWebhookEvent
1576 | | DisputeChallengedWebhookEvent
1577 | | DisputeExpiredWebhookEvent
1578 | | DisputeLostWebhookEvent
1579 | | DisputeOpenedWebhookEvent
1580 | | DisputeWonWebhookEvent
1581 | | LicenseKeyCreatedWebhookEvent
1582 | | PaymentCancelledWebhookEvent
1583 | | PaymentFailedWebhookEvent
1584 | | PaymentProcessingWebhookEvent
1585 | | PaymentSucceededWebhookEvent
1586 | | RefundFailedWebhookEvent
1587 | | RefundSucceededWebhookEvent
1588 | | SubscriptionActiveWebhookEvent
1589 | | SubscriptionCancelledWebhookEvent
1590 | | SubscriptionExpiredWebhookEvent
1591 | | SubscriptionFailedWebhookEvent
1592 | | SubscriptionOnHoldWebhookEvent
1593 | | SubscriptionPlanChangedWebhookEvent
1594 | | SubscriptionRenewedWebhookEvent;
1595 |
1596 | export type UnwrapWebhookEvent =
1597 | | DisputeAcceptedWebhookEvent
1598 | | DisputeCancelledWebhookEvent
1599 | | DisputeChallengedWebhookEvent
1600 | | DisputeExpiredWebhookEvent
1601 | | DisputeLostWebhookEvent
1602 | | DisputeOpenedWebhookEvent
1603 | | DisputeWonWebhookEvent
1604 | | LicenseKeyCreatedWebhookEvent
1605 | | PaymentCancelledWebhookEvent
1606 | | PaymentFailedWebhookEvent
1607 | | PaymentProcessingWebhookEvent
1608 | | PaymentSucceededWebhookEvent
1609 | | RefundFailedWebhookEvent
1610 | | RefundSucceededWebhookEvent
1611 | | SubscriptionActiveWebhookEvent
1612 | | SubscriptionCancelledWebhookEvent
1613 | | SubscriptionExpiredWebhookEvent
1614 | | SubscriptionFailedWebhookEvent
1615 | | SubscriptionOnHoldWebhookEvent
1616 | | SubscriptionPlanChangedWebhookEvent
1617 | | SubscriptionRenewedWebhookEvent;
1618 |
1619 | export interface WebhookCreateParams {
1620 | /**
1621 | * Url of the webhook
1622 | */
1623 | url: string;
1624 |
1625 | description?: string | null;
1626 |
1627 | /**
1628 | * Create the webhook in a disabled state.
1629 | *
1630 | * Default is false
1631 | */
1632 | disabled?: boolean | null;
1633 |
1634 | /**
1635 | * Filter events to the webhook.
1636 | *
1637 | * Webhook event will only be sent for events in the list.
1638 | */
1639 | filter_types?: Array<WebhookEventsAPI.WebhookEventType>;
1640 |
1641 | /**
1642 | * Custom headers to be passed
1643 | */
1644 | headers?: { [key: string]: string } | null;
1645 |
1646 | /**
1647 | * The request's idempotency key
1648 | */
1649 | idempotency_key?: string | null;
1650 |
1651 | /**
1652 | * Metadata to be passed to the webhook Defaut is {}
1653 | */
1654 | metadata?: { [key: string]: string } | null;
1655 |
1656 | rate_limit?: number | null;
1657 | }
1658 |
1659 | export interface WebhookUpdateParams {
1660 | /**
1661 | * Description of the webhook
1662 | */
1663 | description?: string | null;
1664 |
1665 | /**
1666 | * To Disable the endpoint, set it to true.
1667 | */
1668 | disabled?: boolean | null;
1669 |
1670 | /**
1671 | * Filter events to the endpoint.
1672 | *
1673 | * Webhook event will only be sent for events in the list.
1674 | */
1675 | filter_types?: Array<WebhookEventsAPI.WebhookEventType> | null;
1676 |
1677 | /**
1678 | * Metadata
1679 | */
1680 | metadata?: { [key: string]: string } | null;
1681 |
1682 | /**
1683 | * Rate limit
1684 | */
1685 | rate_limit?: number | null;
1686 |
1687 | /**
1688 | * Url endpoint
1689 | */
1690 | url?: string | null;
1691 | }
1692 |
1693 | export interface WebhookListParams extends CursorPagePaginationParams {}
1694 |
1695 | Webhooks.Headers = Headers;
1696 |
1697 | export declare namespace Webhooks {
1698 | export {
1699 | type WebhookDetails as WebhookDetails,
1700 | type WebhookRetrieveSecretResponse as WebhookRetrieveSecretResponse,
1701 | type DisputeAcceptedWebhookEvent as DisputeAcceptedWebhookEvent,
1702 | type DisputeCancelledWebhookEvent as DisputeCancelledWebhookEvent,
1703 | type DisputeChallengedWebhookEvent as DisputeChallengedWebhookEvent,
1704 | type DisputeExpiredWebhookEvent as DisputeExpiredWebhookEvent,
1705 | type DisputeLostWebhookEvent as DisputeLostWebhookEvent,
1706 | type DisputeOpenedWebhookEvent as DisputeOpenedWebhookEvent,
1707 | type DisputeWonWebhookEvent as DisputeWonWebhookEvent,
1708 | type LicenseKeyCreatedWebhookEvent as LicenseKeyCreatedWebhookEvent,
1709 | type PaymentCancelledWebhookEvent as PaymentCancelledWebhookEvent,
1710 | type PaymentFailedWebhookEvent as PaymentFailedWebhookEvent,
1711 | type PaymentProcessingWebhookEvent as PaymentProcessingWebhookEvent,
1712 | type PaymentSucceededWebhookEvent as PaymentSucceededWebhookEvent,
1713 | type RefundFailedWebhookEvent as RefundFailedWebhookEvent,
1714 | type RefundSucceededWebhookEvent as RefundSucceededWebhookEvent,
1715 | type SubscriptionActiveWebhookEvent as SubscriptionActiveWebhookEvent,
1716 | type SubscriptionCancelledWebhookEvent as SubscriptionCancelledWebhookEvent,
1717 | type SubscriptionExpiredWebhookEvent as SubscriptionExpiredWebhookEvent,
1718 | type SubscriptionFailedWebhookEvent as SubscriptionFailedWebhookEvent,
1719 | type SubscriptionOnHoldWebhookEvent as SubscriptionOnHoldWebhookEvent,
1720 | type SubscriptionPlanChangedWebhookEvent as SubscriptionPlanChangedWebhookEvent,
1721 | type SubscriptionRenewedWebhookEvent as SubscriptionRenewedWebhookEvent,
1722 | type UnsafeUnwrapWebhookEvent as UnsafeUnwrapWebhookEvent,
1723 | type UnwrapWebhookEvent as UnwrapWebhookEvent,
1724 | type WebhookDetailsCursorPagePagination as WebhookDetailsCursorPagePagination,
1725 | type WebhookCreateParams as WebhookCreateParams,
1726 | type WebhookUpdateParams as WebhookUpdateParams,
1727 | type WebhookListParams as WebhookListParams,
1728 | };
1729 |
1730 | export {
1731 | Headers as Headers,
1732 | type HeaderRetrieveResponse as HeaderRetrieveResponse,
1733 | type HeaderUpdateParams as HeaderUpdateParams,
1734 | };
1735 | }
1736 |
```
--------------------------------------------------------------------------------
/src/client.ts:
--------------------------------------------------------------------------------
```typescript
1 | // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2 |
3 | import type { RequestInit, RequestInfo, BodyInit } from './internal/builtin-types';
4 | import type { HTTPMethod, PromiseOrValue, MergedRequestInit, FinalizedRequestInit } from './internal/types';
5 | import { uuid4 } from './internal/utils/uuid';
6 | import { validatePositiveInteger, isAbsoluteURL, safeJSON } from './internal/utils/values';
7 | import { sleep } from './internal/utils/sleep';
8 | export type { Logger, LogLevel } from './internal/utils/log';
9 | import { castToError, isAbortError } from './internal/errors';
10 | import type { APIResponseProps } from './internal/parse';
11 | import { getPlatformHeaders } from './internal/detect-platform';
12 | import * as Shims from './internal/shims';
13 | import * as Opts from './internal/request-options';
14 | import { VERSION } from './version';
15 | import * as Errors from './core/error';
16 | import * as Pagination from './core/pagination';
17 | import {
18 | AbstractPage,
19 | type CursorPagePaginationParams,
20 | CursorPagePaginationResponse,
21 | type DefaultPageNumberPaginationParams,
22 | DefaultPageNumberPaginationResponse,
23 | } from './core/pagination';
24 | import * as Uploads from './core/uploads';
25 | import * as API from './resources/index';
26 | import { APIPromise } from './core/api-promise';
27 | import {
28 | AddonCreateParams,
29 | AddonListParams,
30 | AddonResponse,
31 | AddonResponsesDefaultPageNumberPagination,
32 | AddonUpdateImagesResponse,
33 | AddonUpdateParams,
34 | Addons,
35 | } from './resources/addons';
36 | import {
37 | Brand,
38 | BrandCreateParams,
39 | BrandListResponse,
40 | BrandUpdateImagesResponse,
41 | BrandUpdateParams,
42 | Brands,
43 | } from './resources/brands';
44 | import {
45 | CheckoutSessionCreateParams,
46 | CheckoutSessionRequest,
47 | CheckoutSessionResponse,
48 | CheckoutSessionStatus,
49 | CheckoutSessions,
50 | } from './resources/checkout-sessions';
51 | import {
52 | Discount,
53 | DiscountCreateParams,
54 | DiscountListParams,
55 | DiscountType,
56 | DiscountUpdateParams,
57 | Discounts,
58 | DiscountsDefaultPageNumberPagination,
59 | } from './resources/discounts';
60 | import {
61 | Dispute,
62 | DisputeListParams,
63 | DisputeListResponse,
64 | DisputeListResponsesDefaultPageNumberPagination,
65 | DisputeStage,
66 | DisputeStatus,
67 | Disputes,
68 | GetDispute,
69 | } from './resources/disputes';
70 | import {
71 | LicenseKeyInstance,
72 | LicenseKeyInstanceListParams,
73 | LicenseKeyInstanceUpdateParams,
74 | LicenseKeyInstances,
75 | LicenseKeyInstancesDefaultPageNumberPagination,
76 | } from './resources/license-key-instances';
77 | import {
78 | LicenseKey,
79 | LicenseKeyListParams,
80 | LicenseKeyStatus,
81 | LicenseKeyUpdateParams,
82 | LicenseKeys,
83 | LicenseKeysDefaultPageNumberPagination,
84 | } from './resources/license-keys';
85 | import {
86 | LicenseActivateParams,
87 | LicenseActivateResponse,
88 | LicenseDeactivateParams,
89 | LicenseValidateParams,
90 | LicenseValidateResponse,
91 | Licenses,
92 | } from './resources/licenses';
93 | import {
94 | Meter,
95 | MeterAggregation,
96 | MeterCreateParams,
97 | MeterFilter,
98 | MeterListParams,
99 | Meters,
100 | MetersDefaultPageNumberPagination,
101 | } from './resources/meters';
102 | import {
103 | CountryCode,
104 | Currency,
105 | Misc,
106 | MiscListSupportedCountriesResponse,
107 | TaxCategory,
108 | } from './resources/misc';
109 | import {
110 | AttachExistingCustomer,
111 | BillingAddress,
112 | CreateNewCustomer,
113 | CustomerLimitedDetails,
114 | CustomerRequest,
115 | IntentStatus,
116 | NewCustomer,
117 | OneTimeProductCartItem,
118 | Payment,
119 | PaymentCreateParams,
120 | PaymentCreateResponse,
121 | PaymentListParams,
122 | PaymentListResponse,
123 | PaymentListResponsesDefaultPageNumberPagination,
124 | PaymentMethodTypes,
125 | PaymentRetrieveLineItemsResponse,
126 | Payments,
127 | } from './resources/payments';
128 | import {
129 | PayoutListParams,
130 | PayoutListResponse,
131 | PayoutListResponsesDefaultPageNumberPagination,
132 | Payouts,
133 | } from './resources/payouts';
134 | import {
135 | Refund,
136 | RefundCreateParams,
137 | RefundListParams,
138 | RefundListResponse,
139 | RefundListResponsesDefaultPageNumberPagination,
140 | RefundStatus,
141 | Refunds,
142 | } from './resources/refunds';
143 | import {
144 | AddonCartResponseItem,
145 | AttachAddon,
146 | OnDemandSubscription,
147 | Subscription,
148 | SubscriptionChangePlanParams,
149 | SubscriptionChargeParams,
150 | SubscriptionChargeResponse,
151 | SubscriptionCreateParams,
152 | SubscriptionCreateResponse,
153 | SubscriptionListParams,
154 | SubscriptionListResponse,
155 | SubscriptionListResponsesDefaultPageNumberPagination,
156 | SubscriptionRetrieveUsageHistoryParams,
157 | SubscriptionRetrieveUsageHistoryResponse,
158 | SubscriptionRetrieveUsageHistoryResponsesDefaultPageNumberPagination,
159 | SubscriptionStatus,
160 | SubscriptionUpdateParams,
161 | Subscriptions,
162 | TimeInterval,
163 | } from './resources/subscriptions';
164 | import {
165 | Event,
166 | EventInput,
167 | EventsDefaultPageNumberPagination,
168 | UsageEventIngestParams,
169 | UsageEventIngestResponse,
170 | UsageEventListParams,
171 | UsageEvents,
172 | } from './resources/usage-events';
173 | import { WebhookEventType, WebhookEvents, WebhookPayload } from './resources/webhook-events';
174 | import {
175 | Customer,
176 | CustomerCreateParams,
177 | CustomerListParams,
178 | CustomerPortalSession,
179 | CustomerUpdateParams,
180 | Customers,
181 | CustomersDefaultPageNumberPagination,
182 | } from './resources/customers/customers';
183 | import { Invoices } from './resources/invoices/invoices';
184 | import {
185 | AddMeterToPrice,
186 | LicenseKeyDuration,
187 | Price,
188 | Product,
189 | ProductCreateParams,
190 | ProductListParams,
191 | ProductListResponse,
192 | ProductListResponsesDefaultPageNumberPagination,
193 | ProductUpdateFilesParams,
194 | ProductUpdateFilesResponse,
195 | ProductUpdateParams,
196 | Products,
197 | } from './resources/products/products';
198 | import {
199 | DisputeAcceptedWebhookEvent,
200 | DisputeCancelledWebhookEvent,
201 | DisputeChallengedWebhookEvent,
202 | DisputeExpiredWebhookEvent,
203 | DisputeLostWebhookEvent,
204 | DisputeOpenedWebhookEvent,
205 | DisputeWonWebhookEvent,
206 | LicenseKeyCreatedWebhookEvent,
207 | PaymentCancelledWebhookEvent,
208 | PaymentFailedWebhookEvent,
209 | PaymentProcessingWebhookEvent,
210 | PaymentSucceededWebhookEvent,
211 | RefundFailedWebhookEvent,
212 | RefundSucceededWebhookEvent,
213 | SubscriptionActiveWebhookEvent,
214 | SubscriptionCancelledWebhookEvent,
215 | SubscriptionExpiredWebhookEvent,
216 | SubscriptionFailedWebhookEvent,
217 | SubscriptionOnHoldWebhookEvent,
218 | SubscriptionPlanChangedWebhookEvent,
219 | SubscriptionRenewedWebhookEvent,
220 | UnsafeUnwrapWebhookEvent,
221 | UnwrapWebhookEvent,
222 | WebhookCreateParams,
223 | WebhookDetails,
224 | WebhookDetailsCursorPagePagination,
225 | WebhookListParams,
226 | WebhookRetrieveSecretResponse,
227 | WebhookUpdateParams,
228 | Webhooks,
229 | } from './resources/webhooks/webhooks';
230 | import { type Fetch } from './internal/builtin-types';
231 | import { HeadersLike, NullableHeaders, buildHeaders } from './internal/headers';
232 | import { FinalRequestOptions, RequestOptions } from './internal/request-options';
233 | import { readEnv } from './internal/utils/env';
234 | import {
235 | type LogLevel,
236 | type Logger,
237 | formatRequestDetails,
238 | loggerFor,
239 | parseLogLevel,
240 | } from './internal/utils/log';
241 | import { isEmptyObj } from './internal/utils/values';
242 |
243 | const environments = {
244 | live_mode: 'https://live.dodopayments.com',
245 | test_mode: 'https://test.dodopayments.com',
246 | };
247 | type Environment = keyof typeof environments;
248 |
249 | export interface ClientOptions {
250 | /**
251 | * Bearer Token for API authentication
252 | */
253 | bearerToken?: string | undefined;
254 |
255 | /**
256 | * Defaults to process.env['DODO_PAYMENTS_WEBHOOK_KEY'].
257 | */
258 | webhookKey?: string | null | undefined;
259 |
260 | /**
261 | * Specifies the environment to use for the API.
262 | *
263 | * Each environment maps to a different base URL:
264 | * - `live_mode` corresponds to `https://live.dodopayments.com`
265 | * - `test_mode` corresponds to `https://test.dodopayments.com`
266 | */
267 | environment?: Environment | undefined;
268 |
269 | /**
270 | * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
271 | *
272 | * Defaults to process.env['DODO_PAYMENTS_BASE_URL'].
273 | */
274 | baseURL?: string | null | undefined;
275 |
276 | /**
277 | * The maximum amount of time (in milliseconds) that the client should wait for a response
278 | * from the server before timing out a single request.
279 | *
280 | * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
281 | * much longer than this timeout before the promise succeeds or fails.
282 | *
283 | * @unit milliseconds
284 | */
285 | timeout?: number | undefined;
286 | /**
287 | * Additional `RequestInit` options to be passed to `fetch` calls.
288 | * Properties will be overridden by per-request `fetchOptions`.
289 | */
290 | fetchOptions?: MergedRequestInit | undefined;
291 |
292 | /**
293 | * Specify a custom `fetch` function implementation.
294 | *
295 | * If not provided, we expect that `fetch` is defined globally.
296 | */
297 | fetch?: Fetch | undefined;
298 |
299 | /**
300 | * The maximum number of times that the client will retry a request in case of a
301 | * temporary failure, like a network error or a 5XX error from the server.
302 | *
303 | * @default 2
304 | */
305 | maxRetries?: number | undefined;
306 |
307 | /**
308 | * Default headers to include with every request to the API.
309 | *
310 | * These can be removed in individual requests by explicitly setting the
311 | * header to `null` in request options.
312 | */
313 | defaultHeaders?: HeadersLike | undefined;
314 |
315 | /**
316 | * Default query parameters to include with every request to the API.
317 | *
318 | * These can be removed in individual requests by explicitly setting the
319 | * param to `undefined` in request options.
320 | */
321 | defaultQuery?: Record<string, string | undefined> | undefined;
322 |
323 | /**
324 | * Set the log level.
325 | *
326 | * Defaults to process.env['DODO_PAYMENTS_LOG'] or 'warn' if it isn't set.
327 | */
328 | logLevel?: LogLevel | undefined;
329 |
330 | /**
331 | * Set the logger.
332 | *
333 | * Defaults to globalThis.console.
334 | */
335 | logger?: Logger | undefined;
336 | }
337 |
338 | /**
339 | * API Client for interfacing with the Dodo Payments API.
340 | */
341 | export class DodoPayments {
342 | bearerToken: string;
343 | webhookKey: string | null;
344 |
345 | baseURL: string;
346 | maxRetries: number;
347 | timeout: number;
348 | logger: Logger | undefined;
349 | logLevel: LogLevel | undefined;
350 | fetchOptions: MergedRequestInit | undefined;
351 |
352 | private fetch: Fetch;
353 | #encoder: Opts.RequestEncoder;
354 | protected idempotencyHeader?: string;
355 | private _options: ClientOptions;
356 |
357 | /**
358 | * API Client for interfacing with the Dodo Payments API.
359 | *
360 | * @param {string | undefined} [opts.bearerToken=process.env['DODO_PAYMENTS_API_KEY'] ?? undefined]
361 | * @param {string | null | undefined} [opts.webhookKey=process.env['DODO_PAYMENTS_WEBHOOK_KEY'] ?? null]
362 | * @param {Environment} [opts.environment=live_mode] - Specifies the environment URL to use for the API.
363 | * @param {string} [opts.baseURL=process.env['DODO_PAYMENTS_BASE_URL'] ?? https://live.dodopayments.com] - Override the default base URL for the API.
364 | * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
365 | * @param {MergedRequestInit} [opts.fetchOptions] - Additional `RequestInit` options to be passed to `fetch` calls.
366 | * @param {Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
367 | * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
368 | * @param {HeadersLike} opts.defaultHeaders - Default headers to include with every request to the API.
369 | * @param {Record<string, string | undefined>} opts.defaultQuery - Default query parameters to include with every request to the API.
370 | */
371 | constructor({
372 | baseURL = readEnv('DODO_PAYMENTS_BASE_URL'),
373 | bearerToken = readEnv('DODO_PAYMENTS_API_KEY'),
374 | webhookKey = readEnv('DODO_PAYMENTS_WEBHOOK_KEY') ?? null,
375 | ...opts
376 | }: ClientOptions = {}) {
377 | if (bearerToken === undefined) {
378 | throw new Errors.DodoPaymentsError(
379 | "The DODO_PAYMENTS_API_KEY environment variable is missing or empty; either provide it, or instantiate the DodoPayments client with an bearerToken option, like new DodoPayments({ bearerToken: 'My Bearer Token' }).",
380 | );
381 | }
382 |
383 | const options: ClientOptions = {
384 | bearerToken,
385 | webhookKey,
386 | ...opts,
387 | baseURL,
388 | environment: opts.environment ?? 'live_mode',
389 | };
390 |
391 | if (baseURL && opts.environment) {
392 | throw new Errors.DodoPaymentsError(
393 | 'Ambiguous URL; The `baseURL` option (or DODO_PAYMENTS_BASE_URL env var) and the `environment` option are given. If you want to use the environment you must pass baseURL: null',
394 | );
395 | }
396 |
397 | this.baseURL = options.baseURL || environments[options.environment || 'live_mode'];
398 | this.timeout = options.timeout ?? DodoPayments.DEFAULT_TIMEOUT /* 1 minute */;
399 | this.logger = options.logger ?? console;
400 | const defaultLogLevel = 'warn';
401 | // Set default logLevel early so that we can log a warning in parseLogLevel.
402 | this.logLevel = defaultLogLevel;
403 | this.logLevel =
404 | parseLogLevel(options.logLevel, 'ClientOptions.logLevel', this) ??
405 | parseLogLevel(readEnv('DODO_PAYMENTS_LOG'), "process.env['DODO_PAYMENTS_LOG']", this) ??
406 | defaultLogLevel;
407 | this.fetchOptions = options.fetchOptions;
408 | this.maxRetries = options.maxRetries ?? 2;
409 | this.fetch = options.fetch ?? Shims.getDefaultFetch();
410 | this.#encoder = Opts.FallbackEncoder;
411 |
412 | this._options = options;
413 |
414 | this.bearerToken = bearerToken;
415 | this.webhookKey = webhookKey;
416 | }
417 |
418 | /**
419 | * Create a new client instance re-using the same options given to the current client with optional overriding.
420 | */
421 | withOptions(options: Partial<ClientOptions>): this {
422 | const client = new (this.constructor as any as new (props: ClientOptions) => typeof this)({
423 | ...this._options,
424 | environment: options.environment ? options.environment : undefined,
425 | baseURL: options.environment ? undefined : this.baseURL,
426 | maxRetries: this.maxRetries,
427 | timeout: this.timeout,
428 | logger: this.logger,
429 | logLevel: this.logLevel,
430 | fetch: this.fetch,
431 | fetchOptions: this.fetchOptions,
432 | bearerToken: this.bearerToken,
433 | webhookKey: this.webhookKey,
434 | ...options,
435 | });
436 | return client;
437 | }
438 |
439 | /**
440 | * Check whether the base URL is set to its default.
441 | */
442 | #baseURLOverridden(): boolean {
443 | return this.baseURL !== environments[this._options.environment || 'live_mode'];
444 | }
445 |
446 | protected defaultQuery(): Record<string, string | undefined> | undefined {
447 | return this._options.defaultQuery;
448 | }
449 |
450 | protected validateHeaders({ values, nulls }: NullableHeaders) {
451 | return;
452 | }
453 |
454 | protected async authHeaders(opts: FinalRequestOptions): Promise<NullableHeaders | undefined> {
455 | return buildHeaders([{ Authorization: `Bearer ${this.bearerToken}` }]);
456 | }
457 |
458 | /**
459 | * Basic re-implementation of `qs.stringify` for primitive types.
460 | */
461 | protected stringifyQuery(query: Record<string, unknown>): string {
462 | return Object.entries(query)
463 | .filter(([_, value]) => typeof value !== 'undefined')
464 | .map(([key, value]) => {
465 | if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
466 | return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
467 | }
468 | if (value === null) {
469 | return `${encodeURIComponent(key)}=`;
470 | }
471 | throw new Errors.DodoPaymentsError(
472 | `Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
473 | );
474 | })
475 | .join('&');
476 | }
477 |
478 | private getUserAgent(): string {
479 | return `${this.constructor.name}/JS ${VERSION}`;
480 | }
481 |
482 | protected defaultIdempotencyKey(): string {
483 | return `stainless-node-retry-${uuid4()}`;
484 | }
485 |
486 | protected makeStatusError(
487 | status: number,
488 | error: Object,
489 | message: string | undefined,
490 | headers: Headers,
491 | ): Errors.APIError {
492 | return Errors.APIError.generate(status, error, message, headers);
493 | }
494 |
495 | buildURL(
496 | path: string,
497 | query: Record<string, unknown> | null | undefined,
498 | defaultBaseURL?: string | undefined,
499 | ): string {
500 | const baseURL = (!this.#baseURLOverridden() && defaultBaseURL) || this.baseURL;
501 | const url =
502 | isAbsoluteURL(path) ?
503 | new URL(path)
504 | : new URL(baseURL + (baseURL.endsWith('/') && path.startsWith('/') ? path.slice(1) : path));
505 |
506 | const defaultQuery = this.defaultQuery();
507 | if (!isEmptyObj(defaultQuery)) {
508 | query = { ...defaultQuery, ...query };
509 | }
510 |
511 | if (typeof query === 'object' && query && !Array.isArray(query)) {
512 | url.search = this.stringifyQuery(query as Record<string, unknown>);
513 | }
514 |
515 | return url.toString();
516 | }
517 |
518 | /**
519 | * Used as a callback for mutating the given `FinalRequestOptions` object.
520 | */
521 | protected async prepareOptions(options: FinalRequestOptions): Promise<void> {}
522 |
523 | /**
524 | * Used as a callback for mutating the given `RequestInit` object.
525 | *
526 | * This is useful for cases where you want to add certain headers based off of
527 | * the request properties, e.g. `method` or `url`.
528 | */
529 | protected async prepareRequest(
530 | request: RequestInit,
531 | { url, options }: { url: string; options: FinalRequestOptions },
532 | ): Promise<void> {}
533 |
534 | get<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
535 | return this.methodRequest('get', path, opts);
536 | }
537 |
538 | post<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
539 | return this.methodRequest('post', path, opts);
540 | }
541 |
542 | patch<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
543 | return this.methodRequest('patch', path, opts);
544 | }
545 |
546 | put<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
547 | return this.methodRequest('put', path, opts);
548 | }
549 |
550 | delete<Rsp>(path: string, opts?: PromiseOrValue<RequestOptions>): APIPromise<Rsp> {
551 | return this.methodRequest('delete', path, opts);
552 | }
553 |
554 | private methodRequest<Rsp>(
555 | method: HTTPMethod,
556 | path: string,
557 | opts?: PromiseOrValue<RequestOptions>,
558 | ): APIPromise<Rsp> {
559 | return this.request(
560 | Promise.resolve(opts).then((opts) => {
561 | return { method, path, ...opts };
562 | }),
563 | );
564 | }
565 |
566 | request<Rsp>(
567 | options: PromiseOrValue<FinalRequestOptions>,
568 | remainingRetries: number | null = null,
569 | ): APIPromise<Rsp> {
570 | return new APIPromise(this, this.makeRequest(options, remainingRetries, undefined));
571 | }
572 |
573 | private async makeRequest(
574 | optionsInput: PromiseOrValue<FinalRequestOptions>,
575 | retriesRemaining: number | null,
576 | retryOfRequestLogID: string | undefined,
577 | ): Promise<APIResponseProps> {
578 | const options = await optionsInput;
579 | const maxRetries = options.maxRetries ?? this.maxRetries;
580 | if (retriesRemaining == null) {
581 | retriesRemaining = maxRetries;
582 | }
583 |
584 | await this.prepareOptions(options);
585 |
586 | const { req, url, timeout } = await this.buildRequest(options, {
587 | retryCount: maxRetries - retriesRemaining,
588 | });
589 |
590 | await this.prepareRequest(req, { url, options });
591 |
592 | /** Not an API request ID, just for correlating local log entries. */
593 | const requestLogID = 'log_' + ((Math.random() * (1 << 24)) | 0).toString(16).padStart(6, '0');
594 | const retryLogStr = retryOfRequestLogID === undefined ? '' : `, retryOf: ${retryOfRequestLogID}`;
595 | const startTime = Date.now();
596 |
597 | loggerFor(this).debug(
598 | `[${requestLogID}] sending request`,
599 | formatRequestDetails({
600 | retryOfRequestLogID,
601 | method: options.method,
602 | url,
603 | options,
604 | headers: req.headers,
605 | }),
606 | );
607 |
608 | if (options.signal?.aborted) {
609 | throw new Errors.APIUserAbortError();
610 | }
611 |
612 | const controller = new AbortController();
613 | const response = await this.fetchWithTimeout(url, req, timeout, controller).catch(castToError);
614 | const headersTime = Date.now();
615 |
616 | if (response instanceof globalThis.Error) {
617 | const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
618 | if (options.signal?.aborted) {
619 | throw new Errors.APIUserAbortError();
620 | }
621 | // detect native connection timeout errors
622 | // deno throws "TypeError: error sending request for url (https://example/): client error (Connect): tcp connect error: Operation timed out (os error 60): Operation timed out (os error 60)"
623 | // undici throws "TypeError: fetch failed" with cause "ConnectTimeoutError: Connect Timeout Error (attempted address: example:443, timeout: 1ms)"
624 | // others do not provide enough information to distinguish timeouts from other connection errors
625 | const isTimeout =
626 | isAbortError(response) ||
627 | /timed? ?out/i.test(String(response) + ('cause' in response ? String(response.cause) : ''));
628 | if (retriesRemaining) {
629 | loggerFor(this).info(
630 | `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - ${retryMessage}`,
631 | );
632 | loggerFor(this).debug(
633 | `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (${retryMessage})`,
634 | formatRequestDetails({
635 | retryOfRequestLogID,
636 | url,
637 | durationMs: headersTime - startTime,
638 | message: response.message,
639 | }),
640 | );
641 | return this.retryRequest(options, retriesRemaining, retryOfRequestLogID ?? requestLogID);
642 | }
643 | loggerFor(this).info(
644 | `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} - error; no more retries left`,
645 | );
646 | loggerFor(this).debug(
647 | `[${requestLogID}] connection ${isTimeout ? 'timed out' : 'failed'} (error; no more retries left)`,
648 | formatRequestDetails({
649 | retryOfRequestLogID,
650 | url,
651 | durationMs: headersTime - startTime,
652 | message: response.message,
653 | }),
654 | );
655 | if (isTimeout) {
656 | throw new Errors.APIConnectionTimeoutError();
657 | }
658 | throw new Errors.APIConnectionError({ cause: response });
659 | }
660 |
661 | const responseInfo = `[${requestLogID}${retryLogStr}] ${req.method} ${url} ${
662 | response.ok ? 'succeeded' : 'failed'
663 | } with status ${response.status} in ${headersTime - startTime}ms`;
664 |
665 | if (!response.ok) {
666 | const shouldRetry = await this.shouldRetry(response);
667 | if (retriesRemaining && shouldRetry) {
668 | const retryMessage = `retrying, ${retriesRemaining} attempts remaining`;
669 |
670 | // We don't need the body of this response.
671 | await Shims.CancelReadableStream(response.body);
672 | loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
673 | loggerFor(this).debug(
674 | `[${requestLogID}] response error (${retryMessage})`,
675 | formatRequestDetails({
676 | retryOfRequestLogID,
677 | url: response.url,
678 | status: response.status,
679 | headers: response.headers,
680 | durationMs: headersTime - startTime,
681 | }),
682 | );
683 | return this.retryRequest(
684 | options,
685 | retriesRemaining,
686 | retryOfRequestLogID ?? requestLogID,
687 | response.headers,
688 | );
689 | }
690 |
691 | const retryMessage = shouldRetry ? `error; no more retries left` : `error; not retryable`;
692 |
693 | loggerFor(this).info(`${responseInfo} - ${retryMessage}`);
694 |
695 | const errText = await response.text().catch((err: any) => castToError(err).message);
696 | const errJSON = safeJSON(errText);
697 | const errMessage = errJSON ? undefined : errText;
698 |
699 | loggerFor(this).debug(
700 | `[${requestLogID}] response error (${retryMessage})`,
701 | formatRequestDetails({
702 | retryOfRequestLogID,
703 | url: response.url,
704 | status: response.status,
705 | headers: response.headers,
706 | message: errMessage,
707 | durationMs: Date.now() - startTime,
708 | }),
709 | );
710 |
711 | const err = this.makeStatusError(response.status, errJSON, errMessage, response.headers);
712 | throw err;
713 | }
714 |
715 | loggerFor(this).info(responseInfo);
716 | loggerFor(this).debug(
717 | `[${requestLogID}] response start`,
718 | formatRequestDetails({
719 | retryOfRequestLogID,
720 | url: response.url,
721 | status: response.status,
722 | headers: response.headers,
723 | durationMs: headersTime - startTime,
724 | }),
725 | );
726 |
727 | return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
728 | }
729 |
730 | getAPIList<Item, PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>>(
731 | path: string,
732 | Page: new (...args: any[]) => PageClass,
733 | opts?: RequestOptions,
734 | ): Pagination.PagePromise<PageClass, Item> {
735 | return this.requestAPIList(Page, { method: 'get', path, ...opts });
736 | }
737 |
738 | requestAPIList<
739 | Item = unknown,
740 | PageClass extends Pagination.AbstractPage<Item> = Pagination.AbstractPage<Item>,
741 | >(
742 | Page: new (...args: ConstructorParameters<typeof Pagination.AbstractPage>) => PageClass,
743 | options: FinalRequestOptions,
744 | ): Pagination.PagePromise<PageClass, Item> {
745 | const request = this.makeRequest(options, null, undefined);
746 | return new Pagination.PagePromise<PageClass, Item>(this as any as DodoPayments, request, Page);
747 | }
748 |
749 | async fetchWithTimeout(
750 | url: RequestInfo,
751 | init: RequestInit | undefined,
752 | ms: number,
753 | controller: AbortController,
754 | ): Promise<Response> {
755 | const { signal, method, ...options } = init || {};
756 | if (signal) signal.addEventListener('abort', () => controller.abort());
757 |
758 | const timeout = setTimeout(() => controller.abort(), ms);
759 |
760 | const isReadableBody =
761 | ((globalThis as any).ReadableStream && options.body instanceof (globalThis as any).ReadableStream) ||
762 | (typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
763 |
764 | const fetchOptions: RequestInit = {
765 | signal: controller.signal as any,
766 | ...(isReadableBody ? { duplex: 'half' } : {}),
767 | method: 'GET',
768 | ...options,
769 | };
770 | if (method) {
771 | // Custom methods like 'patch' need to be uppercased
772 | // See https://github.com/nodejs/undici/issues/2294
773 | fetchOptions.method = method.toUpperCase();
774 | }
775 |
776 | try {
777 | // use undefined this binding; fetch errors if bound to something else in browser/cloudflare
778 | return await this.fetch.call(undefined, url, fetchOptions);
779 | } finally {
780 | clearTimeout(timeout);
781 | }
782 | }
783 |
784 | private async shouldRetry(response: Response): Promise<boolean> {
785 | // Note this is not a standard header.
786 | const shouldRetryHeader = response.headers.get('x-should-retry');
787 |
788 | // If the server explicitly says whether or not to retry, obey.
789 | if (shouldRetryHeader === 'true') return true;
790 | if (shouldRetryHeader === 'false') return false;
791 |
792 | // Retry on request timeouts.
793 | if (response.status === 408) return true;
794 |
795 | // Retry on lock timeouts.
796 | if (response.status === 409) return true;
797 |
798 | // Retry on rate limits.
799 | if (response.status === 429) return true;
800 |
801 | // Retry internal errors.
802 | if (response.status >= 500) return true;
803 |
804 | return false;
805 | }
806 |
807 | private async retryRequest(
808 | options: FinalRequestOptions,
809 | retriesRemaining: number,
810 | requestLogID: string,
811 | responseHeaders?: Headers | undefined,
812 | ): Promise<APIResponseProps> {
813 | let timeoutMillis: number | undefined;
814 |
815 | // Note the `retry-after-ms` header may not be standard, but is a good idea and we'd like proactive support for it.
816 | const retryAfterMillisHeader = responseHeaders?.get('retry-after-ms');
817 | if (retryAfterMillisHeader) {
818 | const timeoutMs = parseFloat(retryAfterMillisHeader);
819 | if (!Number.isNaN(timeoutMs)) {
820 | timeoutMillis = timeoutMs;
821 | }
822 | }
823 |
824 | // About the Retry-After header: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After
825 | const retryAfterHeader = responseHeaders?.get('retry-after');
826 | if (retryAfterHeader && !timeoutMillis) {
827 | const timeoutSeconds = parseFloat(retryAfterHeader);
828 | if (!Number.isNaN(timeoutSeconds)) {
829 | timeoutMillis = timeoutSeconds * 1000;
830 | } else {
831 | timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
832 | }
833 | }
834 |
835 | // If the API asks us to wait a certain amount of time (and it's a reasonable amount),
836 | // just do what it says, but otherwise calculate a default
837 | if (!(timeoutMillis && 0 <= timeoutMillis && timeoutMillis < 60 * 1000)) {
838 | const maxRetries = options.maxRetries ?? this.maxRetries;
839 | timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
840 | }
841 | await sleep(timeoutMillis);
842 |
843 | return this.makeRequest(options, retriesRemaining - 1, requestLogID);
844 | }
845 |
846 | private calculateDefaultRetryTimeoutMillis(retriesRemaining: number, maxRetries: number): number {
847 | const initialRetryDelay = 0.5;
848 | const maxRetryDelay = 8.0;
849 |
850 | const numRetries = maxRetries - retriesRemaining;
851 |
852 | // Apply exponential backoff, but not more than the max.
853 | const sleepSeconds = Math.min(initialRetryDelay * Math.pow(2, numRetries), maxRetryDelay);
854 |
855 | // Apply some jitter, take up to at most 25 percent of the retry time.
856 | const jitter = 1 - Math.random() * 0.25;
857 |
858 | return sleepSeconds * jitter * 1000;
859 | }
860 |
861 | async buildRequest(
862 | inputOptions: FinalRequestOptions,
863 | { retryCount = 0 }: { retryCount?: number } = {},
864 | ): Promise<{ req: FinalizedRequestInit; url: string; timeout: number }> {
865 | const options = { ...inputOptions };
866 | const { method, path, query, defaultBaseURL } = options;
867 |
868 | const url = this.buildURL(path!, query as Record<string, unknown>, defaultBaseURL);
869 | if ('timeout' in options) validatePositiveInteger('timeout', options.timeout);
870 | options.timeout = options.timeout ?? this.timeout;
871 | const { bodyHeaders, body } = this.buildBody({ options });
872 | const reqHeaders = await this.buildHeaders({ options: inputOptions, method, bodyHeaders, retryCount });
873 |
874 | const req: FinalizedRequestInit = {
875 | method,
876 | headers: reqHeaders,
877 | ...(options.signal && { signal: options.signal }),
878 | ...((globalThis as any).ReadableStream &&
879 | body instanceof (globalThis as any).ReadableStream && { duplex: 'half' }),
880 | ...(body && { body }),
881 | ...((this.fetchOptions as any) ?? {}),
882 | ...((options.fetchOptions as any) ?? {}),
883 | };
884 |
885 | return { req, url, timeout: options.timeout };
886 | }
887 |
888 | private async buildHeaders({
889 | options,
890 | method,
891 | bodyHeaders,
892 | retryCount,
893 | }: {
894 | options: FinalRequestOptions;
895 | method: HTTPMethod;
896 | bodyHeaders: HeadersLike;
897 | retryCount: number;
898 | }): Promise<Headers> {
899 | let idempotencyHeaders: HeadersLike = {};
900 | if (this.idempotencyHeader && method !== 'get') {
901 | if (!options.idempotencyKey) options.idempotencyKey = this.defaultIdempotencyKey();
902 | idempotencyHeaders[this.idempotencyHeader] = options.idempotencyKey;
903 | }
904 |
905 | const headers = buildHeaders([
906 | idempotencyHeaders,
907 | {
908 | Accept: 'application/json',
909 | 'User-Agent': this.getUserAgent(),
910 | 'X-Stainless-Retry-Count': String(retryCount),
911 | ...(options.timeout ? { 'X-Stainless-Timeout': String(Math.trunc(options.timeout / 1000)) } : {}),
912 | ...getPlatformHeaders(),
913 | },
914 | await this.authHeaders(options),
915 | this._options.defaultHeaders,
916 | bodyHeaders,
917 | options.headers,
918 | ]);
919 |
920 | this.validateHeaders(headers);
921 |
922 | return headers.values;
923 | }
924 |
925 | private buildBody({ options: { body, headers: rawHeaders } }: { options: FinalRequestOptions }): {
926 | bodyHeaders: HeadersLike;
927 | body: BodyInit | undefined;
928 | } {
929 | if (!body) {
930 | return { bodyHeaders: undefined, body: undefined };
931 | }
932 | const headers = buildHeaders([rawHeaders]);
933 | if (
934 | // Pass raw type verbatim
935 | ArrayBuffer.isView(body) ||
936 | body instanceof ArrayBuffer ||
937 | body instanceof DataView ||
938 | (typeof body === 'string' &&
939 | // Preserve legacy string encoding behavior for now
940 | headers.values.has('content-type')) ||
941 | // `Blob` is superset of `File`
942 | ((globalThis as any).Blob && body instanceof (globalThis as any).Blob) ||
943 | // `FormData` -> `multipart/form-data`
944 | body instanceof FormData ||
945 | // `URLSearchParams` -> `application/x-www-form-urlencoded`
946 | body instanceof URLSearchParams ||
947 | // Send chunked stream (each chunk has own `length`)
948 | ((globalThis as any).ReadableStream && body instanceof (globalThis as any).ReadableStream)
949 | ) {
950 | return { bodyHeaders: undefined, body: body as BodyInit };
951 | } else if (
952 | typeof body === 'object' &&
953 | (Symbol.asyncIterator in body ||
954 | (Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))
955 | ) {
956 | return { bodyHeaders: undefined, body: Shims.ReadableStreamFrom(body as AsyncIterable<Uint8Array>) };
957 | } else {
958 | return this.#encoder({ body, headers });
959 | }
960 | }
961 |
962 | static DodoPayments = this;
963 | static DEFAULT_TIMEOUT = 60000; // 1 minute
964 |
965 | static DodoPaymentsError = Errors.DodoPaymentsError;
966 | static APIError = Errors.APIError;
967 | static APIConnectionError = Errors.APIConnectionError;
968 | static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
969 | static APIUserAbortError = Errors.APIUserAbortError;
970 | static NotFoundError = Errors.NotFoundError;
971 | static ConflictError = Errors.ConflictError;
972 | static RateLimitError = Errors.RateLimitError;
973 | static BadRequestError = Errors.BadRequestError;
974 | static AuthenticationError = Errors.AuthenticationError;
975 | static InternalServerError = Errors.InternalServerError;
976 | static PermissionDeniedError = Errors.PermissionDeniedError;
977 | static UnprocessableEntityError = Errors.UnprocessableEntityError;
978 |
979 | static toFile = Uploads.toFile;
980 |
981 | checkoutSessions: API.CheckoutSessions = new API.CheckoutSessions(this);
982 | payments: API.Payments = new API.Payments(this);
983 | subscriptions: API.Subscriptions = new API.Subscriptions(this);
984 | invoices: API.Invoices = new API.Invoices(this);
985 | licenses: API.Licenses = new API.Licenses(this);
986 | licenseKeys: API.LicenseKeys = new API.LicenseKeys(this);
987 | licenseKeyInstances: API.LicenseKeyInstances = new API.LicenseKeyInstances(this);
988 | customers: API.Customers = new API.Customers(this);
989 | refunds: API.Refunds = new API.Refunds(this);
990 | disputes: API.Disputes = new API.Disputes(this);
991 | payouts: API.Payouts = new API.Payouts(this);
992 | products: API.Products = new API.Products(this);
993 | misc: API.Misc = new API.Misc(this);
994 | discounts: API.Discounts = new API.Discounts(this);
995 | addons: API.Addons = new API.Addons(this);
996 | brands: API.Brands = new API.Brands(this);
997 | webhooks: API.Webhooks = new API.Webhooks(this);
998 | webhookEvents: API.WebhookEvents = new API.WebhookEvents(this);
999 | usageEvents: API.UsageEvents = new API.UsageEvents(this);
1000 | meters: API.Meters = new API.Meters(this);
1001 | }
1002 |
1003 | DodoPayments.CheckoutSessions = CheckoutSessions;
1004 | DodoPayments.Payments = Payments;
1005 | DodoPayments.Subscriptions = Subscriptions;
1006 | DodoPayments.Invoices = Invoices;
1007 | DodoPayments.Licenses = Licenses;
1008 | DodoPayments.LicenseKeys = LicenseKeys;
1009 | DodoPayments.LicenseKeyInstances = LicenseKeyInstances;
1010 | DodoPayments.Customers = Customers;
1011 | DodoPayments.Refunds = Refunds;
1012 | DodoPayments.Disputes = Disputes;
1013 | DodoPayments.Payouts = Payouts;
1014 | DodoPayments.Products = Products;
1015 | DodoPayments.Misc = Misc;
1016 | DodoPayments.Discounts = Discounts;
1017 | DodoPayments.Addons = Addons;
1018 | DodoPayments.Brands = Brands;
1019 | DodoPayments.Webhooks = Webhooks;
1020 | DodoPayments.WebhookEvents = WebhookEvents;
1021 | DodoPayments.UsageEvents = UsageEvents;
1022 | DodoPayments.Meters = Meters;
1023 |
1024 | export declare namespace DodoPayments {
1025 | export type RequestOptions = Opts.RequestOptions;
1026 |
1027 | export import DefaultPageNumberPagination = Pagination.DefaultPageNumberPagination;
1028 | export {
1029 | type DefaultPageNumberPaginationParams as DefaultPageNumberPaginationParams,
1030 | type DefaultPageNumberPaginationResponse as DefaultPageNumberPaginationResponse,
1031 | };
1032 |
1033 | export import CursorPagePagination = Pagination.CursorPagePagination;
1034 | export {
1035 | type CursorPagePaginationParams as CursorPagePaginationParams,
1036 | type CursorPagePaginationResponse as CursorPagePaginationResponse,
1037 | };
1038 |
1039 | export {
1040 | CheckoutSessions as CheckoutSessions,
1041 | type CheckoutSessionRequest as CheckoutSessionRequest,
1042 | type CheckoutSessionResponse as CheckoutSessionResponse,
1043 | type CheckoutSessionStatus as CheckoutSessionStatus,
1044 | type CheckoutSessionCreateParams as CheckoutSessionCreateParams,
1045 | };
1046 |
1047 | export {
1048 | Payments as Payments,
1049 | type AttachExistingCustomer as AttachExistingCustomer,
1050 | type BillingAddress as BillingAddress,
1051 | type CreateNewCustomer as CreateNewCustomer,
1052 | type CustomerLimitedDetails as CustomerLimitedDetails,
1053 | type CustomerRequest as CustomerRequest,
1054 | type IntentStatus as IntentStatus,
1055 | type NewCustomer as NewCustomer,
1056 | type OneTimeProductCartItem as OneTimeProductCartItem,
1057 | type Payment as Payment,
1058 | type PaymentMethodTypes as PaymentMethodTypes,
1059 | type PaymentCreateResponse as PaymentCreateResponse,
1060 | type PaymentListResponse as PaymentListResponse,
1061 | type PaymentRetrieveLineItemsResponse as PaymentRetrieveLineItemsResponse,
1062 | type PaymentListResponsesDefaultPageNumberPagination as PaymentListResponsesDefaultPageNumberPagination,
1063 | type PaymentCreateParams as PaymentCreateParams,
1064 | type PaymentListParams as PaymentListParams,
1065 | };
1066 |
1067 | export {
1068 | Subscriptions as Subscriptions,
1069 | type AddonCartResponseItem as AddonCartResponseItem,
1070 | type AttachAddon as AttachAddon,
1071 | type OnDemandSubscription as OnDemandSubscription,
1072 | type Subscription as Subscription,
1073 | type SubscriptionStatus as SubscriptionStatus,
1074 | type TimeInterval as TimeInterval,
1075 | type SubscriptionCreateResponse as SubscriptionCreateResponse,
1076 | type SubscriptionListResponse as SubscriptionListResponse,
1077 | type SubscriptionChargeResponse as SubscriptionChargeResponse,
1078 | type SubscriptionRetrieveUsageHistoryResponse as SubscriptionRetrieveUsageHistoryResponse,
1079 | type SubscriptionListResponsesDefaultPageNumberPagination as SubscriptionListResponsesDefaultPageNumberPagination,
1080 | type SubscriptionRetrieveUsageHistoryResponsesDefaultPageNumberPagination as SubscriptionRetrieveUsageHistoryResponsesDefaultPageNumberPagination,
1081 | type SubscriptionCreateParams as SubscriptionCreateParams,
1082 | type SubscriptionUpdateParams as SubscriptionUpdateParams,
1083 | type SubscriptionListParams as SubscriptionListParams,
1084 | type SubscriptionChangePlanParams as SubscriptionChangePlanParams,
1085 | type SubscriptionChargeParams as SubscriptionChargeParams,
1086 | type SubscriptionRetrieveUsageHistoryParams as SubscriptionRetrieveUsageHistoryParams,
1087 | };
1088 |
1089 | export { Invoices as Invoices };
1090 |
1091 | export {
1092 | Licenses as Licenses,
1093 | type LicenseActivateResponse as LicenseActivateResponse,
1094 | type LicenseValidateResponse as LicenseValidateResponse,
1095 | type LicenseActivateParams as LicenseActivateParams,
1096 | type LicenseDeactivateParams as LicenseDeactivateParams,
1097 | type LicenseValidateParams as LicenseValidateParams,
1098 | };
1099 |
1100 | export {
1101 | LicenseKeys as LicenseKeys,
1102 | type LicenseKey as LicenseKey,
1103 | type LicenseKeyStatus as LicenseKeyStatus,
1104 | type LicenseKeysDefaultPageNumberPagination as LicenseKeysDefaultPageNumberPagination,
1105 | type LicenseKeyUpdateParams as LicenseKeyUpdateParams,
1106 | type LicenseKeyListParams as LicenseKeyListParams,
1107 | };
1108 |
1109 | export {
1110 | LicenseKeyInstances as LicenseKeyInstances,
1111 | type LicenseKeyInstance as LicenseKeyInstance,
1112 | type LicenseKeyInstancesDefaultPageNumberPagination as LicenseKeyInstancesDefaultPageNumberPagination,
1113 | type LicenseKeyInstanceUpdateParams as LicenseKeyInstanceUpdateParams,
1114 | type LicenseKeyInstanceListParams as LicenseKeyInstanceListParams,
1115 | };
1116 |
1117 | export {
1118 | Customers as Customers,
1119 | type Customer as Customer,
1120 | type CustomerPortalSession as CustomerPortalSession,
1121 | type CustomersDefaultPageNumberPagination as CustomersDefaultPageNumberPagination,
1122 | type CustomerCreateParams as CustomerCreateParams,
1123 | type CustomerUpdateParams as CustomerUpdateParams,
1124 | type CustomerListParams as CustomerListParams,
1125 | };
1126 |
1127 | export {
1128 | Refunds as Refunds,
1129 | type Refund as Refund,
1130 | type RefundStatus as RefundStatus,
1131 | type RefundListResponse as RefundListResponse,
1132 | type RefundListResponsesDefaultPageNumberPagination as RefundListResponsesDefaultPageNumberPagination,
1133 | type RefundCreateParams as RefundCreateParams,
1134 | type RefundListParams as RefundListParams,
1135 | };
1136 |
1137 | export {
1138 | Disputes as Disputes,
1139 | type Dispute as Dispute,
1140 | type DisputeStage as DisputeStage,
1141 | type DisputeStatus as DisputeStatus,
1142 | type GetDispute as GetDispute,
1143 | type DisputeListResponse as DisputeListResponse,
1144 | type DisputeListResponsesDefaultPageNumberPagination as DisputeListResponsesDefaultPageNumberPagination,
1145 | type DisputeListParams as DisputeListParams,
1146 | };
1147 |
1148 | export {
1149 | Payouts as Payouts,
1150 | type PayoutListResponse as PayoutListResponse,
1151 | type PayoutListResponsesDefaultPageNumberPagination as PayoutListResponsesDefaultPageNumberPagination,
1152 | type PayoutListParams as PayoutListParams,
1153 | };
1154 |
1155 | export {
1156 | Products as Products,
1157 | type AddMeterToPrice as AddMeterToPrice,
1158 | type LicenseKeyDuration as LicenseKeyDuration,
1159 | type Price as Price,
1160 | type Product as Product,
1161 | type ProductListResponse as ProductListResponse,
1162 | type ProductUpdateFilesResponse as ProductUpdateFilesResponse,
1163 | type ProductListResponsesDefaultPageNumberPagination as ProductListResponsesDefaultPageNumberPagination,
1164 | type ProductCreateParams as ProductCreateParams,
1165 | type ProductUpdateParams as ProductUpdateParams,
1166 | type ProductListParams as ProductListParams,
1167 | type ProductUpdateFilesParams as ProductUpdateFilesParams,
1168 | };
1169 |
1170 | export {
1171 | Misc as Misc,
1172 | type CountryCode as CountryCode,
1173 | type Currency as Currency,
1174 | type TaxCategory as TaxCategory,
1175 | type MiscListSupportedCountriesResponse as MiscListSupportedCountriesResponse,
1176 | };
1177 |
1178 | export {
1179 | Discounts as Discounts,
1180 | type Discount as Discount,
1181 | type DiscountType as DiscountType,
1182 | type DiscountsDefaultPageNumberPagination as DiscountsDefaultPageNumberPagination,
1183 | type DiscountCreateParams as DiscountCreateParams,
1184 | type DiscountUpdateParams as DiscountUpdateParams,
1185 | type DiscountListParams as DiscountListParams,
1186 | };
1187 |
1188 | export {
1189 | Addons as Addons,
1190 | type AddonResponse as AddonResponse,
1191 | type AddonUpdateImagesResponse as AddonUpdateImagesResponse,
1192 | type AddonResponsesDefaultPageNumberPagination as AddonResponsesDefaultPageNumberPagination,
1193 | type AddonCreateParams as AddonCreateParams,
1194 | type AddonUpdateParams as AddonUpdateParams,
1195 | type AddonListParams as AddonListParams,
1196 | };
1197 |
1198 | export {
1199 | Brands as Brands,
1200 | type Brand as Brand,
1201 | type BrandListResponse as BrandListResponse,
1202 | type BrandUpdateImagesResponse as BrandUpdateImagesResponse,
1203 | type BrandCreateParams as BrandCreateParams,
1204 | type BrandUpdateParams as BrandUpdateParams,
1205 | };
1206 |
1207 | export {
1208 | Webhooks as Webhooks,
1209 | type WebhookDetails as WebhookDetails,
1210 | type WebhookRetrieveSecretResponse as WebhookRetrieveSecretResponse,
1211 | type DisputeAcceptedWebhookEvent as DisputeAcceptedWebhookEvent,
1212 | type DisputeCancelledWebhookEvent as DisputeCancelledWebhookEvent,
1213 | type DisputeChallengedWebhookEvent as DisputeChallengedWebhookEvent,
1214 | type DisputeExpiredWebhookEvent as DisputeExpiredWebhookEvent,
1215 | type DisputeLostWebhookEvent as DisputeLostWebhookEvent,
1216 | type DisputeOpenedWebhookEvent as DisputeOpenedWebhookEvent,
1217 | type DisputeWonWebhookEvent as DisputeWonWebhookEvent,
1218 | type LicenseKeyCreatedWebhookEvent as LicenseKeyCreatedWebhookEvent,
1219 | type PaymentCancelledWebhookEvent as PaymentCancelledWebhookEvent,
1220 | type PaymentFailedWebhookEvent as PaymentFailedWebhookEvent,
1221 | type PaymentProcessingWebhookEvent as PaymentProcessingWebhookEvent,
1222 | type PaymentSucceededWebhookEvent as PaymentSucceededWebhookEvent,
1223 | type RefundFailedWebhookEvent as RefundFailedWebhookEvent,
1224 | type RefundSucceededWebhookEvent as RefundSucceededWebhookEvent,
1225 | type SubscriptionActiveWebhookEvent as SubscriptionActiveWebhookEvent,
1226 | type SubscriptionCancelledWebhookEvent as SubscriptionCancelledWebhookEvent,
1227 | type SubscriptionExpiredWebhookEvent as SubscriptionExpiredWebhookEvent,
1228 | type SubscriptionFailedWebhookEvent as SubscriptionFailedWebhookEvent,
1229 | type SubscriptionOnHoldWebhookEvent as SubscriptionOnHoldWebhookEvent,
1230 | type SubscriptionPlanChangedWebhookEvent as SubscriptionPlanChangedWebhookEvent,
1231 | type SubscriptionRenewedWebhookEvent as SubscriptionRenewedWebhookEvent,
1232 | type UnsafeUnwrapWebhookEvent as UnsafeUnwrapWebhookEvent,
1233 | type UnwrapWebhookEvent as UnwrapWebhookEvent,
1234 | type WebhookDetailsCursorPagePagination as WebhookDetailsCursorPagePagination,
1235 | type WebhookCreateParams as WebhookCreateParams,
1236 | type WebhookUpdateParams as WebhookUpdateParams,
1237 | type WebhookListParams as WebhookListParams,
1238 | };
1239 |
1240 | export {
1241 | WebhookEvents as WebhookEvents,
1242 | type WebhookEventType as WebhookEventType,
1243 | type WebhookPayload as WebhookPayload,
1244 | };
1245 |
1246 | export {
1247 | UsageEvents as UsageEvents,
1248 | type Event as Event,
1249 | type EventInput as EventInput,
1250 | type UsageEventIngestResponse as UsageEventIngestResponse,
1251 | type EventsDefaultPageNumberPagination as EventsDefaultPageNumberPagination,
1252 | type UsageEventListParams as UsageEventListParams,
1253 | type UsageEventIngestParams as UsageEventIngestParams,
1254 | };
1255 |
1256 | export {
1257 | Meters as Meters,
1258 | type Meter as Meter,
1259 | type MeterAggregation as MeterAggregation,
1260 | type MeterFilter as MeterFilter,
1261 | type MetersDefaultPageNumberPagination as MetersDefaultPageNumberPagination,
1262 | type MeterCreateParams as MeterCreateParams,
1263 | type MeterListParams as MeterListParams,
1264 | };
1265 | }
1266 |
```