chargebee 2.20.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 +38 -0
- package/README.md +29 -0
- package/lib/chargebee.js +20 -6
- package/lib/resources/api_endpoints.js +7 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
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
|
+
|
|
10
|
+
### v2.21.0 (2023-04-28)
|
|
11
|
+
* * *
|
|
12
|
+
|
|
13
|
+
#### Fixes:
|
|
14
|
+
* SubscriptionId attribute has been maid as required in InAppSubscription resource.
|
|
15
|
+
|
|
16
|
+
#### New Attributes:
|
|
17
|
+
* TotalContractValueBeforeTax has been added to the ContractTerm resource.
|
|
18
|
+
* TotalContractValueBeforeTax#SubscriptionContractTerm has been added to the Subscription resource.
|
|
19
|
+
* TotalContractValueBeforeTax#SubscriptionEstimateContractTerm has been addded to the SubscriptionEstimate resource.
|
|
20
|
+
* CouponConstraints has been added to the Coupon resource.
|
|
21
|
+
|
|
22
|
+
#### New Resource:
|
|
23
|
+
* NonSubscription have been added.
|
|
24
|
+
|
|
25
|
+
#### Added Input Parameters:
|
|
26
|
+
* contract_term[total_amount_raised_before_tax]#ImportSubscriptionRequest, contract_term[total_amount_raised_before_tax]#ImportForItemsRequest, contract_term[total_amount_raised_before_tax]#ImportContractTermRequest and contract_term[total_amount_raised_before_tax]#ImportForCustomerRequest parameter has been added to Subscription resource.
|
|
27
|
+
* contract_term[total_contract_value_before_tax]#ImportContractTermRequest parameter has been added to Subscription resource.
|
|
28
|
+
* coupon_constraints[entity_type]#CreateForItemsRequestParams, coupon_constraints[type]#CreateForItemsRequestParams and coupon_constraints[value]#CreateForItemsRequestParams parameter has been added to the Coupon resource.
|
|
29
|
+
* coupon_constraints[entity_type]#UpdateForItemsRequestParams, coupon_constraints[type]#UpdateForItemsRequestParams and coupon_constraints[value]#UpdateForItemsRequestParams parameter has been added to the Coupon resource.
|
|
30
|
+
* export_type#CustomersRequest and export_type#SubscriptionsRequest parameter has been added to the Export resource.
|
|
31
|
+
|
|
32
|
+
#### New Enum Class:
|
|
33
|
+
* ExportType has been added.
|
|
34
|
+
|
|
35
|
+
#### New Enum values:
|
|
36
|
+
* pending_authorization has been added to StatusEnum#PaymentIntentPaymentAttempt to the PaymentIntent resource.
|
|
37
|
+
|
|
38
|
+
|
|
1
39
|
### v2.20.0 (2023-03-24)
|
|
2
40
|
* * *
|
|
3
41
|
|
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() {
|
|
@@ -2579,6 +2579,13 @@ var _endpoints = {
|
|
|
2579
2579
|
true
|
|
2580
2580
|
]
|
|
2581
2581
|
],
|
|
2582
|
+
"non_subscription": [[
|
|
2583
|
+
"process_receipt",
|
|
2584
|
+
"POST",
|
|
2585
|
+
"/non_subscriptions",
|
|
2586
|
+
"/one_time_purchase",
|
|
2587
|
+
true
|
|
2588
|
+
]],
|
|
2582
2589
|
"entitlement_override": [
|
|
2583
2590
|
[
|
|
2584
2591
|
"add_entitlement_override_for_subscription",
|