@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
|
@@ -3,101 +3,102 @@ import { avoidUnhandledPromises } from 'tests/async-utilities';
|
|
|
3
3
|
import iframes from '@/state/iframes';
|
|
4
4
|
|
|
5
5
|
describe('RebillyInstruments Update', () => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let error;
|
|
12
|
-
try {
|
|
13
|
-
await rebillyInstruments.update();
|
|
14
|
-
} catch (e) {
|
|
15
|
-
error = e;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
expect(error).toEqual(
|
|
19
|
-
new Error('Update method cannot be called before mounting instruments')
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
|
|
24
|
-
it.skip('should call changeLocale when updating locale options', async () => {
|
|
25
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
26
|
-
|
|
27
|
-
const call = vi.fn();
|
|
28
|
-
// Simulate mounted iframe
|
|
29
|
-
const fakeIFrameComponent = {
|
|
30
|
-
destroy: vi.fn(),
|
|
31
|
-
component: {
|
|
32
|
-
call
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
iframes.form = fakeIFrameComponent;
|
|
36
|
-
|
|
37
|
-
await rebillyInstruments.update({ locale: 'ja' });
|
|
38
|
-
|
|
39
|
-
expect(call).toBeCalledWith('changeLocale', 'ja');
|
|
40
|
-
// It would be better to match real UI instead of implementation state
|
|
41
|
-
expect(rebillyInstruments.state.options.locale).toBe('ja');
|
|
42
|
-
expect(rebillyInstruments.state.translate.locale).toBe('ja');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('should destroy and update when updating options different than locale', async () => {
|
|
46
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
47
|
-
const formElement = document.querySelector('.form-selector');
|
|
48
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
49
|
-
|
|
50
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
51
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const call = vi.fn();
|
|
55
|
-
// Simulate mounted iframe
|
|
56
|
-
const fakeIFrameComponent = {
|
|
57
|
-
destroy: vi.fn(),
|
|
58
|
-
component: {
|
|
59
|
-
call
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
iframes.form = fakeIFrameComponent;
|
|
63
|
-
|
|
64
|
-
await rebillyInstruments.update({
|
|
65
|
-
countryCode: 'ES'
|
|
66
|
-
});
|
|
6
|
+
it('should throw an error when methods are not mounted', async () => {
|
|
7
|
+
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
8
|
+
|
|
9
|
+
rebillyInstruments.state.hasMounted = false;
|
|
67
10
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
74
|
-
const formElement = document.querySelector('.form-selector');
|
|
75
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
76
|
-
|
|
77
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
78
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
79
|
-
|
|
80
|
-
const call = vi.fn();
|
|
81
|
-
// Simulate mounted iframe
|
|
82
|
-
const fakeIFrameComponent = {
|
|
83
|
-
destroy: vi.fn(),
|
|
84
|
-
component: {
|
|
85
|
-
call
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
iframes.form = fakeIFrameComponent;
|
|
90
|
-
|
|
91
|
-
await rebillyInstruments.update({
|
|
92
|
-
items: [
|
|
93
|
-
{
|
|
94
|
-
planId: 'test-plan-id-1',
|
|
95
|
-
quantity: 5
|
|
11
|
+
let error;
|
|
12
|
+
try {
|
|
13
|
+
await rebillyInstruments.update();
|
|
14
|
+
} catch (e) {
|
|
15
|
+
error = e;
|
|
96
16
|
}
|
|
97
|
-
|
|
17
|
+
|
|
18
|
+
expect(error).toEqual(
|
|
19
|
+
new Error(
|
|
20
|
+
'Update method cannot be called before mounting instruments',
|
|
21
|
+
),
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
|
|
26
|
+
it.skip('should call changeLocale when updating locale options', async () => {
|
|
27
|
+
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
28
|
+
|
|
29
|
+
const call = vi.fn();
|
|
30
|
+
// Simulate mounted iframe
|
|
31
|
+
const fakeIFrameComponent = {
|
|
32
|
+
destroy: vi.fn(),
|
|
33
|
+
component: {
|
|
34
|
+
call,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
iframes.form = fakeIFrameComponent;
|
|
38
|
+
|
|
39
|
+
await rebillyInstruments.update({ locale: 'ja' });
|
|
40
|
+
|
|
41
|
+
expect(call).toBeCalledWith('changeLocale', 'ja');
|
|
42
|
+
// It would be better to match real UI instead of implementation state
|
|
43
|
+
expect(rebillyInstruments.state.options.locale).toBe('ja');
|
|
44
|
+
expect(rebillyInstruments.state.translate.locale).toBe('ja');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should destroy and update when updating options different than locale', async () => {
|
|
48
|
+
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
49
|
+
const formElement = document.querySelector('.form-selector');
|
|
50
|
+
const summaryElement = document.querySelector('.summary-selector');
|
|
51
|
+
|
|
52
|
+
expect(formElement.innerHTML).not.toEqual('');
|
|
53
|
+
expect(summaryElement.innerHTML).not.toEqual('');
|
|
54
|
+
|
|
55
|
+
const call = vi.fn();
|
|
56
|
+
// Simulate mounted iframe
|
|
57
|
+
const fakeIFrameComponent = {
|
|
58
|
+
destroy: vi.fn(),
|
|
59
|
+
component: {
|
|
60
|
+
call,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
iframes.form = fakeIFrameComponent;
|
|
64
|
+
|
|
65
|
+
await rebillyInstruments.update({
|
|
66
|
+
countryCode: 'ES',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(rebillyInstruments.state.options.countryCode).toEqual('ES');
|
|
70
|
+
await avoidUnhandledPromises();
|
|
98
71
|
});
|
|
99
72
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
73
|
+
it('should replace the items with different options', async () => {
|
|
74
|
+
const rebillyInstruments = await RenderMockRebillyInstruments();
|
|
75
|
+
const formElement = document.querySelector('.form-selector');
|
|
76
|
+
const summaryElement = document.querySelector('.summary-selector');
|
|
77
|
+
|
|
78
|
+
expect(formElement.innerHTML).not.toEqual('');
|
|
79
|
+
expect(summaryElement.innerHTML).not.toEqual('');
|
|
80
|
+
|
|
81
|
+
const call = vi.fn();
|
|
82
|
+
// Simulate mounted iframe
|
|
83
|
+
const fakeIFrameComponent = {
|
|
84
|
+
destroy: vi.fn(),
|
|
85
|
+
component: {
|
|
86
|
+
call,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
iframes.form = fakeIFrameComponent;
|
|
91
|
+
|
|
92
|
+
await rebillyInstruments.update({
|
|
93
|
+
items: [
|
|
94
|
+
{
|
|
95
|
+
planId: 'test-plan-id-1',
|
|
96
|
+
quantity: 5,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(rebillyInstruments.state.options.items[0].quantity).toEqual(5);
|
|
102
|
+
await avoidUnhandledPromises();
|
|
103
|
+
});
|
|
103
104
|
});
|
package/src/i18n/en.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
2
|
+
"en": {
|
|
3
|
+
"summary": {
|
|
4
|
+
"subTotal": "Sub Total",
|
|
5
|
+
"discounts": "Discounts",
|
|
6
|
+
"taxes": "Taxes",
|
|
7
|
+
"shipping": "Shipping",
|
|
8
|
+
"total": "Total"
|
|
9
|
+
},
|
|
10
|
+
"deposit": {
|
|
11
|
+
"goBack": "Choose another amount"
|
|
12
|
+
},
|
|
13
|
+
"form": {
|
|
14
|
+
"expressCheckout": "Express checkout",
|
|
15
|
+
"or": "Or",
|
|
16
|
+
"popupOverlayText": "Click here to show popup window",
|
|
17
|
+
"andMore": "and more",
|
|
18
|
+
"error": {
|
|
19
|
+
"noPaymentMethods": "No payment methods available for this transaction, please contact support.",
|
|
20
|
+
"invoiceIsPaid": "The invoice has been fully paid."
|
|
21
|
+
},
|
|
22
|
+
"loaderMessages": {
|
|
23
|
+
"processingPayment": "Processing payment instrument."
|
|
24
|
+
},
|
|
25
|
+
"bumpOffer": {
|
|
26
|
+
"title": "Yes, I want to upgrade!",
|
|
27
|
+
"startingAt": "Starting at {basePrice}"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"paymentMethods": {
|
|
31
|
+
"payment-card": "Payment card",
|
|
32
|
+
"ach": "Bank account"
|
|
33
|
+
}
|
|
33
34
|
}
|
|
34
|
-
}
|
|
35
35
|
}
|
package/src/i18n/es.json
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
29
|
-
|
|
2
|
+
"es": {
|
|
3
|
+
"summary": {
|
|
4
|
+
"subTotal": "Sub Total",
|
|
5
|
+
"discounts": "Descuentos",
|
|
6
|
+
"taxes": "Impuestos",
|
|
7
|
+
"shipping": "Envío",
|
|
8
|
+
"total": "Total"
|
|
9
|
+
},
|
|
10
|
+
"deposit": {
|
|
11
|
+
"goBack": "Elija otro monto a depositar"
|
|
12
|
+
},
|
|
13
|
+
"form": {
|
|
14
|
+
"expressCheckout": "Chequeo rápido",
|
|
15
|
+
"or": "O pague con",
|
|
16
|
+
"andMore": "y más",
|
|
17
|
+
"popupOverlayText": "Haga clic aquí para mostrar la ventana emergente",
|
|
18
|
+
"error": {
|
|
19
|
+
"noPaymentMethods": "No hay métodos de pago disponibles para esta transacción, por favor, póngase en contacto con el servicio de asistencia.",
|
|
20
|
+
"invoiceIsPaid": "La factura ha sido completamente pagada."
|
|
21
|
+
},
|
|
22
|
+
"bumpOffer": {
|
|
23
|
+
"title": "¡Sí, me gustaría actualizar!",
|
|
24
|
+
"startingAt": "A partir de {basePrice}"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"paymentMethods": {
|
|
28
|
+
"payment-card": "Tarjeta de crédito",
|
|
29
|
+
"ach": "Cuenta bancaria"
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
|
-
}
|
|
32
32
|
}
|
package/src/i18n/i18n.spec.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { Translate } from './index';
|
|
2
2
|
|
|
3
3
|
describe('i18n Class', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const canTranslate = document.createElement('div');
|
|
5
|
+
canTranslate.innerHTML = 'Discounts';
|
|
6
|
+
canTranslate.setAttribute('data-rebilly-i18n', 'summary.discounts');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const canNotTranslate = document.createElement('div');
|
|
9
|
+
canNotTranslate.innerHTML = 'Untouched';
|
|
10
|
+
canNotTranslate.setAttribute('data-rebilly-i18n', 'does.not.exist');
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
document.body.append(canTranslate);
|
|
13
|
+
document.body.append(canNotTranslate);
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
it('can translate element with proper data attribute and skip wrong translation path or languages', () => {
|
|
16
|
+
const translate = new Translate();
|
|
17
|
+
translate.init('es-US');
|
|
18
|
+
translate.translateItems();
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
const [translated, untouched] = document.querySelectorAll(
|
|
21
|
+
'[data-rebilly-i18n]',
|
|
22
|
+
);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
expect(translated.innerHTML).toEqual('Descuentos');
|
|
25
|
+
expect(untouched.innerHTML).toEqual('Untouched');
|
|
26
|
+
});
|
|
27
27
|
});
|
package/src/i18n/index.js
CHANGED
|
@@ -3,57 +3,57 @@ import en from './en.json';
|
|
|
3
3
|
import es from './es.json';
|
|
4
4
|
|
|
5
5
|
export class Translate {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
6
|
+
constructor() {
|
|
7
|
+
this.locale = '';
|
|
8
|
+
this.items = [];
|
|
9
|
+
this.languages = {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
init(locale, messages) {
|
|
13
|
+
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
14
|
+
this.locale = this.getLocale(locale);
|
|
15
|
+
this.languages = merge({}, { ...en, ...es }, messages);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
translateItems() {
|
|
19
|
+
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
20
|
+
|
|
21
|
+
if (this.locale in this.languages) {
|
|
22
|
+
return this.items.forEach((item) => {
|
|
23
|
+
const translate = this.getTranslation(
|
|
24
|
+
item.dataset.rebillyI18n,
|
|
25
|
+
this.languages[this.locale],
|
|
26
|
+
);
|
|
27
|
+
if (translate) {
|
|
28
|
+
item.innerHTML = translate;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
updateTranslationsToNewLocale(newLocale) {
|
|
36
|
+
this.locale = newLocale;
|
|
37
|
+
this.translateItems();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getLocale(locale = this.locale) {
|
|
41
|
+
if (!locale.includes('-') || locale in this.languages) {
|
|
42
|
+
return locale;
|
|
29
43
|
}
|
|
30
|
-
|
|
44
|
+
locale = locale.replace(/[-._]\w+$/gi, '');
|
|
45
|
+
return this.getLocale(locale);
|
|
31
46
|
}
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
48
|
+
translateItem(item) {
|
|
49
|
+
const locale = this.getLocale();
|
|
50
|
+
return this.getTranslation(
|
|
51
|
+
item.dataset.rebillyI18n,
|
|
52
|
+
this.languages[locale],
|
|
53
|
+
);
|
|
54
|
+
}
|
|
39
55
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return locale;
|
|
56
|
+
getTranslation(prop, lan = this.languages[this.locale]) {
|
|
57
|
+
return prop.split('.').reduce((acc, val) => acc?.[val], lan);
|
|
43
58
|
}
|
|
44
|
-
locale = locale.replace(/[-._]\w+$/gi, '');
|
|
45
|
-
return this.getLocale(locale);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
translateItem(item) {
|
|
49
|
-
const locale = this.getLocale();
|
|
50
|
-
return this.getTranslation(
|
|
51
|
-
item.dataset.rebillyI18n,
|
|
52
|
-
this.languages[locale],
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getTranslation(prop, lan = this.languages[this.locale]) {
|
|
57
|
-
return prop.split('.').reduce((acc, val) => acc?.[val], lan);
|
|
58
|
-
}
|
|
59
59
|
}
|
package/src/instance.js
CHANGED
|
@@ -9,40 +9,40 @@ import { destroy } from './functions/destroy';
|
|
|
9
9
|
import { show } from './functions/show';
|
|
10
10
|
|
|
11
11
|
export class RebillyInstrumentsInstance {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
12
|
+
constructor() {
|
|
13
|
+
this.state = state;
|
|
14
|
+
this.iframes = iframes;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async mount(options) {
|
|
18
|
+
await mount(options);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async destroy() {
|
|
22
|
+
await destroy();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async update(newOptions) {
|
|
26
|
+
await update({ newOptions });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async purchase(payload) {
|
|
30
|
+
await purchase({ payload });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async setup(payload) {
|
|
34
|
+
await setup({ payload });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async show(componentName, payload) {
|
|
38
|
+
await show({ componentName, payload });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get version() {
|
|
42
|
+
return 'RebillyInstruments Ver.[VI]{version}[/VI]';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
on(eventName, callback) {
|
|
46
|
+
on({ eventName, callback });
|
|
47
|
+
}
|
|
48
48
|
}
|
package/src/instance.spec.js
CHANGED
|
@@ -4,39 +4,41 @@ import RebillyInstruments from './index';
|
|
|
4
4
|
import { RebillyInstrumentsInstance } from './instance';
|
|
5
5
|
|
|
6
6
|
describe('RebillyInstruments instance', () => {
|
|
7
|
-
|
|
7
|
+
let rebillyInstruments;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
rebillyInstruments = RebillyInstruments;
|
|
11
|
+
});
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
it('should have default export as instance of class', () => {
|
|
14
|
+
expect(RebillyInstruments).toBeInstanceOf(RebillyInstrumentsInstance);
|
|
15
|
+
});
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
it('should be mountable', async () => {
|
|
18
|
+
vi.spyOn(rebillyInstruments, 'mount');
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
document.body.innerHTML = `
|
|
21
21
|
<div class="form-selector"></div>
|
|
22
22
|
<div class="summary-selector"></div>
|
|
23
23
|
`;
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
25
|
+
const options = {
|
|
26
|
+
form: '.form-selector',
|
|
27
|
+
summary: '.summary-selector',
|
|
28
|
+
apiMode: 'sandbox',
|
|
29
|
+
items: [
|
|
30
|
+
{
|
|
31
|
+
planId: 'test-plan-id',
|
|
32
|
+
quantity: 1,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
setupFramepay: setupFramepayMock,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
await rebillyInstruments.mount(options);
|
|
39
|
+
|
|
40
|
+
expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
|
|
41
|
+
expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
|
|
42
|
+
await avoidUnhandledPromises();
|
|
43
|
+
});
|
|
42
44
|
});
|