@rebilly/instruments 1.0.1-beta → 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 +23 -5
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +361 -2
- package/dist/events/base-event.js +51 -37
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +11 -8
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +60 -41
- package/dist/functions/initialize.spec.js +13 -13
- package/dist/functions/mount/fetch-summary-data.js +46 -0
- package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
- package/dist/functions/mount/index.js +346 -0
- package/dist/functions/mount/mount.spec.js +135 -0
- package/dist/functions/on.js +26 -18
- package/dist/functions/on.spec.js +45 -63
- package/dist/functions/purchase.js +41 -154
- package/dist/functions/purchase.spec.js +60 -76
- package/dist/functions/show.js +39 -43
- package/dist/functions/show.spec.js +57 -0
- package/dist/functions/update.js +60 -5
- 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/i18n.spec.js +6 -23
- package/dist/i18n/index.js +44 -67
- package/dist/index.js +70 -71
- package/dist/index.spec.js +24 -44
- package/dist/loader/index.js +63 -62
- package/dist/loader/loader.spec.js +14 -11
- package/dist/storefront/index.js +28 -39
- package/dist/storefront/models/plan-model.js +37 -54
- package/dist/storefront/models/product-model.js +25 -36
- package/dist/storefront/models/ready-to-pay-model.js +38 -42
- package/dist/storefront/models/summary-model.js +72 -99
- package/dist/storefront/plans.js +37 -84
- package/dist/storefront/plans.spec.js +61 -151
- package/dist/storefront/products.js +35 -83
- package/dist/storefront/products.spec.js +60 -150
- package/dist/storefront/purchase.js +27 -64
- package/dist/storefront/purchase.spec.js +51 -87
- package/dist/storefront/ready-to-pay.js +45 -107
- package/dist/storefront/ready-to-pay.spec.js +72 -147
- package/dist/storefront/storefront.spec.js +6 -6
- package/dist/storefront/summary.js +37 -84
- package/dist/storefront/summary.spec.js +135 -240
- 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/style/payment-instruments/payment-card.js +35 -0
- package/dist/style/utils/color-values.js +22 -0
- 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/add-dom-element.js +12 -34
- package/dist/utils/format-currency.js +4 -4
- package/dist/utils/has-valid-css-selector.js +2 -2
- package/dist/utils/index.js +15 -31
- package/dist/utils/is-dom-element.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +12 -17
- 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/views/method-selector/get-payment-methods.js +55 -0
- 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/views/summary.js +162 -0
- package/dist/views/summary.spec.js +148 -0
- package/package.json +12 -6
- 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 +43 -20
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +29 -0
- package/src/functions/mount/fetch-summary-data.spec.js +41 -0
- package/src/functions/mount/index.js +312 -0
- package/src/functions/mount/mount.spec.js +171 -0
- 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 +27 -7
- package/src/functions/show.spec.js +61 -0
- package/src/functions/update.js +50 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +20 -12
- package/src/index.js +43 -49
- package/src/index.spec.js +11 -42
- 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 +90 -21
- 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 -103
- package/dist/components/form/form.js +0 -110
- package/dist/components/form/form.spec.js +0 -135
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/get-payment-methods.js +0 -42
- package/dist/components/form/method-selector.js +0 -61
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -20
- package/dist/components/form/zoid-helpers.js +0 -130
- package/dist/components/result.js +0 -66
- package/dist/components/summary.js +0 -60
- package/dist/components/summary.spec.js +0 -144
- package/dist/events/instrument-ready.js +0 -51
- package/dist/events/purchase-complete.js +0 -51
- package/dist/functions/mount.js +0 -311
- package/dist/functions/mount.spec.js +0 -203
- package/dist/styles/base-styles.js +0 -12
- package/dist/styles/flat-theme-object.js +0 -42
- package/dist/styles/framepay.js +0 -15
- package/dist/styles/main.js +0 -25
- package/dist/styles/payment-card.js +0 -12
- package/dist/styles/shade-tint-values-helper.js +0 -28
- package/dist/styles/style-variables.js +0 -43
- package/dist/utils/camel-case.js +0 -12
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -77
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -88
- 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 -114
- 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/functions/mount.js +0 -204
- package/src/functions/mount.spec.js +0 -172
- package/src/styles/base-styles.js +0 -741
- 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,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _getPaymentMethods = require("./get-payment-methods");
|
|
4
|
+
|
|
5
|
+
var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
|
|
6
|
+
|
|
7
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
+
|
|
9
|
+
class TestInstance {
|
|
10
|
+
constructor() {
|
|
11
|
+
this.loader = {
|
|
12
|
+
startLoading: jest.fn()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
it('should only return the allowed methods', () => {
|
|
19
|
+
const instance = new TestInstance();
|
|
20
|
+
const methods = [new _readyToPayModel.default({
|
|
21
|
+
method: 'payment-card',
|
|
22
|
+
feature: {
|
|
23
|
+
name: 'Google Pay',
|
|
24
|
+
merchantName: 'google-pay-merchant-name',
|
|
25
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
26
|
+
},
|
|
27
|
+
brands: ['Visa'],
|
|
28
|
+
filters: []
|
|
29
|
+
}), new _readyToPayModel.default({
|
|
30
|
+
method: 'bitcoin',
|
|
31
|
+
filters: []
|
|
32
|
+
}), new _readyToPayModel.default({
|
|
33
|
+
method: 'payment-card',
|
|
34
|
+
brands: ['Visa'],
|
|
35
|
+
filters: []
|
|
36
|
+
})];
|
|
37
|
+
const results = (0, _getPaymentMethods.getPaymentMethods)({
|
|
38
|
+
methods,
|
|
39
|
+
state: instance
|
|
40
|
+
});
|
|
41
|
+
expect(results.hasOwnProperty('EXPRESS_METHODS')).toEqual(true);
|
|
42
|
+
expect(results['EXPRESS_METHODS'].length).toEqual(1);
|
|
43
|
+
expect(results['METHODS'].length).toEqual(1);
|
|
44
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mountMethodSelector = mountMethodSelector;
|
|
7
|
+
exports.updateMethodSelector = updateMethodSelector;
|
|
8
|
+
exports.baseMethodSelectorHTML = void 0;
|
|
9
|
+
|
|
10
|
+
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
11
|
+
|
|
12
|
+
var _getPaymentMethods = require("./get-payment-methods");
|
|
13
|
+
|
|
14
|
+
var _mountExpressMethods = require("./mount-express-methods");
|
|
15
|
+
|
|
16
|
+
var _generateDigitalWallet = require("./generate-digital-wallet");
|
|
17
|
+
|
|
18
|
+
var _mountMethods = require("./mount-methods");
|
|
19
|
+
|
|
20
|
+
var _fetchSummaryData = require("../../functions/mount/fetch-summary-data");
|
|
21
|
+
|
|
22
|
+
/* eslint-disable no-undef */
|
|
23
|
+
const baseMethodSelectorHTML = compactExpressInstruments => `
|
|
24
|
+
<div class="rebilly-instruments-content">
|
|
25
|
+
<div class="rebilly-instruments-method-selector">
|
|
26
|
+
<div class="rebilly-instruments-express-methods ${compactExpressInstruments ? 'is-compact' : ''}">
|
|
27
|
+
<span data-rebilly-i18n="form.expressCheckout" class="rebilly-instruments-express-methods-label">Express checkout</span>
|
|
28
|
+
<div class="rebilly-instruments-express-methods-container"></div>
|
|
29
|
+
</div>
|
|
30
|
+
<div class="rebilly-instruments-divider">
|
|
31
|
+
<span class="rebilly-instruments-divider-label" data-rebilly-i18n="form.or">Or</span>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="rebilly-instruments-methods"></div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
`;
|
|
37
|
+
|
|
38
|
+
exports.baseMethodSelectorHTML = baseMethodSelectorHTML;
|
|
39
|
+
|
|
40
|
+
function mountMethodSelector({
|
|
41
|
+
state,
|
|
42
|
+
formOptions
|
|
43
|
+
}) {
|
|
44
|
+
const {
|
|
45
|
+
readyToPay,
|
|
46
|
+
summary,
|
|
47
|
+
plans,
|
|
48
|
+
products,
|
|
49
|
+
mainStyle
|
|
50
|
+
} = formOptions;
|
|
51
|
+
const {
|
|
52
|
+
EXPRESS_METHODS,
|
|
53
|
+
METHODS
|
|
54
|
+
} = (0, _getPaymentMethods.getPaymentMethods)({
|
|
55
|
+
methods: readyToPay,
|
|
56
|
+
state
|
|
57
|
+
});
|
|
58
|
+
state.form.innerHTML += baseMethodSelectorHTML(state.options.paymentInstruments.compactExpressInstruments);
|
|
59
|
+
const EXPRESS_METHODS_CONTAINER = document.querySelector('.rebilly-instruments-express-methods-container');
|
|
60
|
+
const METHODS_DIVIDER = document.querySelector('.rebilly-instruments-divider');
|
|
61
|
+
METHODS_DIVIDER.style.display = METHODS.length && EXPRESS_METHODS.length ? 'block' : 'none';
|
|
62
|
+
const METHODS_CONTAINER = document.querySelector('.rebilly-instruments-methods');
|
|
63
|
+
state.configs.digitalWallet = (0, _generateDigitalWallet.generateDigitalWallet)({
|
|
64
|
+
state,
|
|
65
|
+
summary,
|
|
66
|
+
EXPRESS_METHODS
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (METHODS.length) {
|
|
70
|
+
(0, _mountMethods.MountMethods)({
|
|
71
|
+
state,
|
|
72
|
+
METHODS_CONTAINER,
|
|
73
|
+
METHODS,
|
|
74
|
+
mainStyle,
|
|
75
|
+
plans,
|
|
76
|
+
products
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
METHODS_CONTAINER.style.display = 'none';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (EXPRESS_METHODS.length) {
|
|
83
|
+
(0, _mountExpressMethods.mountExpressMethods)({
|
|
84
|
+
state,
|
|
85
|
+
EXPRESS_METHODS,
|
|
86
|
+
EXPRESS_METHODS_CONTAINER
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
EXPRESS_METHODS_CONTAINER.parentNode.style.display = 'none';
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
state.translate.translateItems();
|
|
93
|
+
state.loader.stopLoading({
|
|
94
|
+
id: 'initForm'
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function updateMethodSelector({
|
|
99
|
+
state,
|
|
100
|
+
mainStyle
|
|
101
|
+
}) {
|
|
102
|
+
state.loader.startLoading({
|
|
103
|
+
id: 'initForm'
|
|
104
|
+
});
|
|
105
|
+
const {
|
|
106
|
+
riskMetadata
|
|
107
|
+
} = await (0, _riskDataCollector.collectData)();
|
|
108
|
+
const {
|
|
109
|
+
readyToPay,
|
|
110
|
+
summary: summaryData,
|
|
111
|
+
plans,
|
|
112
|
+
products
|
|
113
|
+
} = await (0, _fetchSummaryData.fetchSummaryData)({
|
|
114
|
+
state,
|
|
115
|
+
riskMetadata
|
|
116
|
+
});
|
|
117
|
+
const formOptions = {
|
|
118
|
+
summary: summaryData,
|
|
119
|
+
readyToPay,
|
|
120
|
+
plans,
|
|
121
|
+
products,
|
|
122
|
+
mainStyle
|
|
123
|
+
};
|
|
124
|
+
state.form.querySelectorAll(':not(.rebilly-instruments-confirmation)').forEach(element => {
|
|
125
|
+
if (!element.classList.contains('rebilly-instruments-loader') && !element.classList.contains('rebilly-instruments-loader-spinner')) {
|
|
126
|
+
element.remove();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
mountMethodSelector({
|
|
130
|
+
state,
|
|
131
|
+
formOptions
|
|
132
|
+
});
|
|
133
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
|
|
4
|
+
|
|
5
|
+
var _readyToPayModel = _interopRequireDefault(require("../../storefront/models/ready-to-pay-model"));
|
|
6
|
+
|
|
7
|
+
var _loader = require("../../loader");
|
|
8
|
+
|
|
9
|
+
var _i18n = require("../../i18n");
|
|
10
|
+
|
|
11
|
+
var _index = require("./index");
|
|
12
|
+
|
|
13
|
+
var _asyncUtilities = require("../../../tests/async-utilities");
|
|
14
|
+
|
|
15
|
+
var _storefrontMock = require("../../../tests/mocks/storefront-mock");
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
describe('Summary component', () => {
|
|
20
|
+
let formElement;
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
formElement = document.createElement('div');
|
|
23
|
+
document.body.append(formElement);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
class TestMountMethodSelectorInstance {
|
|
27
|
+
constructor({
|
|
28
|
+
configs = {},
|
|
29
|
+
options = {},
|
|
30
|
+
form = formElement,
|
|
31
|
+
loader = new _loader.Loader(),
|
|
32
|
+
translate = new _i18n.Translate(),
|
|
33
|
+
zoidComponents = {}
|
|
34
|
+
} = {}) {
|
|
35
|
+
this.configs = configs;
|
|
36
|
+
this.options = options;
|
|
37
|
+
this.form = form;
|
|
38
|
+
this.loader = loader;
|
|
39
|
+
this.translate = translate;
|
|
40
|
+
this.zoidComponents = zoidComponents;
|
|
41
|
+
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const options = {
|
|
47
|
+
intent: {
|
|
48
|
+
countryCode: 'US',
|
|
49
|
+
items: [{
|
|
50
|
+
planId: 'my-awesome-product',
|
|
51
|
+
quantity: 1,
|
|
52
|
+
thumbnail: ''
|
|
53
|
+
}, {
|
|
54
|
+
planId: 'awesome-t-shirt',
|
|
55
|
+
quantity: 2,
|
|
56
|
+
thumbnail: ''
|
|
57
|
+
}]
|
|
58
|
+
},
|
|
59
|
+
paymentInstruments: {
|
|
60
|
+
googlePay: {
|
|
61
|
+
displayOptions: {
|
|
62
|
+
buttonColor: 'black',
|
|
63
|
+
buttonHeight: '44px',
|
|
64
|
+
buttonType: 'short'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
compactExpressInstruments: true
|
|
68
|
+
},
|
|
69
|
+
_computed: {
|
|
70
|
+
paymentMethodsUrl: ''
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const summaryData = new _summaryModel.default({
|
|
74
|
+
currency: 'USD',
|
|
75
|
+
lineItems: [{
|
|
76
|
+
type: 'debit',
|
|
77
|
+
description: 'My Awesome Product',
|
|
78
|
+
unitPrice: 30,
|
|
79
|
+
quantity: 1,
|
|
80
|
+
price: 30,
|
|
81
|
+
productId: 'my-awesome-product',
|
|
82
|
+
planId: 'my-awesome-product'
|
|
83
|
+
}, {
|
|
84
|
+
type: 'debit',
|
|
85
|
+
description: 'Awesome T-Shirt',
|
|
86
|
+
unitPrice: 20,
|
|
87
|
+
quantity: 2,
|
|
88
|
+
price: 40,
|
|
89
|
+
productId: 'my-app',
|
|
90
|
+
planId: 'awesome-t-shirt'
|
|
91
|
+
}],
|
|
92
|
+
subtotalAmount: 70,
|
|
93
|
+
taxAmount: 0,
|
|
94
|
+
shippingAmount: 0,
|
|
95
|
+
discountsAmount: 0,
|
|
96
|
+
total: 70
|
|
97
|
+
});
|
|
98
|
+
const readyToPayData = [new _readyToPayModel.default({
|
|
99
|
+
method: 'payment-card',
|
|
100
|
+
feature: {
|
|
101
|
+
name: 'Google Pay',
|
|
102
|
+
merchantName: 'google-pay-merchant-name',
|
|
103
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
104
|
+
},
|
|
105
|
+
brands: ['Visa'],
|
|
106
|
+
filters: []
|
|
107
|
+
})];
|
|
108
|
+
const configs = {
|
|
109
|
+
websiteId: 'test-website-id'
|
|
110
|
+
};
|
|
111
|
+
it('should inject the proper HTML for express methods', async () => {
|
|
112
|
+
const mountSummaryInstance = new TestMountMethodSelectorInstance({
|
|
113
|
+
configs,
|
|
114
|
+
options
|
|
115
|
+
});
|
|
116
|
+
mountSummaryInstance.loader.DOM.form = mountSummaryInstance.form;
|
|
117
|
+
(0, _index.mountMethodSelector)({
|
|
118
|
+
state: mountSummaryInstance,
|
|
119
|
+
formOptions: {
|
|
120
|
+
summary: summaryData,
|
|
121
|
+
readyToPay: readyToPayData
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const form = document.querySelector('.rebilly-instruments-form');
|
|
125
|
+
expect(form).toMatchSnapshot();
|
|
126
|
+
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
127
|
+
});
|
|
128
|
+
it('should allow updating method selector', async () => {
|
|
129
|
+
const state = new TestMountMethodSelectorInstance({
|
|
130
|
+
configs,
|
|
131
|
+
options
|
|
132
|
+
});
|
|
133
|
+
state.loader.DOM.form = state.form;
|
|
134
|
+
await (0, _index.updateMethodSelector)({
|
|
135
|
+
state,
|
|
136
|
+
mainStyle: 'any main style'
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mountExpressMethods = mountExpressMethods;
|
|
7
|
+
|
|
8
|
+
var _googlePay = _interopRequireDefault(require("./express-methods/google-pay"));
|
|
9
|
+
|
|
10
|
+
var _applePay = _interopRequireDefault(require("./express-methods/apple-pay"));
|
|
11
|
+
|
|
12
|
+
var _paypal = _interopRequireDefault(require("./express-methods/paypal"));
|
|
13
|
+
|
|
14
|
+
var _getMethodData = require("./get-method-data");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function mountExpressMethods({
|
|
19
|
+
state,
|
|
20
|
+
EXPRESS_METHODS,
|
|
21
|
+
EXPRESS_METHODS_CONTAINER
|
|
22
|
+
}) {
|
|
23
|
+
// A child div for each method must be created before mounting.
|
|
24
|
+
// Any DOM operation (innerHTML, append, etc) done on the parent div (EXPRESS_METHODS_CONTAINER) in between
|
|
25
|
+
// the two Postmate's instantiation (1 parent, 1 child) will cause the parent <-> child handshake to fail
|
|
26
|
+
EXPRESS_METHODS.forEach(expressMethod => {
|
|
27
|
+
const {
|
|
28
|
+
METHOD_ID
|
|
29
|
+
} = (0, _getMethodData.getMethodData)(expressMethod);
|
|
30
|
+
EXPRESS_METHODS_CONTAINER.innerHTML += `
|
|
31
|
+
<div class="rebilly-instruments-${METHOD_ID}-method"></div>
|
|
32
|
+
`;
|
|
33
|
+
});
|
|
34
|
+
EXPRESS_METHODS.forEach(expressMethod => {
|
|
35
|
+
const {
|
|
36
|
+
method,
|
|
37
|
+
feature
|
|
38
|
+
} = expressMethod;
|
|
39
|
+
const {
|
|
40
|
+
METHOD_ID,
|
|
41
|
+
METHOD_TYPE
|
|
42
|
+
} = (0, _getMethodData.getMethodData)(expressMethod);
|
|
43
|
+
|
|
44
|
+
if ((feature === null || feature === void 0 ? void 0 : feature.name) === 'Google Pay') {
|
|
45
|
+
(0, _googlePay.default)({
|
|
46
|
+
state,
|
|
47
|
+
METHOD_ID
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if ((feature === null || feature === void 0 ? void 0 : feature.name) === 'Apple Pay') {
|
|
52
|
+
(0, _applePay.default)({
|
|
53
|
+
state,
|
|
54
|
+
METHOD_ID,
|
|
55
|
+
METHOD_TYPE,
|
|
56
|
+
EXPRESS_METHODS,
|
|
57
|
+
EXPRESS_METHODS_CONTAINER
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (method === 'paypal') {
|
|
62
|
+
(0, _paypal.default)({
|
|
63
|
+
state,
|
|
64
|
+
METHOD_ID,
|
|
65
|
+
METHOD_TYPE
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MountMethods = MountMethods;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
9
|
+
|
|
10
|
+
var _modal = require("../modal");
|
|
11
|
+
|
|
12
|
+
var _iframe = require("../common/iframe");
|
|
13
|
+
|
|
14
|
+
var _getMethodData = require("./get-method-data");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
function MountMethods({
|
|
19
|
+
state,
|
|
20
|
+
METHODS_CONTAINER,
|
|
21
|
+
METHODS,
|
|
22
|
+
mainStyle,
|
|
23
|
+
plans,
|
|
24
|
+
products
|
|
25
|
+
}) {
|
|
26
|
+
METHODS.forEach(async method => {
|
|
27
|
+
var _state$options$paymen;
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
METHOD_ID: methodId,
|
|
31
|
+
METHOD_TYPE: methodType
|
|
32
|
+
} = (0, _getMethodData.getMethodData)(method);
|
|
33
|
+
const {
|
|
34
|
+
paymentMethodsUrl
|
|
35
|
+
} = state.options._computed || 'https://www.example.com';
|
|
36
|
+
const selector = `rebilly-instruments-${methodId}`;
|
|
37
|
+
const isiFrame = methodId === 'payment-card' && !((_state$options$paymen = state.options.paymentInstruments[methodType]) !== null && _state$options$paymen !== void 0 && _state$options$paymen.popup);
|
|
38
|
+
const model = {
|
|
39
|
+
configs: state.configs,
|
|
40
|
+
options: state.options,
|
|
41
|
+
mainStyle,
|
|
42
|
+
method,
|
|
43
|
+
plans,
|
|
44
|
+
products
|
|
45
|
+
};
|
|
46
|
+
METHODS_CONTAINER.insertAdjacentHTML('beforeend', `<div id="${selector}" data-rebilly-instruments-type="${methodId}"></div>`);
|
|
47
|
+
const container = document.querySelector(`#${selector}`);
|
|
48
|
+
|
|
49
|
+
if (isiFrame) {
|
|
50
|
+
const iframe = await new _iframe.MethodIframe({
|
|
51
|
+
name: methodId,
|
|
52
|
+
url: `${paymentMethodsUrl}/${methodId}`,
|
|
53
|
+
container,
|
|
54
|
+
model
|
|
55
|
+
});
|
|
56
|
+
iframe.bindEventListeners({
|
|
57
|
+
loader: state.loader,
|
|
58
|
+
id: method.method
|
|
59
|
+
});
|
|
60
|
+
state.iframeComponents.push(iframe);
|
|
61
|
+
} else {
|
|
62
|
+
container.insertAdjacentHTML('beforeend', `<button class="${selector} rebilly-instruments-button" data-rebilly-i18n="paymentMethods.${method.method}">${(0, _lodash.default)(method.method)}</button>`);
|
|
63
|
+
const paymentCardButton = document.querySelector(`.${selector}`);
|
|
64
|
+
paymentCardButton.addEventListener('click', async () => {
|
|
65
|
+
const iframe = await (0, _modal.mountModal)({
|
|
66
|
+
state,
|
|
67
|
+
name: methodId,
|
|
68
|
+
url: `${paymentMethodsUrl}/${methodId}`,
|
|
69
|
+
model
|
|
70
|
+
});
|
|
71
|
+
state.iframeComponents.push(iframe);
|
|
72
|
+
});
|
|
73
|
+
state.loader.stopLoading({
|
|
74
|
+
id: method.method
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mountModal = mountModal;
|
|
7
|
+
|
|
8
|
+
var _iframe = require("./common/iframe");
|
|
9
|
+
|
|
10
|
+
const modalTemplate = (isRedirect, method) => `
|
|
11
|
+
<div class="rebilly-instruments-modal-overlay">
|
|
12
|
+
<div class="rebilly-instruments-modal-container ${method ? `rebilly-instruments-${method}` : ''} ${isRedirect ? 'is-redirect' : ''}">
|
|
13
|
+
<svg class="rebilly-instruments-modal-close" viewBox="0 0 30 30" xmlns="http://www.w3.org/2000/svg">
|
|
14
|
+
<path d="m15 13.5858 7.2929-7.293c.3905-.3904 1.0237-.3904 1.4142 0 .3905.3906.3905 1.0238 0 1.4143L16.4142 15l7.293 7.2929c.3904.3905.3904 1.0237 0 1.4142-.3906.3905-1.0238.3905-1.4143 0L15 16.4142l-7.2929 7.293c-.3905.3904-1.0237.3904-1.4142 0-.3905-.3906-.3905-1.0238 0-1.4143L13.5858 15l-7.293-7.2929c-.3904-.3905-.3904-1.0237 0-1.4142.3906-.3905 1.0238-.3905 1.4143 0L15 13.5858Z" fill-rule="nonzero"/>
|
|
15
|
+
</svg>
|
|
16
|
+
<div class="rebilly-instruments-modal-content"></div>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
`;
|
|
20
|
+
|
|
21
|
+
async function mountModal({
|
|
22
|
+
name = '',
|
|
23
|
+
url = '',
|
|
24
|
+
model = {},
|
|
25
|
+
classListArray = [],
|
|
26
|
+
close = () => {},
|
|
27
|
+
state = null
|
|
28
|
+
} = {}) {
|
|
29
|
+
var _model$method;
|
|
30
|
+
|
|
31
|
+
const method = model === null || model === void 0 ? void 0 : (_model$method = model.method) === null || _model$method === void 0 ? void 0 : _model$method.method;
|
|
32
|
+
const isRedirect = name === 'rebilly-instruments-approval-url';
|
|
33
|
+
state.form.insertAdjacentHTML('beforeend', modalTemplate(isRedirect, method));
|
|
34
|
+
const modalOverlay = document.querySelector('.rebilly-instruments-modal-overlay');
|
|
35
|
+
const modalContainer = document.querySelector('.rebilly-instruments-modal-container');
|
|
36
|
+
const closeButton = document.querySelector('.rebilly-instruments-modal-close');
|
|
37
|
+
const modalContent = document.querySelector('.rebilly-instruments-modal-content');
|
|
38
|
+
document.body.style.overflow = 'hidden';
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
modalOverlay.classList.add('is-visible');
|
|
41
|
+
modalContainer.classList.add('is-visible');
|
|
42
|
+
}, 240);
|
|
43
|
+
state.loader.addDOMElement({
|
|
44
|
+
section: 'modal',
|
|
45
|
+
el: modalContent
|
|
46
|
+
});
|
|
47
|
+
state.loader.startLoading({
|
|
48
|
+
section: 'modal',
|
|
49
|
+
id: 'modal-content'
|
|
50
|
+
});
|
|
51
|
+
const injectedModel = {
|
|
52
|
+
configs: state.configs,
|
|
53
|
+
options: state.options,
|
|
54
|
+
...model
|
|
55
|
+
};
|
|
56
|
+
const iframe = await new _iframe.ModalIframe({
|
|
57
|
+
name,
|
|
58
|
+
url,
|
|
59
|
+
model: injectedModel,
|
|
60
|
+
classListArray,
|
|
61
|
+
container: modalContent
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const closeModal = (...args) => {
|
|
65
|
+
modalContainer.classList.remove('is-visible');
|
|
66
|
+
modalOverlay.classList.remove('is-visible');
|
|
67
|
+
setTimeout(() => {
|
|
68
|
+
document.body.style.overflow = 'auto';
|
|
69
|
+
modalOverlay.children.forEach(child => child.remove());
|
|
70
|
+
modalOverlay.remove();
|
|
71
|
+
close(...args);
|
|
72
|
+
iframe.destroy();
|
|
73
|
+
}, 300);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
iframe.bindEventListeners({
|
|
77
|
+
close: closeModal,
|
|
78
|
+
loader: state.loader
|
|
79
|
+
});
|
|
80
|
+
modalOverlay.addEventListener('click', closeModal);
|
|
81
|
+
closeButton.addEventListener('click', closeModal);
|
|
82
|
+
return iframe;
|
|
83
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.mountResult = mountResult;
|
|
7
|
+
|
|
8
|
+
var _iframe = require("./common/iframe");
|
|
9
|
+
|
|
10
|
+
var _renderUtilities = require("./common/render-utilities");
|
|
11
|
+
|
|
12
|
+
async function mountResult({
|
|
13
|
+
purchase,
|
|
14
|
+
mainStyle,
|
|
15
|
+
state
|
|
16
|
+
}) {
|
|
17
|
+
const resultContainerClassName = 'rebilly-instruments-result';
|
|
18
|
+
(0, _renderUtilities.replaceContent)(state.form, `<div class="${resultContainerClassName}"></div>`);
|
|
19
|
+
state.loader.startLoading({
|
|
20
|
+
id: 'result'
|
|
21
|
+
});
|
|
22
|
+
const container = document.querySelector(`.${resultContainerClassName}`);
|
|
23
|
+
const {
|
|
24
|
+
paymentMethodsUrl
|
|
25
|
+
} = state.options._computed;
|
|
26
|
+
const model = {
|
|
27
|
+
configs: state.configs,
|
|
28
|
+
options: state.options,
|
|
29
|
+
mainStyle,
|
|
30
|
+
purchase
|
|
31
|
+
};
|
|
32
|
+
const iframe = await new _iframe.ViewIframe({
|
|
33
|
+
name: 'rebilly-instruments-result',
|
|
34
|
+
url: `${paymentMethodsUrl}/result`,
|
|
35
|
+
container,
|
|
36
|
+
model
|
|
37
|
+
});
|
|
38
|
+
iframe.bindEventListeners({
|
|
39
|
+
loader: state.loader
|
|
40
|
+
});
|
|
41
|
+
state.iframeComponents.push(iframe);
|
|
42
|
+
}
|