chargebee 3.3.0 → 3.4.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/esm/util.js CHANGED
@@ -148,47 +148,52 @@ export function encodeListParams(paramObj) {
148
148
  }
149
149
  return encodeParams(paramObj);
150
150
  }
151
- export function getHost(env) {
151
+ export function getHost(env, subDomain) {
152
+ if (subDomain != null) {
153
+ return env.site + '.' + subDomain + env.hostSuffix;
154
+ }
152
155
  return env.site + env.hostSuffix;
153
156
  }
154
- export function encodeParams(paramObj, serialized, scope, index) {
157
+ export function encodeParams(paramObj, serialized, scope, index, jsonKeys, level = 0) {
155
158
  let key, value;
156
159
  if (typeof serialized === 'undefined' || serialized === null) {
157
160
  serialized = [];
158
161
  }
159
162
  for (key in paramObj) {
160
163
  value = paramObj[key];
164
+ const originalKey = key;
161
165
  if (scope) {
162
- key = '' + scope + '[' + key + ']';
166
+ key = `${scope}[${key}]`;
163
167
  }
164
168
  if (typeof index !== 'undefined' && index !== null) {
165
- key = key + '[' + index + ']';
169
+ key = `${key}[${index}]`;
170
+ }
171
+ if (jsonKeys && jsonKeys[originalKey] === level) {
172
+ let attrVal = '';
173
+ if (value !== null) {
174
+ attrVal = encodeURIComponent(Object.prototype.toString.call(value) === '[object String]'
175
+ ? trim(value)
176
+ : JSON.stringify(value));
177
+ }
178
+ serialized.push(encodeURIComponent(key) + '=' + attrVal);
166
179
  }
167
- if (isArray(value)) {
180
+ else if (isArray(value) &&
181
+ !(jsonKeys && jsonKeys[originalKey] === level)) {
168
182
  for (let arrIdx = 0; arrIdx < value.length; arrIdx++) {
169
183
  if (typeof value[arrIdx] === 'object' || isArray(value[arrIdx])) {
170
- encodeParams(value[arrIdx], serialized, key, arrIdx);
184
+ encodeParams(value[arrIdx], serialized, key, arrIdx, jsonKeys, level + 1);
171
185
  }
172
186
  else {
173
187
  if (typeof value[arrIdx] !== 'undefined') {
174
- serialized.push(encodeURIComponent(key + '[' + arrIdx + ']') +
188
+ serialized.push(encodeURIComponent(`${key}[${arrIdx}]`) +
175
189
  '=' +
176
190
  encodeURIComponent(trim(value[arrIdx]) !== '' ? value[arrIdx] : ''));
177
191
  }
178
192
  }
179
193
  }
180
194
  }
181
- else if (key === 'meta_data' || key === 'metadata') {
182
- let attrVal = '';
183
- if (value !== null) {
184
- attrVal = encodeURIComponent(Object.prototype.toString.call(value) === '[object String]'
185
- ? trim(value)
186
- : JSON.stringify(value));
187
- }
188
- serialized.push(encodeURIComponent(key) + '=' + attrVal);
189
- }
190
195
  else if (typeof value === 'object' && !isArray(value)) {
191
- encodeParams(value, serialized, key);
196
+ encodeParams(value, serialized, key, undefined, jsonKeys, level + 1);
192
197
  }
193
198
  else {
194
199
  if (typeof value !== 'undefined') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chargebee",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "description": "A library for integrating with Chargebee.",
5
5
  "scripts": {
6
6
  "prepack": "npm install && npm run build",
package/types/core.d.ts CHANGED
@@ -9,6 +9,7 @@ declare module 'chargebee' {
9
9
  export type ChargebeeResponse<T> = T & {
10
10
  headers: { [key: string]: string };
11
11
  isIdempotencyReplayed?: boolean | string;
12
+ httpStatusCode: number | null;
12
13
  };
13
14
  export type ChargebeeRequestHeader = {
14
15
  [key: string]: string | undefined;
@@ -135,7 +136,8 @@ declare module 'chargebee' {
135
136
  | 'price_variant'
136
137
  | 'omnichannel_subscription'
137
138
  | 'omnichannel_subscription_item'
138
- | 'omnichannel_transaction';
139
+ | 'omnichannel_transaction'
140
+ | 'recorded_purchase';
139
141
  type EventNameEnum = 'cancellation_page_loaded';
140
142
  type EventTypeEnum =
141
143
  | 'coupon_created'
@@ -329,6 +331,10 @@ declare module 'chargebee' {
329
331
  | 'omnichannel_subscription_item_grace_period_expired'
330
332
  | 'omnichannel_subscription_item_dunning_started'
331
333
  | 'omnichannel_subscription_item_dunning_expired'
334
+ | 'rule_created'
335
+ | 'rule_updated'
336
+ | 'rule_deleted'
337
+ | 'record_purchase_failed'
332
338
  | 'plan_created'
333
339
  | 'plan_updated'
334
340
  | 'plan_deleted'
package/types/index.d.ts CHANGED
@@ -65,6 +65,7 @@
65
65
  ///<reference path='./resources/Ramp.d.ts' />
66
66
  ///<reference path='./resources/RecordedPurchase.d.ts' />
67
67
  ///<reference path='./resources/ResourceMigration.d.ts' />
68
+ ///<reference path='./resources/Rule.d.ts' />
68
69
  ///<reference path='./resources/SiteMigrationDetail.d.ts' />
69
70
  ///<reference path='./resources/Subscription.d.ts' />
70
71
  ///<reference path='./resources/SubscriptionEntitlement.d.ts' />
@@ -76,6 +77,7 @@
76
77
  ///<reference path='./resources/Transaction.d.ts' />
77
78
  ///<reference path='./resources/UnbilledCharge.d.ts' />
78
79
  ///<reference path='./resources/Usage.d.ts' />
80
+ ///<reference path='./resources/UsageEvent.d.ts' />
79
81
  ///<reference path='./resources/VirtualBankAccount.d.ts' />
80
82
 
81
83
  export type Config = {
@@ -163,6 +165,7 @@ declare module 'chargebee' {
163
165
  ramp: Ramp.RampResource;
164
166
  recordedPurchase: RecordedPurchase.RecordedPurchaseResource;
165
167
  resourceMigration: ResourceMigration.ResourceMigrationResource;
168
+ rule: Rule.RuleResource;
166
169
  siteMigrationDetail: SiteMigrationDetail.SiteMigrationDetailResource;
167
170
  subscription: Subscription.SubscriptionResource;
168
171
  subscriptionEntitlement: SubscriptionEntitlement.SubscriptionEntitlementResource;
@@ -170,6 +173,7 @@ declare module 'chargebee' {
170
173
  transaction: Transaction.TransactionResource;
171
174
  unbilledCharge: UnbilledCharge.UnbilledChargeResource;
172
175
  usage: Usage.UsageResource;
176
+ usageEvent: UsageEvent.UsageEventResource;
173
177
  virtualBankAccount: VirtualBankAccount.VirtualBankAccountResource;
174
178
  }
175
179
  }
@@ -18,6 +18,7 @@ declare module 'chargebee' {
18
18
  updated_at?: number;
19
19
  channel?: ChannelEnum;
20
20
  business_entity_id?: string;
21
+ deleted: boolean;
21
22
  }
22
23
 
23
24
  export namespace AttachedItem {
@@ -79,6 +79,7 @@ declare module 'chargebee' {
79
79
  | 'omnichannel_subscription'
80
80
  | 'omnichannel_subscription_item'
81
81
  | 'omnichannel_transaction'
82
+ | 'recorded_purchase'
82
83
  | 'item_family'
83
84
  | 'item'
84
85
  | 'item_price'
@@ -41,6 +41,7 @@ declare module 'chargebee' {
41
41
  invoice_notes?: string;
42
42
  meta_data?: any;
43
43
  coupon_constraints?: Coupon.CouponConstraint[];
44
+ deleted: boolean;
44
45
  }
45
46
 
46
47
  export namespace Coupon {
@@ -160,10 +161,7 @@ declare module 'chargebee' {
160
161
  discount_type?: 'fixed_amount' | 'percentage' | 'offer_quantity';
161
162
  discount_amount?: number;
162
163
  currency_code?: string;
163
- discount_percentage?: number /**
164
- * @deprecated Please refer API docs to use other attributes
165
- */;
166
-
164
+ discount_percentage?: number;
167
165
  discount_quantity?: number;
168
166
  apply_on: 'invoice_amount' | 'each_specified_item';
169
167
  duration_type?: 'one_time' | 'forever' | 'limited_period';
@@ -188,10 +186,7 @@ declare module 'chargebee' {
188
186
  discount_type?: 'fixed_amount' | 'percentage' | 'offer_quantity';
189
187
  discount_amount?: number;
190
188
  currency_code?: string;
191
- discount_percentage?: number /**
192
- * @deprecated Please refer API docs to use other attributes
193
- */;
194
-
189
+ discount_percentage?: number;
195
190
  discount_quantity?: number;
196
191
  apply_on: 'invoice_amount' | 'each_specified_item';
197
192
  duration_type?: 'one_time' | 'forever' | 'limited_period';
@@ -216,10 +211,7 @@ declare module 'chargebee' {
216
211
  discount_type?: 'fixed_amount' | 'percentage' | 'offer_quantity';
217
212
  discount_amount?: number;
218
213
  currency_code?: string;
219
- discount_percentage?: number /**
220
- * @deprecated Please refer API docs to use other attributes
221
- */;
222
-
214
+ discount_percentage?: number;
223
215
  discount_quantity?: number;
224
216
  apply_on?: 'invoice_amount' | 'each_specified_item';
225
217
  duration_type?: 'one_time' | 'forever' | 'limited_period';
@@ -259,10 +251,7 @@ declare module 'chargebee' {
259
251
  discount_type?: 'fixed_amount' | 'percentage' | 'offer_quantity';
260
252
  discount_amount?: number;
261
253
  currency_code?: string;
262
- discount_percentage?: number /**
263
- * @deprecated Please refer API docs to use other attributes
264
- */;
265
-
254
+ discount_percentage?: number;
266
255
  discount_quantity?: number;
267
256
  apply_on?: 'invoice_amount' | 'each_specified_item';
268
257
  duration_type?: 'one_time' | 'forever' | 'limited_period';
@@ -7,7 +7,7 @@ declare module 'chargebee' {
7
7
  customer_id: string;
8
8
  subscription_id?: string;
9
9
  reference_invoice_id?: string;
10
- type: 'adjustment' | 'refundable';
10
+ type: 'adjustment' | 'refundable' | 'store';
11
11
  reason_code?:
12
12
  | 'write_off'
13
13
  | 'subscription_change'
@@ -360,6 +360,7 @@ declare module 'chargebee' {
360
360
  | 'not_paid'
361
361
  | 'voided'
362
362
  | 'pending';
363
+ tax_application?: 'pre_tax' | 'post_tax';
363
364
  }
364
365
  export interface ShippingAddress {
365
366
  first_name?: string;
@@ -409,7 +410,7 @@ declare module 'chargebee' {
409
410
  reference_invoice_id?: string;
410
411
  customer_id?: string;
411
412
  total?: number;
412
- type: 'adjustment' | 'refundable';
413
+ type: 'adjustment' | 'refundable' | 'store';
413
414
  reason_code?:
414
415
  | 'product_unsatisfactory'
415
416
  | 'service_unsatisfactory'
@@ -480,7 +481,7 @@ declare module 'chargebee' {
480
481
  customer_id?: string;
481
482
  subscription_id?: string;
482
483
  reference_invoice_id: string;
483
- type: 'adjustment' | 'refundable';
484
+ type: 'adjustment' | 'refundable' | 'store';
484
485
  currency_code?: string;
485
486
  create_reason_code: string;
486
487
  date: number;
@@ -4,7 +4,7 @@
4
4
  declare module 'chargebee' {
5
5
  export interface CreditNoteEstimate {
6
6
  reference_invoice_id: string;
7
- type: 'adjustment' | 'refundable';
7
+ type: 'adjustment' | 'refundable' | 'store';
8
8
  price_type: PriceTypeEnum;
9
9
  currency_code: string;
10
10
  sub_total: number;
@@ -608,7 +608,6 @@ declare module 'chargebee' {
608
608
  export interface MoveInputParam {
609
609
  id_at_from_site: string;
610
610
  from_site: string;
611
- tax_providers_fields?: TaxProvidersFieldsMoveInputParam[];
612
611
  }
613
612
  export interface ChangeBillingDateInputParam {
614
613
  billing_date?: number;
@@ -627,7 +626,6 @@ declare module 'chargebee' {
627
626
  export interface MergeInputParam {
628
627
  from_customer_id: string;
629
628
  to_customer_id: string;
630
- tax_providers_fields?: TaxProvidersFieldsMergeInputParam[];
631
629
  }
632
630
  export interface RelationshipsInputParam {
633
631
  parent_id?: string;
@@ -921,16 +919,6 @@ declare module 'chargebee' {
921
919
  invoice_id: string;
922
920
  allocation_amount?: number;
923
921
  }
924
- export interface TaxProvidersFieldsMoveInputParam {
925
- provider_name?: string;
926
- field_id?: string;
927
- field_value?: string;
928
- }
929
- export interface TaxProvidersFieldsMergeInputParam {
930
- provider_name?: string;
931
- field_id?: string;
932
- field_value?: string;
933
- }
934
922
  export interface ParentAccountAccessRelationshipsInputParam {
935
923
  portal_edit_child_subscriptions?: 'yes' | 'view_only' | 'no';
936
924
  portal_download_child_invoices?: 'yes' | 'view_only' | 'no';
@@ -17,6 +17,7 @@ declare module 'chargebee' {
17
17
  currency_code: string;
18
18
  parent_periods?: DifferentialPrice.ParentPeriod[];
19
19
  business_entity_id?: string;
20
+ deleted: boolean;
20
21
  }
21
22
 
22
23
  export namespace DifferentialPrice {
@@ -3,6 +3,7 @@
3
3
  ///<reference path='./filter.d.ts'/>
4
4
  declare module 'chargebee' {
5
5
  export interface Feature {
6
+ [key: string]: unknown;
6
7
  id: string;
7
8
  name: string;
8
9
  description?: string;
@@ -54,6 +54,7 @@ declare module 'chargebee' {
54
54
  line_item_discounts?: Invoice.LineItemDiscount[];
55
55
  taxes?: Invoice.Tax[];
56
56
  line_item_taxes?: Invoice.LineItemTax[];
57
+ line_item_credits?: Invoice.LineItemCredit[];
57
58
  line_item_tiers?: Invoice.LineItemTier[];
58
59
  linked_payments?: Invoice.LinkedPayment[];
59
60
  dunning_attempts?: Invoice.DunningAttempt[];
@@ -566,6 +567,11 @@ declare module 'chargebee' {
566
567
  tax_amount_in_local_currency?: number;
567
568
  local_currency_code?: string;
568
569
  }
570
+ export interface LineItemCredit {
571
+ cn_id: string;
572
+ applied_amount: number;
573
+ line_item_id?: string;
574
+ }
569
575
  export interface LineItemTier {
570
576
  line_item_id?: string;
571
577
  starting_unit: number;
@@ -627,6 +633,7 @@ declare module 'chargebee' {
627
633
  cn_create_reason_code?: string;
628
634
  cn_date?: number;
629
635
  cn_status: 'adjusted' | 'refunded' | 'refund_due' | 'voided';
636
+ tax_application?: 'pre_tax' | 'post_tax';
630
637
  }
631
638
  export interface AdjustmentCreditNote {
632
639
  cn_id: string;
@@ -16,6 +16,7 @@ declare module 'chargebee' {
16
16
  taxes?: InvoiceEstimate.Tax[];
17
17
  line_item_taxes?: InvoiceEstimate.LineItemTax[];
18
18
  line_item_tiers?: InvoiceEstimate.LineItemTier[];
19
+ line_item_credits?: InvoiceEstimate.LineItemCredit[];
19
20
  line_item_discounts?: InvoiceEstimate.LineItemDiscount[];
20
21
  round_off_amount?: number;
21
22
  customer_id?: string;
@@ -125,6 +126,11 @@ declare module 'chargebee' {
125
126
  quantity_used_in_decimal?: string;
126
127
  unit_amount_in_decimal?: string;
127
128
  }
129
+ export interface LineItemCredit {
130
+ cn_id: string;
131
+ applied_amount: number;
132
+ line_item_id?: string;
133
+ }
128
134
  export interface LineItemDiscount {
129
135
  line_item_id: string;
130
136
  discount_type:
@@ -30,6 +30,7 @@ declare module 'chargebee' {
30
30
  bundle_items?: Item.BundleItem[];
31
31
  bundle_configuration?: Item.BundleConfiguration;
32
32
  metadata?: any;
33
+ deleted: boolean;
33
34
  business_entity_id?: string;
34
35
  }
35
36
 
@@ -12,6 +12,7 @@ declare module 'chargebee' {
12
12
  updated_at?: number;
13
13
  channel?: ChannelEnum;
14
14
  business_entity_id?: string;
15
+ deleted: boolean;
15
16
  }
16
17
 
17
18
  export namespace ItemFamily {
@@ -48,6 +48,7 @@ declare module 'chargebee' {
48
48
  parent_item_id?: string;
49
49
  show_description_in_invoices?: boolean;
50
50
  show_description_in_quotes?: boolean;
51
+ deleted: boolean;
51
52
  business_entity_id?: string;
52
53
  }
53
54
 
@@ -317,7 +317,7 @@ declare module 'chargebee' {
317
317
  }
318
318
  export interface LinkedCreditNote {
319
319
  amount?: number;
320
- type: 'adjustment' | 'refundable';
320
+ type: 'adjustment' | 'refundable' | 'store';
321
321
  id: string;
322
322
  status: 'adjusted' | 'refunded' | 'refund_due' | 'voided';
323
323
  amount_adjusted?: number;
@@ -15,6 +15,7 @@ declare module 'chargebee' {
15
15
  archived_at?: number;
16
16
  attributes?: PriceVariant.Attribute[];
17
17
  business_entity_id?: string;
18
+ deleted: boolean;
18
19
  }
19
20
 
20
21
  export namespace PriceVariant {
@@ -0,0 +1,33 @@
1
+ ///<reference path='./../core.d.ts'/>
2
+ ///<reference path='./../index.d.ts'/>
3
+
4
+ declare module 'chargebee' {
5
+ export interface Rule {
6
+ id: string;
7
+ namespace: string;
8
+ rule_name: string;
9
+ rule_order?: number;
10
+ status: 'active' | 'disabled';
11
+ conditions?: string;
12
+ outcome?: string;
13
+ deleted: boolean;
14
+ created_at: number;
15
+ modified_at: number;
16
+ }
17
+
18
+ export namespace Rule {
19
+ export class RuleResource {
20
+ retrieve(
21
+ rule_id: string,
22
+ headers?: ChargebeeRequestHeader,
23
+ ): Promise<ChargebeeResponse<RetrieveResponse>>;
24
+ }
25
+
26
+ export interface RetrieveResponse {
27
+ rule: Rule;
28
+ }
29
+
30
+ // REQUEST PARAMS
31
+ //---------------
32
+ }
33
+ }
@@ -1174,6 +1174,7 @@ declare module 'chargebee' {
1174
1174
  tiers?: TiersImportUnbilledChargesInputParam[];
1175
1175
  }
1176
1176
  export interface ImportForItemsInputParam {
1177
+ exhausted_coupon_ids?: string[];
1177
1178
  id?: string;
1178
1179
  trial_end?: number;
1179
1180
  billing_cycles?: number /**
@@ -0,0 +1,53 @@
1
+ ///<reference path='./../core.d.ts'/>
2
+ ///<reference path='./../index.d.ts'/>
3
+
4
+ declare module 'chargebee' {
5
+ export interface UsageEvent {
6
+ subscription_id: string;
7
+ deduplication_id: string;
8
+ usage_timestamp: number;
9
+ properties: any;
10
+ }
11
+
12
+ export namespace UsageEvent {
13
+ export class UsageEventResource {
14
+ create(
15
+ input: CreateInputParam,
16
+ headers?: ChargebeeRequestHeader,
17
+ ): Promise<ChargebeeResponse<CreateResponse>>;
18
+
19
+ batchIngest(
20
+ input: BatchIngestInputParam,
21
+ headers?: ChargebeeRequestHeader,
22
+ ): Promise<ChargebeeResponse<BatchIngestResponse>>;
23
+ }
24
+
25
+ export interface CreateResponse {
26
+ usage_event: UsageEvent;
27
+ }
28
+
29
+ export interface BatchIngestResponse {
30
+ batch_id: string;
31
+ failed_events: any[];
32
+ }
33
+
34
+ // REQUEST PARAMS
35
+ //---------------
36
+
37
+ export interface CreateInputParam {
38
+ deduplication_id: string;
39
+ subscription_id: string;
40
+ usage_timestamp: number;
41
+ properties: any;
42
+ }
43
+ export interface BatchIngestInputParam {
44
+ events?: EventsBatchIngestInputParam[];
45
+ }
46
+ export interface EventsBatchIngestInputParam {
47
+ deduplication_id: string;
48
+ subscription_id: string;
49
+ usage_timestamp: number;
50
+ properties: any;
51
+ }
52
+ }
53
+ }