@rebilly/instruments 4.5.0 → 4.6.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/.babelrc +24 -26
- package/CHANGELOG.md +7 -0
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +14 -3
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +419 -411
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +323 -287
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +151 -146
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -53
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- package/.prettierrc.js +0 -11
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
import BaseModel from './base-model';
|
|
2
2
|
|
|
3
3
|
export class AddressModel {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
17
|
+
get isPaid() {
|
|
18
|
+
return this.status === InvoiceModel.Status.paid;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,85 +1,94 @@
|
|
|
1
1
|
import BaseModel from './base-model';
|
|
2
2
|
|
|
3
3
|
export class PlanPricingBracketModel {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
static SimpleFormulas = {
|
|
14
|
+
fixedFee: 'fixed-fee',
|
|
15
|
+
flatRate: 'flat-rate',
|
|
16
|
+
};
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
static BracketFormulas = {
|
|
19
|
+
stairstep: 'stairstep',
|
|
20
|
+
tiered: 'tiered',
|
|
21
|
+
volume: 'volume',
|
|
22
|
+
};
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
static Formulas = {
|
|
25
|
+
...PlanPricingModel.SimpleFormulas,
|
|
26
|
+
...PlanPricingModel.BracketFormulas,
|
|
27
|
+
};
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
constructor({
|
|
30
|
+
formula = PlanPricingModel.Formulas.fixedFee,
|
|
31
|
+
price = 0,
|
|
32
|
+
maxQuantity = null,
|
|
33
|
+
brackets = [],
|
|
34
|
+
} = {}) {
|
|
35
|
+
this.formula = formula;
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
get isSimple() {
|
|
61
|
+
return Object.values(PlanPricingModel.SimpleFormulas).includes(
|
|
62
|
+
this.formula,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
58
65
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
66
|
+
get isBracket() {
|
|
67
|
+
return Object.values(PlanPricingModel.BracketFormulas).includes(
|
|
68
|
+
this.formula,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
62
71
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
|
|
74
|
-
|
|
82
|
+
constructor(fields = {}) {
|
|
83
|
+
super(fields);
|
|
75
84
|
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
this.pricing = new PlanPricingModel(fields.pricing || {});
|
|
86
|
+
}
|
|
78
87
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
static FeatureName = {
|
|
5
|
+
paypalBillingAgreement: 'PayPal billing agreement',
|
|
6
|
+
googlePay: 'Google Pay',
|
|
7
|
+
applePay: 'Apple Pay',
|
|
8
|
+
};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
constructor({
|
|
11
|
+
name = '',
|
|
12
|
+
expirationTime = '',
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
// Apple Pay fields
|
|
15
|
+
displayName = '',
|
|
16
|
+
country = '',
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Google Pay fields
|
|
19
|
+
merchantName = '',
|
|
20
|
+
merchantOrigin = '',
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
// Paypal fields
|
|
23
|
+
paypalMerchantId = '',
|
|
24
|
+
billingAgreementToken = '',
|
|
25
|
+
paypalClientId = '',
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
33
|
+
this.displayName = displayName;
|
|
34
|
+
this.country = country;
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.paypalClientId = paypalClientId;
|
|
36
|
+
this.merchantName = merchantName;
|
|
37
|
+
this.merchantOrigin = merchantOrigin;
|
|
42
38
|
|
|
43
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
super(fields);
|
|
9
|
-
this.invoiceIds = invoiceIds || [];
|
|
10
|
-
}
|
|
4
|
+
constructor({ invoiceIds = [], ...fields }) {
|
|
5
|
+
super(fields);
|
|
6
|
+
this.invoiceIds = invoiceIds || [];
|
|
7
|
+
}
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
get invoiceId() {
|
|
10
|
+
return this.invoiceIds[0] || null;
|
|
11
|
+
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
13
|
+
get hasInvoice() {
|
|
14
|
+
return !!this.invoiceId;
|
|
15
|
+
}
|
|
16
|
+
}
|