Skip to content

Migration guide for v3

Sriram Thiagarajan edited this page Nov 14, 2024 · 2 revisions

This guide walks you through the changes to be done when migrating from chargebee-typescript v2.x or chargebee v2.x to chargebee v3.x.

Breaking changes

Here's the list of breaking changes between in v3

  • Names of the resources, operations etc. have been changed from snake_case to camelCase. For example, configuration option api_key is now apiKey.
  • Minimum Node.js version is 18
  • Class based models are replaced with TypeScript types.
  • Response will contain headers instead of responseHeaders.
  • Response will contain isIdempotencyReplayed field instead of isIdempotencyReplayed() method.

Upgrade to v3

npm install chargebee@^3

Code samples

Instantiation

Main export is renamed from ChargeBee to Chargebee. Config options need to be passed during instantiation rather than calling the configure function.

Before:

import { ChargeBee } from "chargebee-typescript";
const chargebee = new ChargeBee();

chargebee.configure({
  site: "{{site}}",
  api_key: "{{api-key}}"
});

After:

import Chargebee from "chargebee";

const chargebee = new Chargebee({
  site: "{{site}}",
  apiKey: "{{api-key}}"
});

Making requests

Trailing .request() method has been removed and calling the any operation function will make the API request directly.

Before:

const response = await chargebee.customer.list().request();

After:

const response = await chargebee.customer.list();

Configuring request timeout

Before:

import { ChargeBee } from "chargebee-typescript";
const chargebee = new ChargeBee();

chargebee.configure({
  site: "{site}",
  api_key: "{site_api_key}"
});
chargebee.updateRequestTimeoutInMillis(500);

After:

import Chargebee from "chargebee";

const chargebee = new Chargebee({
  site: "{{site}}",
  apiKey: "{{api-key}}",
  timeout: 500
});

Using custom headers and custom fields

Before:

const customer = chargebee.customer
  .create()
  .headers({ "some-headers-key": "some-headers-value" })
  .request();

After:

const { customer } = await chargebee.customer.create(
  {
    email: "[email protected]",
    cf_host_url: "http://xyz.com" // `cf_host_url` is a custom field in Customer object
  },
  {
    "chargebee-event-email": "all-disabled" // Header To disable webhooks
  }
);

Multiple instances of Chargebee

Before:

import { ChargeBee } from "chargebee-typescript";
const chargebee = new ChargeBee();

const response = await chargebee.customer.list().request(null, {
  site: "merchant-us"
});

const response = await chargebee.customer.list().request(null, {
  site: "merchant-eu"
});

After:

const chargebeeSiteUS = new Chargebee({
  apiKey: "{api-key}",
  site: "my-site-us"
});

const chargebeeSiteEU = new Chargebee({
  apiKey: "{api-key}",
  site: "my-site-eu"
});

Take a look at the README for more code samples.