@rebilly/instruments 1.0.2-beta.1 → 1.0.2-beta.10
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 +13 -4
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +350 -0
- package/dist/events/base-event.js +40 -11
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +10 -7
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +24 -20
- package/dist/functions/initialize.spec.js +4 -4
- package/dist/functions/mount/fetch-summary-data.js +26 -11
- package/dist/functions/mount/fetch-summary-data.spec.js +15 -16
- package/dist/functions/mount/index.js +168 -106
- package/dist/functions/mount/mount.spec.js +14 -36
- package/dist/functions/on.js +25 -17
- package/dist/functions/on.spec.js +36 -18
- package/dist/functions/purchase.js +33 -74
- package/dist/functions/purchase.spec.js +17 -14
- package/dist/functions/show.js +31 -8
- package/dist/functions/show.spec.js +42 -17
- package/dist/functions/update.js +60 -4
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/index.js +5 -0
- package/dist/index.js +67 -55
- package/dist/index.spec.js +6 -10
- package/dist/loader/index.js +24 -4
- package/dist/loader/loader.spec.js +4 -4
- package/dist/storefront/models/ready-to-pay-model.js +7 -1
- package/dist/storefront/plans.js +9 -10
- package/dist/storefront/plans.spec.js +20 -20
- package/dist/storefront/products.js +9 -10
- package/dist/storefront/products.spec.js +20 -20
- package/dist/storefront/purchase.js +9 -8
- package/dist/storefront/purchase.spec.js +7 -4
- package/dist/storefront/ready-to-pay.js +12 -11
- package/dist/storefront/ready-to-pay.spec.js +24 -19
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +11 -12
- package/dist/storefront/summary.spec.js +25 -24
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/{styles → style/payment-instruments}/payment-card.js +14 -6
- package/dist/{styles/shade-tint-values-helper.js → style/utils/color-values.js} +5 -9
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/format-currency.js +1 -0
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/index.js +3 -19
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/{components/form → views/method-selector}/get-payment-methods.js +22 -6
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/{components → views}/summary.js +36 -25
- package/dist/{components → views}/summary.spec.js +49 -22
- package/package.json +11 -5
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +23 -18
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +16 -13
- package/src/functions/mount/fetch-summary-data.spec.js +22 -27
- package/src/functions/mount/index.js +194 -133
- package/src/functions/mount/mount.spec.js +83 -84
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +26 -6
- package/src/functions/show.spec.js +41 -19
- package/src/functions/update.js +49 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +19 -11
- package/src/index.js +42 -51
- package/src/index.spec.js +11 -20
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +65 -33
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -113
- package/dist/components/form/form.js +0 -143
- package/dist/components/form/form.spec.js +0 -111
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/method-selector.js +0 -60
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -24
- package/dist/components/form/zoid-helpers.js +0 -131
- package/dist/components/result.js +0 -68
- package/dist/events/instrument-ready.js +0 -24
- package/dist/events/purchase-complete.js +0 -24
- package/dist/styles/base-styles.js +0 -793
- package/dist/styles/flat-theme-object.js +0 -23
- package/dist/styles/framepay.js +0 -38
- package/dist/styles/main.js +0 -29
- package/dist/styles/style-variables.js +0 -44
- package/dist/utils/camel-case.js +0 -10
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -81
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -117
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -117
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/styles/base-styles.js +0 -784
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
4
|
+
|
|
5
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
6
|
+
|
|
7
|
+
describe('RebillyInstruments Update', () => {
|
|
8
|
+
it('should throw an error when methods are not mounted', async () => {
|
|
9
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
10
|
+
rebillyInstruments.state.hasMounted = false;
|
|
11
|
+
let error;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
await rebillyInstruments.update();
|
|
15
|
+
} catch (e) {
|
|
16
|
+
error = e;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
expect(error).toEqual(new Error('Update method cannot be called before mounting instruments'));
|
|
20
|
+
}); // TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
|
|
21
|
+
|
|
22
|
+
it.skip('should call changeLocale when updating locale options', async () => {
|
|
23
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
24
|
+
const call = jest.fn(); // Simulate mounted iframe
|
|
25
|
+
|
|
26
|
+
const fakeIFrameComponent = {
|
|
27
|
+
destroy: jest.fn(),
|
|
28
|
+
component: {
|
|
29
|
+
call
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
|
|
33
|
+
await rebillyInstruments.update({
|
|
34
|
+
options: {
|
|
35
|
+
locale: 'ja'
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
expect(call).toBeCalledWith('changeLocale', 'ja'); // It would be better to match real UI instead of implementation state
|
|
39
|
+
|
|
40
|
+
expect(rebillyInstruments.state.options.locale).toBe('ja');
|
|
41
|
+
expect(rebillyInstruments.state.translate.locale).toBe('ja');
|
|
42
|
+
});
|
|
43
|
+
it('should destroy and update when updating options different than locale', async () => {
|
|
44
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
45
|
+
const formElement = document.querySelector('.form-selector');
|
|
46
|
+
const summaryElement = document.querySelector('.summary-selector');
|
|
47
|
+
expect(formElement.innerHTML).not.toEqual('');
|
|
48
|
+
expect(summaryElement.innerHTML).not.toEqual('');
|
|
49
|
+
const call = jest.fn(); // Simulate mounted iframe
|
|
50
|
+
|
|
51
|
+
const fakeIFrameComponent = {
|
|
52
|
+
destroy: jest.fn(),
|
|
53
|
+
component: {
|
|
54
|
+
call
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
|
|
58
|
+
await rebillyInstruments.update({
|
|
59
|
+
options: {
|
|
60
|
+
intent: {
|
|
61
|
+
countryCode: 'ES'
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
expect(rebillyInstruments.state.options.intent.countryCode).toEqual('ES');
|
|
66
|
+
expect(formElement.innerHTML).toEqual('');
|
|
67
|
+
expect(summaryElement.innerHTML).toEqual('');
|
|
68
|
+
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
69
|
+
});
|
|
70
|
+
it('should replace the intent items with different options', async () => {
|
|
71
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
72
|
+
const formElement = document.querySelector('.form-selector');
|
|
73
|
+
const summaryElement = document.querySelector('.summary-selector');
|
|
74
|
+
expect(formElement.innerHTML).not.toEqual('');
|
|
75
|
+
expect(summaryElement.innerHTML).not.toEqual('');
|
|
76
|
+
const call = jest.fn(); // Simulate mounted iframe
|
|
77
|
+
|
|
78
|
+
const fakeIFrameComponent = {
|
|
79
|
+
destroy: jest.fn(),
|
|
80
|
+
component: {
|
|
81
|
+
call
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
rebillyInstruments.iframeComponents = [fakeIFrameComponent];
|
|
85
|
+
await rebillyInstruments.update({
|
|
86
|
+
options: {
|
|
87
|
+
intent: {
|
|
88
|
+
items: [{
|
|
89
|
+
planId: 'test-plan-id-1',
|
|
90
|
+
quantity: 5
|
|
91
|
+
}]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
expect(rebillyInstruments.state.options.intent.items[0].quantity).toEqual(5);
|
|
96
|
+
expect(formElement.innerHTML).toEqual('');
|
|
97
|
+
expect(summaryElement.innerHTML).toEqual('');
|
|
98
|
+
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
99
|
+
});
|
|
100
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"en": {
|
|
3
|
+
"summary": {
|
|
4
|
+
"subTotal": "Sub Total",
|
|
5
|
+
"discounts": "Discouts",
|
|
6
|
+
"taxes": "Taxes",
|
|
7
|
+
"shipping": "Shipping",
|
|
8
|
+
"total": "Total"
|
|
9
|
+
},
|
|
10
|
+
"form": {
|
|
11
|
+
"expressCheckout": "Express checkout",
|
|
12
|
+
"or": "Or",
|
|
13
|
+
"popupOverlayText": "Click here to show popup window"
|
|
14
|
+
},
|
|
15
|
+
"paymentMethods": {
|
|
16
|
+
"payment-card": "Payment card"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"es": {
|
|
3
|
+
"summary": {
|
|
4
|
+
"subTotal": "Sub Total",
|
|
5
|
+
"discounts": "Descuentos",
|
|
6
|
+
"taxes": "Impuestos",
|
|
7
|
+
"shipping": "Envío",
|
|
8
|
+
"total": "Total"
|
|
9
|
+
},
|
|
10
|
+
"form": {
|
|
11
|
+
"expressCheckout": "Chequeo rápido",
|
|
12
|
+
"or": "O pague con",
|
|
13
|
+
"popupOverlayText": "Haga clic aquí para mostrar la ventana emergente"
|
|
14
|
+
},
|
|
15
|
+
"paymentMethods": {
|
|
16
|
+
"payment-card": "Tarjeta de crédito"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/dist/i18n/index.js
CHANGED
|
@@ -44,6 +44,11 @@ class Translate {
|
|
|
44
44
|
return false;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
updateTranslationsToNewLocale(newLocale) {
|
|
48
|
+
this.locale = newLocale;
|
|
49
|
+
this.translateItems();
|
|
50
|
+
}
|
|
51
|
+
|
|
47
52
|
getLocale(locale = this.locale) {
|
|
48
53
|
if (!locale.includes('-') || locale in this.languages) {
|
|
49
54
|
return locale;
|
package/dist/index.js
CHANGED
|
@@ -3,45 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.RebillyInstrumentsInstance = void 0;
|
|
7
|
-
|
|
8
|
-
var _initialize = require("./functions/initialize");
|
|
6
|
+
exports.default = exports.RebillyInstrumentsInstance = exports.InstrumentsState = void 0;
|
|
9
7
|
|
|
10
8
|
var _mount = require("./functions/mount");
|
|
11
9
|
|
|
12
10
|
var _purchase = require("./functions/purchase");
|
|
13
11
|
|
|
14
|
-
var _show = require("./functions/show");
|
|
15
|
-
|
|
16
12
|
var _on = require("./functions/on");
|
|
17
13
|
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var _summary = require("./storefront/summary");
|
|
21
|
-
|
|
22
|
-
var _plans = require("./storefront/plans");
|
|
23
|
-
|
|
24
|
-
var _products = require("./storefront/products");
|
|
25
|
-
|
|
26
|
-
var _purchase2 = require("./storefront/purchase");
|
|
27
|
-
|
|
28
|
-
var _summary2 = require("./components/summary");
|
|
29
|
-
|
|
30
|
-
var _form = require("./components/form/form");
|
|
14
|
+
var _update = require("./functions/update");
|
|
31
15
|
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
var _result = require("./components/result");
|
|
16
|
+
var _destroy = require("./functions/destroy");
|
|
35
17
|
|
|
36
18
|
var _loader = require("./loader");
|
|
37
19
|
|
|
38
20
|
var _i18n = require("./i18n");
|
|
39
21
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
var _initialize = require("./functions/initialize");
|
|
23
|
+
|
|
24
|
+
var _show = require("./functions/show");
|
|
25
|
+
|
|
26
|
+
class InstrumentsState {
|
|
43
27
|
constructor() {
|
|
44
|
-
this.configs = null;
|
|
45
28
|
this.options = null;
|
|
46
29
|
this.mountingPoints = null;
|
|
47
30
|
this.storefront = null;
|
|
@@ -49,36 +32,65 @@ class RebillyInstrumentsInstance {
|
|
|
49
32
|
this.summary = null;
|
|
50
33
|
this.loader = new _loader.Loader();
|
|
51
34
|
this.translate = new _i18n.Translate();
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
35
|
+
this.iframeComponents = [];
|
|
36
|
+
this.hasMounted = false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.InstrumentsState = InstrumentsState;
|
|
42
|
+
|
|
43
|
+
class RebillyInstrumentsInstance {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.state = new InstrumentsState(); // TODO: mountConfirmation, mountResult have different contract shape when they look similar
|
|
46
|
+
// TODO: review test coverage of UpdateSummary and UpdateMethodSelector as no tests were broken
|
|
47
|
+
// when commenting them
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
initialize(configs) {
|
|
51
|
+
(0, _initialize.initialize)({
|
|
52
|
+
state: this.state,
|
|
53
|
+
configs
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async mount(options) {
|
|
58
|
+
await (0, _mount.mount)({
|
|
59
|
+
state: this.state,
|
|
60
|
+
...options
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async destroy() {
|
|
65
|
+
await (0, _destroy.destroy)({
|
|
66
|
+
state: this.state
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async update(newConfig) {
|
|
71
|
+
await (0, _update.update)(this.state, newConfig);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async purchase(payload) {
|
|
75
|
+
await (0, _purchase.purchase)({
|
|
76
|
+
state: this.state,
|
|
77
|
+
payload
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async show(componentName, payload) {
|
|
82
|
+
await (0, _show.show)({
|
|
83
|
+
componentName,
|
|
84
|
+
payload,
|
|
85
|
+
state: this.state
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
on(eventName, callback) {
|
|
90
|
+
(0, _on.on)({
|
|
91
|
+
eventName,
|
|
92
|
+
callback
|
|
93
|
+
});
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
}
|
package/dist/index.spec.js
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var _index = _interopRequireWildcard(require("./index"));
|
|
4
4
|
|
|
5
|
+
var _asyncUtilities = require("../tests/async-utilities");
|
|
6
|
+
|
|
7
|
+
var _initialize = require("./functions/initialize");
|
|
8
|
+
|
|
5
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
6
10
|
|
|
7
11
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -21,16 +25,7 @@ describe('RebillyInstruments instance', () => {
|
|
|
21
25
|
it('should have default export as instance of class', () => {
|
|
22
26
|
expect(_index.default).toBeInstanceOf(_index.RebillyInstrumentsInstance);
|
|
23
27
|
});
|
|
24
|
-
it('should be
|
|
25
|
-
jest.spyOn(rebillyInstruments, 'initialize');
|
|
26
|
-
const config = {
|
|
27
|
-
test: 'value'
|
|
28
|
-
};
|
|
29
|
-
rebillyInstruments.initialize(config);
|
|
30
|
-
expect(rebillyInstruments.initialize).toHaveBeenCalledTimes(1);
|
|
31
|
-
expect(rebillyInstruments.initialize).toHaveBeenCalledWith(config);
|
|
32
|
-
});
|
|
33
|
-
it('should be mountable', () => {
|
|
28
|
+
it('should be mountable', async () => {
|
|
34
29
|
jest.spyOn(rebillyInstruments, 'mount');
|
|
35
30
|
document.body.innerHTML = `
|
|
36
31
|
<div class="form-selector"></div>
|
|
@@ -44,6 +39,7 @@ describe('RebillyInstruments instance', () => {
|
|
|
44
39
|
rebillyInstruments.mount(options);
|
|
45
40
|
expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
|
|
46
41
|
expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
|
|
42
|
+
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
47
43
|
});
|
|
48
44
|
it('should be able to trigger a purchase', () => {
|
|
49
45
|
jest.spyOn(rebillyInstruments, 'purchase');
|
package/dist/loader/index.js
CHANGED
|
@@ -13,9 +13,10 @@ class Loader {
|
|
|
13
13
|
constructor() {
|
|
14
14
|
this.summary = [];
|
|
15
15
|
this.form = [];
|
|
16
|
+
this.modal = [];
|
|
16
17
|
this.DOM = {
|
|
17
18
|
loading: `
|
|
18
|
-
<div class="rebilly-instruments-loader active">
|
|
19
|
+
<div class="rebilly-instruments-loader is-active">
|
|
19
20
|
<div class="rebilly-instruments-loader-spinner"></div>
|
|
20
21
|
</div>
|
|
21
22
|
`
|
|
@@ -31,7 +32,6 @@ class Loader {
|
|
|
31
32
|
if ((0, _isDomElement.default)(el)) {
|
|
32
33
|
el.style.position = 'relative';
|
|
33
34
|
el.style.minHeight = minHeight;
|
|
34
|
-
el.style.paddingTop = section === 'form' ? '8px' : '0px';
|
|
35
35
|
this.DOM[section] = el;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -48,7 +48,7 @@ class Loader {
|
|
|
48
48
|
if (!this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
49
49
|
this.DOM[section].innerHTML = this.DOM.loading;
|
|
50
50
|
} else {
|
|
51
|
-
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.add('active');
|
|
51
|
+
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.add('is-active');
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -64,10 +64,30 @@ class Loader {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
if (!this[section].length && this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
67
|
-
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.remove('active');
|
|
67
|
+
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.remove('is-active');
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
clearAll() {
|
|
72
|
+
this.form.forEach(id => {
|
|
73
|
+
this.stopLoading({
|
|
74
|
+
id
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
this.summary.forEach(id => {
|
|
78
|
+
this.stopLoading({
|
|
79
|
+
section: 'summary',
|
|
80
|
+
id
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
this.modal.forEach(id => {
|
|
84
|
+
this.stopLoading({
|
|
85
|
+
section: 'modal',
|
|
86
|
+
id
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
71
91
|
}
|
|
72
92
|
|
|
73
93
|
exports.Loader = Loader;
|
|
@@ -46,11 +46,11 @@ describe('Loader Class', () => {
|
|
|
46
46
|
id: 'loadForm'
|
|
47
47
|
});
|
|
48
48
|
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
49
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
49
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
50
50
|
loader.stopLoading({
|
|
51
51
|
id: 'loadForm'
|
|
52
52
|
});
|
|
53
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(false);
|
|
53
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(false);
|
|
54
54
|
});
|
|
55
55
|
it('keeps loading when there are Ids on the element array', () => {
|
|
56
56
|
loader.startLoading({
|
|
@@ -60,10 +60,10 @@ describe('Loader Class', () => {
|
|
|
60
60
|
id: 'updateForm'
|
|
61
61
|
});
|
|
62
62
|
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
63
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
63
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
64
64
|
loader.stopLoading({
|
|
65
65
|
id: 'loadForm'
|
|
66
66
|
});
|
|
67
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('active')).toEqual(true);
|
|
67
|
+
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
68
68
|
});
|
|
69
69
|
});
|
|
@@ -8,12 +8,18 @@ exports.default = exports.ReadyToPayFeatureModel = void 0;
|
|
|
8
8
|
class ReadyToPayFeatureModel {
|
|
9
9
|
constructor({
|
|
10
10
|
name = '',
|
|
11
|
+
// Google Pay fields
|
|
12
|
+
merchantName = '',
|
|
13
|
+
merchantOrigin = '',
|
|
14
|
+
// Plaid fields
|
|
11
15
|
linkToken = '',
|
|
12
16
|
expirationTime = ''
|
|
13
17
|
} = {}) {
|
|
14
18
|
this.name = name;
|
|
19
|
+
this.merchantName = merchantName;
|
|
20
|
+
this.merchantOrigin = merchantOrigin;
|
|
15
21
|
this.linkToken = linkToken;
|
|
16
|
-
this.
|
|
22
|
+
this.expirationTime = expirationTime;
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
}
|
package/dist/storefront/plans.js
CHANGED
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchPlans = fetchPlans;
|
|
7
7
|
|
|
8
8
|
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
async function
|
|
13
|
-
data = null
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
async function fetchPlans({
|
|
13
|
+
data = null,
|
|
14
|
+
state = null
|
|
15
|
+
}) {
|
|
16
|
+
if (!state.storefront) {
|
|
16
17
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
if (!
|
|
20
|
+
if (!state.configs || !state.options) {
|
|
20
21
|
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -34,13 +35,11 @@ async function FetchPlans({
|
|
|
34
35
|
|
|
35
36
|
const {
|
|
36
37
|
items: planItems
|
|
37
|
-
} = await
|
|
38
|
+
} = await state.storefront.plans.getAll(filterByPlanId);
|
|
38
39
|
return planItems.map(({
|
|
39
40
|
fields
|
|
40
41
|
}) => new _planModel.default(fields));
|
|
41
42
|
} catch (error) {
|
|
42
43
|
throw error;
|
|
43
44
|
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
;
|
|
45
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _plans = require("./plans");
|
|
12
12
|
|
|
13
13
|
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
14
14
|
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
|
+
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
|
|
17
19
|
describe('Storefront API Plan', () => {
|
|
@@ -25,10 +27,6 @@ describe('Storefront API Plan', () => {
|
|
|
25
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
fetchPlans(...args) {
|
|
29
|
-
return _plans.FetchPlans.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
it('can fetch plans', async () => {
|
|
@@ -39,7 +37,9 @@ describe('Storefront API Plan', () => {
|
|
|
39
37
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
|
|
40
38
|
const instance = new TestPlansInstance();
|
|
41
39
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
42
|
-
const response = await
|
|
40
|
+
const response = await (0, _plans.fetchPlans)({
|
|
41
|
+
state: instance
|
|
42
|
+
});
|
|
43
43
|
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
44
44
|
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
45
45
|
filter: ''
|
|
@@ -51,7 +51,8 @@ describe('Storefront API Plan', () => {
|
|
|
51
51
|
it('can fetch plans with filter', async () => {
|
|
52
52
|
const instance = new TestPlansInstance();
|
|
53
53
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
54
|
-
await
|
|
54
|
+
await (0, _plans.fetchPlans)({
|
|
55
|
+
state: instance,
|
|
55
56
|
data: {
|
|
56
57
|
lineItems: [{
|
|
57
58
|
planId: 'test-plan-id-1'
|
|
@@ -64,28 +65,27 @@ describe('Storefront API Plan', () => {
|
|
|
64
65
|
filter: 'id:test-plan-id-1,test-plan-id-2'
|
|
65
66
|
});
|
|
66
67
|
});
|
|
67
|
-
it('should throw errors with no configs or options', () => {
|
|
68
|
-
const NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
68
|
+
it('should throw errors with no configs or options', async () => {
|
|
69
69
|
const noConfigOrOptionsInstance = new TestPlansInstance({
|
|
70
70
|
configs: null,
|
|
71
71
|
options: null
|
|
72
72
|
});
|
|
73
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
74
|
+
state: noConfigOrOptionsInstance
|
|
75
|
+
}));
|
|
73
76
|
const noConfigInstance = new TestPlansInstance({
|
|
74
77
|
configs: null,
|
|
75
78
|
options: {}
|
|
76
79
|
});
|
|
80
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
81
|
+
state: noConfigInstance
|
|
82
|
+
}));
|
|
77
83
|
const noOptionsInstance = new TestPlansInstance({
|
|
78
84
|
configs: {},
|
|
79
85
|
options: null
|
|
80
86
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
expect(async () => {
|
|
85
|
-
await noConfigInstance.fetchPlans();
|
|
86
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
87
|
-
expect(async () => {
|
|
88
|
-
await noOptionsInstance.fetchPlans();
|
|
89
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
87
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
88
|
+
state: noOptionsInstance
|
|
89
|
+
}));
|
|
90
90
|
});
|
|
91
91
|
});
|
|
@@ -3,20 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchProducts = fetchProducts;
|
|
7
7
|
|
|
8
8
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
async function
|
|
13
|
-
data = null
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
async function fetchProducts({
|
|
13
|
+
data = null,
|
|
14
|
+
state
|
|
15
|
+
}) {
|
|
16
|
+
if (!state.storefront) {
|
|
16
17
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
if (!
|
|
20
|
+
if (!state.configs || !state.options) {
|
|
20
21
|
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -32,13 +33,11 @@ async function FetchProducts({
|
|
|
32
33
|
|
|
33
34
|
const {
|
|
34
35
|
items: productItems
|
|
35
|
-
} = await
|
|
36
|
+
} = await state.storefront.products.getAll(filterByProductId);
|
|
36
37
|
return productItems.map(({
|
|
37
38
|
fields
|
|
38
39
|
}) => new _productModel.default(fields));
|
|
39
40
|
} catch (error) {
|
|
40
41
|
throw error;
|
|
41
42
|
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
;
|
|
43
|
+
}
|