-
Notifications
You must be signed in to change notification settings - Fork 30
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.
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 nowapiKey
. - Minimum Node.js version is 18
- Class based models are replaced with TypeScript types.
- Response will contain
headers
instead ofresponseHeaders
. - Response will contain
isIdempotencyReplayed
field instead ofisIdempotencyReplayed()
method.
npm install chargebee@^3
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}}"
});
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();
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
});
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
}
);
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.