balena-sdk
Version:
The Balena JavaScript SDK
323 lines (322 loc) • 10.7 kB
TypeScript
import type { BalenaRequestStreamResult } from 'balena-request';
import type { InjectedDependenciesParam, InjectedOptionsParam } from '..';
export interface BillingAccountAddressInfo {
address1: string;
address2: string;
city: string;
state: string;
zip: string;
country: string;
phone: string;
}
export interface AccountInfo {
email?: string;
account_state: string;
company_name?: string;
address: {
address1?: string;
address2?: string;
city?: string;
state?: string;
zip?: string;
country?: string;
phone?: string;
};
tax_id?: {
type: string;
value: string;
} | null;
}
export type BillingInfoType = 'bank_account' | 'credit_card' | 'paypal' | 'card' | 'link' | 'cashapp' | 'sepa_debit' | 'us_bank_account';
export interface BillingInfo {
full_name: string;
first_name: string;
last_name: string;
company: string;
vat_number: string;
address1: string;
address2: string;
city: string;
state: string;
zip: string;
country: string;
phone: string;
type?: BillingInfoType;
}
export interface CardBillingInfo extends BillingInfo {
card_type: string;
year: string;
month: string;
first_one: string;
last_four: string;
}
export interface BankAccountBillingInfo extends BillingInfo {
account_type: string;
last_four: string;
name_on_account: string;
routing_number: string;
}
export interface TokenBillingSubmitInfo {
token_id: string;
'g-recaptcha-response'?: string;
token_type?: 'payment_method' | 'setup_intent';
setAsCompanyAddress?: boolean;
}
export interface BillingPlanInfo {
name: string;
title: string;
code: string;
tier: string;
currentPeriodEndDate?: string;
intervalUnit?: string;
intervalLength?: string;
addonPlan?: BillingAddonPlanInfo;
billing: BillingPlanBillingInfo;
support: {
name: string;
title: string;
};
}
export interface BillingAddonPlanInfo {
code: string;
currentPeriodEndDate?: string;
billing: BillingPlanBillingInfo;
addOns: Array<{
code: string;
unitCostCents?: string;
quantity?: string;
}>;
}
export interface BillingPlanBillingInfo {
currency: string;
totalCostCents: string;
charges: Array<{
itemType: string;
name: string;
code: string;
unitCostCents: string;
quantity: string;
isQuantifiable?: boolean;
}>;
}
type BillingV1InvoiceState = 'pending' | 'paid' | 'failed' | 'past_due' | 'open' | 'closed' | 'voided' | 'processing';
type BillingV2InvoiceState = 'draft' | 'open' | 'paid' | 'uncollectible' | 'void';
export interface InvoiceInfo {
closed_at: string;
created_at: string;
due_on: string;
currency: string;
invoice_number: string;
subtotal_in_cents: string;
total_in_cents: string;
uuid: string;
state: BillingV1InvoiceState | BillingV2InvoiceState;
}
export interface PlanChangeOptions {
tier: string;
cycle: 'monthly' | 'annual';
planChangeReason?: string;
}
declare const getBillingModel: ({ request, sdkInstance, }: InjectedDependenciesParam, { apiUrl, isBrowser }: InjectedOptionsParam) => {
/**
* @summary Get the user's billing account
* @name getAccount
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @fulfil {Object} - billing account
* @returns {Promise}
*
* @example
* balena.models.billing.getAccount(orgId).then(function(billingAccount) {
* console.log(billingAccount);
* });
*/
getAccount: (organization: string | number) => Promise<AccountInfo>;
/**
* @summary Get the current billing plan
* @name getPlan
* @public
* @function
* @memberof balena.models.billing
*
* @fulfil {Object} - billing plan
* @returns {Promise}
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @example
* balena.models.billing.getPlan(orgId).then(function(billingPlan) {
* console.log(billingPlan);
* });
*/
getPlan: (organization: string | number) => Promise<BillingPlanInfo>;
/**
* @summary Get the current billing information
* @name getBillingInfo
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @fulfil {Object} - billing information
* @returns {Promise}
*
* @example
* balena.models.billing.getBillingInfo(orgId).then(function(billingInfo) {
* console.log(billingInfo);
* });
*/
getBillingInfo: (organization: string | number) => Promise<BillingInfo>;
/**
* @summary Create a Stripe setup intent required for setting billing information
* @name createSetupIntent
* @public
* @function
* @memberof balena.models.billing
*
* @param {Object} setupIntentParams - an object containing the parameters for the setup intent creation
* @param {(String|Number)} extraParams.organization - handle (string) or id (number) of the target organization.
* @param {(String|undefined)} [extraParams.'g-recaptcha-response'] - the captcha response
*
* @fulfil {Object} - partial stripe setup intent object
* @returns {Promise}
*
* @example
* balena.models.billing.createSetupIntent(orgId).then(function(setupIntent) {
* console.log(setupIntent);
* });
*/
createSetupIntent: ({ organization, ...extraParams }: {
organization: string | number;
"g-recaptcha-response"?: string;
}) => Promise<{
id: string;
client_secret: string;
}>;
/**
* @summary Update the current billing information
* @name updateBillingInfo
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
* @param {Object} billingInfo - an object containing a billing info token_id
*
* @param {String} billingInfo.token_id - the token id generated for the billing info form
* @param {(String|undefined)} [billingInfo.'g-recaptcha-response'] - the captcha response
* @param {(String|undefined)} [billingInfo.token_type] - token type
* @fulfil {Object} - billing information
* @returns {Promise}
*
* @example
* balena.models.billing.updateBillingInfo(orgId, { token_id: 'xxxxxxx' }).then(function(billingInfo) {
* console.log(billingInfo);
* });
*/
updateBillingInfo: (organization: string | number, billingInfo: TokenBillingSubmitInfo) => Promise<BillingInfo>;
/**
* @summary Remove an organization's billing information
* @name removeBillingInfo
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @returns {Promise}
*
* @example
* balena.models.billing.removeBillingInfo(orgId).then(function() {
* console.log("Success");
* });
*/
removeBillingInfo: (organization: string | number) => Promise<BillingInfo>;
/**
* @summary Update the current billing account information
* @name updateAccountInfo
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
* @param {AccountInfo} accountInfo - an object containing billing account info
*
* @example
* balena.models.billing.updateAccountInfo(orgId, { email: 'hello@balena.io' })
*
* @example
* balena.models.billing.updateAccountInfo(orgId, { email: 'hello@balena.io' })
*/
updateAccountInfo: (organization: string | number, accountInfo: Partial<AccountInfo>) => Promise<void>;
/**
* @summary Change the current billing plan
* @name changePlan
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
* @param {Object} planChangeOptions - an object containing the billing plan change options
*
* @param {String} billingInfo.tier - the code of the target billing plan
* @param {String} billingInfo.cycle - the billing cycle
* @param {String} [billingInfo.planChangeReason] - the reason for changing the current plan
*
* @returns {Promise}
*
* @example
* balena.models.billing.changePlan(orgId, { billingCode: 'prototype-v2', cycle: 'annual' }).then(function() {
* console.log('Plan changed!');
* });
*/
changePlan: (organization: string | number, { cycle, ...restPlanChangeOptions }: PlanChangeOptions) => Promise<void>;
/**
* @summary Get the available invoices
* @name getInvoices
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
*
* @fulfil {Object} - invoices
* @returns {Promise}
*
* @example
* balena.models.billing.getInvoices(orgId).then(function(invoices) {
* console.log(invoices);
* });
*/
getInvoices: (organization: string | number) => Promise<InvoiceInfo[]>;
/**
* @summary Download a specific invoice
* @name downloadInvoice
* @public
* @function
* @memberof balena.models.billing
*
* @param {(String|Number)} organization - handle (string) or id (number) of the target organization.
* @param {String} - an invoice number
*
* @fulfil {Blob|ReadableStream} - blob on the browser, download stream on node
* @returns {Promise}
*
* @example
* # Browser
* balena.models.billing.downloadInvoice(orgId, '0000').then(function(blob) {
* console.log(blob);
* });
* # Node
* balena.models.billing.downloadInvoice(orgId, '0000').then(function(stream) {
* stream.pipe(fs.createWriteStream('foo/bar/invoice-0000.pdf'));
* });
*/
downloadInvoice(organization: string | number, invoiceNumber: string): Promise<Blob | BalenaRequestStreamResult>;
};
export default getBillingModel;