chargebee 2.21.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +29 -0
- package/lib/chargebee.js +20 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
### v2.22.0 (2023-05-16)
|
|
2
|
+
* * *
|
|
3
|
+
|
|
4
|
+
#### New Feature:
|
|
5
|
+
* Added setIdempotencyKey("UUID") utility to pass **Idempotency key** along with request headers to allow a safe retry of POST requests.
|
|
6
|
+
* Added isIdempotencyReplayed utility to differentiate between original and replayed requests.
|
|
7
|
+
* Added headers utility to fetch the response headers.
|
|
8
|
+
|
|
9
|
+
|
|
1
10
|
### v2.21.0 (2023-04-28)
|
|
2
11
|
* * *
|
|
3
12
|
|
package/README.md
CHANGED
|
@@ -21,6 +21,35 @@ Then require the library as:
|
|
|
21
21
|
|
|
22
22
|
var chargebee = require('chargebee');
|
|
23
23
|
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Create an idempotent request
|
|
27
|
+
[Idempotency keys](https://apidocs.chargebee.com/docs/api) are passed along with request headers to allow a safe retry of POST requests.
|
|
28
|
+
|
|
29
|
+
```node
|
|
30
|
+
var chargebee = require("chargebee");
|
|
31
|
+
chargebee.configure({site : "{site}", api_key : "{site_api_key}"})
|
|
32
|
+
chargebee.customer.create({
|
|
33
|
+
first_name : "John",
|
|
34
|
+
last_name : "Doe",
|
|
35
|
+
email : "john@test.com"
|
|
36
|
+
})
|
|
37
|
+
.setIdempotencyKey("<<UUID>>") // Replace <<UUID>> with a unique string
|
|
38
|
+
.request(function(error,result, headers) {
|
|
39
|
+
if(error){
|
|
40
|
+
//handle error
|
|
41
|
+
console.log(error);
|
|
42
|
+
}else{
|
|
43
|
+
console.log(result);
|
|
44
|
+
console.log(headers); // Retrieves response headers
|
|
45
|
+
console.log(isIdempotencyReplayed); // Retrieves idempotency replayed header value
|
|
46
|
+
var customer = result.customer;
|
|
47
|
+
var card = result.card;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
`isIdempotencyReplayed()` method can be accessed to differentiate between original and replayed requests.
|
|
52
|
+
|
|
24
53
|
## Documentation
|
|
25
54
|
|
|
26
55
|
The full documentation can be found on the chargebee site here:
|
package/lib/chargebee.js
CHANGED
|
@@ -3,12 +3,15 @@ var ChargeBee = {};
|
|
|
3
3
|
var Q = require("q");
|
|
4
4
|
var os = require("os");
|
|
5
5
|
var Buffer = require("safer-buffer").Buffer;
|
|
6
|
+
const IDEMPOTENCY_HEADER = "chargebee-idempotency-key";
|
|
7
|
+
const IDEMPOTENCY_REPLAY_HEADER = 'chargebee-idempotency-replayed';
|
|
8
|
+
|
|
6
9
|
ChargeBee._env = {
|
|
7
10
|
protocol: 'https',
|
|
8
11
|
hostSuffix: '.chargebee.com',
|
|
9
12
|
apiPath: '/api/v2',
|
|
10
13
|
timeout: 80000,
|
|
11
|
-
clientVersion: 'v2.
|
|
14
|
+
clientVersion: 'v2.22.0',
|
|
12
15
|
port: 443,
|
|
13
16
|
timemachineWaitInMillis: 3000,
|
|
14
17
|
exportWaitInMillis: 3000
|
|
@@ -24,6 +27,12 @@ ChargeBee.updateRequestTimeoutInMillis = function(timeout) {
|
|
|
24
27
|
|
|
25
28
|
ChargeBee._endpoints = require('./resources/api_endpoints.js');
|
|
26
29
|
|
|
30
|
+
RequestWrapper.prototype.setIdempotencyKey = function(idempotencyKey) {
|
|
31
|
+
this.headers({[IDEMPOTENCY_HEADER]: idempotencyKey});
|
|
32
|
+
return this;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
|
|
27
36
|
|
|
28
37
|
ChargeBee._waitToProcessComplete = function(retrieveHandling){
|
|
29
38
|
if(typeof retrieveHandling == 'undefined' || !ChargeBee._util.isFunction(retrieveHandling)){
|
|
@@ -131,6 +140,7 @@ RequestWrapper.prototype.headers = function(headers) {
|
|
|
131
140
|
return this;
|
|
132
141
|
};
|
|
133
142
|
|
|
143
|
+
|
|
134
144
|
RequestWrapper.prototype.request = function(callBack, envOptions) {
|
|
135
145
|
var env = {};
|
|
136
146
|
var jsonConstructor = {}.constructor;
|
|
@@ -147,11 +157,11 @@ RequestWrapper.prototype.request = function(callBack, envOptions) {
|
|
|
147
157
|
if (typeof callBack !== 'undefined' && !ChargeBee._util.isFunction(callBack)) {
|
|
148
158
|
throw new Error('The callback parameter passed is incorrect.');
|
|
149
159
|
}
|
|
150
|
-
function callBackWrapper(err, response) {
|
|
160
|
+
function callBackWrapper(err, response, headers) {
|
|
151
161
|
if (err) {
|
|
152
162
|
deferred.reject(err);
|
|
153
163
|
} else {
|
|
154
|
-
deferred.resolve(response);
|
|
164
|
+
deferred.resolve({'response': response, 'headers': headers});
|
|
155
165
|
}
|
|
156
166
|
};
|
|
157
167
|
ChargeBee._core.makeApiRequest(env, callBackWrapper, this.apiCall.httpMethod, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam, params, this.httpHeaders, this.apiCall.isListReq);
|
|
@@ -224,9 +234,9 @@ ChargeBee._core = (function() {
|
|
|
224
234
|
}
|
|
225
235
|
if (res.statusCode < 200 || res.statusCode > 299) {
|
|
226
236
|
response.http_status_code = res.statusCode;
|
|
227
|
-
callBack(response, null);
|
|
237
|
+
callBack(response, null, res.headers);
|
|
228
238
|
} else {
|
|
229
|
-
callBack(null, response);
|
|
239
|
+
callBack(null, response, res.headers);
|
|
230
240
|
}
|
|
231
241
|
});
|
|
232
242
|
};
|
|
@@ -460,7 +470,11 @@ ChargeBee._util = (function() {
|
|
|
460
470
|
if (callback) {
|
|
461
471
|
deferred.promise.then(function(res) {
|
|
462
472
|
setTimeout(function() {
|
|
463
|
-
|
|
473
|
+
isIdempotencyReplayed = false
|
|
474
|
+
if(typeof res.headers[IDEMPOTENCY_REPLAY_HEADER] !== 'undefined' && res.headers[IDEMPOTENCY_REPLAY_HEADER] !== ''){
|
|
475
|
+
isIdempotencyReplayed = res.headers[IDEMPOTENCY_REPLAY_HEADER];
|
|
476
|
+
}
|
|
477
|
+
callback(null, res.response, res.headers);
|
|
464
478
|
}, 0);
|
|
465
479
|
}, function(err) {
|
|
466
480
|
setTimeout(function() {
|