orb-billing
Version:
The official TypeScript library for the Orb API
129 lines • 5.84 kB
JavaScript
;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
Object.defineProperty(exports, "__esModule", { value: true });
exports.InvoicesPage = exports.InvoiceListSummaryResponsesPage = exports.Invoices = void 0;
const resource_1 = require("../resource.js");
const core_1 = require("../core.js");
const shared_1 = require("./shared.js");
Object.defineProperty(exports, "InvoicesPage", { enumerable: true, get: function () { return shared_1.InvoicesPage; } });
const pagination_1 = require("../pagination.js");
/**
* An [`Invoice`](/core-concepts#invoice) is a fundamental billing entity, representing the request for payment for
* a single subscription. This includes a set of line items, which correspond to prices in the subscription's plan and
* can represent fixed recurring fees or usage-based fees. They are generated at the end of a billing period, or as
* the result of an action, such as a cancellation.
*/
class Invoices extends resource_1.APIResource {
/**
* This endpoint is used to create a one-off invoice for a customer.
*/
create(body, options) {
return this._client.post('/invoices', { body, ...options });
}
/**
* This endpoint allows you to update the `metadata`, `net_terms`, `due_date`,
* `invoice_date`, and `auto_collection` properties on an invoice. If you pass null
* for the metadata value, it will clear any existing metadata for that invoice.
*
* `metadata` can be modified regardless of invoice state. `net_terms`, `due_date`,
* `invoice_date`, and `auto_collection` can only be modified if the invoice is in
* a `draft` state. `invoice_date` can only be modified for non-subscription
* invoices.
*/
update(invoiceId, body, options) {
return this._client.put(`/invoices/${invoiceId}`, { body, ...options });
}
list(query = {}, options) {
if ((0, core_1.isRequestOptions)(query)) {
return this.list({}, query);
}
return this._client.getAPIList('/invoices', shared_1.InvoicesPage, { query, ...options });
}
/**
* This endpoint deletes an invoice line item from a draft invoice.
*
* This endpoint only allows deletion of one-off line items (not subscription-based
* line items). The invoice must be in a draft status for this operation to
* succeed.
*/
deleteLineItem(invoiceId, lineItemId, options) {
return this._client.delete(`/invoices/${invoiceId}/invoice_line_items/${lineItemId}`, {
...options,
headers: { Accept: '*/*', ...options?.headers },
});
}
/**
* This endpoint is used to fetch an [`Invoice`](/core-concepts#invoice) given an
* identifier.
*/
fetch(invoiceId, options) {
return this._client.get(`/invoices/${invoiceId}`, options);
}
/**
* This endpoint can be used to fetch the upcoming
* [invoice](/core-concepts#invoice) for the current billing period given a
* subscription.
*/
fetchUpcoming(query, options) {
return this._client.get('/invoices/upcoming', { query, ...options });
}
issue(invoiceId, body = {}, options) {
if ((0, core_1.isRequestOptions)(body)) {
return this.issue(invoiceId, {}, body);
}
return this._client.post(`/invoices/${invoiceId}/issue`, { body, ...options });
}
issueSummary(invoiceId, body = {}, options) {
if ((0, core_1.isRequestOptions)(body)) {
return this.issueSummary(invoiceId, {}, body);
}
return this._client.post(`/invoices/summary/${invoiceId}/issue`, { body, ...options });
}
listSummary(query = {}, options) {
if ((0, core_1.isRequestOptions)(query)) {
return this.listSummary({}, query);
}
return this._client.getAPIList('/invoices/summary', InvoiceListSummaryResponsesPage, {
query,
...options,
});
}
/**
* This endpoint allows an invoice's status to be set to the `paid` status. This
* can only be done to invoices that are in the `issued` or `synced` status.
*/
markPaid(invoiceId, body, options) {
return this._client.post(`/invoices/${invoiceId}/mark_paid`, { body, ...options });
}
/**
* This endpoint collects payment for an invoice. By default, it uses the
* customer's default payment method. Optionally, a shared payment token (SPT) can
* be provided to pay using agent-granted credentials instead. This action can only
* be taken on invoices with status "issued".
*/
pay(invoiceId, body, options) {
return this._client.post(`/invoices/${invoiceId}/pay`, { body, ...options });
}
/**
* This endpoint allows an invoice's status to be set to the `void` status. This
* can only be done to invoices that are in the `issued` status.
*
* If the associated invoice has used the customer balance to change the amount
* due, the customer balance operation will be reverted. For example, if the
* invoice used \$10 of customer balance, that amount will be added back to the
* customer balance upon voiding.
*
* If the invoice was used to purchase a credit block, but the invoice is not yet
* paid, the credit block will be voided. If the invoice was created due to a
* top-up, the top-up will be disabled.
*/
void(invoiceId, options) {
return this._client.post(`/invoices/${invoiceId}/void`, options);
}
}
exports.Invoices = Invoices;
class InvoiceListSummaryResponsesPage extends pagination_1.Page {
}
exports.InvoiceListSummaryResponsesPage = InvoiceListSummaryResponsesPage;
Invoices.InvoiceListSummaryResponsesPage = InvoiceListSummaryResponsesPage;
//# sourceMappingURL=invoices.js.map