@rebilly/instruments 4.4.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 +14 -0
- package/dist/index.js +14 -40
- package/dist/index.min.js +14 -40
- package/package.json +16 -5
- 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 +420 -408
- 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 +325 -289
- 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 +149 -134
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -49
- 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
package/src/style/base/theme.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import theme from './default-theme';
|
|
2
2
|
|
|
3
3
|
export class Theme {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
constructor(overrides = {}) {
|
|
5
|
+
this.overrides = overrides;
|
|
6
|
+
this.theme = theme;
|
|
7
|
+
}
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
static nonCssProperties = ['labels'];
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
overrideTheme() {
|
|
12
|
+
Object.keys(this.overrides).forEach((prop) => {
|
|
13
|
+
this.theme[prop] = this.overrides[prop];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
get cssVars() {
|
|
18
|
+
return Object.keys(this.theme)
|
|
19
|
+
.filter((v) => !Theme.nonCssProperties.includes(v))
|
|
20
|
+
.map((p, i) => `${!i ? '' : ' '}--rebilly-${p}: ${this.theme[p]};`)
|
|
21
|
+
.join('\n');
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
build() {
|
|
25
|
+
this.overrideTheme();
|
|
26
|
+
return {
|
|
27
|
+
cssVars: this.cssVars,
|
|
28
|
+
};
|
|
28
29
|
}
|
|
29
|
-
}
|
|
30
30
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Theme } from './theme';
|
|
2
2
|
|
|
3
3
|
describe('RebillyInstruments theme', () => {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
it('builds the theme object', () => {
|
|
5
|
+
const theme = new Theme().build();
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
expect(theme).toMatchSnapshot();
|
|
8
|
+
});
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
it('properly overrides the default properties', () => {
|
|
11
|
+
const overrides = {
|
|
12
|
+
colorPrimary: 'red',
|
|
13
|
+
buttonBorderRadius: '30px',
|
|
14
|
+
};
|
|
15
|
+
const theme = new Theme(overrides).build();
|
|
16
|
+
expect(theme.cssVars).toMatch('--rebilly-colorPrimary: red;');
|
|
17
|
+
expect(theme.cssVars).toMatch('--rebilly-buttonBorderRadius: 30px;');
|
|
18
|
+
});
|
|
19
19
|
});
|
package/src/style/index.js
CHANGED
|
@@ -2,10 +2,10 @@ import { Theme } from './base/theme';
|
|
|
2
2
|
import { vars } from './base';
|
|
3
3
|
|
|
4
4
|
export const mainStyleVars = (themeOverride) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const resolvedTheme = new Theme(themeOverride).build();
|
|
6
|
+
const style = `
|
|
7
7
|
${vars(resolvedTheme)}
|
|
8
8
|
`;
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
return style;
|
|
11
11
|
};
|
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
export default class Border {
|
|
2
|
-
|
|
2
|
+
allStyles = [
|
|
3
|
+
'none',
|
|
4
|
+
'hidden',
|
|
5
|
+
'dotted',
|
|
6
|
+
'dashed',
|
|
7
|
+
'solid',
|
|
8
|
+
'double',
|
|
9
|
+
'groove',
|
|
10
|
+
'ridge',
|
|
11
|
+
'inset',
|
|
12
|
+
'outset',
|
|
13
|
+
'initial',
|
|
14
|
+
'inherit',
|
|
15
|
+
];
|
|
3
16
|
|
|
4
|
-
|
|
5
|
-
|
|
17
|
+
constructor(str) {
|
|
18
|
+
this.str = str || '';
|
|
6
19
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
const style = this.allStyles.find((s) => this.str.includes(s));
|
|
21
|
+
const borderProps = this.str.split(style).map((a) => a.trim());
|
|
22
|
+
this.border = [borderProps[0], style, borderProps[1]];
|
|
23
|
+
}
|
|
11
24
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
get stylePosition() {
|
|
26
|
+
let stylePosition = 0;
|
|
27
|
+
if (this.border.length === 3) {
|
|
28
|
+
stylePosition = 1;
|
|
29
|
+
} else if (this.border.length === 2) {
|
|
30
|
+
if (this.allStyles.includes(this.border[0])) {
|
|
31
|
+
stylePosition = 0;
|
|
32
|
+
} else {
|
|
33
|
+
stylePosition = 1;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return stylePosition;
|
|
22
37
|
}
|
|
23
|
-
return stylePosition;
|
|
24
|
-
}
|
|
25
38
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
updateColor(color) {
|
|
40
|
+
this.border[this.stylePosition + 1] = color;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
30
43
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
44
|
+
get value() {
|
|
45
|
+
return this.border.join(' ');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -3,13 +3,13 @@ import Values from 'values.js';
|
|
|
3
3
|
export const colorValues = (color) => new Values(color);
|
|
4
4
|
|
|
5
5
|
export function alphaColor(color, alphaValue = 1) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
if (color === null) {
|
|
7
|
+
return color;
|
|
8
|
+
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const _alphaColor = colorValues(color);
|
|
11
|
+
_alphaColor.alpha = alphaValue;
|
|
12
|
+
return _alphaColor.rgbString();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export const mutedTextColor = (color) => alphaColor(color, 0.5);
|
|
@@ -17,19 +17,19 @@ export const mutedTextColor = (color) => alphaColor(color, 0.5);
|
|
|
17
17
|
export const mutedBorderColor = (color) => alphaColor(color, 0.25);
|
|
18
18
|
|
|
19
19
|
export const darken = (color, percent) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
if (color === null) {
|
|
21
|
+
return color;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
24
|
+
const _color = colorValues(color);
|
|
25
|
+
return _color.shade(percent).hexString();
|
|
26
|
+
};
|
|
27
27
|
|
|
28
28
|
export const lighten = (color, percent) => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
if (color === null) {
|
|
30
|
+
return color;
|
|
31
|
+
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
33
|
+
const _color = colorValues(color);
|
|
34
|
+
return _color.tint(percent).hexString();
|
|
35
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export function minifyCss(_content) {
|
|
2
2
|
let content = _content;
|
|
3
3
|
// Remove all comments and new lines
|
|
4
|
-
content = content.replace(
|
|
4
|
+
content = content.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g, '');
|
|
5
5
|
// Remove spaces between selectors
|
|
6
|
-
content = content.replace(
|
|
6
|
+
content = content.replace(/\s{2,}/g, ' ');
|
|
7
7
|
// Remove spaces of nested { }
|
|
8
|
-
content = content.replace(
|
|
8
|
+
content = content.replace(/\s([{:}])\s/g, '$1');
|
|
9
9
|
// Remove spaces between , and ;
|
|
10
|
-
content = content.replace(
|
|
10
|
+
content = content.replace(/([;,])\s/g, '$1');
|
|
11
11
|
// Remove important! spaces
|
|
12
|
-
content = content.replace(
|
|
12
|
+
content = content.replace(/\s!/g, '!');
|
|
13
13
|
return content;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export default function addDOMElement({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
element = 'div',
|
|
3
|
+
attributes = {},
|
|
4
|
+
content = null,
|
|
5
|
+
target = 'body',
|
|
6
|
+
insertMethod = 'append',
|
|
7
7
|
} = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
const ELEMENT = document.createElement(element);
|
|
9
|
+
const ELEMENT_ATTRIBUTES = Object.entries(attributes);
|
|
10
|
+
ELEMENT_ATTRIBUTES.forEach(([attribute, value]) => {
|
|
11
|
+
ELEMENT.setAttribute(attribute, value);
|
|
12
|
+
});
|
|
13
|
+
if (content) {
|
|
14
|
+
ELEMENT.innerHTML = content;
|
|
15
|
+
}
|
|
16
|
+
document[target][insertMethod](ELEMENT);
|
|
17
17
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default function formatCurrency(number, currency) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const converToNumber = Number(number);
|
|
3
|
+
if (Number.isNaN(converToNumber) || number === null) return '-';
|
|
4
|
+
return new Intl.NumberFormat('en-US', {
|
|
5
|
+
style: 'currency',
|
|
6
|
+
currency: currency || 'USD',
|
|
7
|
+
}).format(number);
|
|
7
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export default function hasValidCSSSelector(selector) {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
const REGEX_CSS_SELECTOR = /([.#][_a-z]+[_a-z0-9-:\\]*)/gi;
|
|
3
|
+
return typeof selector === 'string' && selector.match(REGEX_CSS_SELECTOR);
|
|
4
4
|
}
|
package/src/utils/index.js
CHANGED
|
@@ -6,10 +6,10 @@ import formatCurrency from './format-currency';
|
|
|
6
6
|
import sleep from './sleep';
|
|
7
7
|
|
|
8
8
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
addDOMElement,
|
|
10
|
+
processPropertyAsDOMElement,
|
|
11
|
+
isDOMElement,
|
|
12
|
+
hasValidCSSSelector,
|
|
13
|
+
formatCurrency,
|
|
14
|
+
sleep,
|
|
15
15
|
};
|
|
@@ -2,30 +2,30 @@ import hasValidCSSSelector from './has-valid-css-selector';
|
|
|
2
2
|
import isDOMElement from './is-dom-element';
|
|
3
3
|
|
|
4
4
|
export default function processPropertyAsDOMElement({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
prop,
|
|
6
|
+
propName = 'Mounting',
|
|
7
|
+
isRequired = true,
|
|
8
8
|
} = {}) {
|
|
9
|
-
|
|
9
|
+
let DOMElement;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
if (typeof prop === 'undefined') {
|
|
12
|
+
throw new Error('processPropertyDOMElement: Missing argument "prop"');
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
if (hasValidCSSSelector(prop)) {
|
|
16
|
+
DOMElement = document.querySelector(prop);
|
|
17
|
+
} else if (isDOMElement(prop)) {
|
|
18
|
+
DOMElement = prop;
|
|
19
|
+
} else {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Please provide a valid CSS class, id or DOM element for "${propName}" property`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
if (!DOMElement && isRequired) {
|
|
26
|
+
throw new Error(
|
|
27
|
+
`Could not find DOM element with CSS class or id "${prop}" to mount ${propName}`,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
return DOMElement;
|
|
31
31
|
}
|
package/src/utils/quantity.js
CHANGED
|
@@ -1,49 +1,47 @@
|
|
|
1
1
|
import { toRaw } from 'vue';
|
|
2
2
|
|
|
3
3
|
const defaultOptions = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
minimum: 1,
|
|
5
|
+
maximum: Number.MAX_SAFE_INTEGER,
|
|
6
|
+
multipleOf: 1,
|
|
7
7
|
};
|
|
8
|
-
export const isObject = val => typeof val === 'object';
|
|
8
|
+
export const isObject = (val) => typeof val === 'object';
|
|
9
9
|
|
|
10
10
|
export function parseQuantity({ quantity }) {
|
|
11
|
-
|
|
12
|
-
{ ...defaultOptions, ...quantity } :
|
|
13
|
-
quantity;
|
|
11
|
+
return isObject(quantity) ? { ...defaultOptions, ...quantity } : quantity;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
export function mergeOptionsItemsQuantity(items) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
return items.map((item) => ({
|
|
16
|
+
...item,
|
|
17
|
+
quantity: parseQuantity(item),
|
|
18
|
+
}));
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export function getQuantityValue(quantity) {
|
|
24
|
-
|
|
22
|
+
return isObject(quantity) ? quantity.default : quantity;
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
export function mapItemsQuantities(items) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
return items.map(({ planId, quantity }) => ({
|
|
27
|
+
planId,
|
|
28
|
+
quantity: getQuantityValue(quantity),
|
|
29
|
+
}));
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
export function createQuantitiesMap(items) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
return items.reduce((map, item) => {
|
|
34
|
+
map.set(item.planId, toRaw(item.quantity));
|
|
35
|
+
return map;
|
|
36
|
+
}, new Map());
|
|
39
37
|
}
|
|
40
38
|
|
|
41
39
|
export function updateItemQuantityFromMap(quantitiesByPlanId) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
40
|
+
return function updateQuantity(item) {
|
|
41
|
+
const quantity = quantitiesByPlanId.get(item.planId) || item.quantity;
|
|
42
|
+
if (isObject(quantity)) {
|
|
43
|
+
quantity.default = getQuantityValue(item.quantity);
|
|
44
|
+
item.quantity = quantity;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
package/src/utils/sleep.js
CHANGED
|
@@ -2,46 +2,47 @@ import state from '../state';
|
|
|
2
2
|
import iframes from '../state/iframes';
|
|
3
3
|
import { mountMethodSelector } from './method-selector';
|
|
4
4
|
import { fetchReadyToPay } from '../storefront/ready-to-pay';
|
|
5
|
+
import { mountForm } from './form';
|
|
5
6
|
|
|
6
7
|
export async function mountAmountSelector() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
iframe.component?.call('route', {
|
|
26
|
-
name: 'amount-selector'
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
iframe.component?.call('update', model);
|
|
30
|
-
|
|
31
|
-
iframe?.component?.on('confirm-amount', async (data) => {
|
|
32
|
-
const { amount, currency } = data;
|
|
33
|
-
state.data.money = {
|
|
34
|
-
amount,
|
|
35
|
-
currency,
|
|
8
|
+
if (state.data.money) {
|
|
9
|
+
state.data.money.amount = null;
|
|
10
|
+
state.data.money.currency = null;
|
|
11
|
+
state.updateModel();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const iframe = iframes.form;
|
|
15
|
+
if (!iframe) {
|
|
16
|
+
await mountForm();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const modelSafeState = state.toModel();
|
|
20
|
+
const model = {
|
|
21
|
+
options: modelSafeState.options,
|
|
22
|
+
data: modelSafeState.data,
|
|
23
|
+
mainStyleVars: modelSafeState.mainStyleVars,
|
|
36
24
|
};
|
|
37
25
|
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
iframe.component?.call('route', {
|
|
27
|
+
name: 'amount-selector',
|
|
40
28
|
});
|
|
41
29
|
|
|
42
|
-
|
|
30
|
+
iframe.component?.call('update', model);
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
iframe?.component?.on('confirm-amount', async (data) => {
|
|
33
|
+
const { amount, currency } = data;
|
|
34
|
+
state.data.money = {
|
|
35
|
+
amount,
|
|
36
|
+
currency,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const readyToPayUpdated = await fetchReadyToPay({
|
|
40
|
+
riskMetadata: state.data.riskMetadata,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
state.data.readyToPay = readyToPayUpdated;
|
|
44
|
+
|
|
45
|
+
state.updateModel();
|
|
46
|
+
mountMethodSelector();
|
|
47
|
+
});
|
|
48
|
+
}
|