chargebee 2.46.0 → 2.47.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 CHANGED
@@ -1,3 +1,44 @@
1
+ ### v2.47.0 (2025-02-10)
2
+ * * *
3
+
4
+ #### New Resources:
5
+ * Rule has been added.
6
+ * UsageEvent has been added.
7
+
8
+ #### New Attribute:
9
+ * deleted has been added to AttachedItem.
10
+ * deleted has been added to Coupon.
11
+ * deleted has been added to DifferentialPrice.
12
+ * deleted has been added to ItemFamily.
13
+ * deleted has been added to ItemPrice.
14
+ * deleted has been added to Item.
15
+ * deleted has been added to PriceVariant.
16
+ * tax_application has abeend added to CreditNote#Allocation.
17
+ * tax_application has been added to Invoice#AppliedCredit.
18
+ * line_item_credit has been added to Invoice.
19
+
20
+ #### New Input Params:
21
+ * exhausted_coupon_ids has been added to Subscription#ImportForItems.
22
+
23
+ #### New Enums
24
+ * STORE has been added in CreditNote#TypeEnum.
25
+ * STORE has been added in CreditNoteEstimate#TypeEnum.
26
+ * STORE has been added in Order#TypeEnum.
27
+ * TaxApplicationEnum has been added in CreditNote#Application.
28
+ * TaxApplicationEnum has been added in Invoice#AppliedCredit.
29
+ * RECORDED_PURCHASE has been added in EntityTypeEnum.
30
+ * RECORD_PURCHASE_FAILED, has been added in EventTypeEnum.
31
+
32
+ #### Deleted Input Params
33
+ * tax_providers_fields has been removed from Customer#MoveParams.
34
+ * tax_providers_fields has been removed from Customer#MergeParams
35
+
36
+ #### Deprecated input params.
37
+ * deprecated label in discount_quantity has been removed from Coupon#CreateParams.
38
+ * deprecated label in discount_quantity has been removed from Coupon#UpdateParams.
39
+ * deprecated label in discount_quantity has been removed from Coupon#CreateForItemsParams.
40
+ * deprecated label in discount_quantity has been removed from Coupon#UpdateForItemsParams.
41
+
1
42
  ### v2.46.0 (2024-12-19)
2
43
  * * *
3
44
 
package/lib/chargebee.js CHANGED
@@ -11,7 +11,7 @@ ChargeBee._env = {
11
11
  hostSuffix: '.chargebee.com',
12
12
  apiPath: '/api/v2',
13
13
  timeout: 80000,
14
- clientVersion: 'v2.46.0',
14
+ clientVersion: 'v2.47.0',
15
15
  port: 443,
16
16
  timemachineWaitInMillis: 3000,
17
17
  exportWaitInMillis: 3000
@@ -164,7 +164,7 @@ RequestWrapper.prototype.request = function(callBack, envOptions) {
164
164
  deferred.resolve(response);
165
165
  }
166
166
  };
167
- ChargeBee._core.makeApiRequest(env, callBackWrapper, this.apiCall.httpMethod, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam, params, this.httpHeaders, this.apiCall.isListReq);
167
+ ChargeBee._core.makeApiRequest(env, callBackWrapper, this.apiCall.httpMethod, this.apiCall.urlPrefix, this.apiCall.urlSuffix, urlIdParam, params, this.httpHeaders, this.apiCall.isListReq, this.apiCall.subDomain, this.apiCall.isJsonRequest, this.apiCall.jsonKeys);
168
168
  return deferred.promise;
169
169
  };
170
170
 
@@ -241,7 +241,7 @@ ChargeBee._core = (function() {
241
241
  response.isIdempotencyReplayed = res.headers[IDEMPOTENCY_REPLAYED_HEADER];
242
242
  }
243
243
  response.headers = res.headers;
244
-
244
+ response.http_status_code = res.statusCode;
245
245
  callBack(null, response);
246
246
  }
247
247
  });
@@ -256,7 +256,7 @@ ChargeBee._core = (function() {
256
256
  };
257
257
  };
258
258
 
259
- coreRef.makeApiRequest = function(env, callBack, httpMethod, urlPrefix, urlSuffix, urlIdParam, params, headers, isListReq) {
259
+ coreRef.makeApiRequest = function(env, callBack, httpMethod, urlPrefix, urlSuffix, urlIdParam, params, headers, isListReq, subDomain, isJsonRequest, jsonKeys) {
260
260
  var path = getApiURL(env, urlPrefix, urlSuffix, urlIdParam);
261
261
  if (typeof params === 'undefined' || params === null) {
262
262
  params = {};
@@ -266,13 +266,14 @@ ChargeBee._core = (function() {
266
266
  path += "?" + queryParam;
267
267
  params = {};
268
268
  }
269
- var data = encodeParams(params);
269
+ var data = isJsonRequest ? JSON.stringify(params) : encodeParams(params, null, null, null, jsonKeys);
270
+ var contentTypeHeader = !isJsonRequest ? 'application/x-www-form-urlencoded; charset=utf-8' : 'application/json;charset=UTF-8';
270
271
  var protocol = (env.protocol === 'http' ? http : https);
271
272
 
272
273
  ChargeBee._util.extend(true, headers, {
273
274
  'Authorization': 'Basic ' + Buffer.from(env.api_key+':').toString('base64'),
274
275
  'Accept': 'application/json',
275
- 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
276
+ 'Content-Type': contentTypeHeader,
276
277
  "Content-Length": data.length,
277
278
  'User-Agent': "Chargebee-NodeJs-Client " + env.clientVersion,
278
279
  'Lang-Version': process.version,
@@ -280,7 +281,7 @@ ChargeBee._core = (function() {
280
281
  });
281
282
 
282
283
  var req = protocol.request({
283
- "hostname": getHost(env),
284
+ "hostname": getHost(env, subDomain),
284
285
  "path": path,
285
286
  "method": httpMethod,
286
287
  "port": env.port,
@@ -303,7 +304,10 @@ ChargeBee._core = (function() {
303
304
  '/' + encodeURIComponent(urlIdParam).replace(/%2F/g,'/') : '') + (urlSuffix !== null ? urlSuffix : '');
304
305
  }
305
306
 
306
- function getHost(env) {
307
+ function getHost(env, subDomain) {
308
+ if(subDomain != null ) {
309
+ return env.site + '.' + subDomain + env.hostSuffix;
310
+ }
307
311
  return env.site + env.hostSuffix;
308
312
  }
309
313
 
@@ -320,45 +324,59 @@ ChargeBee._core = (function() {
320
324
  return encodeParams(paramObj);
321
325
  }
322
326
 
323
- var encodeParams = function(paramObj, serialized, scope, index) {
324
- var key, value;
327
+ var encodeParams = function (paramObj, serialized, scope, index, jsonKeys, level = 0) {
328
+ let key, value;
325
329
  if (typeof serialized === 'undefined' || serialized === null) {
326
330
  serialized = [];
327
331
  }
328
332
  for (key in paramObj) {
329
- value = paramObj[key];
333
+ value = paramObj[key]
334
+ const originalKey = key;
330
335
  if (scope) {
331
336
  key = "" + scope + "[" + key + "]";
332
337
  }
333
338
  if (typeof index !== 'undefined' && index !== null) {
334
339
  key = key + "[" + index + "]";
335
340
  }
336
-
337
- if (ChargeBee._util.isArray(value)) {
338
- for (var arrIdx = 0; arrIdx < value.length; arrIdx++) {
341
+ if (jsonKeys && jsonKeys[originalKey] === level) {
342
+ let attrVal = '';
343
+ if (value !== null) {
344
+ attrVal = encodeURIComponent(
345
+ Object.prototype.toString.call(value) === '[object String]'
346
+ ? ChargeBee._util.trim(value)
347
+ : JSON.stringify(value),
348
+ );
349
+ }
350
+ serialized.push(encodeURIComponent(key) + '=' + attrVal);
351
+ } else if (ChargeBee._util.isArray(value) && !(jsonKeys && jsonKeys[originalKey] === level)) {
352
+ for (let arrIdx = 0; arrIdx < value.length; arrIdx++) {
339
353
  if (typeof value[arrIdx] === 'object' || ChargeBee._util.isArray(value[arrIdx])) {
340
- encodeParams(value[arrIdx], serialized, key, arrIdx);
354
+ encodeParams(
355
+ value[arrIdx],
356
+ serialized,
357
+ key,
358
+ arrIdx,
359
+ jsonKeys,
360
+ level + 1,
361
+ );
341
362
  } else {
342
363
  if (typeof value[arrIdx] !== 'undefined') {
343
364
  serialized.push(encodeURIComponent(key + "[" + arrIdx + "]") + "=" + encodeURIComponent(ChargeBee._util.trim(value[arrIdx]) !== '' ? value[arrIdx] : ''));
344
365
  }
345
366
  }
346
367
  }
347
- } else if(["meta_data", "metadata"].indexOf(key) !== -1) {
348
- var attrVal="";
349
- if(value !== null) {
350
- attrVal = encodeURIComponent(Object.prototype.toString.call(value) === "[object String]" ? ChargeBee._util.trim(value) : JSON.stringify(value));
351
- }
352
- serialized.push(encodeURIComponent(key) + "=" + attrVal);
353
368
  } else if (typeof value === 'object' && !ChargeBee._util.isArray(value)) {
354
- encodeParams(value, serialized, key);
369
+ encodeParams(value, serialized, key, undefined, jsonKeys, level + 1);
355
370
  } else {
356
371
  if (typeof value !== 'undefined') {
357
- serialized.push(encodeURIComponent(key) + "=" + encodeURIComponent(ChargeBee._util.trim(value) !== '' ? value : ''));
372
+ serialized.push(
373
+ encodeURIComponent(key) +
374
+ '=' +
375
+ encodeURIComponent(ChargeBee._util.trim(value) !== '' ? value : ''),
376
+ );
358
377
  }
359
378
  }
360
379
  }
361
-
362
380
  return serialized.join('&').replace(/%20/g, '+');
363
381
  };
364
382
  var throwError = function(callBack,type,httpStatusCode, errorCode, message, detail) {
@@ -502,7 +520,12 @@ ChargeBee._util = (function() {
502
520
  "urlPrefix": metaArr[2],
503
521
  "urlSuffix": metaArr[3],
504
522
  "hasIdInUrl": metaArr[4],
505
- "isListReq": metaArr[0]==="list"};
523
+ "isListReq": metaArr[0]==="list",
524
+ "subDomain": metaArr[5],
525
+ "isJsonRequest": metaArr[6],
526
+ "jsonKeys": metaArr[7],
527
+
528
+ };
506
529
  module.exports[res][apiCall.methodName] = createApiFunc(apiCall);
507
530
  }
508
531
  }