UNPKG

orb-billing

Version:

The official TypeScript library for the Orb API

181 lines 9.31 kB
"use strict"; // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. Object.defineProperty(exports, "__esModule", { value: true }); exports.Customers = void 0; const tslib_1 = require("../../internal/tslib.js"); const resource_1 = require("../../core/resource.js"); const BalanceTransactionsAPI = tslib_1.__importStar(require("./balance-transactions.js")); const balance_transactions_1 = require("./balance-transactions.js"); const CostsAPI = tslib_1.__importStar(require("./costs.js")); const costs_1 = require("./costs.js"); const CreditsAPI = tslib_1.__importStar(require("./credits/credits.js")); const credits_1 = require("./credits/credits.js"); const pagination_1 = require("../../core/pagination.js"); const headers_1 = require("../../internal/headers.js"); const path_1 = require("../../internal/utils/path.js"); /** * A customer is a buyer of your products, and the other party to the billing relationship. * * In Orb, customers are assigned system generated identifiers automatically, but it's often desirable to have these * match existing identifiers in your system. To avoid having to denormalize Orb ID information, you can pass in an * `external_customer_id` with your own identifier. See * [Customer ID Aliases](/events-and-metrics/customer-aliases) for further information about how these * aliases work in Orb. * * In addition to having an identifier in your system, a customer may exist in a payment provider solution like * Stripe. Use the `payment_provider_id` and the `payment_provider` enum field to express this mapping. * * A customer also has a timezone (from the standard [IANA timezone database](https://www.iana.org/time-zones)), which * defaults to your account's timezone. See [Timezone localization](/essentials/timezones) for * information on what this timezone parameter influences within Orb. */ class Customers extends resource_1.APIResource { constructor() { super(...arguments); this.costs = new CostsAPI.Costs(this._client); this.credits = new CreditsAPI.Credits(this._client); this.balanceTransactions = new BalanceTransactionsAPI.BalanceTransactions(this._client); } /** * This operation is used to create an Orb customer, who is party to the core * billing relationship. See [Customer](/core-concepts##customer) for an overview * of the customer resource. * * This endpoint is critical in the following Orb functionality: * * - Automated charges can be configured by setting `payment_provider` and * `payment_provider_id` to automatically issue invoices * - [Customer ID Aliases](/events-and-metrics/customer-aliases) can be configured * by setting `external_customer_id` * - [Timezone localization](/essentials/timezones) can be configured on a * per-customer basis by setting the `timezone` parameter */ create(body, options) { return this._client.post('/customers', { body, ...options }); } /** * This endpoint can be used to update the `payment_provider`, * `payment_provider_id`, `name`, `email`, `email_delivery`, `tax_id`, * `auto_collection`, `metadata`, `shipping_address`, `billing_address`, * `additional_emails`, and `currency` of an existing customer. `currency` can only * be set if it has not already been set on the customer. Other fields on a * customer are currently immutable. */ update(customerID, body, options) { return this._client.put((0, path_1.path) `/customers/${customerID}`, { body, ...options }); } /** * This endpoint returns a list of all customers for an account. The list of * customers is ordered starting from the most recently created customer. This * endpoint follows Orb's * [standardized pagination format](/api-reference/pagination). * * See [Customer](/core-concepts##customer) for an overview of the customer model. */ list(query = {}, options) { return this._client.getAPIList('/customers', (pagination_1.Page), { query, ...options }); } /** * This performs a deletion of this customer, its subscriptions, and its invoices, * provided the customer does not have any issued invoices. Customers with issued * invoices cannot be deleted. This operation is irreversible. Note that this is a * _soft_ deletion, but the data will be inaccessible through the API and Orb * dashboard. * * For a hard-deletion, please reach out to the Orb team directly. * * **Note**: This operation happens asynchronously and can be expected to take a * few minutes to propagate to related resources. However, querying for the * customer on subsequent GET requests while deletion is in process will reflect * its deletion. */ delete(customerID, options) { return this._client.delete((0, path_1.path) `/customers/${customerID}`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]), }); } /** * Creates a portal session for the customer, returning a short-lived URL that * provides authenticated access to the customer's billing portal. The session * expires after `expires_in_minutes` (default 60, max 180). By default, creating a * new session invalidates any other active portal sessions for the customer; pass * `invalidate_existing=false` to allow concurrent sessions. */ createPortalSession(customerID, body, options) { return this._client.post((0, path_1.path) `/customers/${customerID}/portal_sessions`, { body, ...options }); } /** * Creates a portal session for the customer, returning a short-lived URL that * provides authenticated access to the customer's billing portal. The session * expires after `expires_in_minutes` (default 60, max 180). By default, creating a * new session invalidates any other active portal sessions for the customer; pass * `invalidate_existing=false` to allow concurrent sessions. */ createPortalSessionByExternalID(externalCustomerID, body, options) { return this._client.post((0, path_1.path) `/customers/external_customer_id/${externalCustomerID}/portal_sessions`, { body, ...options, }); } /** * This endpoint is used to fetch customer details given an identifier. If the * `Customer` is in the process of being deleted, only the properties `id` and * `deleted: true` will be returned. * * See the [Customer resource](/core-concepts#customer) for a full discussion of * the Customer model. */ fetch(customerID, options) { return this._client.get((0, path_1.path) `/customers/${customerID}`, options); } /** * This endpoint is used to fetch customer details given an `external_customer_id` * (see [Customer ID Aliases](/events-and-metrics/customer-aliases)). * * Note that the resource and semantics of this endpoint exactly mirror * [Get Customer](fetch-customer). */ fetchByExternalID(externalCustomerID, options) { return this._client.get((0, path_1.path) `/customers/external_customer_id/${externalCustomerID}`, options); } /** * Sync Orb's payment methods for the customer with their gateway. * * This method can be called before taking an action that may cause the customer to * be charged, ensuring that the most up-to-date payment method is charged. * * **Note**: This functionality is currently only available for Stripe. */ syncPaymentMethodsFromGateway(customerID, options) { return this._client.post((0, path_1.path) `/customers/${customerID}/sync_payment_methods_from_gateway`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]), }); } /** * Sync Orb's payment methods for the customer with their gateway. * * This method can be called before taking an action that may cause the customer to * be charged, ensuring that the most up-to-date payment method is charged. * * **Note**: This functionality is currently only available for Stripe. */ syncPaymentMethodsFromGatewayByExternalCustomerID(externalCustomerID, options) { return this._client.post((0, path_1.path) `/customers/external_customer_id/${externalCustomerID}/sync_payment_methods_from_gateway`, { ...options, headers: (0, headers_1.buildHeaders)([{ Accept: '*/*' }, options?.headers]) }); } /** * This endpoint is used to update customer details given an `external_customer_id` * (see [Customer ID Aliases](/events-and-metrics/customer-aliases)). Note that the * resource and semantics of this endpoint exactly mirror * [Update Customer](update-customer). */ updateByExternalID(id, body, options) { return this._client.put((0, path_1.path) `/customers/external_customer_id/${id}`, { body, ...options }); } } exports.Customers = Customers; Customers.Costs = costs_1.Costs; Customers.Credits = credits_1.Credits; Customers.BalanceTransactions = balance_transactions_1.BalanceTransactions; //# sourceMappingURL=customers.js.map