@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.
- package/.babelrc +24 -26
- package/CHANGELOG.md +14 -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,21 +1,21 @@
|
|
|
1
1
|
import state from '../../state';
|
|
2
2
|
|
|
3
3
|
const triggerTranslations = () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
4
|
+
state.translate.init(state.options.locale, state.options.i18n);
|
|
5
|
+
state.translate.translateItems();
|
|
6
|
+
};
|
|
7
7
|
|
|
8
8
|
export default () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
if (
|
|
10
|
+
state.options.locale === 'auto' &&
|
|
11
|
+
state.data.riskMetadata?.browserData?.language
|
|
12
|
+
) {
|
|
13
|
+
const {
|
|
14
|
+
browserData: { language },
|
|
15
|
+
} = state.data.riskMetadata;
|
|
16
|
+
state.options.locale = language;
|
|
17
|
+
}
|
|
18
|
+
state.translate.init(state.options.locale, state.options.i18n);
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
return triggerTranslations;
|
|
21
|
+
};
|
|
@@ -1,100 +1,100 @@
|
|
|
1
1
|
import decodeJwt from 'jwt-decode';
|
|
2
2
|
import merge from 'lodash.merge';
|
|
3
3
|
import { parseQuantity } from '../../utils/quantity';
|
|
4
|
-
import { validateOptions
|
|
4
|
+
import { validateOptions } from '../../data/options-schema';
|
|
5
5
|
|
|
6
6
|
export function handleComputedProperty(options) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
options._computed = {
|
|
8
|
+
paymentMethodsUrl:
|
|
9
|
+
options._dev?.paymentMethodsUrl ??
|
|
10
|
+
'https://forms.secure-payments.app',
|
|
11
|
+
};
|
|
12
|
+
return options;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export function handleNestedPropertiesDefaultValues(options) {
|
|
14
|
-
|
|
16
|
+
/*
|
|
15
17
|
The JSON Schema default property doesn't work on nested schemas.
|
|
16
18
|
So we'll need to handle the default properties in these instances.
|
|
17
19
|
In most cases default property in schema is sufficient.
|
|
18
20
|
|
|
19
21
|
see https://ajv.js.org/guide/modifying-data.html#assigning-defaults
|
|
20
22
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
if (options.deposit?.currency) {
|
|
24
|
+
options.deposit = merge(
|
|
25
|
+
{
|
|
26
|
+
editable: true,
|
|
27
|
+
buttons: [],
|
|
28
|
+
customAmount: {
|
|
29
|
+
minimum: 1,
|
|
30
|
+
maximum: 1000000000000,
|
|
31
|
+
multipleOf: 1,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
options.deposit || {},
|
|
35
|
+
);
|
|
31
36
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
// default to first deposit button if there is no deposit amount
|
|
38
|
+
if (Number.isNaN(options.deposit.amount)) {
|
|
39
|
+
if (options.deposit.buttons.length > 0) {
|
|
40
|
+
[options.deposit.amount] = options.deposit.buttons;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} else if (options.deposit?.depositRequestId) {
|
|
44
|
+
options.deposit = merge(
|
|
45
|
+
{
|
|
46
|
+
customAmount: {
|
|
47
|
+
minimum: 1,
|
|
48
|
+
maximum: 1000000000000,
|
|
49
|
+
multipleOf: 1,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
options.deposit || {},
|
|
53
|
+
);
|
|
37
54
|
}
|
|
38
|
-
|
|
39
|
-
} else if (options.deposit?.depositRequestId) {
|
|
40
|
-
options.deposit = merge({
|
|
41
|
-
customAmount: {
|
|
42
|
-
minimum: 1,
|
|
43
|
-
maximum: 1000000000000,
|
|
44
|
-
multipleOf: 1,
|
|
45
|
-
}
|
|
46
|
-
}, (options.deposit || {}));
|
|
47
|
-
}
|
|
48
55
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
if (options.items) {
|
|
57
|
+
options.items = options.items.map((item) => ({
|
|
58
|
+
...item,
|
|
59
|
+
quantity: parseQuantity(item),
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
return options;
|
|
57
64
|
}
|
|
58
65
|
|
|
59
66
|
export function handleJwtDestructuring(options) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
if (cashierRequestId && !options.deposit) {
|
|
81
|
-
options.deposit = {};
|
|
82
|
-
options.deposit.depositRequestId = cashierRequestId;
|
|
67
|
+
if (options.jwt && !options.publishableKey) {
|
|
68
|
+
const {
|
|
69
|
+
merchant: organizationId,
|
|
70
|
+
claims: { transactionId, invoiceId, websiteId, cashierRequestId },
|
|
71
|
+
} = decodeJwt(options.jwt);
|
|
72
|
+
Object.entries({
|
|
73
|
+
organizationId,
|
|
74
|
+
transactionId,
|
|
75
|
+
invoiceId,
|
|
76
|
+
websiteId,
|
|
77
|
+
}).forEach(([key, value]) => {
|
|
78
|
+
if (value) {
|
|
79
|
+
options[key] = value;
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (cashierRequestId && !options.deposit) {
|
|
83
|
+
options.deposit = {};
|
|
84
|
+
options.deposit.depositRequestId = cashierRequestId;
|
|
85
|
+
}
|
|
83
86
|
}
|
|
84
|
-
}
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
return options;
|
|
87
89
|
}
|
|
88
90
|
|
|
89
|
-
export default ({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
validOptions = handleComputedProperty(validOptions);
|
|
97
|
-
}
|
|
91
|
+
export default ({ options = {} } = {}) => {
|
|
92
|
+
let validOptions = validateOptions(options);
|
|
93
|
+
if (validOptions) {
|
|
94
|
+
validOptions = handleJwtDestructuring(validOptions);
|
|
95
|
+
validOptions = handleNestedPropertiesDefaultValues(validOptions);
|
|
96
|
+
validOptions = handleComputedProperty(validOptions);
|
|
97
|
+
}
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
}
|
|
99
|
+
return validOptions;
|
|
100
|
+
};
|