Subscriptions

March 12, 2025 ยท View on GitHub

(subscriptions)

Overview

Available Operations

create

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.create({
    status: "past_due",
    currencyCode: "NZD",
    customerId: "<id>",
    addressId: "<id>",
    items: [
      {
        priceId: "<id>",
        quantity: "<value>",
      },
    ],
    billingDetails: {
      paymentTerms: {
        paymentInterval: "day",
        paymentFrequency: 690.25,
      },
      enableCheckout: false,
      additionalInformation: "<value>",
      purchaseOrderNumber: "<value>",
    },
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsCreate } from "open-billing/funcs/subscriptionsCreate.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsCreate(openBilling, {
    status: "past_due",
    currencyCode: "NZD",
    customerId: "<id>",
    addressId: "<id>",
    items: [
      {
        priceId: "<id>",
        quantity: "<value>",
      },
    ],
    billingDetails: {
      paymentTerms: {
        paymentInterval: "day",
        paymentFrequency: 690.25,
      },
      enableCheckout: false,
      additionalInformation: "<value>",
      purchaseOrderNumber: "<value>",
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionCreateRequestBody:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionCreateResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionCreateResponseBody400application/json
errors.APIError4XX, 5XX*/*

list

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.list({});

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsList } from "open-billing/funcs/subscriptionsList.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsList(openBilling, {});

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionListRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionListResponseBody[]>

Errors

Error TypeStatus CodeContent Type
errors.APIError4XX, 5XX*/*

cancel

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.cancel({
    subscriptionId: "<id>",
    requestBody: {},
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsCancel } from "open-billing/funcs/subscriptionsCancel.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsCancel(openBilling, {
    subscriptionId: "<id>",
    requestBody: {},
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionCancelSubscriptionRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionCancelSubscriptionResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionCancelSubscriptionResponseBody400application/json
errors.SubscriptionCancelSubscriptionSubscriptionsResponseBody404application/json
errors.APIError4XX, 5XX*/*

pause

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.pause({
    subscriptionId: "<id>",
    requestBody: {
      onResume: "continue_existing_billing_period",
    },
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsPause } from "open-billing/funcs/subscriptionsPause.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsPause(openBilling, {
    subscriptionId: "<id>",
    requestBody: {
      onResume: "continue_existing_billing_period",
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionPauseSubscriptionRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionPauseSubscriptionResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionPauseSubscriptionResponseBody400application/json
errors.SubscriptionPauseSubscriptionSubscriptionsResponseBody404application/json
errors.SubscriptionPauseSubscriptionSubscriptionsResponseResponseBody409application/json
errors.APIError4XX, 5XX*/*

resume

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.resume({
    subscriptionId: "<id>",
    requestBody: {},
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsResume } from "open-billing/funcs/subscriptionsResume.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsResume(openBilling, {
    subscriptionId: "<id>",
    requestBody: {},
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionResumeSubscriptionRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionResumeSubscriptionResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionResumeSubscriptionResponseBody400application/json
errors.SubscriptionResumeSubscriptionSubscriptionsResponseBody404application/json
errors.APIError4XX, 5XX*/*

activate

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.activate({
    subscriptionId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsActivate } from "open-billing/funcs/subscriptionsActivate.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsActivate(openBilling, {
    subscriptionId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionActivateSubscriptionRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionActivateSubscriptionResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionActivateSubscriptionResponseBody400application/json
errors.SubscriptionActivateSubscriptionSubscriptionsResponseBody404application/json
errors.APIError4XX, 5XX*/*

update

Example Usage

import { OpenBilling } from "open-billing";

const openBilling = new OpenBilling({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const result = await openBilling.subscriptions.update({
    subscriptionId: "<id>",
    requestBody: {},
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { OpenBillingCore } from "open-billing/core.js";
import { subscriptionsUpdate } from "open-billing/funcs/subscriptionsUpdate.js";

// Use `OpenBillingCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const openBilling = new OpenBillingCore({
  security: {
    bearer: process.env["OPENBILLING_BEARER"] ?? "",
    organizationId: process.env["OPENBILLING_ORGANIZATION_ID"] ?? "",
  },
});

async function run() {
  const res = await subscriptionsUpdate(openBilling, {
    subscriptionId: "<id>",
    requestBody: {},
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

ParameterTypeRequiredDescription
requestoperations.SubscriptionUpdateSubscriptionRequest:heavy_check_mark:The request object to use for the request.
optionsRequestOptions:heavy_minus_sign:Used to set various options for making HTTP requests.
options.fetchOptionsRequestInit:heavy_minus_sign:Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retriesRetryConfig:heavy_minus_sign:Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.SubscriptionUpdateSubscriptionResponseBody>

Errors

Error TypeStatus CodeContent Type
errors.SubscriptionUpdateSubscriptionResponseBody400application/json
errors.SubscriptionUpdateSubscriptionSubscriptionsResponseBody404application/json
errors.APIError4XX, 5XX*/*