@dodopayments/fastify 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/customer-portal/customer-portal.d.ts.map +1 -1
- package/dist/index.cjs +819 -128
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +819 -128
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4178,7 +4178,7 @@ const safeJSON = (text) => {
|
|
|
4178
4178
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4179
4179
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4180
4180
|
|
|
4181
|
-
const VERSION = '2.
|
|
4181
|
+
const VERSION = '2.23.2'; // x-release-please-version
|
|
4182
4182
|
|
|
4183
4183
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4184
4184
|
/**
|
|
@@ -4388,6 +4388,25 @@ const FallbackEncoder = ({ headers, body }) => {
|
|
|
4388
4388
|
};
|
|
4389
4389
|
};
|
|
4390
4390
|
|
|
4391
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4392
|
+
/**
|
|
4393
|
+
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
4394
|
+
*/
|
|
4395
|
+
function stringifyQuery(query) {
|
|
4396
|
+
return Object.entries(query)
|
|
4397
|
+
.filter(([_, value]) => typeof value !== 'undefined')
|
|
4398
|
+
.map(([key, value]) => {
|
|
4399
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
4400
|
+
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
4401
|
+
}
|
|
4402
|
+
if (value === null) {
|
|
4403
|
+
return `${encodeURIComponent(key)}=`;
|
|
4404
|
+
}
|
|
4405
|
+
throw new DodoPaymentsError(`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.`);
|
|
4406
|
+
})
|
|
4407
|
+
.join('&');
|
|
4408
|
+
}
|
|
4409
|
+
|
|
4391
4410
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4392
4411
|
const levelNumbers = {
|
|
4393
4412
|
off: 0,
|
|
@@ -4481,6 +4500,11 @@ async function defaultParseResponse(client, props) {
|
|
|
4481
4500
|
const mediaType = contentType?.split(';')[0]?.trim();
|
|
4482
4501
|
const isJSON = mediaType?.includes('application/json') || mediaType?.endsWith('+json');
|
|
4483
4502
|
if (isJSON) {
|
|
4503
|
+
const contentLength = response.headers.get('content-length');
|
|
4504
|
+
if (contentLength === '0') {
|
|
4505
|
+
// if there is no content we can't do anything
|
|
4506
|
+
return undefined;
|
|
4507
|
+
}
|
|
4484
4508
|
const json = await response.json();
|
|
4485
4509
|
return json;
|
|
4486
4510
|
}
|
|
@@ -4901,6 +4925,16 @@ class Addons extends APIResource {
|
|
|
4901
4925
|
}
|
|
4902
4926
|
}
|
|
4903
4927
|
|
|
4928
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4929
|
+
let Balances$1 = class Balances extends APIResource {
|
|
4930
|
+
retrieveLedger(query = {}, options) {
|
|
4931
|
+
return this._client.getAPIList('/balances/ledger', (DefaultPageNumberPagination), {
|
|
4932
|
+
query,
|
|
4933
|
+
...options,
|
|
4934
|
+
});
|
|
4935
|
+
}
|
|
4936
|
+
};
|
|
4937
|
+
|
|
4904
4938
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4905
4939
|
class Brands extends APIResource {
|
|
4906
4940
|
create(body, options) {
|
|
@@ -4931,66 +4965,155 @@ class CheckoutSessions extends APIResource {
|
|
|
4931
4965
|
retrieve(id, options) {
|
|
4932
4966
|
return this._client.get(path `/checkouts/${id}`, options);
|
|
4933
4967
|
}
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4937
|
-
let CustomerPortal$1 = class CustomerPortal extends APIResource {
|
|
4938
|
-
create(customerID, params = {}, options) {
|
|
4939
|
-
const { send_email } = params ?? {};
|
|
4940
|
-
return this._client.post(path `/customers/${customerID}/customer-portal/session`, {
|
|
4941
|
-
query: { send_email },
|
|
4942
|
-
...options,
|
|
4943
|
-
});
|
|
4944
|
-
}
|
|
4945
|
-
};
|
|
4946
|
-
|
|
4947
|
-
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4948
|
-
class LedgerEntries extends APIResource {
|
|
4949
|
-
create(customerID, body, options) {
|
|
4950
|
-
return this._client.post(path `/customers/${customerID}/wallets/ledger-entries`, { body, ...options });
|
|
4951
|
-
}
|
|
4952
|
-
list(customerID, query = {}, options) {
|
|
4953
|
-
return this._client.getAPIList(path `/customers/${customerID}/wallets/ledger-entries`, (DefaultPageNumberPagination), { query, ...options });
|
|
4968
|
+
preview(body, options) {
|
|
4969
|
+
return this._client.post('/checkouts/preview', { body, ...options });
|
|
4954
4970
|
}
|
|
4955
4971
|
}
|
|
4956
4972
|
|
|
4957
4973
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4958
|
-
class
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
|
|
4966
|
-
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
4970
|
-
|
|
4971
|
-
|
|
4972
|
-
|
|
4973
|
-
|
|
4974
|
-
|
|
4974
|
+
class Balances extends APIResource {
|
|
4975
|
+
/**
|
|
4976
|
+
* Returns the credit balance details for a specific customer and credit
|
|
4977
|
+
* entitlement.
|
|
4978
|
+
*
|
|
4979
|
+
* # Authentication
|
|
4980
|
+
*
|
|
4981
|
+
* Requires an API key with `Viewer` role or higher.
|
|
4982
|
+
*
|
|
4983
|
+
* # Path Parameters
|
|
4984
|
+
*
|
|
4985
|
+
* - `credit_entitlement_id` - The unique identifier of the credit entitlement
|
|
4986
|
+
* - `customer_id` - The unique identifier of the customer
|
|
4987
|
+
*
|
|
4988
|
+
* # Responses
|
|
4989
|
+
*
|
|
4990
|
+
* - `200 OK` - Returns the customer's balance
|
|
4991
|
+
* - `404 Not Found` - Credit entitlement or customer balance not found
|
|
4992
|
+
* - `500 Internal Server Error` - Database or server error
|
|
4993
|
+
*/
|
|
4994
|
+
retrieve(customerID, params, options) {
|
|
4995
|
+
const { credit_entitlement_id } = params;
|
|
4996
|
+
return this._client.get(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}`, options);
|
|
4975
4997
|
}
|
|
4976
|
-
|
|
4977
|
-
|
|
4998
|
+
/**
|
|
4999
|
+
* Returns a paginated list of customer credit balances for the given credit
|
|
5000
|
+
* entitlement.
|
|
5001
|
+
*
|
|
5002
|
+
* # Authentication
|
|
5003
|
+
*
|
|
5004
|
+
* Requires an API key with `Viewer` role or higher.
|
|
5005
|
+
*
|
|
5006
|
+
* # Path Parameters
|
|
5007
|
+
*
|
|
5008
|
+
* - `credit_entitlement_id` - The unique identifier of the credit entitlement
|
|
5009
|
+
*
|
|
5010
|
+
* # Query Parameters
|
|
5011
|
+
*
|
|
5012
|
+
* - `page_size` - Number of items per page (default: 10, max: 100)
|
|
5013
|
+
* - `page_number` - Zero-based page number (default: 0)
|
|
5014
|
+
* - `customer_id` - Optional filter by specific customer
|
|
5015
|
+
*
|
|
5016
|
+
* # Responses
|
|
5017
|
+
*
|
|
5018
|
+
* - `200 OK` - Returns list of customer balances
|
|
5019
|
+
* - `404 Not Found` - Credit entitlement not found
|
|
5020
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5021
|
+
*/
|
|
5022
|
+
list(creditEntitlementID, query = {}, options) {
|
|
5023
|
+
return this._client.getAPIList(path `/credit-entitlements/${creditEntitlementID}/balances`, (DefaultPageNumberPagination), { query, ...options });
|
|
4978
5024
|
}
|
|
4979
|
-
|
|
4980
|
-
|
|
5025
|
+
/**
|
|
5026
|
+
* For credit entries, a new grant is created. For debit entries, credits are
|
|
5027
|
+
* deducted from existing grants using FIFO (oldest first).
|
|
5028
|
+
*
|
|
5029
|
+
* # Authentication
|
|
5030
|
+
*
|
|
5031
|
+
* Requires an API key with `Editor` role.
|
|
5032
|
+
*
|
|
5033
|
+
* # Path Parameters
|
|
5034
|
+
*
|
|
5035
|
+
* - `credit_entitlement_id` - The unique identifier of the credit entitlement
|
|
5036
|
+
* - `customer_id` - The unique identifier of the customer
|
|
5037
|
+
*
|
|
5038
|
+
* # Request Body
|
|
5039
|
+
*
|
|
5040
|
+
* - `entry_type` - "credit" or "debit"
|
|
5041
|
+
* - `amount` - Amount to credit or debit
|
|
5042
|
+
* - `reason` - Optional human-readable reason
|
|
5043
|
+
* - `expires_at` - Optional expiration for credited amount (only for credit type)
|
|
5044
|
+
* - `idempotency_key` - Optional key to prevent duplicate entries
|
|
5045
|
+
*
|
|
5046
|
+
* # Responses
|
|
5047
|
+
*
|
|
5048
|
+
* - `201 Created` - Ledger entry created successfully
|
|
5049
|
+
* - `400 Bad Request` - Invalid request (e.g., debit with insufficient balance)
|
|
5050
|
+
* - `404 Not Found` - Credit entitlement or customer not found
|
|
5051
|
+
* - `409 Conflict` - Idempotency key already exists
|
|
5052
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5053
|
+
*/
|
|
5054
|
+
createLedgerEntry(customerID, params, options) {
|
|
5055
|
+
const { credit_entitlement_id, ...body } = params;
|
|
5056
|
+
return this._client.post(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/ledger-entries`, { body, ...options });
|
|
4981
5057
|
}
|
|
4982
|
-
|
|
4983
|
-
|
|
5058
|
+
/**
|
|
5059
|
+
* Returns a paginated list of credit grants with optional filtering by status.
|
|
5060
|
+
*
|
|
5061
|
+
* # Authentication
|
|
5062
|
+
*
|
|
5063
|
+
* Requires an API key with `Viewer` role or higher.
|
|
5064
|
+
*
|
|
5065
|
+
* # Path Parameters
|
|
5066
|
+
*
|
|
5067
|
+
* - `credit_entitlement_id` - The unique identifier of the credit entitlement
|
|
5068
|
+
* - `customer_id` - The unique identifier of the customer
|
|
5069
|
+
*
|
|
5070
|
+
* # Query Parameters
|
|
5071
|
+
*
|
|
5072
|
+
* - `page_size` - Number of items per page (default: 10, max: 100)
|
|
5073
|
+
* - `page_number` - Zero-based page number (default: 0)
|
|
5074
|
+
* - `status` - Filter by status: active, expired, depleted
|
|
5075
|
+
*
|
|
5076
|
+
* # Responses
|
|
5077
|
+
*
|
|
5078
|
+
* - `200 OK` - Returns list of grants
|
|
5079
|
+
* - `404 Not Found` - Credit entitlement not found
|
|
5080
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5081
|
+
*/
|
|
5082
|
+
listGrants(customerID, params, options) {
|
|
5083
|
+
const { credit_entitlement_id, ...query } = params;
|
|
5084
|
+
return this._client.getAPIList(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/grants`, (DefaultPageNumberPagination), { query, ...options });
|
|
4984
5085
|
}
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
5086
|
+
/**
|
|
5087
|
+
* Returns a paginated list of credit transaction history with optional filtering.
|
|
5088
|
+
*
|
|
5089
|
+
* # Authentication
|
|
5090
|
+
*
|
|
5091
|
+
* Requires an API key with `Viewer` role or higher.
|
|
5092
|
+
*
|
|
5093
|
+
* # Path Parameters
|
|
5094
|
+
*
|
|
5095
|
+
* - `credit_entitlement_id` - The unique identifier of the credit entitlement
|
|
5096
|
+
* - `customer_id` - The unique identifier of the customer
|
|
5097
|
+
*
|
|
5098
|
+
* # Query Parameters
|
|
5099
|
+
*
|
|
5100
|
+
* - `page_size` - Number of items per page (default: 10, max: 100)
|
|
5101
|
+
* - `page_number` - Zero-based page number (default: 0)
|
|
5102
|
+
* - `transaction_type` - Filter by transaction type
|
|
5103
|
+
* - `start_date` - Filter entries from this date
|
|
5104
|
+
* - `end_date` - Filter entries until this date
|
|
5105
|
+
*
|
|
5106
|
+
* # Responses
|
|
5107
|
+
*
|
|
5108
|
+
* - `200 OK` - Returns list of ledger entries
|
|
5109
|
+
* - `404 Not Found` - Credit entitlement not found
|
|
5110
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5111
|
+
*/
|
|
5112
|
+
listLedger(customerID, params, options) {
|
|
5113
|
+
const { credit_entitlement_id, ...query } = params;
|
|
5114
|
+
return this._client.getAPIList(path `/credit-entitlements/${credit_entitlement_id}/balances/${customerID}/ledger`, (DefaultPageNumberPagination), { query, ...options });
|
|
4990
5115
|
}
|
|
4991
5116
|
}
|
|
4992
|
-
Customers.CustomerPortal = CustomerPortal$1;
|
|
4993
|
-
Customers.Wallets = Wallets;
|
|
4994
5117
|
|
|
4995
5118
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4996
5119
|
const brand_privateNullableHeaders = /* @__PURE__ */ Symbol('brand.privateNullableHeaders');
|
|
@@ -5060,6 +5183,313 @@ const buildHeaders = (newHeaders) => {
|
|
|
5060
5183
|
return { [brand_privateNullableHeaders]: true, values: targetHeaders, nulls: nullHeaders };
|
|
5061
5184
|
};
|
|
5062
5185
|
|
|
5186
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5187
|
+
class CreditEntitlements extends APIResource {
|
|
5188
|
+
constructor() {
|
|
5189
|
+
super(...arguments);
|
|
5190
|
+
this.balances = new Balances(this._client);
|
|
5191
|
+
}
|
|
5192
|
+
/**
|
|
5193
|
+
* Credit entitlements define reusable credit templates that can be attached to
|
|
5194
|
+
* products. Each entitlement defines how credits behave in terms of expiration,
|
|
5195
|
+
* rollover, and overage.
|
|
5196
|
+
*
|
|
5197
|
+
* # Authentication
|
|
5198
|
+
*
|
|
5199
|
+
* Requires an API key with `Editor` role.
|
|
5200
|
+
*
|
|
5201
|
+
* # Request Body
|
|
5202
|
+
*
|
|
5203
|
+
* - `name` - Human-readable name of the credit entitlement (1-255 characters,
|
|
5204
|
+
* required)
|
|
5205
|
+
* - `description` - Optional description (max 1000 characters)
|
|
5206
|
+
* - `precision` - Decimal precision for credit amounts (0-10 decimal places)
|
|
5207
|
+
* - `unit` - Unit of measurement for the credit (e.g., "API Calls", "Tokens",
|
|
5208
|
+
* "Credits")
|
|
5209
|
+
* - `expires_after_days` - Number of days after which credits expire (optional)
|
|
5210
|
+
* - `rollover_enabled` - Whether unused credits can rollover to the next period
|
|
5211
|
+
* - `rollover_percentage` - Percentage of unused credits that rollover (0-100)
|
|
5212
|
+
* - `rollover_timeframe_count` - Count of timeframe periods for rollover limit
|
|
5213
|
+
* - `rollover_timeframe_interval` - Interval type (day, week, month, year)
|
|
5214
|
+
* - `max_rollover_count` - Maximum number of times credits can be rolled over
|
|
5215
|
+
* - `overage_enabled` - Whether overage charges apply when credits run out
|
|
5216
|
+
* (requires price_per_unit)
|
|
5217
|
+
* - `overage_limit` - Maximum overage units allowed (optional)
|
|
5218
|
+
* - `currency` - Currency for pricing (required if price_per_unit is set)
|
|
5219
|
+
* - `price_per_unit` - Price per credit unit (decimal)
|
|
5220
|
+
*
|
|
5221
|
+
* # Responses
|
|
5222
|
+
*
|
|
5223
|
+
* - `201 Created` - Credit entitlement created successfully, returns the full
|
|
5224
|
+
* entitlement object
|
|
5225
|
+
* - `422 Unprocessable Entity` - Invalid request parameters or validation failure
|
|
5226
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5227
|
+
*
|
|
5228
|
+
* # Business Logic
|
|
5229
|
+
*
|
|
5230
|
+
* - A unique ID with prefix `cde_` is automatically generated for the entitlement
|
|
5231
|
+
* - Created and updated timestamps are automatically set
|
|
5232
|
+
* - Currency is required when price_per_unit is set
|
|
5233
|
+
* - price_per_unit is required when overage_enabled is true
|
|
5234
|
+
* - rollover_timeframe_count and rollover_timeframe_interval must both be set or
|
|
5235
|
+
* both be null
|
|
5236
|
+
*/
|
|
5237
|
+
create(body, options) {
|
|
5238
|
+
return this._client.post('/credit-entitlements', { body, ...options });
|
|
5239
|
+
}
|
|
5240
|
+
/**
|
|
5241
|
+
* Returns the full details of a single credit entitlement including all
|
|
5242
|
+
* configuration settings for expiration, rollover, and overage policies.
|
|
5243
|
+
*
|
|
5244
|
+
* # Authentication
|
|
5245
|
+
*
|
|
5246
|
+
* Requires an API key with `Viewer` role or higher.
|
|
5247
|
+
*
|
|
5248
|
+
* # Path Parameters
|
|
5249
|
+
*
|
|
5250
|
+
* - `id` - The unique identifier of the credit entitlement (format: `cde_...`)
|
|
5251
|
+
*
|
|
5252
|
+
* # Responses
|
|
5253
|
+
*
|
|
5254
|
+
* - `200 OK` - Returns the full credit entitlement object
|
|
5255
|
+
* - `404 Not Found` - Credit entitlement does not exist or does not belong to the
|
|
5256
|
+
* authenticated business
|
|
5257
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5258
|
+
*
|
|
5259
|
+
* # Business Logic
|
|
5260
|
+
*
|
|
5261
|
+
* - Only non-deleted credit entitlements can be retrieved through this endpoint
|
|
5262
|
+
* - The entitlement must belong to the authenticated business (business_id check)
|
|
5263
|
+
* - Deleted entitlements return a 404 error and must be retrieved via the list
|
|
5264
|
+
* endpoint with `deleted=true`
|
|
5265
|
+
*/
|
|
5266
|
+
retrieve(id, options) {
|
|
5267
|
+
return this._client.get(path `/credit-entitlements/${id}`, options);
|
|
5268
|
+
}
|
|
5269
|
+
/**
|
|
5270
|
+
* Allows partial updates to a credit entitlement's configuration. Only the fields
|
|
5271
|
+
* provided in the request body will be updated; all other fields remain unchanged.
|
|
5272
|
+
* This endpoint supports nullable fields using the double option pattern.
|
|
5273
|
+
*
|
|
5274
|
+
* # Authentication
|
|
5275
|
+
*
|
|
5276
|
+
* Requires an API key with `Editor` role.
|
|
5277
|
+
*
|
|
5278
|
+
* # Path Parameters
|
|
5279
|
+
*
|
|
5280
|
+
* - `id` - The unique identifier of the credit entitlement to update (format:
|
|
5281
|
+
* `cde_...`)
|
|
5282
|
+
*
|
|
5283
|
+
* # Request Body (all fields optional)
|
|
5284
|
+
*
|
|
5285
|
+
* - `name` - Human-readable name of the credit entitlement (1-255 characters)
|
|
5286
|
+
* - `description` - Optional description (max 1000 characters)
|
|
5287
|
+
* - `unit` - Unit of measurement for the credit (1-50 characters)
|
|
5288
|
+
*
|
|
5289
|
+
* Note: `precision` cannot be modified after creation as it would invalidate
|
|
5290
|
+
* existing grants.
|
|
5291
|
+
*
|
|
5292
|
+
* - `expires_after_days` - Number of days after which credits expire (use `null`
|
|
5293
|
+
* to remove expiration)
|
|
5294
|
+
* - `rollover_enabled` - Whether unused credits can rollover to the next period
|
|
5295
|
+
* - `rollover_percentage` - Percentage of unused credits that rollover (0-100,
|
|
5296
|
+
* nullable)
|
|
5297
|
+
* - `rollover_timeframe_count` - Count of timeframe periods for rollover limit
|
|
5298
|
+
* (nullable)
|
|
5299
|
+
* - `rollover_timeframe_interval` - Interval type (day, week, month, year,
|
|
5300
|
+
* nullable)
|
|
5301
|
+
* - `max_rollover_count` - Maximum number of times credits can be rolled over
|
|
5302
|
+
* (nullable)
|
|
5303
|
+
* - `overage_enabled` - Whether overage charges apply when credits run out
|
|
5304
|
+
* - `overage_limit` - Maximum overage units allowed (nullable)
|
|
5305
|
+
* - `currency` - Currency for pricing (nullable)
|
|
5306
|
+
* - `price_per_unit` - Price per credit unit (decimal, nullable)
|
|
5307
|
+
*
|
|
5308
|
+
* # Responses
|
|
5309
|
+
*
|
|
5310
|
+
* - `200 OK` - Credit entitlement updated successfully
|
|
5311
|
+
* - `404 Not Found` - Credit entitlement does not exist or does not belong to the
|
|
5312
|
+
* authenticated business
|
|
5313
|
+
* - `422 Unprocessable Entity` - Invalid request parameters or validation failure
|
|
5314
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5315
|
+
*
|
|
5316
|
+
* # Business Logic
|
|
5317
|
+
*
|
|
5318
|
+
* - Only non-deleted credit entitlements can be updated
|
|
5319
|
+
* - Fields set to `null` explicitly will clear the database value (using double
|
|
5320
|
+
* option pattern)
|
|
5321
|
+
* - The `updated_at` timestamp is automatically updated on successful modification
|
|
5322
|
+
* - Changes take effect immediately but do not retroactively affect existing
|
|
5323
|
+
* credit grants
|
|
5324
|
+
* - The merged state is validated: currency required with price, rollover
|
|
5325
|
+
* timeframe fields together, price required for overage
|
|
5326
|
+
*/
|
|
5327
|
+
update(id, body, options) {
|
|
5328
|
+
return this._client.patch(path `/credit-entitlements/${id}`, {
|
|
5329
|
+
body,
|
|
5330
|
+
...options,
|
|
5331
|
+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
|
|
5332
|
+
});
|
|
5333
|
+
}
|
|
5334
|
+
/**
|
|
5335
|
+
* Returns a paginated list of credit entitlements, allowing filtering of deleted
|
|
5336
|
+
* entitlements. By default, only non-deleted entitlements are returned.
|
|
5337
|
+
*
|
|
5338
|
+
* # Authentication
|
|
5339
|
+
*
|
|
5340
|
+
* Requires an API key with `Viewer` role or higher.
|
|
5341
|
+
*
|
|
5342
|
+
* # Query Parameters
|
|
5343
|
+
*
|
|
5344
|
+
* - `page_size` - Number of items per page (default: 10, max: 100)
|
|
5345
|
+
* - `page_number` - Zero-based page number (default: 0)
|
|
5346
|
+
* - `deleted` - Boolean flag to list deleted entitlements instead of active ones
|
|
5347
|
+
* (default: false)
|
|
5348
|
+
*
|
|
5349
|
+
* # Responses
|
|
5350
|
+
*
|
|
5351
|
+
* - `200 OK` - Returns a list of credit entitlements wrapped in a response object
|
|
5352
|
+
* - `422 Unprocessable Entity` - Invalid query parameters (e.g., page_size > 100)
|
|
5353
|
+
* - `500 Internal Server Error` - Database or server error
|
|
5354
|
+
*
|
|
5355
|
+
* # Business Logic
|
|
5356
|
+
*
|
|
5357
|
+
* - Results are ordered by creation date in descending order (newest first)
|
|
5358
|
+
* - Only entitlements belonging to the authenticated business are returned
|
|
5359
|
+
* - The `deleted` parameter controls visibility of soft-deleted entitlements
|
|
5360
|
+
* - Pagination uses offset-based pagination (offset = page_number \* page_size)
|
|
5361
|
+
*/
|
|
5362
|
+
list(query = {}, options) {
|
|
5363
|
+
return this._client.getAPIList('/credit-entitlements', (DefaultPageNumberPagination), {
|
|
5364
|
+
query,
|
|
5365
|
+
...options,
|
|
5366
|
+
});
|
|
5367
|
+
}
|
|
5368
|
+
delete(id, options) {
|
|
5369
|
+
return this._client.delete(path `/credit-entitlements/${id}`, {
|
|
5370
|
+
...options,
|
|
5371
|
+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
|
|
5372
|
+
});
|
|
5373
|
+
}
|
|
5374
|
+
/**
|
|
5375
|
+
* Undeletes a soft-deleted credit entitlement by clearing `deleted_at`, making it
|
|
5376
|
+
* available again through standard list and get endpoints.
|
|
5377
|
+
*
|
|
5378
|
+
* # Authentication
|
|
5379
|
+
*
|
|
5380
|
+
* Requires an API key with `Editor` role.
|
|
5381
|
+
*
|
|
5382
|
+
* # Path Parameters
|
|
5383
|
+
*
|
|
5384
|
+
* - `id` - The unique identifier of the credit entitlement to restore (format:
|
|
5385
|
+
* `cde_...`)
|
|
5386
|
+
*
|
|
5387
|
+
* # Responses
|
|
5388
|
+
*
|
|
5389
|
+
* - `200 OK` - Credit entitlement restored successfully
|
|
5390
|
+
* - `500 Internal Server Error` - Database error, entitlement not found, or
|
|
5391
|
+
* entitlement is not deleted
|
|
5392
|
+
*
|
|
5393
|
+
* # Business Logic
|
|
5394
|
+
*
|
|
5395
|
+
* - Only deleted credit entitlements can be restored
|
|
5396
|
+
* - The query filters for `deleted_at IS NOT NULL`, so non-deleted entitlements
|
|
5397
|
+
* will result in 0 rows affected
|
|
5398
|
+
* - If no rows are affected (entitlement doesn't exist, doesn't belong to
|
|
5399
|
+
* business, or is not deleted), returns 500
|
|
5400
|
+
* - The `updated_at` timestamp is automatically updated on successful restoration
|
|
5401
|
+
* - Once restored, the entitlement becomes immediately available in the standard
|
|
5402
|
+
* list and get endpoints
|
|
5403
|
+
* - All configuration settings are preserved during delete/restore operations
|
|
5404
|
+
*
|
|
5405
|
+
* # Error Handling
|
|
5406
|
+
*
|
|
5407
|
+
* This endpoint returns 500 Internal Server Error in several cases:
|
|
5408
|
+
*
|
|
5409
|
+
* - The credit entitlement does not exist
|
|
5410
|
+
* - The credit entitlement belongs to a different business
|
|
5411
|
+
* - The credit entitlement is not currently deleted (already active)
|
|
5412
|
+
*
|
|
5413
|
+
* Callers should verify the entitlement exists and is deleted before calling this
|
|
5414
|
+
* endpoint.
|
|
5415
|
+
*/
|
|
5416
|
+
undelete(id, options) {
|
|
5417
|
+
return this._client.post(path `/credit-entitlements/${id}/undelete`, {
|
|
5418
|
+
...options,
|
|
5419
|
+
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
|
|
5420
|
+
});
|
|
5421
|
+
}
|
|
5422
|
+
}
|
|
5423
|
+
CreditEntitlements.Balances = Balances;
|
|
5424
|
+
|
|
5425
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5426
|
+
let CustomerPortal$1 = class CustomerPortal extends APIResource {
|
|
5427
|
+
create(customerID, params = {}, options) {
|
|
5428
|
+
const { send_email } = params ?? {};
|
|
5429
|
+
return this._client.post(path `/customers/${customerID}/customer-portal/session`, {
|
|
5430
|
+
query: { send_email },
|
|
5431
|
+
...options,
|
|
5432
|
+
});
|
|
5433
|
+
}
|
|
5434
|
+
};
|
|
5435
|
+
|
|
5436
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5437
|
+
class LedgerEntries extends APIResource {
|
|
5438
|
+
create(customerID, body, options) {
|
|
5439
|
+
return this._client.post(path `/customers/${customerID}/wallets/ledger-entries`, { body, ...options });
|
|
5440
|
+
}
|
|
5441
|
+
list(customerID, query = {}, options) {
|
|
5442
|
+
return this._client.getAPIList(path `/customers/${customerID}/wallets/ledger-entries`, (DefaultPageNumberPagination), { query, ...options });
|
|
5443
|
+
}
|
|
5444
|
+
}
|
|
5445
|
+
|
|
5446
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5447
|
+
class Wallets extends APIResource {
|
|
5448
|
+
constructor() {
|
|
5449
|
+
super(...arguments);
|
|
5450
|
+
this.ledgerEntries = new LedgerEntries(this._client);
|
|
5451
|
+
}
|
|
5452
|
+
list(customerID, options) {
|
|
5453
|
+
return this._client.get(path `/customers/${customerID}/wallets`, options);
|
|
5454
|
+
}
|
|
5455
|
+
}
|
|
5456
|
+
Wallets.LedgerEntries = LedgerEntries;
|
|
5457
|
+
|
|
5458
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5459
|
+
class Customers extends APIResource {
|
|
5460
|
+
constructor() {
|
|
5461
|
+
super(...arguments);
|
|
5462
|
+
this.customerPortal = new CustomerPortal$1(this._client);
|
|
5463
|
+
this.wallets = new Wallets(this._client);
|
|
5464
|
+
}
|
|
5465
|
+
create(body, options) {
|
|
5466
|
+
return this._client.post('/customers', { body, ...options });
|
|
5467
|
+
}
|
|
5468
|
+
retrieve(customerID, options) {
|
|
5469
|
+
return this._client.get(path `/customers/${customerID}`, options);
|
|
5470
|
+
}
|
|
5471
|
+
update(customerID, body, options) {
|
|
5472
|
+
return this._client.patch(path `/customers/${customerID}`, { body, ...options });
|
|
5473
|
+
}
|
|
5474
|
+
list(query = {}, options) {
|
|
5475
|
+
return this._client.getAPIList('/customers', (DefaultPageNumberPagination), {
|
|
5476
|
+
query,
|
|
5477
|
+
...options,
|
|
5478
|
+
});
|
|
5479
|
+
}
|
|
5480
|
+
/**
|
|
5481
|
+
* List all credit entitlements for a customer with their current balances
|
|
5482
|
+
*/
|
|
5483
|
+
listCreditEntitlements(customerID, options) {
|
|
5484
|
+
return this._client.get(path `/customers/${customerID}/credit-entitlements`, options);
|
|
5485
|
+
}
|
|
5486
|
+
retrievePaymentMethods(customerID, options) {
|
|
5487
|
+
return this._client.get(path `/customers/${customerID}/payment-methods`, options);
|
|
5488
|
+
}
|
|
5489
|
+
}
|
|
5490
|
+
Customers.CustomerPortal = CustomerPortal$1;
|
|
5491
|
+
Customers.Wallets = Wallets;
|
|
5492
|
+
|
|
5063
5493
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5064
5494
|
class Discounts extends APIResource {
|
|
5065
5495
|
/**
|
|
@@ -5099,6 +5529,14 @@ class Discounts extends APIResource {
|
|
|
5099
5529
|
headers: buildHeaders([{ Accept: '*/*' }, options?.headers]),
|
|
5100
5530
|
});
|
|
5101
5531
|
}
|
|
5532
|
+
/**
|
|
5533
|
+
* Validate and fetch a discount by its code name (e.g., "SAVE20"). This allows
|
|
5534
|
+
* real-time validation directly against the API using the human-readable discount
|
|
5535
|
+
* code instead of requiring the internal discount_id.
|
|
5536
|
+
*/
|
|
5537
|
+
retrieveByCode(code, options) {
|
|
5538
|
+
return this._client.get(path `/discounts/code/${code}`, options);
|
|
5539
|
+
}
|
|
5102
5540
|
}
|
|
5103
5541
|
|
|
5104
5542
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
@@ -5297,6 +5735,9 @@ class Misc extends APIResource {
|
|
|
5297
5735
|
|
|
5298
5736
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5299
5737
|
class Payments extends APIResource {
|
|
5738
|
+
/**
|
|
5739
|
+
* @deprecated
|
|
5740
|
+
*/
|
|
5300
5741
|
create(body, options) {
|
|
5301
5742
|
return this._client.post('/payments', { body, ...options });
|
|
5302
5743
|
}
|
|
@@ -5332,11 +5773,29 @@ class Images extends APIResource {
|
|
|
5332
5773
|
}
|
|
5333
5774
|
}
|
|
5334
5775
|
|
|
5776
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5777
|
+
class ShortLinks extends APIResource {
|
|
5778
|
+
/**
|
|
5779
|
+
* Gives a Short Checkout URL with custom slug for a product. Uses a Static
|
|
5780
|
+
* Checkout URL under the hood.
|
|
5781
|
+
*/
|
|
5782
|
+
create(id, body, options) {
|
|
5783
|
+
return this._client.post(path `/products/${id}/short_links`, { body, ...options });
|
|
5784
|
+
}
|
|
5785
|
+
/**
|
|
5786
|
+
* Lists all short links created by the business.
|
|
5787
|
+
*/
|
|
5788
|
+
list(query = {}, options) {
|
|
5789
|
+
return this._client.getAPIList('/products/short_links', (DefaultPageNumberPagination), { query, ...options });
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
|
|
5335
5793
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5336
5794
|
class Products extends APIResource {
|
|
5337
5795
|
constructor() {
|
|
5338
5796
|
super(...arguments);
|
|
5339
5797
|
this.images = new Images(this._client);
|
|
5798
|
+
this.shortLinks = new ShortLinks(this._client);
|
|
5340
5799
|
}
|
|
5341
5800
|
create(body, options) {
|
|
5342
5801
|
return this._client.post('/products', { body, ...options });
|
|
@@ -5374,6 +5833,7 @@ class Products extends APIResource {
|
|
|
5374
5833
|
}
|
|
5375
5834
|
}
|
|
5376
5835
|
Products.Images = Images;
|
|
5836
|
+
Products.ShortLinks = ShortLinks;
|
|
5377
5837
|
|
|
5378
5838
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5379
5839
|
class Refunds extends APIResource {
|
|
@@ -5393,6 +5853,9 @@ class Refunds extends APIResource {
|
|
|
5393
5853
|
|
|
5394
5854
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
5395
5855
|
class Subscriptions extends APIResource {
|
|
5856
|
+
/**
|
|
5857
|
+
* @deprecated
|
|
5858
|
+
*/
|
|
5396
5859
|
create(body, options) {
|
|
5397
5860
|
return this._client.post('/subscriptions', { body, ...options });
|
|
5398
5861
|
}
|
|
@@ -5418,6 +5881,15 @@ class Subscriptions extends APIResource {
|
|
|
5418
5881
|
charge(subscriptionID, body, options) {
|
|
5419
5882
|
return this._client.post(path `/subscriptions/${subscriptionID}/charge`, { body, ...options });
|
|
5420
5883
|
}
|
|
5884
|
+
previewChangePlan(subscriptionID, body, options) {
|
|
5885
|
+
return this._client.post(path `/subscriptions/${subscriptionID}/change-plan/preview`, {
|
|
5886
|
+
body,
|
|
5887
|
+
...options,
|
|
5888
|
+
});
|
|
5889
|
+
}
|
|
5890
|
+
retrieveCreditUsage(subscriptionID, options) {
|
|
5891
|
+
return this._client.get(path `/subscriptions/${subscriptionID}/credit-usage`, options);
|
|
5892
|
+
}
|
|
5421
5893
|
/**
|
|
5422
5894
|
* Get detailed usage history for a subscription that includes usage-based billing
|
|
5423
5895
|
* (metered components). This endpoint provides insights into customer usage
|
|
@@ -5465,6 +5937,12 @@ class Subscriptions extends APIResource {
|
|
|
5465
5937
|
retrieveUsageHistory(subscriptionID, query = {}, options) {
|
|
5466
5938
|
return this._client.getAPIList(path `/subscriptions/${subscriptionID}/usage-history`, (DefaultPageNumberPagination), { query, ...options });
|
|
5467
5939
|
}
|
|
5940
|
+
updatePaymentMethod(subscriptionID, body, options) {
|
|
5941
|
+
return this._client.post(path `/subscriptions/${subscriptionID}/update-payment-method`, {
|
|
5942
|
+
body,
|
|
5943
|
+
...options,
|
|
5944
|
+
});
|
|
5945
|
+
}
|
|
5468
5946
|
}
|
|
5469
5947
|
|
|
5470
5948
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
@@ -6586,6 +7064,8 @@ class DodoPayments {
|
|
|
6586
7064
|
this.webhookEvents = new WebhookEvents(this);
|
|
6587
7065
|
this.usageEvents = new UsageEvents(this);
|
|
6588
7066
|
this.meters = new Meters(this);
|
|
7067
|
+
this.balances = new Balances$1(this);
|
|
7068
|
+
this.creditEntitlements = new CreditEntitlements(this);
|
|
6589
7069
|
if (bearerToken === undefined) {
|
|
6590
7070
|
throw new DodoPaymentsError("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' }).");
|
|
6591
7071
|
}
|
|
@@ -6650,18 +7130,7 @@ class DodoPayments {
|
|
|
6650
7130
|
* Basic re-implementation of `qs.stringify` for primitive types.
|
|
6651
7131
|
*/
|
|
6652
7132
|
stringifyQuery(query) {
|
|
6653
|
-
return
|
|
6654
|
-
.filter(([_, value]) => typeof value !== 'undefined')
|
|
6655
|
-
.map(([key, value]) => {
|
|
6656
|
-
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
|
|
6657
|
-
return `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
6658
|
-
}
|
|
6659
|
-
if (value === null) {
|
|
6660
|
-
return `${encodeURIComponent(key)}=`;
|
|
6661
|
-
}
|
|
6662
|
-
throw new DodoPaymentsError(`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.`);
|
|
6663
|
-
})
|
|
6664
|
-
.join('&');
|
|
7133
|
+
return stringifyQuery(query);
|
|
6665
7134
|
}
|
|
6666
7135
|
getUserAgent() {
|
|
6667
7136
|
return `${this.constructor.name}/JS ${VERSION}`;
|
|
@@ -6825,7 +7294,9 @@ class DodoPayments {
|
|
|
6825
7294
|
return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
|
|
6826
7295
|
}
|
|
6827
7296
|
getAPIList(path, Page, opts) {
|
|
6828
|
-
return this.requestAPIList(Page,
|
|
7297
|
+
return this.requestAPIList(Page, opts && 'then' in opts ?
|
|
7298
|
+
opts.then((opts) => ({ method: 'get', path, ...opts }))
|
|
7299
|
+
: { method: 'get', path, ...opts });
|
|
6829
7300
|
}
|
|
6830
7301
|
requestAPIList(Page, options) {
|
|
6831
7302
|
const request = this.makeRequest(options, null, undefined);
|
|
@@ -6833,9 +7304,10 @@ class DodoPayments {
|
|
|
6833
7304
|
}
|
|
6834
7305
|
async fetchWithTimeout(url, init, ms, controller) {
|
|
6835
7306
|
const { signal, method, ...options } = init || {};
|
|
7307
|
+
const abort = this._makeAbort(controller);
|
|
6836
7308
|
if (signal)
|
|
6837
|
-
signal.addEventListener('abort',
|
|
6838
|
-
const timeout = setTimeout(
|
|
7309
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
7310
|
+
const timeout = setTimeout(abort, ms);
|
|
6839
7311
|
const isReadableBody = (globalThis.ReadableStream && options.body instanceof globalThis.ReadableStream) ||
|
|
6840
7312
|
(typeof options.body === 'object' && options.body !== null && Symbol.asyncIterator in options.body);
|
|
6841
7313
|
const fetchOptions = {
|
|
@@ -6900,9 +7372,9 @@ class DodoPayments {
|
|
|
6900
7372
|
timeoutMillis = Date.parse(retryAfterHeader) - Date.now();
|
|
6901
7373
|
}
|
|
6902
7374
|
}
|
|
6903
|
-
// If the API asks us to wait a certain amount of time
|
|
6904
|
-
//
|
|
6905
|
-
if (
|
|
7375
|
+
// If the API asks us to wait a certain amount of time, just do what it
|
|
7376
|
+
// says, but otherwise calculate a default
|
|
7377
|
+
if (timeoutMillis === undefined) {
|
|
6906
7378
|
const maxRetries = options.maxRetries ?? this.maxRetries;
|
|
6907
7379
|
timeoutMillis = this.calculateDefaultRetryTimeoutMillis(retriesRemaining, maxRetries);
|
|
6908
7380
|
}
|
|
@@ -6964,6 +7436,11 @@ class DodoPayments {
|
|
|
6964
7436
|
this.validateHeaders(headers);
|
|
6965
7437
|
return headers.values;
|
|
6966
7438
|
}
|
|
7439
|
+
_makeAbort(controller) {
|
|
7440
|
+
// note: we can't just inline this method inside `fetchWithTimeout()` because then the closure
|
|
7441
|
+
// would capture all request options, and cause a memory leak.
|
|
7442
|
+
return () => controller.abort();
|
|
7443
|
+
}
|
|
6967
7444
|
buildBody({ options: { body, headers: rawHeaders } }) {
|
|
6968
7445
|
if (!body) {
|
|
6969
7446
|
return { bodyHeaders: undefined, body: undefined };
|
|
@@ -6992,6 +7469,13 @@ class DodoPayments {
|
|
|
6992
7469
|
(Symbol.iterator in body && 'next' in body && typeof body.next === 'function'))) {
|
|
6993
7470
|
return { bodyHeaders: undefined, body: ReadableStreamFrom(body) };
|
|
6994
7471
|
}
|
|
7472
|
+
else if (typeof body === 'object' &&
|
|
7473
|
+
headers.values.get('content-type') === 'application/x-www-form-urlencoded') {
|
|
7474
|
+
return {
|
|
7475
|
+
bodyHeaders: { 'content-type': 'application/x-www-form-urlencoded' },
|
|
7476
|
+
body: this.stringifyQuery(body),
|
|
7477
|
+
};
|
|
7478
|
+
}
|
|
6995
7479
|
else {
|
|
6996
7480
|
return __classPrivateFieldGet(this, _DodoPayments_encoder, "f").call(this, { body, headers });
|
|
6997
7481
|
}
|
|
@@ -7036,6 +7520,8 @@ DodoPayments.Webhooks = Webhooks$1;
|
|
|
7036
7520
|
DodoPayments.WebhookEvents = WebhookEvents;
|
|
7037
7521
|
DodoPayments.UsageEvents = UsageEvents;
|
|
7038
7522
|
DodoPayments.Meters = Meters;
|
|
7523
|
+
DodoPayments.Balances = Balances$1;
|
|
7524
|
+
DodoPayments.CreditEntitlements = CreditEntitlements;
|
|
7039
7525
|
|
|
7040
7526
|
// src/checkout/checkout.ts
|
|
7041
7527
|
var checkoutQuerySchema = objectType({
|
|
@@ -7616,23 +8102,33 @@ var PaymentSchema = objectType({
|
|
|
7616
8102
|
payload_type: literalType("Payment"),
|
|
7617
8103
|
billing: objectType({
|
|
7618
8104
|
city: stringType().nullable(),
|
|
7619
|
-
country: stringType()
|
|
8105
|
+
country: stringType(),
|
|
7620
8106
|
state: stringType().nullable(),
|
|
7621
8107
|
street: stringType().nullable(),
|
|
7622
8108
|
zipcode: stringType().nullable()
|
|
7623
8109
|
}),
|
|
7624
8110
|
brand_id: stringType(),
|
|
7625
8111
|
business_id: stringType(),
|
|
8112
|
+
card_holder_name: stringType().nullable(),
|
|
7626
8113
|
card_issuing_country: stringType().nullable(),
|
|
7627
8114
|
card_last_four: stringType().nullable(),
|
|
7628
8115
|
card_network: stringType().nullable(),
|
|
7629
8116
|
card_type: stringType().nullable(),
|
|
8117
|
+
checkout_session_id: stringType().nullable(),
|
|
7630
8118
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7631
8119
|
currency: stringType(),
|
|
8120
|
+
custom_field_responses: arrayType(
|
|
8121
|
+
objectType({
|
|
8122
|
+
key: stringType(),
|
|
8123
|
+
value: stringType()
|
|
8124
|
+
})
|
|
8125
|
+
).nullable(),
|
|
7632
8126
|
customer: objectType({
|
|
7633
8127
|
customer_id: stringType(),
|
|
7634
8128
|
email: stringType(),
|
|
7635
|
-
|
|
8129
|
+
metadata: recordType(anyType()),
|
|
8130
|
+
name: stringType(),
|
|
8131
|
+
phone_number: stringType().nullable()
|
|
7636
8132
|
}),
|
|
7637
8133
|
digital_products_delivered: booleanType(),
|
|
7638
8134
|
discount_id: stringType().nullable(),
|
|
@@ -7643,27 +8139,25 @@ var PaymentSchema = objectType({
|
|
|
7643
8139
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7644
8140
|
currency: stringType(),
|
|
7645
8141
|
dispute_id: stringType(),
|
|
7646
|
-
dispute_stage: enumType([
|
|
7647
|
-
"pre_dispute",
|
|
7648
|
-
"dispute_opened",
|
|
7649
|
-
"dispute_won",
|
|
7650
|
-
"dispute_lost"
|
|
7651
|
-
]),
|
|
8142
|
+
dispute_stage: enumType(["pre_dispute", "dispute", "pre_arbitration"]),
|
|
7652
8143
|
dispute_status: enumType([
|
|
7653
8144
|
"dispute_opened",
|
|
7654
|
-
"
|
|
7655
|
-
"dispute_lost",
|
|
8145
|
+
"dispute_expired",
|
|
7656
8146
|
"dispute_accepted",
|
|
7657
8147
|
"dispute_cancelled",
|
|
7658
|
-
"dispute_challenged"
|
|
8148
|
+
"dispute_challenged",
|
|
8149
|
+
"dispute_won",
|
|
8150
|
+
"dispute_lost"
|
|
7659
8151
|
]),
|
|
7660
8152
|
payment_id: stringType(),
|
|
7661
8153
|
remarks: stringType().nullable()
|
|
7662
8154
|
})
|
|
7663
|
-
).
|
|
8155
|
+
).default([]),
|
|
7664
8156
|
error_code: stringType().nullable(),
|
|
7665
8157
|
error_message: stringType().nullable(),
|
|
7666
|
-
|
|
8158
|
+
invoice_id: stringType().nullable(),
|
|
8159
|
+
invoice_url: stringType().nullable(),
|
|
8160
|
+
metadata: recordType(anyType()),
|
|
7667
8161
|
payment_id: stringType(),
|
|
7668
8162
|
payment_link: stringType().nullable(),
|
|
7669
8163
|
payment_method: stringType().nullable(),
|
|
@@ -7676,21 +8170,34 @@ var PaymentSchema = objectType({
|
|
|
7676
8170
|
).nullable(),
|
|
7677
8171
|
refunds: arrayType(
|
|
7678
8172
|
objectType({
|
|
7679
|
-
amount: numberType(),
|
|
8173
|
+
amount: numberType().nullable(),
|
|
7680
8174
|
business_id: stringType(),
|
|
7681
8175
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7682
|
-
currency: stringType(),
|
|
8176
|
+
currency: stringType().nullable(),
|
|
7683
8177
|
is_partial: booleanType(),
|
|
7684
8178
|
payment_id: stringType(),
|
|
7685
8179
|
reason: stringType().nullable(),
|
|
7686
8180
|
refund_id: stringType(),
|
|
7687
|
-
status: enumType(["succeeded", "failed", "pending"])
|
|
8181
|
+
status: enumType(["succeeded", "failed", "pending", "review"])
|
|
7688
8182
|
})
|
|
7689
|
-
)
|
|
8183
|
+
),
|
|
8184
|
+
refund_status: enumType(["partial", "full"]).nullable(),
|
|
7690
8185
|
settlement_amount: numberType(),
|
|
7691
8186
|
settlement_currency: stringType(),
|
|
7692
8187
|
settlement_tax: numberType().nullable(),
|
|
7693
|
-
status: enumType([
|
|
8188
|
+
status: enumType([
|
|
8189
|
+
"succeeded",
|
|
8190
|
+
"failed",
|
|
8191
|
+
"cancelled",
|
|
8192
|
+
"processing",
|
|
8193
|
+
"requires_customer_action",
|
|
8194
|
+
"requires_merchant_action",
|
|
8195
|
+
"requires_payment_method",
|
|
8196
|
+
"requires_confirmation",
|
|
8197
|
+
"requires_capture",
|
|
8198
|
+
"partially_captured",
|
|
8199
|
+
"partially_captured_and_capturable"
|
|
8200
|
+
]).nullable(),
|
|
7694
8201
|
subscription_id: stringType().nullable(),
|
|
7695
8202
|
tax: numberType().nullable(),
|
|
7696
8203
|
total_amount: numberType(),
|
|
@@ -7703,10 +8210,10 @@ var SubscriptionSchema = objectType({
|
|
|
7703
8210
|
addon_id: stringType(),
|
|
7704
8211
|
quantity: numberType()
|
|
7705
8212
|
})
|
|
7706
|
-
)
|
|
8213
|
+
),
|
|
7707
8214
|
billing: objectType({
|
|
7708
8215
|
city: stringType().nullable(),
|
|
7709
|
-
country: stringType()
|
|
8216
|
+
country: stringType(),
|
|
7710
8217
|
state: stringType().nullable(),
|
|
7711
8218
|
street: stringType().nullable(),
|
|
7712
8219
|
zipcode: stringType().nullable()
|
|
@@ -7718,15 +8225,72 @@ var SubscriptionSchema = objectType({
|
|
|
7718
8225
|
customer: objectType({
|
|
7719
8226
|
customer_id: stringType(),
|
|
7720
8227
|
email: stringType(),
|
|
7721
|
-
|
|
8228
|
+
metadata: recordType(anyType()),
|
|
8229
|
+
name: stringType(),
|
|
8230
|
+
phone_number: stringType().nullable()
|
|
7722
8231
|
}),
|
|
8232
|
+
custom_field_responses: arrayType(
|
|
8233
|
+
objectType({
|
|
8234
|
+
key: stringType(),
|
|
8235
|
+
value: stringType()
|
|
8236
|
+
})
|
|
8237
|
+
).nullable(),
|
|
8238
|
+
discount_cycles_remaining: numberType().nullable(),
|
|
7723
8239
|
discount_id: stringType().nullable(),
|
|
7724
|
-
|
|
7725
|
-
|
|
8240
|
+
expires_at: stringType().transform((d) => new Date(d)).nullable(),
|
|
8241
|
+
credit_entitlement_cart: arrayType(
|
|
8242
|
+
objectType({
|
|
8243
|
+
credit_entitlement_id: stringType(),
|
|
8244
|
+
credit_entitlement_name: stringType(),
|
|
8245
|
+
credits_amount: stringType(),
|
|
8246
|
+
overage_balance: stringType(),
|
|
8247
|
+
overage_behavior: enumType([
|
|
8248
|
+
"forgive_at_reset",
|
|
8249
|
+
"invoice_at_billing",
|
|
8250
|
+
"carry_deficit",
|
|
8251
|
+
"carry_deficit_auto_repay"
|
|
8252
|
+
]),
|
|
8253
|
+
overage_enabled: booleanType(),
|
|
8254
|
+
product_id: stringType(),
|
|
8255
|
+
remaining_balance: stringType(),
|
|
8256
|
+
rollover_enabled: booleanType(),
|
|
8257
|
+
unit: stringType(),
|
|
8258
|
+
expires_after_days: numberType().nullable(),
|
|
8259
|
+
low_balance_threshold_percent: numberType().nullable(),
|
|
8260
|
+
max_rollover_count: numberType().nullable(),
|
|
8261
|
+
overage_limit: stringType().nullable(),
|
|
8262
|
+
rollover_percentage: numberType().nullable(),
|
|
8263
|
+
rollover_timeframe_count: numberType().nullable(),
|
|
8264
|
+
rollover_timeframe_interval: enumType(["Day", "Week", "Month", "Year"]).nullable()
|
|
8265
|
+
})
|
|
8266
|
+
),
|
|
8267
|
+
meter_credit_entitlement_cart: arrayType(
|
|
8268
|
+
objectType({
|
|
8269
|
+
credit_entitlement_id: stringType(),
|
|
8270
|
+
meter_id: stringType(),
|
|
8271
|
+
meter_name: stringType(),
|
|
8272
|
+
meter_units_per_credit: stringType(),
|
|
8273
|
+
product_id: stringType()
|
|
8274
|
+
})
|
|
8275
|
+
),
|
|
8276
|
+
meters: arrayType(
|
|
8277
|
+
objectType({
|
|
8278
|
+
currency: stringType(),
|
|
8279
|
+
description: stringType().nullable(),
|
|
8280
|
+
free_threshold: numberType(),
|
|
8281
|
+
measurement_unit: stringType(),
|
|
8282
|
+
meter_id: stringType(),
|
|
8283
|
+
name: stringType(),
|
|
8284
|
+
price_per_unit: stringType().nullable()
|
|
8285
|
+
})
|
|
8286
|
+
),
|
|
8287
|
+
metadata: recordType(anyType()),
|
|
8288
|
+
next_billing_date: stringType().transform((d) => new Date(d)),
|
|
7726
8289
|
on_demand: booleanType(),
|
|
7727
8290
|
payment_frequency_count: numberType(),
|
|
7728
8291
|
payment_frequency_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
7729
|
-
|
|
8292
|
+
payment_method_id: stringType().nullable(),
|
|
8293
|
+
previous_billing_date: stringType().transform((d) => new Date(d)),
|
|
7730
8294
|
product_id: stringType(),
|
|
7731
8295
|
quantity: numberType(),
|
|
7732
8296
|
recurring_pre_tax_amount: numberType(),
|
|
@@ -7734,7 +8298,6 @@ var SubscriptionSchema = objectType({
|
|
|
7734
8298
|
"pending",
|
|
7735
8299
|
"active",
|
|
7736
8300
|
"on_hold",
|
|
7737
|
-
"paused",
|
|
7738
8301
|
"cancelled",
|
|
7739
8302
|
"expired",
|
|
7740
8303
|
"failed"
|
|
@@ -7742,20 +8305,29 @@ var SubscriptionSchema = objectType({
|
|
|
7742
8305
|
subscription_id: stringType(),
|
|
7743
8306
|
subscription_period_count: numberType(),
|
|
7744
8307
|
subscription_period_interval: enumType(["Day", "Week", "Month", "Year"]),
|
|
8308
|
+
tax_id: stringType().nullable(),
|
|
7745
8309
|
tax_inclusive: booleanType(),
|
|
7746
8310
|
trial_period_days: numberType()
|
|
7747
8311
|
});
|
|
7748
8312
|
var RefundSchema = objectType({
|
|
7749
8313
|
payload_type: literalType("Refund"),
|
|
7750
|
-
amount: numberType(),
|
|
8314
|
+
amount: numberType().nullable(),
|
|
7751
8315
|
business_id: stringType(),
|
|
7752
8316
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7753
|
-
|
|
8317
|
+
customer: objectType({
|
|
8318
|
+
customer_id: stringType(),
|
|
8319
|
+
email: stringType(),
|
|
8320
|
+
metadata: recordType(anyType()),
|
|
8321
|
+
name: stringType(),
|
|
8322
|
+
phone_number: stringType().nullable()
|
|
8323
|
+
}),
|
|
8324
|
+
currency: stringType().nullable(),
|
|
7754
8325
|
is_partial: booleanType(),
|
|
8326
|
+
metadata: recordType(anyType()),
|
|
7755
8327
|
payment_id: stringType(),
|
|
7756
8328
|
reason: stringType().nullable(),
|
|
7757
8329
|
refund_id: stringType(),
|
|
7758
|
-
status: enumType(["succeeded", "failed", "pending"])
|
|
8330
|
+
status: enumType(["succeeded", "failed", "pending", "review"])
|
|
7759
8331
|
});
|
|
7760
8332
|
var DisputeSchema = objectType({
|
|
7761
8333
|
payload_type: literalType("Dispute"),
|
|
@@ -7763,27 +8335,31 @@ var DisputeSchema = objectType({
|
|
|
7763
8335
|
business_id: stringType(),
|
|
7764
8336
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7765
8337
|
currency: stringType(),
|
|
8338
|
+
customer: objectType({
|
|
8339
|
+
customer_id: stringType(),
|
|
8340
|
+
email: stringType(),
|
|
8341
|
+
metadata: recordType(anyType()),
|
|
8342
|
+
name: stringType(),
|
|
8343
|
+
phone_number: stringType().nullable()
|
|
8344
|
+
}),
|
|
7766
8345
|
dispute_id: stringType(),
|
|
7767
|
-
dispute_stage: enumType([
|
|
7768
|
-
"pre_dispute",
|
|
7769
|
-
"dispute_opened",
|
|
7770
|
-
"dispute_won",
|
|
7771
|
-
"dispute_lost"
|
|
7772
|
-
]),
|
|
8346
|
+
dispute_stage: enumType(["pre_dispute", "dispute", "pre_arbitration"]),
|
|
7773
8347
|
dispute_status: enumType([
|
|
7774
8348
|
"dispute_opened",
|
|
7775
|
-
"
|
|
7776
|
-
"dispute_lost",
|
|
8349
|
+
"dispute_expired",
|
|
7777
8350
|
"dispute_accepted",
|
|
7778
8351
|
"dispute_cancelled",
|
|
7779
|
-
"dispute_challenged"
|
|
8352
|
+
"dispute_challenged",
|
|
8353
|
+
"dispute_won",
|
|
8354
|
+
"dispute_lost"
|
|
7780
8355
|
]),
|
|
7781
8356
|
payment_id: stringType(),
|
|
8357
|
+
reason: stringType().nullable(),
|
|
7782
8358
|
remarks: stringType().nullable()
|
|
7783
8359
|
});
|
|
7784
8360
|
var LicenseKeySchema = objectType({
|
|
7785
8361
|
payload_type: literalType("LicenseKey"),
|
|
7786
|
-
activations_limit: numberType(),
|
|
8362
|
+
activations_limit: numberType().nullable(),
|
|
7787
8363
|
business_id: stringType(),
|
|
7788
8364
|
created_at: stringType().transform((d) => new Date(d)),
|
|
7789
8365
|
customer_id: stringType(),
|
|
@@ -7793,7 +8369,7 @@ var LicenseKeySchema = objectType({
|
|
|
7793
8369
|
key: stringType(),
|
|
7794
8370
|
payment_id: stringType(),
|
|
7795
8371
|
product_id: stringType(),
|
|
7796
|
-
status: enumType(["active", "
|
|
8372
|
+
status: enumType(["active", "expired", "disabled"]),
|
|
7797
8373
|
subscription_id: stringType().nullable()
|
|
7798
8374
|
});
|
|
7799
8375
|
var PaymentSucceededPayloadSchema = objectType({
|
|
@@ -7892,12 +8468,6 @@ var SubscriptionRenewedPayloadSchema = objectType({
|
|
|
7892
8468
|
timestamp: stringType().transform((d) => new Date(d)),
|
|
7893
8469
|
data: SubscriptionSchema
|
|
7894
8470
|
});
|
|
7895
|
-
var SubscriptionPausedPayloadSchema = objectType({
|
|
7896
|
-
business_id: stringType(),
|
|
7897
|
-
type: literalType("subscription.paused"),
|
|
7898
|
-
timestamp: stringType().transform((d) => new Date(d)),
|
|
7899
|
-
data: SubscriptionSchema
|
|
7900
|
-
});
|
|
7901
8471
|
var SubscriptionPlanChangedPayloadSchema = objectType({
|
|
7902
8472
|
business_id: stringType(),
|
|
7903
8473
|
type: literalType("subscription.plan_changed"),
|
|
@@ -7934,6 +8504,94 @@ var LicenseKeyCreatedPayloadSchema = objectType({
|
|
|
7934
8504
|
timestamp: stringType().transform((d) => new Date(d)),
|
|
7935
8505
|
data: LicenseKeySchema
|
|
7936
8506
|
});
|
|
8507
|
+
var CreditLedgerEntrySchema = objectType({
|
|
8508
|
+
payload_type: literalType("CreditLedgerEntry"),
|
|
8509
|
+
id: stringType(),
|
|
8510
|
+
amount: stringType(),
|
|
8511
|
+
balance_after: stringType(),
|
|
8512
|
+
balance_before: stringType(),
|
|
8513
|
+
business_id: stringType(),
|
|
8514
|
+
created_at: stringType().transform((d) => new Date(d)),
|
|
8515
|
+
credit_entitlement_id: stringType(),
|
|
8516
|
+
customer_id: stringType(),
|
|
8517
|
+
is_credit: booleanType(),
|
|
8518
|
+
overage_after: stringType(),
|
|
8519
|
+
overage_before: stringType(),
|
|
8520
|
+
transaction_type: enumType([
|
|
8521
|
+
"credit_added",
|
|
8522
|
+
"credit_deducted",
|
|
8523
|
+
"credit_expired",
|
|
8524
|
+
"credit_rolled_over",
|
|
8525
|
+
"rollover_forfeited",
|
|
8526
|
+
"overage_charged",
|
|
8527
|
+
"auto_top_up",
|
|
8528
|
+
"manual_adjustment",
|
|
8529
|
+
"refund"
|
|
8530
|
+
]),
|
|
8531
|
+
description: stringType().nullable(),
|
|
8532
|
+
grant_id: stringType().nullable(),
|
|
8533
|
+
reference_id: stringType().nullable(),
|
|
8534
|
+
reference_type: stringType().nullable()
|
|
8535
|
+
});
|
|
8536
|
+
var CreditBalanceLowSchema = objectType({
|
|
8537
|
+
payload_type: literalType("CreditBalanceLow"),
|
|
8538
|
+
customer_id: stringType(),
|
|
8539
|
+
subscription_id: stringType(),
|
|
8540
|
+
credit_entitlement_id: stringType(),
|
|
8541
|
+
credit_entitlement_name: stringType(),
|
|
8542
|
+
available_balance: stringType(),
|
|
8543
|
+
subscription_credits_amount: stringType(),
|
|
8544
|
+
threshold_percent: numberType(),
|
|
8545
|
+
threshold_amount: stringType()
|
|
8546
|
+
});
|
|
8547
|
+
var CreditAddedPayloadSchema = objectType({
|
|
8548
|
+
business_id: stringType(),
|
|
8549
|
+
type: literalType("credit.added"),
|
|
8550
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8551
|
+
data: CreditLedgerEntrySchema
|
|
8552
|
+
});
|
|
8553
|
+
var CreditDeductedPayloadSchema = objectType({
|
|
8554
|
+
business_id: stringType(),
|
|
8555
|
+
type: literalType("credit.deducted"),
|
|
8556
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8557
|
+
data: CreditLedgerEntrySchema
|
|
8558
|
+
});
|
|
8559
|
+
var CreditExpiredPayloadSchema = objectType({
|
|
8560
|
+
business_id: stringType(),
|
|
8561
|
+
type: literalType("credit.expired"),
|
|
8562
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8563
|
+
data: CreditLedgerEntrySchema
|
|
8564
|
+
});
|
|
8565
|
+
var CreditRolledOverPayloadSchema = objectType({
|
|
8566
|
+
business_id: stringType(),
|
|
8567
|
+
type: literalType("credit.rolled_over"),
|
|
8568
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8569
|
+
data: CreditLedgerEntrySchema
|
|
8570
|
+
});
|
|
8571
|
+
var CreditRolloverForfeitedPayloadSchema = objectType({
|
|
8572
|
+
business_id: stringType(),
|
|
8573
|
+
type: literalType("credit.rollover_forfeited"),
|
|
8574
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8575
|
+
data: CreditLedgerEntrySchema
|
|
8576
|
+
});
|
|
8577
|
+
var CreditOverageChargedPayloadSchema = objectType({
|
|
8578
|
+
business_id: stringType(),
|
|
8579
|
+
type: literalType("credit.overage_charged"),
|
|
8580
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8581
|
+
data: CreditLedgerEntrySchema
|
|
8582
|
+
});
|
|
8583
|
+
var CreditManualAdjustmentPayloadSchema = objectType({
|
|
8584
|
+
business_id: stringType(),
|
|
8585
|
+
type: literalType("credit.manual_adjustment"),
|
|
8586
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8587
|
+
data: CreditLedgerEntrySchema
|
|
8588
|
+
});
|
|
8589
|
+
var CreditBalanceLowPayloadSchema = objectType({
|
|
8590
|
+
business_id: stringType(),
|
|
8591
|
+
type: literalType("credit.balance_low"),
|
|
8592
|
+
timestamp: stringType().transform((d) => new Date(d)),
|
|
8593
|
+
data: CreditBalanceLowSchema
|
|
8594
|
+
});
|
|
7937
8595
|
var WebhookPayloadSchema = discriminatedUnionType("type", [
|
|
7938
8596
|
PaymentSucceededPayloadSchema,
|
|
7939
8597
|
PaymentFailedPayloadSchema,
|
|
@@ -7951,13 +8609,20 @@ var WebhookPayloadSchema = discriminatedUnionType("type", [
|
|
|
7951
8609
|
SubscriptionActivePayloadSchema,
|
|
7952
8610
|
SubscriptionOnHoldPayloadSchema,
|
|
7953
8611
|
SubscriptionRenewedPayloadSchema,
|
|
7954
|
-
SubscriptionPausedPayloadSchema,
|
|
7955
8612
|
SubscriptionPlanChangedPayloadSchema,
|
|
7956
8613
|
SubscriptionCancelledPayloadSchema,
|
|
7957
8614
|
SubscriptionFailedPayloadSchema,
|
|
7958
8615
|
SubscriptionExpiredPayloadSchema,
|
|
7959
8616
|
SubscriptionUpdatedPayloadSchema,
|
|
7960
|
-
LicenseKeyCreatedPayloadSchema
|
|
8617
|
+
LicenseKeyCreatedPayloadSchema,
|
|
8618
|
+
CreditAddedPayloadSchema,
|
|
8619
|
+
CreditDeductedPayloadSchema,
|
|
8620
|
+
CreditExpiredPayloadSchema,
|
|
8621
|
+
CreditRolledOverPayloadSchema,
|
|
8622
|
+
CreditRolloverForfeitedPayloadSchema,
|
|
8623
|
+
CreditOverageChargedPayloadSchema,
|
|
8624
|
+
CreditManualAdjustmentPayloadSchema,
|
|
8625
|
+
CreditBalanceLowPayloadSchema
|
|
7961
8626
|
]);
|
|
7962
8627
|
|
|
7963
8628
|
// ../../node_modules/@stablelib/base64/lib/base64.js
|
|
@@ -8685,9 +9350,6 @@ async function handleWebhookPayload(payload, config, context) {
|
|
|
8685
9350
|
if (payload.type === "subscription.renewed") {
|
|
8686
9351
|
await callHandler(config.onSubscriptionRenewed, payload);
|
|
8687
9352
|
}
|
|
8688
|
-
if (payload.type === "subscription.paused") {
|
|
8689
|
-
await callHandler(config.onSubscriptionPaused, payload);
|
|
8690
|
-
}
|
|
8691
9353
|
if (payload.type === "subscription.plan_changed") {
|
|
8692
9354
|
await callHandler(config.onSubscriptionPlanChanged, payload);
|
|
8693
9355
|
}
|
|
@@ -8706,6 +9368,30 @@ async function handleWebhookPayload(payload, config, context) {
|
|
|
8706
9368
|
if (payload.type === "license_key.created") {
|
|
8707
9369
|
await callHandler(config.onLicenseKeyCreated, payload);
|
|
8708
9370
|
}
|
|
9371
|
+
if (payload.type === "credit.added") {
|
|
9372
|
+
await callHandler(config.onCreditAdded, payload);
|
|
9373
|
+
}
|
|
9374
|
+
if (payload.type === "credit.deducted") {
|
|
9375
|
+
await callHandler(config.onCreditDeducted, payload);
|
|
9376
|
+
}
|
|
9377
|
+
if (payload.type === "credit.expired") {
|
|
9378
|
+
await callHandler(config.onCreditExpired, payload);
|
|
9379
|
+
}
|
|
9380
|
+
if (payload.type === "credit.rolled_over") {
|
|
9381
|
+
await callHandler(config.onCreditRolledOver, payload);
|
|
9382
|
+
}
|
|
9383
|
+
if (payload.type === "credit.rollover_forfeited") {
|
|
9384
|
+
await callHandler(config.onCreditRolloverForfeited, payload);
|
|
9385
|
+
}
|
|
9386
|
+
if (payload.type === "credit.overage_charged") {
|
|
9387
|
+
await callHandler(config.onCreditOverageCharged, payload);
|
|
9388
|
+
}
|
|
9389
|
+
if (payload.type === "credit.manual_adjustment") {
|
|
9390
|
+
await callHandler(config.onCreditManualAdjustment, payload);
|
|
9391
|
+
}
|
|
9392
|
+
if (payload.type === "credit.balance_low") {
|
|
9393
|
+
await callHandler(config.onCreditBalanceLow, payload);
|
|
9394
|
+
}
|
|
8709
9395
|
}
|
|
8710
9396
|
|
|
8711
9397
|
const Webhooks = ({ webhookKey, ...eventHandlers }) => {
|
|
@@ -8755,14 +9441,19 @@ const CustomerPortal = ({ bearerToken, environment, }) => {
|
|
|
8755
9441
|
const getHandler = async (request, reply) => {
|
|
8756
9442
|
// Extract customerId from query parameters
|
|
8757
9443
|
const { customer_id: customerId, send_email } = request.query;
|
|
8758
|
-
|
|
8759
|
-
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
}
|
|
8765
|
-
if (
|
|
9444
|
+
// Normalize customer_id to string (handle array case)
|
|
9445
|
+
const customerIdValue = customerId
|
|
9446
|
+
? Array.isArray(customerId)
|
|
9447
|
+
? customerId[0]
|
|
9448
|
+
: customerId
|
|
9449
|
+
: undefined;
|
|
9450
|
+
const params = {};
|
|
9451
|
+
if (send_email !== undefined) {
|
|
9452
|
+
// Normalize to string (handle array case)
|
|
9453
|
+
const sendEmailValue = Array.isArray(send_email) ? send_email[0] : send_email;
|
|
9454
|
+
params.send_email = sendEmailValue === "true";
|
|
9455
|
+
}
|
|
9456
|
+
if (!customerIdValue) {
|
|
8766
9457
|
return reply.status(400).send("Missing customerId in query parameters");
|
|
8767
9458
|
}
|
|
8768
9459
|
const dodopayments = new DodoPayments({
|
|
@@ -8770,7 +9461,7 @@ const CustomerPortal = ({ bearerToken, environment, }) => {
|
|
|
8770
9461
|
environment,
|
|
8771
9462
|
});
|
|
8772
9463
|
try {
|
|
8773
|
-
const session = await dodopayments.customers.customerPortal.create(
|
|
9464
|
+
const session = await dodopayments.customers.customerPortal.create(customerIdValue, params);
|
|
8774
9465
|
return reply.redirect(session.link);
|
|
8775
9466
|
}
|
|
8776
9467
|
catch (error) {
|