@rebilly/instruments 4.5.0 → 4.7.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.
Files changed (134) hide show
  1. package/.babelrc +24 -26
  2. package/CHANGELOG.md +14 -0
  3. package/dist/index.js +8 -8
  4. package/dist/index.min.js +8 -8
  5. package/package.json +14 -3
  6. package/project.json +9 -0
  7. package/rollup.config.mjs +21 -26
  8. package/src/data/options-schema/index.js +94 -78
  9. package/src/data/options-schema/schemas/options-schema.js +419 -411
  10. package/src/events/base-event.js +34 -34
  11. package/src/events/events.spec.js +6 -6
  12. package/src/events/index.js +5 -5
  13. package/src/functions/destroy.js +19 -19
  14. package/src/functions/destroy.spec.js +41 -41
  15. package/src/functions/mount/fetch-data.js +200 -193
  16. package/src/functions/mount/fetch-data.spec.js +287 -285
  17. package/src/functions/mount/get-lead-source-data.js +31 -31
  18. package/src/functions/mount/get-lead-source-data.spec.js +19 -19
  19. package/src/functions/mount/index.js +73 -65
  20. package/src/functions/mount/mount.spec.js +77 -66
  21. package/src/functions/mount/setup-element.js +23 -23
  22. package/src/functions/mount/setup-framepay-theme.js +86 -68
  23. package/src/functions/mount/setup-framepay.js +9 -5
  24. package/src/functions/mount/setup-i18n.js +15 -15
  25. package/src/functions/mount/setup-options.js +74 -74
  26. package/src/functions/mount/setup-options.spec.js +323 -287
  27. package/src/functions/mount/setup-storefront.js +15 -20
  28. package/src/functions/mount/setup-styles-vars.js +19 -22
  29. package/src/functions/mount/setup-user-flow.js +51 -47
  30. package/src/functions/on.js +5 -5
  31. package/src/functions/on.spec.js +60 -51
  32. package/src/functions/purchase.js +151 -146
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -53
  35. package/src/functions/setup.spec.js +88 -75
  36. package/src/functions/show.js +13 -14
  37. package/src/functions/show.spec.js +53 -53
  38. package/src/functions/update.js +30 -28
  39. package/src/functions/update.spec.js +94 -93
  40. package/src/i18n/en.json +32 -32
  41. package/src/i18n/es.json +29 -29
  42. package/src/i18n/i18n.spec.js +18 -18
  43. package/src/i18n/index.js +48 -48
  44. package/src/instance.js +36 -36
  45. package/src/instance.spec.js +29 -27
  46. package/src/loader/index.js +95 -70
  47. package/src/loader/loader.spec.js +63 -63
  48. package/src/state/iframes.js +21 -21
  49. package/src/state/index.js +56 -54
  50. package/src/storefront/account-and-website.js +10 -8
  51. package/src/storefront/account-and-website.spec.js +55 -55
  52. package/src/storefront/deposit-requests.js +6 -6
  53. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
  54. package/src/storefront/fetch-products-from-plans.js +52 -51
  55. package/src/storefront/fetch-products-from-plans.spec.js +90 -87
  56. package/src/storefront/index.js +56 -49
  57. package/src/storefront/invoices.js +15 -15
  58. package/src/storefront/invoices.spec.js +69 -65
  59. package/src/storefront/models/account-model.js +29 -32
  60. package/src/storefront/models/base-model.js +6 -9
  61. package/src/storefront/models/deposit-request-model.js +22 -13
  62. package/src/storefront/models/invoice-model.js +16 -16
  63. package/src/storefront/models/payment-metadata.js +4 -4
  64. package/src/storefront/models/plan-model.js +73 -64
  65. package/src/storefront/models/ready-to-pay-model.js +59 -59
  66. package/src/storefront/models/summary-model.js +43 -46
  67. package/src/storefront/models/transaction-model.js +11 -14
  68. package/src/storefront/payment-instruments.js +38 -35
  69. package/src/storefront/payment-instruments.spec.js +81 -62
  70. package/src/storefront/purchase.js +50 -44
  71. package/src/storefront/purchase.spec.js +40 -40
  72. package/src/storefront/ready-to-pay.js +75 -77
  73. package/src/storefront/ready-to-pay.spec.js +59 -54
  74. package/src/storefront/storefront.spec.js +9 -9
  75. package/src/storefront/summary.js +93 -67
  76. package/src/storefront/summary.spec.js +108 -106
  77. package/src/storefront/transactions.js +6 -6
  78. package/src/style/base/default-theme.js +928 -923
  79. package/src/style/base/theme.js +21 -21
  80. package/src/style/base/theme.spec.js +13 -13
  81. package/src/style/index.js +3 -3
  82. package/src/style/utils/border.js +40 -27
  83. package/src/style/utils/color-values.js +18 -18
  84. package/src/style/utils/minifyCss.js +6 -6
  85. package/src/utils/add-dom-element.js +14 -14
  86. package/src/utils/format-currency.js +6 -5
  87. package/src/utils/has-valid-css-selector.js +2 -2
  88. package/src/utils/index.js +6 -6
  89. package/src/utils/is-dom-element.js +1 -1
  90. package/src/utils/process-property-as-dom-element.js +22 -22
  91. package/src/utils/quantity.js +26 -28
  92. package/src/utils/sleep.js +3 -1
  93. package/src/views/amount-selector.js +37 -36
  94. package/src/views/common/iframe/base-iframe.js +53 -52
  95. package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
  96. package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
  97. package/src/views/common/iframe/events/resize-component-handler.js +8 -8
  98. package/src/views/common/iframe/events/show-error-handler.js +2 -2
  99. package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
  100. package/src/views/common/iframe/events/update-addons-handler.js +20 -13
  101. package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
  102. package/src/views/common/iframe/events/update-items-handler.js +26 -22
  103. package/src/views/common/iframe/modal-iframe.js +67 -56
  104. package/src/views/common/iframe/view-iframe.js +11 -11
  105. package/src/views/common/render-utilities.js +2 -2
  106. package/src/views/confirmation.js +33 -30
  107. package/src/views/errors.js +89 -79
  108. package/src/views/form.js +41 -37
  109. package/src/views/method-selector/express-methods.js +46 -46
  110. package/src/views/method-selector/generate-digital-wallet.js +46 -45
  111. package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
  112. package/src/views/method-selector/generate-framepay-config.js +53 -51
  113. package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
  114. package/src/views/method-selector/get-method-data.js +5 -6
  115. package/src/views/method-selector/get-payment-methods.js +18 -16
  116. package/src/views/method-selector/get-payment-methods.spec.js +29 -27
  117. package/src/views/method-selector/index.js +154 -139
  118. package/src/views/method-selector/method-selector.spec.js +13 -13
  119. package/src/views/method-selector/mount-bump-offer.js +65 -49
  120. package/src/views/method-selector/mount-express-methods.js +89 -85
  121. package/src/views/modal.js +74 -67
  122. package/src/views/result.js +14 -14
  123. package/src/views/summary.js +25 -26
  124. package/tests/async-utilities.js +13 -13
  125. package/tests/mocks/framepay-mock.js +9 -8
  126. package/tests/mocks/rebilly-api-mock.js +5 -3
  127. package/tests/mocks/rebilly-instruments-mock.js +121 -117
  128. package/tests/mocks/storefront-api-mock.js +55 -48
  129. package/tests/mocks/storefront-mock.js +10 -14
  130. package/tests/msw/server.js +6 -6
  131. package/tests/setup-test.js +14 -16
  132. package/vitest.config.js +14 -14
  133. package/.eslintrc.js +0 -34
  134. package/.prettierrc.js +0 -11
@@ -1,39 +1,36 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export class AddressModel {
4
- constructor({
5
- firstName = null,
6
- lastName = null,
7
- organization = null,
8
- address = null,
9
- address2 = null,
10
- city = null,
11
- region = null,
12
- country = null,
13
- postalCode = null,
14
- emails = [],
15
- phoneNumbers = [],
16
- } = {}) {
17
- this.firstName = firstName;
18
- this.lastName = lastName;
19
- this.organization = organization;
20
- this.address = address;
21
- this.address2 = address2;
22
- this.city = city;
23
- this.region = region;
24
- this.country = country;
25
- this.postalCode = postalCode;
26
- this.email = emails.find(v => v.primary)?.value || null;
27
- this.phoneNumber = phoneNumbers.find(v => v.primary)?.value || null;
28
- }
4
+ constructor({
5
+ firstName = null,
6
+ lastName = null,
7
+ organization = null,
8
+ address = null,
9
+ address2 = null,
10
+ city = null,
11
+ region = null,
12
+ country = null,
13
+ postalCode = null,
14
+ emails = [],
15
+ phoneNumbers = [],
16
+ } = {}) {
17
+ this.firstName = firstName;
18
+ this.lastName = lastName;
19
+ this.organization = organization;
20
+ this.address = address;
21
+ this.address2 = address2;
22
+ this.city = city;
23
+ this.region = region;
24
+ this.country = country;
25
+ this.postalCode = postalCode;
26
+ this.email = emails.find((v) => v.primary)?.value || null;
27
+ this.phoneNumber = phoneNumbers.find((v) => v.primary)?.value || null;
28
+ }
29
29
  }
30
30
 
31
31
  export default class AccountModel extends BaseModel {
32
- constructor({
33
- primaryAddress = {},
34
- ...fields
35
- } = {}) {
36
- super(fields);
37
- this.address = new AddressModel({...primaryAddress});
38
- }
32
+ constructor({ primaryAddress = {}, ...fields } = {}) {
33
+ super(fields);
34
+ this.address = new AddressModel({ ...primaryAddress });
35
+ }
39
36
  }
@@ -1,10 +1,7 @@
1
1
  export default class BaseModel {
2
- constructor({
3
- ...fields
4
- } = {}) {
5
- Object.entries(fields)
6
- .forEach(([key, value]) => {
7
- this[key] = value;
8
- })
9
- }
10
- }
2
+ constructor({ ...fields } = {}) {
3
+ Object.entries(fields).forEach(([key, value]) => {
4
+ this[key] = value;
5
+ });
6
+ }
7
+ }
@@ -1,15 +1,24 @@
1
- import BaseModel from './base-model';
2
1
  import merge from 'lodash.merge';
2
+ import BaseModel from './base-model';
3
+
3
4
  export default class DepositRequestModel extends BaseModel {
4
- constructor(fields) {
5
- super(fields);
6
- this.amount = Array.isArray(fields.amounts) ? fields.amounts[0] : fields.amount;
7
- this.buttons = fields.buttons ?? [...fields.amounts];
8
- this.editable = typeof fields.editable === "boolean" ? fields.editable : Boolean(fields.customAmount);
9
- this.customAmount = merge({
10
- minimum: 1,
11
- maximum: 1000000000000,
12
- multipleOf: 1,
13
- }, (fields.customAmount || {}));
14
- }
15
- }
5
+ constructor(fields) {
6
+ super(fields);
7
+ this.amount = Array.isArray(fields.amounts)
8
+ ? fields.amounts[0]
9
+ : fields.amount;
10
+ this.buttons = fields.buttons ?? [...fields.amounts];
11
+ this.editable =
12
+ typeof fields.editable === 'boolean'
13
+ ? fields.editable
14
+ : Boolean(fields.customAmount);
15
+ this.customAmount = merge(
16
+ {
17
+ minimum: 1,
18
+ maximum: 1000000000000,
19
+ multipleOf: 1,
20
+ },
21
+ fields.customAmount || {},
22
+ );
23
+ }
24
+ }
@@ -1,20 +1,20 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export default class InvoiceModel extends BaseModel {
4
- static Status = {
5
- draft: 'draft',
6
- unpaid: 'unpaid',
7
- paid: 'paid',
8
- partiallyPaid: 'partially-paid',
9
- pastDue: 'past-due',
10
- abandoned: 'abandoned',
11
- voided: 'voided',
12
- partiallyRefunded: 'partially-refunded',
13
- refunded: 'refunded',
14
- disputed: 'disputed',
15
- }
4
+ static Status = {
5
+ draft: 'draft',
6
+ unpaid: 'unpaid',
7
+ paid: 'paid',
8
+ partiallyPaid: 'partially-paid',
9
+ pastDue: 'past-due',
10
+ abandoned: 'abandoned',
11
+ voided: 'voided',
12
+ partiallyRefunded: 'partially-refunded',
13
+ refunded: 'refunded',
14
+ disputed: 'disputed',
15
+ };
16
16
 
17
- get isPaid() {
18
- return this.status === InvoiceModel.Status.paid;
19
- }
20
- }
17
+ get isPaid() {
18
+ return this.status === InvoiceModel.Status.paid;
19
+ }
20
+ }
@@ -1,7 +1,7 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export default class PaymentMetadataModel extends BaseModel {
4
- get logo () {
5
- return this.landscapeLogo || this.portraitLogo;
6
- }
7
- }
4
+ get logo() {
5
+ return this.landscapeLogo || this.portraitLogo;
6
+ }
7
+ }
@@ -1,85 +1,94 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export class PlanPricingBracketModel {
4
- constructor ({
5
- maxQuantity = null,
6
- price = null
7
- } = {}) {
8
- this.maxQuantity = maxQuantity || Number.MAX_SAFE_INTEGER;
9
- this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
10
- }
4
+ constructor({ maxQuantity = null, price = null } = {}) {
5
+ this.maxQuantity = maxQuantity || Number.MAX_SAFE_INTEGER;
6
+ this.price = !Number.isNaN(parseFloat(price))
7
+ ? parseFloat(price)
8
+ : null;
9
+ }
11
10
  }
12
11
 
13
12
  export class PlanPricingModel {
14
- static SimpleFormulas = {
15
- fixedFee: 'fixed-fee',
16
- flatRate: 'flat-rate'
17
- };
13
+ static SimpleFormulas = {
14
+ fixedFee: 'fixed-fee',
15
+ flatRate: 'flat-rate',
16
+ };
18
17
 
19
- static BracketFormulas = {
20
- stairstep: 'stairstep',
21
- tiered: 'tiered',
22
- volume: 'volume'
23
- };
18
+ static BracketFormulas = {
19
+ stairstep: 'stairstep',
20
+ tiered: 'tiered',
21
+ volume: 'volume',
22
+ };
24
23
 
25
- static Formulas = {
26
- ...PlanPricingModel.SimpleFormulas,
27
- ...PlanPricingModel.BracketFormulas
28
- };
24
+ static Formulas = {
25
+ ...PlanPricingModel.SimpleFormulas,
26
+ ...PlanPricingModel.BracketFormulas,
27
+ };
29
28
 
30
- constructor ({
31
- formula = PlanPricingModel.Formulas.fixedFee,
32
- price = 0,
33
- maxQuantity = null,
34
- brackets = []
35
- } = {}) {
36
- this.formula = formula;
29
+ constructor({
30
+ formula = PlanPricingModel.Formulas.fixedFee,
31
+ price = 0,
32
+ maxQuantity = null,
33
+ brackets = [],
34
+ } = {}) {
35
+ this.formula = formula;
37
36
 
38
- switch (this.formula) {
39
- case PlanPricingModel.Formulas.stairstep:
40
- case PlanPricingModel.Formulas.tiered:
41
- case PlanPricingModel.Formulas.volume:
42
- this.brackets = brackets.map(bracket => new PlanPricingBracketModel(bracket));
43
- break;
44
- case PlanPricingModel.Formulas.flatRate:
45
- this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
46
- this.maxQuantity = maxQuantity;
47
- break;
48
- case PlanPricingModel.Formulas.fixedFee:
49
- default:
50
- this.price = !Number.isNaN(parseFloat(price)) ? parseFloat(price) : null;
51
- break;
37
+ switch (this.formula) {
38
+ case PlanPricingModel.Formulas.stairstep:
39
+ case PlanPricingModel.Formulas.tiered:
40
+ case PlanPricingModel.Formulas.volume:
41
+ this.brackets = brackets.map(
42
+ (bracket) => new PlanPricingBracketModel(bracket),
43
+ );
44
+ break;
45
+ case PlanPricingModel.Formulas.flatRate:
46
+ this.price = !Number.isNaN(parseFloat(price))
47
+ ? parseFloat(price)
48
+ : null;
49
+ this.maxQuantity = maxQuantity;
50
+ break;
51
+ case PlanPricingModel.Formulas.fixedFee:
52
+ default:
53
+ this.price = !Number.isNaN(parseFloat(price))
54
+ ? parseFloat(price)
55
+ : null;
56
+ break;
57
+ }
52
58
  }
53
- }
54
59
 
55
- get isSimple() {
56
- return Object.values(PlanPricingModel.SimpleFormulas).includes(this.formula);
57
- }
60
+ get isSimple() {
61
+ return Object.values(PlanPricingModel.SimpleFormulas).includes(
62
+ this.formula,
63
+ );
64
+ }
58
65
 
59
- get isBracket () {
60
- return Object.values(PlanPricingModel.BracketFormulas).includes(this.formula);
61
- }
66
+ get isBracket() {
67
+ return Object.values(PlanPricingModel.BracketFormulas).includes(
68
+ this.formula,
69
+ );
70
+ }
62
71
 
63
- toPayload() {
64
- return {
65
- ...this,
66
- isSimple: this.isSimple,
67
- isBracket: this.isBracket,
72
+ toPayload() {
73
+ return {
74
+ ...this,
75
+ isSimple: this.isSimple,
76
+ isBracket: this.isBracket,
77
+ };
68
78
  }
69
- }
70
79
  }
71
80
 
72
81
  export default class PlanModel extends BaseModel {
73
- constructor(fields = {}) {
74
- super(fields);
82
+ constructor(fields = {}) {
83
+ super(fields);
75
84
 
76
- this.pricing = new PlanPricingModel(fields.pricing || {});
77
- }
85
+ this.pricing = new PlanPricingModel(fields.pricing || {});
86
+ }
78
87
 
79
- toPayload() {
80
- return {
81
- ...this,
82
- pricing: this.pricing.toPayload(),
88
+ toPayload() {
89
+ return {
90
+ ...this,
91
+ pricing: this.pricing.toPayload(),
92
+ };
83
93
  }
84
- }
85
- }
94
+ }
@@ -1,76 +1,76 @@
1
1
  import PaymentMetadataModel from './payment-metadata';
2
2
 
3
3
  export class ReadyToPayFeatureModel {
4
- static FeatureName = {
5
- paypalBillingAgreement: 'PayPal billing agreement',
6
- googlePay: 'Google Pay',
7
- applePay: 'Apple Pay',
8
- };
4
+ static FeatureName = {
5
+ paypalBillingAgreement: 'PayPal billing agreement',
6
+ googlePay: 'Google Pay',
7
+ applePay: 'Apple Pay',
8
+ };
9
9
 
10
- constructor({
11
- name = '',
12
- expirationTime = '',
10
+ constructor({
11
+ name = '',
12
+ expirationTime = '',
13
13
 
14
- // Apple Pay fields
15
- displayName = '',
16
- country = '',
14
+ // Apple Pay fields
15
+ displayName = '',
16
+ country = '',
17
17
 
18
- // Google Pay fields
19
- merchantName = '',
20
- merchantOrigin = '',
18
+ // Google Pay fields
19
+ merchantName = '',
20
+ merchantOrigin = '',
21
21
 
22
- // Paypal fields
23
- paypalMerchantId = '',
24
- billingAgreementToken = '',
25
- paypalClientId = '',
22
+ // Paypal fields
23
+ paypalMerchantId = '',
24
+ billingAgreementToken = '',
25
+ paypalClientId = '',
26
26
 
27
- // Plaid fields
28
- linkToken = '',
29
- } = {}) {
30
- this.name = name;
31
- this.expirationTime = expirationTime;
32
-
33
- this.displayName = displayName;
34
- this.country = country;
27
+ // Plaid fields
28
+ linkToken = '',
29
+ } = {}) {
30
+ this.name = name;
31
+ this.expirationTime = expirationTime;
35
32
 
36
- this.merchantName = merchantName;
37
- this.merchantOrigin = merchantOrigin;
33
+ this.displayName = displayName;
34
+ this.country = country;
38
35
 
39
- this.paypalMerchantId = paypalMerchantId;
40
- this.billingAgreementToken = billingAgreementToken;
41
- this.paypalClientId = paypalClientId;
36
+ this.merchantName = merchantName;
37
+ this.merchantOrigin = merchantOrigin;
42
38
 
43
- this.linkToken = linkToken;
44
- }
39
+ this.paypalMerchantId = paypalMerchantId;
40
+ this.billingAgreementToken = billingAgreementToken;
41
+ this.paypalClientId = paypalClientId;
42
+
43
+ this.linkToken = linkToken;
44
+ }
45
45
  }
46
46
 
47
47
  export default class ReadyToPayModel {
48
- constructor({
49
- index = null,
50
- method = '',
51
- feature = null,
52
- brands = [],
53
- filters = [],
54
- metadata = null
55
- } = {}) {
56
- this.index = index;
57
- this.method = method;
58
- this.feature = feature ? new ReadyToPayFeatureModel(feature) : null;
59
- this.brands = brands;
60
- this.filters = filters;
61
- this.metadata = metadata ? new PaymentMetadataModel(metadata) : null;
62
- }
48
+ constructor({
49
+ index = null,
50
+ method = '',
51
+ feature = null,
52
+ brands = [],
53
+ filters = [],
54
+ metadata = null,
55
+ } = {}) {
56
+ this.index = index;
57
+ this.method = method;
58
+ this.feature = feature ? new ReadyToPayFeatureModel(feature) : null;
59
+ this.brands = brands;
60
+ this.filters = filters;
61
+ this.metadata = metadata ? new PaymentMetadataModel(metadata) : null;
62
+ }
63
63
 
64
- get optionsPaymentInstrumentsKey() {
65
- switch (this.feature?.name) {
66
- case ReadyToPayFeatureModel.FeatureName.paypalBillingAgreement:
67
- return 'paypal';
68
- case ReadyToPayFeatureModel.FeatureName.googlePay:
69
- return 'googlePay';
70
- case ReadyToPayFeatureModel.FeatureName.applePay:
71
- return 'applePay';
72
- default:
73
- return undefined
64
+ get optionsPaymentInstrumentsKey() {
65
+ switch (this.feature?.name) {
66
+ case ReadyToPayFeatureModel.FeatureName.paypalBillingAgreement:
67
+ return 'paypal';
68
+ case ReadyToPayFeatureModel.FeatureName.googlePay:
69
+ return 'googlePay';
70
+ case ReadyToPayFeatureModel.FeatureName.applePay:
71
+ return 'applePay';
72
+ default:
73
+ return undefined;
74
+ }
74
75
  }
75
- }
76
76
  }
@@ -1,59 +1,56 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export class SummaryLineItemModel extends BaseModel {
4
- constructor({
5
- unitPrice = 0.0,
6
- quantity = 0,
7
- price = 0.0,
8
- ...fields
9
- } = {}) {
10
- super(fields);
11
- this.unitPrice = unitPrice;
12
- this.quantity = quantity;
13
- this.price = price;
14
- }
4
+ constructor({
5
+ unitPrice = 0.0,
6
+ quantity = 0,
7
+ price = 0.0,
8
+ ...fields
9
+ } = {}) {
10
+ super(fields);
11
+ this.unitPrice = unitPrice;
12
+ this.quantity = quantity;
13
+ this.price = price;
14
+ }
15
15
  }
16
16
 
17
17
  export class SummaryTaxModel extends BaseModel {}
18
18
 
19
19
  export class SummaryDiscountModel extends BaseModel {
20
- constructor({
21
- amount = 0,
22
- ...fields
23
- }) {
24
- super(fields);
25
- this.amount = amount;
26
- }
20
+ constructor({ amount = 0, ...fields }) {
21
+ super(fields);
22
+ this.amount = amount;
23
+ }
27
24
  }
28
25
 
29
26
  export default class SummaryModel {
30
- constructor({
31
- currency = '',
32
- lineItems = [],
33
- taxes = [],
34
- discounts = [],
35
- subtotalAmount = 0.0,
36
- taxAmount = 0.0,
37
- shippingAmount = 0.0,
38
- discountsAmount = 0.0,
39
- total = 0.0
40
- } = {}) {
41
- function map(array) {
42
- const list = Array.isArray(array) ? array : [];
43
- return {
44
- // eslint-disable-next-line new-cap
45
- to: (instance) => list.map((item) => new instance(item))
46
- };
47
- }
27
+ constructor({
28
+ currency = '',
29
+ lineItems = [],
30
+ taxes = [],
31
+ discounts = [],
32
+ subtotalAmount = 0.0,
33
+ taxAmount = 0.0,
34
+ shippingAmount = 0.0,
35
+ discountsAmount = 0.0,
36
+ total = 0.0,
37
+ } = {}) {
38
+ function map(array) {
39
+ const list = Array.isArray(array) ? array : [];
40
+ return {
41
+ // eslint-disable-next-line new-cap
42
+ to: (instance) => list.map((item) => new instance(item)),
43
+ };
44
+ }
48
45
 
49
- this.currency = currency;
50
- this.lineItems = map(lineItems).to(SummaryLineItemModel);
51
- this.taxes = map(taxes).to(SummaryTaxModel);
52
- this.discounts = map(discounts).to(SummaryDiscountModel);
53
- this.subtotalAmount = subtotalAmount;
54
- this.taxAmount = taxAmount;
55
- this.shippingAmount = shippingAmount;
56
- this.discountsAmount = discountsAmount;
57
- this.total = total;
58
- }
46
+ this.currency = currency;
47
+ this.lineItems = map(lineItems).to(SummaryLineItemModel);
48
+ this.taxes = map(taxes).to(SummaryTaxModel);
49
+ this.discounts = map(discounts).to(SummaryDiscountModel);
50
+ this.subtotalAmount = subtotalAmount;
51
+ this.taxAmount = taxAmount;
52
+ this.shippingAmount = shippingAmount;
53
+ this.discountsAmount = discountsAmount;
54
+ this.total = total;
55
+ }
59
56
  }
@@ -1,19 +1,16 @@
1
1
  import BaseModel from './base-model';
2
2
 
3
3
  export default class TransactionModel extends BaseModel {
4
- constructor({
5
- invoiceIds = [],
6
- ...fields
7
- }) {
8
- super(fields);
9
- this.invoiceIds = invoiceIds || [];
10
- }
4
+ constructor({ invoiceIds = [], ...fields }) {
5
+ super(fields);
6
+ this.invoiceIds = invoiceIds || [];
7
+ }
11
8
 
12
- get invoiceId () {
13
- return this.invoiceIds[0] || null;
14
- }
9
+ get invoiceId() {
10
+ return this.invoiceIds[0] || null;
11
+ }
15
12
 
16
- get hasInvoice () {
17
- return !!this.invoiceId;
18
- }
19
- }
13
+ get hasInvoice() {
14
+ return !!this.invoiceId;
15
+ }
16
+ }