chargebee
Advanced tools
Comparing version 2.25.3 to 2.26.0
@@ -14,3 +14,3 @@ var ChargeBee = {}; | ||
timeout: 80000, | ||
clientVersion: 'v2.25.3', | ||
clientVersion: 'v2.26.0', | ||
port: 443, | ||
@@ -17,0 +17,0 @@ timemachineWaitInMillis: 3000, |
{ | ||
"name":"chargebee", | ||
"version":"2.25.3", | ||
"version":"2.26.0", | ||
"description":"A library for integrating with ChargeBee.", | ||
@@ -5,0 +5,0 @@ "keywords":[ |
104
README.md
@@ -1,2 +0,2 @@ | ||
# Chargebee Node Client Library - API V2 | ||
# Chargebee Node.js Client Library | ||
@@ -9,3 +9,3 @@ [![npm](https://img.shields.io/npm/v/chargebee.svg?maxAge=3)](https://www.npmjs.com/package/chargebee) | ||
> **Note** | ||
> Chargebee now supports two API versions - [V1](https://apidocs.chargebee.com/docs/api/v1) and [V2](https://apidocs.chargebee.com/docs/api), of which V2 is the latest release and all future developments will happen in V2. This library is for <b>API version V2</b>. If you’re looking for V1, head to [chargebee-v1 branch](https://github.com/chargebee/chargebee-node/tree/chargebee-v1). | ||
> If you’re using [API V1](https://apidocs.chargebee.com/docs/api/v1), head to [chargebee-v1 branch](https://github.com/chargebee/chargebee-node/tree/chargebee-v1). | ||
@@ -30,13 +30,28 @@ ## Requirements | ||
The package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer [here](https://www.chargebee.com/docs/2.0/api_keys.html) for more details. | ||
The package needs to be configured with your site's API key, which is available under Configure Chargebee Section. Refer [here](https://www.chargebee.com/docs/2.0/api_keys.html) for more details. | ||
The full documentation can be found on the Chargebee API Docs: [https://apidocs.chargebee.com/docs/api?lang=node](https://apidocs.chargebee.com/docs/api?lang=node) | ||
```js | ||
var chargebee = require('chargebee'); | ||
const chargebee = require('chargebee'); | ||
chargebee.configure({ | ||
site: 'YOUR_SITE_NAME', | ||
api_key: 'YOUR_API_KEY', | ||
site: '<YOUR_SITE_NAME>', | ||
api_key: '<YOUR_API_KEY>', | ||
}); | ||
``` | ||
Or using ES modules, | ||
```js | ||
import chargebee from 'chargebee'; | ||
chargebee.configure({ | ||
site: '<YOUR_SITE_NAME>', | ||
api_key: '<YOUR_API_KEY>', | ||
}); | ||
``` | ||
### Using Async / Await | ||
@@ -94,46 +109,30 @@ | ||
### Accessing the response object | ||
### Usage with TypeScript | ||
The response object returned by the `request()` method is generic response wrapper. You need to access the resource from it. For example, | ||
You can import the types as shown below. | ||
- To access customer object. | ||
```ts | ||
import chargebee, { Customer } from 'chargebee'; | ||
```js | ||
const result = await chargebee.customer.create({ email: 'john@test.com' }).request(); | ||
console.log(result.customer); | ||
``` | ||
chargebee.configure({ | ||
site: '<YOUR_SITE_NAME>', | ||
api_key: '<YOUR_API_KEY>', | ||
}); | ||
Other resources can be accessed by the same approach. For subscription, it will be `result.subscription` | ||
const createCustomer = async () => { | ||
const inputParams: Customer.CreateInputParam = { | ||
email: 'john@test.com', | ||
first_name: 'John', | ||
last_name: 'Doe', | ||
}; | ||
- To access list response. | ||
const { customer } = await chargebee.customer.create(inputParams).request(); | ||
console.log(customer); | ||
}; | ||
```js | ||
const result = await chargebee.subscription | ||
.list({ | ||
/* params */ | ||
}) | ||
.request(); | ||
// A list of Subscription objects | ||
console.log(result.list.map((obj) => obj.subscription)); | ||
createCustomer(); | ||
``` | ||
**Note** | ||
### Using filters in the List API | ||
If you have a `result` (or children further down the line) and are unsure what properties are available, you can use `Object.keys` to get a list of available accessor properties. Using `Object.keys` in the previous example would yield | ||
```js | ||
// ['list', 'next_offset'] | ||
console.log(Object.keys(result)); | ||
// ['1', '2', '3'], e.g. `result.list` is an array with 3 entries | ||
console.log(Object.keys(result.list)); | ||
// ['activated_at', 'base_currency_code', ...] | ||
// ['activated_at', 'base_currency_code', ...] | ||
// ['activated_at', 'base_currency_code', ...] | ||
// Which means we've reached the bottom and should have all the information available from this request | ||
console.log(result.list.map((obj) => obj.subscription)); | ||
``` | ||
#### Using filters in the List API | ||
For pagination: `offset` is the parameter that is being used. The value used for this parameter must be the value returned for `next_offset` parameter in the previous API call. | ||
@@ -168,3 +167,3 @@ | ||
#### Using custom headers and custom fields: | ||
### Using custom headers and custom fields: | ||
@@ -185,3 +184,3 @@ ```js | ||
### Create an idempotent request | ||
### Creating an idempotent request | ||
@@ -216,2 +215,15 @@ [Idempotency keys](https://apidocs.chargebee.com/docs/api/idempotency?prod_cat_ver=2) are passed along with request headers to allow a safe retry of POST requests. | ||
### Passing API Keys at request level | ||
```js | ||
const newCust = await chargebee.customer.create({ | ||
email: 'john@test.com', | ||
first_name: 'John', | ||
last_name: 'Doe' | ||
}).request({ | ||
site: '<YOUR_SITE_NAME>', | ||
api_key: '<YOUR_API_KEY>', | ||
}); | ||
``` | ||
### Processing Webhooks - API Version Check | ||
@@ -221,10 +233,4 @@ | ||
## Documentation | ||
The full documentation can be found on the Chargebee API Docs: | ||
[https://apidocs.chargebee.com/docs/api?lang=node](https://apidocs.chargebee.com/docs/api?lang=node) | ||
## License | ||
See the [LICENSE](./LICENSE) file. |
Sorry, the diff of this file is too big to display
526545
230