@rebilly/instruments 4.8.1 → 4.8.3
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/CHANGELOG.md +14 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +21 -19
- package/.babelrc +0 -26
- package/project.json +0 -31
- package/rollup.config.mjs +0 -79
- package/src/data/options-schema/index.js +0 -112
- package/src/data/options-schema/schemas/options-schema.js +0 -448
- package/src/events/base-event.js +0 -47
- package/src/events/events.spec.js +0 -11
- package/src/events/index.js +0 -15
- package/src/functions/destroy.js +0 -29
- package/src/functions/destroy.spec.js +0 -63
- package/src/functions/mount/fetch-data.js +0 -236
- package/src/functions/mount/fetch-data.spec.js +0 -317
- package/src/functions/mount/get-lead-source-data.js +0 -46
- package/src/functions/mount/get-lead-source-data.spec.js +0 -38
- package/src/functions/mount/index.js +0 -105
- package/src/functions/mount/mount.spec.js +0 -96
- package/src/functions/mount/setup-element.js +0 -29
- package/src/functions/mount/setup-framepay-theme.js +0 -104
- package/src/functions/mount/setup-framepay.js +0 -26
- package/src/functions/mount/setup-i18n.js +0 -21
- package/src/functions/mount/setup-options.js +0 -100
- package/src/functions/mount/setup-options.spec.js +0 -353
- package/src/functions/mount/setup-storefront.js +0 -23
- package/src/functions/mount/setup-styles-vars.js +0 -30
- package/src/functions/mount/setup-user-flow.js +0 -60
- package/src/functions/on.js +0 -22
- package/src/functions/on.spec.js +0 -75
- package/src/functions/purchase.js +0 -173
- package/src/functions/purchase.spec.js +0 -80
- package/src/functions/setup.js +0 -66
- package/src/functions/setup.spec.js +0 -111
- package/src/functions/show.js +0 -30
- package/src/functions/show.spec.js +0 -62
- package/src/functions/update.js +0 -40
- package/src/functions/update.spec.js +0 -104
- package/src/i18n/en.json +0 -35
- package/src/i18n/es.json +0 -32
- package/src/i18n/i18n.spec.js +0 -27
- package/src/i18n/index.js +0 -59
- package/src/index.js +0 -3
- package/src/instance.js +0 -48
- package/src/instance.spec.js +0 -44
- package/src/loader/index.js +0 -145
- package/src/loader/loader.spec.js +0 -74
- package/src/state/iframes.js +0 -23
- package/src/state/index.js +0 -64
- package/src/storefront/account-and-website.js +0 -18
- package/src/storefront/account-and-website.spec.js +0 -73
- package/src/storefront/deposit-requests.js +0 -12
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +0 -30
- package/src/storefront/fetch-products-from-plans.js +0 -59
- package/src/storefront/fetch-products-from-plans.spec.js +0 -113
- package/src/storefront/index.js +0 -78
- package/src/storefront/invoices.js +0 -23
- package/src/storefront/invoices.spec.js +0 -92
- package/src/storefront/models/account-model.js +0 -36
- package/src/storefront/models/base-model.js +0 -7
- package/src/storefront/models/deposit-request-model.js +0 -24
- package/src/storefront/models/invoice-model.js +0 -20
- package/src/storefront/models/payment-metadata.js +0 -7
- package/src/storefront/models/plan-model.js +0 -94
- package/src/storefront/models/product-model.js +0 -3
- package/src/storefront/models/ready-to-pay-model.js +0 -76
- package/src/storefront/models/summary-model.js +0 -56
- package/src/storefront/models/transaction-model.js +0 -16
- package/src/storefront/models/website-model.js +0 -3
- package/src/storefront/payment-instruments.js +0 -47
- package/src/storefront/payment-instruments.spec.js +0 -88
- package/src/storefront/purchase.js +0 -60
- package/src/storefront/purchase.spec.js +0 -53
- package/src/storefront/ready-to-pay.js +0 -96
- package/src/storefront/ready-to-pay.spec.js +0 -76
- package/src/storefront/storefront.spec.js +0 -14
- package/src/storefront/summary.js +0 -114
- package/src/storefront/summary.spec.js +0 -136
- package/src/storefront/transactions.js +0 -12
- package/src/style/base/__snapshots__/theme.spec.js.snap +0 -143
- package/src/style/base/default-theme.js +0 -955
- package/src/style/base/index.js +0 -688
- package/src/style/base/theme.js +0 -30
- package/src/style/base/theme.spec.js +0 -19
- package/src/style/index.js +0 -11
- package/src/style/utils/border.js +0 -47
- package/src/style/utils/color-values.js +0 -35
- package/src/style/utils/minifyCss.js +0 -14
- package/src/utils/add-dom-element.js +0 -17
- package/src/utils/format-currency.js +0 -8
- package/src/utils/has-valid-css-selector.js +0 -4
- package/src/utils/index.js +0 -15
- package/src/utils/is-dom-element.js +0 -3
- package/src/utils/process-property-as-dom-element.js +0 -31
- package/src/utils/quantity.js +0 -47
- package/src/utils/sleep.js +0 -5
- package/src/views/amount-selector.js +0 -46
- package/src/views/common/iframe/base-iframe.js +0 -66
- package/src/views/common/iframe/events/change-iframe-src-handler.js +0 -6
- package/src/views/common/iframe/events/dispatch-event-handler.js +0 -8
- package/src/views/common/iframe/events/resize-component-handler.js +0 -9
- package/src/views/common/iframe/events/show-error-handler.js +0 -5
- package/src/views/common/iframe/events/stop-loader-handler.js +0 -9
- package/src/views/common/iframe/events/update-addons-handler.js +0 -23
- package/src/views/common/iframe/events/update-coupons-handler.js +0 -12
- package/src/views/common/iframe/events/update-items-handler.js +0 -34
- package/src/views/common/iframe/index.js +0 -5
- package/src/views/common/iframe/modal-iframe.js +0 -82
- package/src/views/common/iframe/view-iframe.js +0 -23
- package/src/views/common/render-utilities.js +0 -4
- package/src/views/confirmation.js +0 -45
- package/src/views/errors.js +0 -115
- package/src/views/form.js +0 -61
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -135
- package/src/views/method-selector/express-methods.js +0 -52
- package/src/views/method-selector/generate-digital-wallet.js +0 -53
- package/src/views/method-selector/generate-digital-wallet.spec.js +0 -121
- package/src/views/method-selector/generate-framepay-config.js +0 -56
- package/src/views/method-selector/generate-framepay-config.spec.js +0 -216
- package/src/views/method-selector/get-method-data.js +0 -11
- package/src/views/method-selector/get-payment-methods.js +0 -25
- package/src/views/method-selector/get-payment-methods.spec.js +0 -41
- package/src/views/method-selector/index.js +0 -223
- package/src/views/method-selector/method-selector.spec.js +0 -20
- package/src/views/method-selector/mount-bump-offer.js +0 -120
- package/src/views/method-selector/mount-express-methods.js +0 -107
- package/src/views/modal.js +0 -103
- package/src/views/result.js +0 -24
- package/src/views/summary.js +0 -38
- package/tests/async-utilities.js +0 -22
- package/tests/mocks/framepay-mock.js +0 -15
- package/tests/mocks/rebilly-api-mock.js +0 -11
- package/tests/mocks/rebilly-instruments-mock.js +0 -141
- package/tests/mocks/storefront-api-mock.js +0 -62
- package/tests/mocks/storefront-mock.js +0 -20
- package/tests/msw/server.js +0 -14
- package/tests/setup-test.js +0 -30
- package/vitest.config.js +0 -18
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-len */
|
|
2
|
-
import state from '../../state';
|
|
3
|
-
import { mountSummary } from '../../views/summary';
|
|
4
|
-
import { mountForm, determineFirstView, removeForm } from '../../views/form';
|
|
5
|
-
import { fetchData } from './fetch-data';
|
|
6
|
-
import Events from '../../events';
|
|
7
|
-
import setupElement from './setup-element';
|
|
8
|
-
import setupStorefront from './setup-storefront';
|
|
9
|
-
import setupOptions from './setup-options';
|
|
10
|
-
import setupFramepayInstance from './setup-framepay';
|
|
11
|
-
import setupStylesVars from './setup-styles-vars';
|
|
12
|
-
import setupI18n from './setup-i18n';
|
|
13
|
-
import setupFramepayTheme from './setup-framepay-theme';
|
|
14
|
-
import setupUserFlow from './setup-user-flow';
|
|
15
|
-
import { showError } from '../../views/errors';
|
|
16
|
-
|
|
17
|
-
/** See src/data/options-schema for options structure */
|
|
18
|
-
export async function mount({
|
|
19
|
-
setupFramepay = setupFramepayInstance,
|
|
20
|
-
...options
|
|
21
|
-
} = {}) {
|
|
22
|
-
try {
|
|
23
|
-
state.data = {};
|
|
24
|
-
state.options = {};
|
|
25
|
-
|
|
26
|
-
// Setup options
|
|
27
|
-
state.options = setupOptions({ options });
|
|
28
|
-
|
|
29
|
-
// Setup DOM
|
|
30
|
-
state.form = setupElement({ element: 'form' });
|
|
31
|
-
state.summary = setupElement({ element: 'summary' });
|
|
32
|
-
// hardcode max-width to not break UX
|
|
33
|
-
// PayPal button cannot exceed 750px;
|
|
34
|
-
state.form.style.maxWidth = '750px';
|
|
35
|
-
if (state.summary) {
|
|
36
|
-
state.summary.style.maxWidth = '750px';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Setup state
|
|
40
|
-
state.storefront = setupStorefront();
|
|
41
|
-
state.mainStyleVars = setupStylesVars();
|
|
42
|
-
state.options.themeFramepay = setupFramepayTheme();
|
|
43
|
-
|
|
44
|
-
// Setup loader
|
|
45
|
-
state.loader.addDOMElement({ el: state.form });
|
|
46
|
-
state.loader.addDOMElement({ section: 'summary', el: state.summary });
|
|
47
|
-
state.loader.startLoading({
|
|
48
|
-
section: 'summary',
|
|
49
|
-
id: 'rebilly-instruments-summary',
|
|
50
|
-
});
|
|
51
|
-
state.loader.startLoading({ id: 'rebilly-instruments-form' });
|
|
52
|
-
|
|
53
|
-
const [data] = await Promise.all([fetchData(), setupFramepay()]);
|
|
54
|
-
state.data = data;
|
|
55
|
-
Events.dataReady.dispatch(state.data);
|
|
56
|
-
|
|
57
|
-
state.i18n = setupI18n();
|
|
58
|
-
|
|
59
|
-
// Update state options from data
|
|
60
|
-
if (!state.options.websiteId && state.data.transaction?.websiteId) {
|
|
61
|
-
state.options.websiteId = state.data.transaction.websiteId;
|
|
62
|
-
} else if (!state.options.websiteId && state.data.invoice?.websiteId) {
|
|
63
|
-
state.options.websiteId = state.data.invoice.websiteId;
|
|
64
|
-
}
|
|
65
|
-
if (
|
|
66
|
-
state.data.transaction &&
|
|
67
|
-
state.data.transaction?.type === 'setup'
|
|
68
|
-
) {
|
|
69
|
-
state.options.transactionType = 'setup';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Mount content
|
|
73
|
-
if (state.form) {
|
|
74
|
-
mountForm().then(() => determineFirstView());
|
|
75
|
-
}
|
|
76
|
-
if (state.summary) {
|
|
77
|
-
mountSummary();
|
|
78
|
-
}
|
|
79
|
-
state.i18n({ state });
|
|
80
|
-
state.hasMounted = true;
|
|
81
|
-
|
|
82
|
-
const invoiceId =
|
|
83
|
-
state.options?.invoiceId || state.data?.transaction?.invoiceId;
|
|
84
|
-
if (invoiceId && state.data.invoice.isPaid) {
|
|
85
|
-
state.loader.stopLoading({ id: 'rebilly-instruments-form' });
|
|
86
|
-
removeForm();
|
|
87
|
-
showError(
|
|
88
|
-
state.translate.getTranslation('form.error.invoiceIsPaid'),
|
|
89
|
-
false,
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (!data.readyToPay?.length) {
|
|
94
|
-
state.loader.stopLoading({ id: 'rebilly-instruments-form' });
|
|
95
|
-
showError(
|
|
96
|
-
state.translate.getTranslation('form.error.noPaymentMethods'),
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
} catch (error) {
|
|
100
|
-
showError(error);
|
|
101
|
-
throw error;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setupUserFlow({ state });
|
|
105
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
|
|
2
|
-
import { sleep } from '@/utils';
|
|
3
|
-
|
|
4
|
-
describe('RebillyInstruments instance', () => {
|
|
5
|
-
it("should inject HTML to the merchant's website", async () => {
|
|
6
|
-
const framePayScriptUrl = 'https://framepay.rebilly.com/rebilly.js';
|
|
7
|
-
const framePayStyleUrl = 'https://framepay.rebilly.com/rebilly.css';
|
|
8
|
-
|
|
9
|
-
const options = {
|
|
10
|
-
form: '.form-selector',
|
|
11
|
-
summary: '.summary-selector',
|
|
12
|
-
locale: 'auto',
|
|
13
|
-
items: [
|
|
14
|
-
{
|
|
15
|
-
planId: 'test-plan-id-1',
|
|
16
|
-
quantity: 1,
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
theme: {
|
|
20
|
-
colorBackground: '#000',
|
|
21
|
-
},
|
|
22
|
-
css: `
|
|
23
|
-
.rebilly-instruments-summary-line-item-synopsis-title {
|
|
24
|
-
color: rgb(0, 68, 212);
|
|
25
|
-
}
|
|
26
|
-
`,
|
|
27
|
-
_dev: {
|
|
28
|
-
framePayStyleLink: framePayStyleUrl,
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
await RenderMockRebillyInstruments(options);
|
|
32
|
-
|
|
33
|
-
const sleepMilliseconds = 1000;
|
|
34
|
-
await sleep(sleepMilliseconds);
|
|
35
|
-
|
|
36
|
-
// Mounts form and summary
|
|
37
|
-
const summarySelector = document.querySelector('.summary-selector');
|
|
38
|
-
const iframe = summarySelector.querySelector('iframe');
|
|
39
|
-
expect(iframe.getAttribute('name')).toEqual(
|
|
40
|
-
'rebilly-instruments-summary',
|
|
41
|
-
);
|
|
42
|
-
expect(iframe.getAttribute('class')).toEqual(
|
|
43
|
-
'rebilly-instruments-iframe',
|
|
44
|
-
);
|
|
45
|
-
expect(iframe.getAttribute('loading')).toEqual('lazy');
|
|
46
|
-
expect(iframe.getAttribute('allow')).toEqual('payment');
|
|
47
|
-
expect(iframe.getAttribute('src')).toEqual(
|
|
48
|
-
'https://forms.test.rebilly.dev?name=rebilly-instruments-summary',
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Theme config overrides initial styles
|
|
52
|
-
const STYLE_VARS = document.querySelectorAll(
|
|
53
|
-
'style[type="text/css"]',
|
|
54
|
-
)[0];
|
|
55
|
-
|
|
56
|
-
expect(STYLE_VARS.innerHTML).toMatch(
|
|
57
|
-
'--rebilly-colorBackground: #000;',
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// Mounts default FramePay script
|
|
61
|
-
const SCRIPTS = [...document.querySelectorAll('head script')];
|
|
62
|
-
const FRAMEPAY_SCRIPT = SCRIPTS.find(
|
|
63
|
-
(script) => script.src === framePayScriptUrl,
|
|
64
|
-
);
|
|
65
|
-
expect(FRAMEPAY_SCRIPT.src).toEqual(framePayScriptUrl);
|
|
66
|
-
|
|
67
|
-
// Mounts _dev FramePay style
|
|
68
|
-
const STYLE_LINKS = [...document.querySelectorAll('head link')];
|
|
69
|
-
const FRAMEPAY_STYLE = STYLE_LINKS.find(
|
|
70
|
-
(script) => script.href === framePayStyleUrl,
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should mount with JWT pruchase data', async () => {
|
|
77
|
-
// Use https://www.jwt.io to help encode and decode JWT
|
|
78
|
-
const jwt =
|
|
79
|
-
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkMGYzNWEzYy03N2M0LTQ0NDItOWFhNC03ODA5NDA2NzBjN2IiLCJleHAiOjE2NzM2NDk0ODcsImlhdCI6MTY0MjExMDczOS4zMjYyNDQsImFjbCI6W3sic2NvcGUiOnsib3JnYW5pemF0aW9uSWQiOlsidGVzdC1vcmdhbml6YXRpb24tZCJdLCJ0cmFuc2FjdGlvbklkIjpbInRlc3QtdHJhbnNhY3Rpb24taWQiXX0sInBlcm1pc3Npb25zIjpbMV19XSwiY2xhaW1zIjp7InRyYW5zYWN0aW9uSWQiOiJ0ZXN0LXRyYW5zYWN0aW9uLWlkIn0sIm1lcmNoYW50IjoidGVzdC1vcmdhbml6YXRpb24taWQiLCJjdXN0b21lciI6eyJpZCI6InRlc3QtY3VzdG9tZXItaWQiLCJuYW1lIjoiVGVzdGVyIFRlc3RlcnNvbiIsImNyZWF0ZWRUaW1lIjoiMjAyMi0wMS0xNFQwMDowMDowMCswMDowMCJ9fQ.h4voW-UvXzXRm1JlxkN8cNHhQ_IIPSWWN9BANfBWEHQ';
|
|
80
|
-
|
|
81
|
-
const options = {
|
|
82
|
-
form: '.form-selector',
|
|
83
|
-
summary: '.summary-selector',
|
|
84
|
-
jwt,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
const instance = await RenderMockRebillyInstruments(options);
|
|
88
|
-
|
|
89
|
-
expect(instance.state.options).toEqual(
|
|
90
|
-
expect.objectContaining({
|
|
91
|
-
transactionId: 'test-transaction-id',
|
|
92
|
-
organizationId: 'test-organization-id',
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { processPropertyAsDOMElement } from '../../utils';
|
|
2
|
-
import state from '../../state';
|
|
3
|
-
|
|
4
|
-
export default ({ element = '' }) => {
|
|
5
|
-
const { options } = state;
|
|
6
|
-
|
|
7
|
-
if (element !== 'form' && element !== 'summary') {
|
|
8
|
-
throw new Error('element must be "form" or "summary"');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const getProp = () => {
|
|
12
|
-
if (options[element]) {
|
|
13
|
-
return options[element];
|
|
14
|
-
}
|
|
15
|
-
switch (element) {
|
|
16
|
-
case 'summary':
|
|
17
|
-
return '.rebilly-instruments-summary';
|
|
18
|
-
case 'form':
|
|
19
|
-
default:
|
|
20
|
-
return '.rebilly-instruments';
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return processPropertyAsDOMElement({
|
|
25
|
-
prop: getProp(),
|
|
26
|
-
propName: element,
|
|
27
|
-
isRequired: ['form'].includes(element),
|
|
28
|
-
});
|
|
29
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import state from '../../state';
|
|
2
|
-
|
|
3
|
-
function processCSS(rawCss) {
|
|
4
|
-
const cssMap = {};
|
|
5
|
-
[...rawCss.matchAll(/(--rebilly.*(?=:))[:\s](.*(?=;))/g)].forEach(
|
|
6
|
-
(item) => {
|
|
7
|
-
cssMap[item[1]] = item[2].trim();
|
|
8
|
-
},
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
function parseValue(value) {
|
|
12
|
-
const cssVariables = value.match(/var\((.+?)\)/g);
|
|
13
|
-
if (cssVariables) {
|
|
14
|
-
let cssValue = value;
|
|
15
|
-
cssVariables.forEach((variable) => {
|
|
16
|
-
const cssVarName = variable.match(/\((.*)\)/i)[1];
|
|
17
|
-
cssValue = value.replace(variable, cssMap[cssVarName]);
|
|
18
|
-
});
|
|
19
|
-
return parseValue(cssValue);
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return Object.entries(cssMap).map(([key, value]) => [
|
|
25
|
-
key,
|
|
26
|
-
parseValue(value),
|
|
27
|
-
]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function replaceCssVars(rawCss) {
|
|
31
|
-
const CssVarsObj = {};
|
|
32
|
-
processCSS(rawCss).forEach(([key, value]) => {
|
|
33
|
-
CssVarsObj[key] = value;
|
|
34
|
-
});
|
|
35
|
-
return CssVarsObj;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const getStyleProps = (obj, particle = '') => {
|
|
39
|
-
const output = {
|
|
40
|
-
color: obj[`--rebilly-${particle}ColorText`],
|
|
41
|
-
fontFamily: obj[`--rebilly-${particle}FontFamily`],
|
|
42
|
-
fontSize: obj[`--rebilly-${particle}FontSize`],
|
|
43
|
-
fontWeight: obj[`--rebilly-${particle}FontWeight`],
|
|
44
|
-
lineHeight: obj[`--rebilly-${particle}FontLineHeight`],
|
|
45
|
-
background: obj[`--rebilly-${particle}ColorBackground`],
|
|
46
|
-
boxShadow: obj[`--rebilly-${particle}BoxShadow`],
|
|
47
|
-
};
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export default () => {
|
|
52
|
-
const fullCss = `
|
|
53
|
-
${state.mainStyleVars}
|
|
54
|
-
${state.options?.css || ''}
|
|
55
|
-
`;
|
|
56
|
-
|
|
57
|
-
const resolvedCssVarsObj = replaceCssVars(fullCss);
|
|
58
|
-
|
|
59
|
-
const framepayStyle = {
|
|
60
|
-
base: {
|
|
61
|
-
...getStyleProps(resolvedCssVarsObj, 'input'),
|
|
62
|
-
':hover': getStyleProps(resolvedCssVarsObj, 'inputHover'),
|
|
63
|
-
':focus': getStyleProps(resolvedCssVarsObj, 'inputFocus'),
|
|
64
|
-
'::placeholder': getStyleProps(
|
|
65
|
-
resolvedCssVarsObj,
|
|
66
|
-
'inputPlaceholder',
|
|
67
|
-
),
|
|
68
|
-
'::selection': getStyleProps(resolvedCssVarsObj, 'inputSelection'),
|
|
69
|
-
},
|
|
70
|
-
invalid: {
|
|
71
|
-
...getStyleProps(resolvedCssVarsObj, 'inputError'),
|
|
72
|
-
':hover': getStyleProps(resolvedCssVarsObj, 'inputErrorHover'),
|
|
73
|
-
':focus': getStyleProps(resolvedCssVarsObj, 'inputErrorFocus'),
|
|
74
|
-
'::placeholder': getStyleProps(
|
|
75
|
-
resolvedCssVarsObj,
|
|
76
|
-
'inputErrorPlaceholder',
|
|
77
|
-
),
|
|
78
|
-
'::selection': getStyleProps(
|
|
79
|
-
resolvedCssVarsObj,
|
|
80
|
-
'inputErrorSelection',
|
|
81
|
-
),
|
|
82
|
-
},
|
|
83
|
-
buttons: {
|
|
84
|
-
base: {
|
|
85
|
-
...getStyleProps(resolvedCssVarsObj, 'buttonSecondary'),
|
|
86
|
-
':hover': getStyleProps(
|
|
87
|
-
resolvedCssVarsObj,
|
|
88
|
-
'buttonSecondaryHover',
|
|
89
|
-
),
|
|
90
|
-
':focus': getStyleProps(
|
|
91
|
-
resolvedCssVarsObj,
|
|
92
|
-
'buttonSecondaryActive',
|
|
93
|
-
),
|
|
94
|
-
},
|
|
95
|
-
active: {
|
|
96
|
-
...getStyleProps(resolvedCssVarsObj, 'button'),
|
|
97
|
-
':hover': getStyleProps(resolvedCssVarsObj, 'buttonHover'),
|
|
98
|
-
':focus': getStyleProps(resolvedCssVarsObj, 'buttonActive'),
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
return framepayStyle;
|
|
104
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import state from '../../state';
|
|
2
|
-
|
|
3
|
-
export default async function setupFramepay() {
|
|
4
|
-
const { _dev } = state.options || {};
|
|
5
|
-
const urls = {
|
|
6
|
-
script:
|
|
7
|
-
_dev?.framePayScriptLink ||
|
|
8
|
-
'https://framepay.rebilly.com/rebilly.js',
|
|
9
|
-
style:
|
|
10
|
-
_dev?.framePayStyleLink ||
|
|
11
|
-
'https://framepay.rebilly.com/rebilly.css',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
const framepayStyle = document.createElement('link');
|
|
16
|
-
framepayStyle.setAttribute('href', urls.style);
|
|
17
|
-
framepayStyle.setAttribute('rel', 'stylesheet');
|
|
18
|
-
document.head.prepend(framepayStyle);
|
|
19
|
-
|
|
20
|
-
const framepayScript = document.createElement('script');
|
|
21
|
-
framepayScript.setAttribute('src', urls.script);
|
|
22
|
-
|
|
23
|
-
framepayScript.onload = () => resolve();
|
|
24
|
-
document.head.append(framepayScript);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import state from '../../state';
|
|
2
|
-
|
|
3
|
-
const triggerTranslations = () => {
|
|
4
|
-
state.translate.init(state.options.locale, state.options.i18n);
|
|
5
|
-
state.translate.translateItems();
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export default () => {
|
|
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
|
-
|
|
20
|
-
return triggerTranslations;
|
|
21
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import decodeJwt from 'jwt-decode';
|
|
2
|
-
import merge from 'lodash.merge';
|
|
3
|
-
import { parseQuantity } from '../../utils/quantity';
|
|
4
|
-
import { validateOptions } from '../../data/options-schema';
|
|
5
|
-
|
|
6
|
-
export function handleComputedProperty(options) {
|
|
7
|
-
options._computed = {
|
|
8
|
-
paymentMethodsUrl:
|
|
9
|
-
options._dev?.paymentMethodsUrl ??
|
|
10
|
-
'https://forms.secure-payments.app',
|
|
11
|
-
};
|
|
12
|
-
return options;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function handleNestedPropertiesDefaultValues(options) {
|
|
16
|
-
/*
|
|
17
|
-
The JSON Schema default property doesn't work on nested schemas.
|
|
18
|
-
So we'll need to handle the default properties in these instances.
|
|
19
|
-
In most cases default property in schema is sufficient.
|
|
20
|
-
|
|
21
|
-
see https://ajv.js.org/guide/modifying-data.html#assigning-defaults
|
|
22
|
-
*/
|
|
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
|
-
);
|
|
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
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (options.items) {
|
|
57
|
-
options.items = options.items.map((item) => ({
|
|
58
|
-
...item,
|
|
59
|
-
quantity: parseQuantity(item),
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return options;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function handleJwtDestructuring(options) {
|
|
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
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return options;
|
|
89
|
-
}
|
|
90
|
-
|
|
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
|
-
|
|
99
|
-
return validOptions;
|
|
100
|
-
};
|