@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
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { MAIN_STYLE as STYLE } from '../../styles/main';
|
|
2
|
-
import { zoidIframe, zoidPopup, dispatch } from './zoid-helpers';
|
|
3
|
-
import { getMethodData } from './get-method-data';
|
|
4
|
-
|
|
5
|
-
export function MountMethodSelector({
|
|
6
|
-
METHODS_CONTAINER,
|
|
7
|
-
METHODS,
|
|
8
|
-
plans,
|
|
9
|
-
products
|
|
10
|
-
}) {
|
|
11
|
-
METHODS_CONTAINER.innerHTML = `<div class="rebilly-instruments-method-selector"></div>`;
|
|
12
|
-
const SELECTOR_CONTAINER = document.querySelector('.rebilly-instruments-method-selector');
|
|
13
|
-
|
|
14
|
-
METHODS.forEach(method => {
|
|
15
|
-
const {METHOD_ID, METHOD_TYPE} = getMethodData(method);
|
|
16
|
-
const {paymentMethodsUrl} = this.options._computed || 'https://www.example.com';
|
|
17
|
-
|
|
18
|
-
const zoidComponent = METHOD_ID;
|
|
19
|
-
const zoidCreateConfig = {
|
|
20
|
-
tag: METHOD_ID,
|
|
21
|
-
url: `${paymentMethodsUrl}/${METHOD_ID}`,
|
|
22
|
-
};
|
|
23
|
-
const zoidMountConfig = {
|
|
24
|
-
configs: this.configs,
|
|
25
|
-
options: this.options,
|
|
26
|
-
MAIN_STYLE: STYLE(this.configs?.theme || {}),
|
|
27
|
-
method,
|
|
28
|
-
plans,
|
|
29
|
-
products,
|
|
30
|
-
dispatch: (event, detail) => {
|
|
31
|
-
dispatch.call(this, event, detail);
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const isiFrame = METHOD_ID === 'payment-card' && !this.options.paymentInstruments[METHOD_TYPE]?.popup;
|
|
36
|
-
const zoidDefaultContext = isiFrame ? zoidIframe : zoidPopup;
|
|
37
|
-
this.zoidComponents[METHOD_ID] = zoidDefaultContext.call(this, {
|
|
38
|
-
zoidComponent,
|
|
39
|
-
zoidCreateConfig,
|
|
40
|
-
zoidMountConfig
|
|
41
|
-
}, {
|
|
42
|
-
SELECTOR_CONTAINER,
|
|
43
|
-
METHOD_ID,
|
|
44
|
-
method
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
import { zoidIframe, dispatch } from './zoid-helpers';
|
|
3
|
-
import { getMethodData } from './get-method-data';
|
|
4
|
-
import { MAIN_STYLE as STYLE } from '../../styles/main';
|
|
5
|
-
|
|
6
|
-
function mountGooglePay({
|
|
7
|
-
METHOD_ID,
|
|
8
|
-
}) {
|
|
9
|
-
const SELECTOR_CONTAINER = document.querySelector('.rebilly-instruments-form-express');
|
|
10
|
-
|
|
11
|
-
const {paymentMethodsUrl} = this.options._computed;
|
|
12
|
-
const zoidComponent = 'googlePay';
|
|
13
|
-
const zoidCreateConfig = {
|
|
14
|
-
tag: METHOD_ID,
|
|
15
|
-
url: `${paymentMethodsUrl}/${METHOD_ID}`,
|
|
16
|
-
prerenderTemplate: () => null
|
|
17
|
-
};
|
|
18
|
-
const zoidMountConfig = {
|
|
19
|
-
configs: this.configs,
|
|
20
|
-
options: this.options,
|
|
21
|
-
MAIN_STYLE: STYLE(this.configs?.theme || {}),
|
|
22
|
-
dispatch,
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
this.zoidComponents.googlePay = zoidIframe.call(this, {
|
|
26
|
-
zoidComponent,
|
|
27
|
-
zoidCreateConfig,
|
|
28
|
-
zoidMountConfig
|
|
29
|
-
}, {
|
|
30
|
-
SELECTOR_CONTAINER,
|
|
31
|
-
METHOD_ID,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function mountApplePay({
|
|
36
|
-
EXPRESS_METHODS_CONTAINER,
|
|
37
|
-
METHOD_ID,
|
|
38
|
-
METHOD_TYPE,
|
|
39
|
-
}) {
|
|
40
|
-
EXPRESS_METHODS_CONTAINER.innerHTML += `
|
|
41
|
-
<div id="rebilly-instruments-${METHOD_ID}" data-rebilly-instruments-express-type="${METHOD_TYPE}"></div>
|
|
42
|
-
`;
|
|
43
|
-
Rebilly.applePay.mount(`#rebilly-instruments-${METHOD_ID}`);
|
|
44
|
-
|
|
45
|
-
Rebilly.on('token-ready', (token) => {
|
|
46
|
-
dispatch('instrument-ready', token);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function mountPaypal() {
|
|
51
|
-
console.log('PayPal - work in progress');
|
|
52
|
-
this.loader.stopLoading({id: 'paypal-express'});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const browserIsSafari = () => window.ApplePaySession;
|
|
56
|
-
|
|
57
|
-
export function mountExpressPaymentMethods({
|
|
58
|
-
EXPRESS_METHODS,
|
|
59
|
-
EXPRESS_METHODS_CONTAINER,
|
|
60
|
-
}) {
|
|
61
|
-
EXPRESS_METHODS.forEach((expressMethod) => {
|
|
62
|
-
const {method, feature} = expressMethod;
|
|
63
|
-
const methodData = getMethodData(expressMethod);
|
|
64
|
-
|
|
65
|
-
if (method === 'paypal') {
|
|
66
|
-
mountPaypal.call(this);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
if (feature?.name === 'Google Pay') {
|
|
70
|
-
mountGooglePay.call(this, {
|
|
71
|
-
...methodData
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (feature?.name === 'Apple Pay' && browserIsSafari()) {
|
|
76
|
-
mountApplePay.call(this, {
|
|
77
|
-
EXPRESS_METHODS_CONTAINER,
|
|
78
|
-
...methodData,
|
|
79
|
-
});
|
|
80
|
-
} else {
|
|
81
|
-
this.loader.stopLoading({id: 'payment-card-express'});
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export function processDigitalWalletOptions(options) {
|
|
2
|
-
const {paymentInstruments} = options;
|
|
3
|
-
const digitalWalletOptions = {};
|
|
4
|
-
|
|
5
|
-
if (paymentInstruments?.googlePay) {
|
|
6
|
-
const {googlePay} = paymentInstruments;
|
|
7
|
-
digitalWalletOptions.merchantConfig = googlePay.merchantConfig; // Throw error?
|
|
8
|
-
digitalWalletOptions.googlePayDisplayOptions = googlePay.displayOptions;
|
|
9
|
-
}
|
|
10
|
-
return digitalWalletOptions;
|
|
11
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import zoid from 'zoid';
|
|
2
|
-
import Events from '../../events';
|
|
3
|
-
import {
|
|
4
|
-
camelCase,
|
|
5
|
-
unKebabCase
|
|
6
|
-
} from '../../utils/index';
|
|
7
|
-
|
|
8
|
-
export const dispatch = (event, detail) => {
|
|
9
|
-
Events[camelCase(event).replace(/-/, '')].dispatch(detail);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function containerTemplate({ doc, uid, focus }) {
|
|
13
|
-
if (doc === null || doc === undefined) {
|
|
14
|
-
doc = document;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const container = doc.createElement('div');
|
|
18
|
-
const text = doc.createElement('p');
|
|
19
|
-
|
|
20
|
-
text.dataset.rebillyI18n = 'form.popupOverlayText';
|
|
21
|
-
text.innerText = this.translate?.translateItem(text) || 'Click here to show popup window';
|
|
22
|
-
container.id = uid;
|
|
23
|
-
container.append(text);
|
|
24
|
-
container.classList.add('rebilly-instruments-overlay');
|
|
25
|
-
container.addEventListener('click', focus);
|
|
26
|
-
|
|
27
|
-
return container;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function zoidIframe({
|
|
31
|
-
zoidComponent,
|
|
32
|
-
zoidCreateConfig,
|
|
33
|
-
zoidMountConfig
|
|
34
|
-
}, {
|
|
35
|
-
SELECTOR_CONTAINER,
|
|
36
|
-
METHOD_ID,
|
|
37
|
-
}) {
|
|
38
|
-
let component = typeof this.zoidComponents[zoidComponent] === "function" ? this.zoidComponents[zoidComponent] : undefined;
|
|
39
|
-
const selector = `rebilly-instruments-${METHOD_ID}`;
|
|
40
|
-
SELECTOR_CONTAINER.innerHTML += `<div id="${selector}" data-rebilly-instruments-type="${METHOD_ID}"></div>`;
|
|
41
|
-
|
|
42
|
-
const METHOD_WRAPPER = document.querySelector(`#${selector}`);
|
|
43
|
-
|
|
44
|
-
if(!component) {
|
|
45
|
-
component = zoid.create({
|
|
46
|
-
...zoidCreateConfig,
|
|
47
|
-
defaultContext: 'iframe',
|
|
48
|
-
dimensions: {
|
|
49
|
-
width: '100%',
|
|
50
|
-
height: '100%'
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
component({
|
|
56
|
-
RebillyInstruments: {
|
|
57
|
-
...zoidMountConfig,
|
|
58
|
-
onFrameResize: (height) => {
|
|
59
|
-
METHOD_WRAPPER.style.height = height;
|
|
60
|
-
},
|
|
61
|
-
onLoading: (id) => {
|
|
62
|
-
this.loader.stopLoading({id});
|
|
63
|
-
},
|
|
64
|
-
},
|
|
65
|
-
onDestroy: () => {
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
METHOD_WRAPPER.remove();
|
|
68
|
-
}, 1000);
|
|
69
|
-
}
|
|
70
|
-
}).render(`#${selector}`);
|
|
71
|
-
|
|
72
|
-
return component;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function zoidPopup({
|
|
76
|
-
zoidComponent,
|
|
77
|
-
zoidCreateConfig,
|
|
78
|
-
zoidMountConfig
|
|
79
|
-
}, {
|
|
80
|
-
SELECTOR_CONTAINER,
|
|
81
|
-
METHOD_ID,
|
|
82
|
-
method,
|
|
83
|
-
}) {
|
|
84
|
-
let component = typeof this.zoidComponents[zoidComponent] === "function" ? this.zoidComponents[zoidComponent] : undefined;
|
|
85
|
-
if (!component) {
|
|
86
|
-
component = zoid.create({
|
|
87
|
-
...zoidCreateConfig,
|
|
88
|
-
defaultContext: 'popup',
|
|
89
|
-
dimensions: {
|
|
90
|
-
width: '600px',
|
|
91
|
-
height: '600px',
|
|
92
|
-
},
|
|
93
|
-
containerTemplate: containerTemplate.bind(this)
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const selector = `rebilly-instruments-${METHOD_ID}`;
|
|
98
|
-
SELECTOR_CONTAINER.innerHTML += `<div id="${selector}" data-rebilly-instruments-type="${METHOD_ID}">
|
|
99
|
-
<button data-rebilly-i18n="paymentMethods.${method.method}" class="rebilly-instruments-button">${unKebabCase(method.method)}</button>
|
|
100
|
-
</div>`;
|
|
101
|
-
|
|
102
|
-
this.loader.stopLoading({id: method.method});
|
|
103
|
-
|
|
104
|
-
const PAYMENT_CARD_BUTTON = document.querySelector(`#${selector} button`);
|
|
105
|
-
PAYMENT_CARD_BUTTON.addEventListener('click', () => {
|
|
106
|
-
component({
|
|
107
|
-
RebillyInstruments: {
|
|
108
|
-
...zoidMountConfig
|
|
109
|
-
}
|
|
110
|
-
}).render();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
return component;
|
|
114
|
-
}
|
package/src/components/result.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import zoid from 'zoid';
|
|
2
|
-
import { MAIN_STYLE } from '../styles/main';
|
|
3
|
-
|
|
4
|
-
export function MountResult({
|
|
5
|
-
purchase,
|
|
6
|
-
}) {
|
|
7
|
-
const resultContainerClassName = 'rebilly-instruments-result';
|
|
8
|
-
this.form.innerHTML += `<div class="${resultContainerClassName}"></div>`;
|
|
9
|
-
this.loader.startLoading({id: 'result'});
|
|
10
|
-
const RESULT_CONTAINER = document.querySelector(`.${resultContainerClassName}`);
|
|
11
|
-
|
|
12
|
-
this.form.querySelectorAll(`:not(.${resultContainerClassName})`).forEach(element => {
|
|
13
|
-
if (!element.classList.contains('rebilly-instruments-loader')
|
|
14
|
-
&& !element.classList.contains('rebilly-instruments-loader-spinner')) {
|
|
15
|
-
element.remove();
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const {paymentMethodsUrl} = this.options._computed;
|
|
20
|
-
const zoidCreateConfig = {
|
|
21
|
-
tag: 'rebilly-instruments-result',
|
|
22
|
-
url: `${paymentMethodsUrl}/result`,
|
|
23
|
-
defaultContext: 'iframe',
|
|
24
|
-
dimensions: {
|
|
25
|
-
width: '100%',
|
|
26
|
-
height: '100%'
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
const zoidMountConfig = {
|
|
30
|
-
configs: this.configs,
|
|
31
|
-
options: this.options,
|
|
32
|
-
MAIN_STYLE: MAIN_STYLE(this.configs?.theme || {}),
|
|
33
|
-
purchase,
|
|
34
|
-
onFrameResize: (height) => {
|
|
35
|
-
RESULT_CONTAINER.style.height = height;
|
|
36
|
-
},
|
|
37
|
-
onLoading: (id) => {
|
|
38
|
-
setTimeout(() => {
|
|
39
|
-
this.loader.stopLoading({id});
|
|
40
|
-
}, 1);
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
if(!this.zoidComponents.result) {
|
|
45
|
-
this.zoidComponents.result = zoid.create(zoidCreateConfig);
|
|
46
|
-
}
|
|
47
|
-
this.zoidComponents.result({
|
|
48
|
-
RebillyInstruments: zoidMountConfig,
|
|
49
|
-
}).render(`.${resultContainerClassName}`);
|
|
50
|
-
};
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import SummaryModel from '@/storefront/models/summary-model';
|
|
2
|
-
import PlanModel from '@/storefront/models/plan-model';
|
|
3
|
-
import ProductModel from '@/storefront/models/product-model';
|
|
4
|
-
import { Loader } from '../loader';
|
|
5
|
-
import { Translate } from '../i18n';
|
|
6
|
-
import { MountSummary } from './summary';
|
|
7
|
-
|
|
8
|
-
describe('Summary component', () => {
|
|
9
|
-
let summaryElement;
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
summaryElement = document.createElement('div');
|
|
12
|
-
document.body.append(summaryElement);
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
class TestMountSummaryInstance {
|
|
16
|
-
constructor({
|
|
17
|
-
configs = {},
|
|
18
|
-
options = {},
|
|
19
|
-
summary = summaryElement,
|
|
20
|
-
loader = new Loader(),
|
|
21
|
-
translate = new Translate(),
|
|
22
|
-
} = {}) {
|
|
23
|
-
this.configs = configs;
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.summary = summary;
|
|
26
|
-
this.loader = loader;
|
|
27
|
-
this.translate = translate;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
mountSummary(summaryProductsPlans, ...args) {
|
|
31
|
-
this.loader.DOM.summary = this.summary;
|
|
32
|
-
return MountSummary.apply(this, args.concat(summaryProductsPlans));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const options = {
|
|
37
|
-
intent: {
|
|
38
|
-
countryCode: 'US',
|
|
39
|
-
items: [
|
|
40
|
-
{
|
|
41
|
-
planId: 'my-awesome-product',
|
|
42
|
-
quantity: 1,
|
|
43
|
-
thumbnail: '',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
planId: 'awesome-t-shirt',
|
|
47
|
-
quantity: 2,
|
|
48
|
-
thumbnail: '',
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const summaryData = new SummaryModel({
|
|
55
|
-
currency: "USD",
|
|
56
|
-
lineItems: [{
|
|
57
|
-
type: "debit",
|
|
58
|
-
description: "My Awesome Product",
|
|
59
|
-
unitPrice: 30,
|
|
60
|
-
quantity: 1,
|
|
61
|
-
price: 30,
|
|
62
|
-
productId: "test-product-1",
|
|
63
|
-
planId: "my-awesome-product"
|
|
64
|
-
}, {
|
|
65
|
-
type: "debit",
|
|
66
|
-
description: "Awesome T-Shirt",
|
|
67
|
-
unitPrice: 20,
|
|
68
|
-
quantity: 2,
|
|
69
|
-
price: 40,
|
|
70
|
-
productId: "test-product-2",
|
|
71
|
-
planId: "awesome-t-shirt"
|
|
72
|
-
}],
|
|
73
|
-
subtotalAmount: 70,
|
|
74
|
-
taxAmount: 0,
|
|
75
|
-
shippingAmount: 0,
|
|
76
|
-
discountsAmount: 0,
|
|
77
|
-
total: 70
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const planData = [
|
|
81
|
-
new PlanModel({name: 'My Awesome Product', id: 'my-awesome-product', productId: 'test-product-1'}),
|
|
82
|
-
new PlanModel({name: 'My Awesome T-Shirt', id: 'awesome-t-shirt', productId: 'test-product-2'})
|
|
83
|
-
];
|
|
84
|
-
|
|
85
|
-
const productData = [
|
|
86
|
-
new ProductModel({description: 'My Awesome Product', id: 'test-product-1'}),
|
|
87
|
-
new ProductModel({description: 'My Awesome T-Shirt', id: 'test-product-2'})
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
const configs = {
|
|
91
|
-
websiteId: 'test-website-id'
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
it('should render the summary correctly', () => {
|
|
95
|
-
const mountSummaryInstance = new TestMountSummaryInstance({configs, options});
|
|
96
|
-
mountSummaryInstance.mountSummary({summary: summaryData, plans: planData, products: productData});
|
|
97
|
-
|
|
98
|
-
// Number of line items
|
|
99
|
-
const itemsContainer = document.querySelector('.rebilly-instruments-summary-line-items');
|
|
100
|
-
expect(itemsContainer).toMatchSnapshot();
|
|
101
|
-
|
|
102
|
-
// Breakdown
|
|
103
|
-
const summaryBreakdown = document.querySelector('.rebilly-instruments-summary-breakdown');
|
|
104
|
-
expect(summaryBreakdown).toMatchSnapshot();
|
|
105
|
-
});
|
|
106
|
-
})
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import BaseEvent from './base-event';
|
|
2
|
-
|
|
3
|
-
export const InstrumentReadyEventName = 'rebilly-instruments-instrument-ready';
|
|
4
|
-
|
|
5
|
-
export default class InstrumentReadyEvent extends BaseEvent {
|
|
6
|
-
constructor({
|
|
7
|
-
name = InstrumentReadyEventName
|
|
8
|
-
} = {}) {
|
|
9
|
-
super(name);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import BaseEvent from './base-event';
|
|
2
|
-
|
|
3
|
-
export const InstrumentReadyEventName = 'rebilly-instruments-purchase-complete';
|
|
4
|
-
|
|
5
|
-
export default class PurchaseCompleteEvent extends BaseEvent {
|
|
6
|
-
constructor({
|
|
7
|
-
name = InstrumentReadyEventName
|
|
8
|
-
} = {}) {
|
|
9
|
-
super(name);
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/functions/mount.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { collectData } from '@rebilly/risk-data-collector';
|
|
2
|
-
import { merge } from 'lodash';
|
|
3
|
-
import { MAIN_STYLE } from '../styles/main';
|
|
4
|
-
import { addDOMElement, processPropertyAsDOMElement } from '../utils';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {Object} Item
|
|
8
|
-
* @property {string} planId - The Rebilly id of the plan.
|
|
9
|
-
* @property {number} quantity - The number of the plans to be purchased.
|
|
10
|
-
* @property {string} thumbnail - The source img for the product. Recommend 100px by 100px.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {Object} Intent
|
|
15
|
-
* @property {"purchase" | "vault"} mode - Which mode the mount is usings. Default "purchase".
|
|
16
|
-
* @property {Array.<Item>} items - Which plans the customer is purchasing.
|
|
17
|
-
* @property {string} customerId - Which customer is associated with the instrument.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {Object} Options
|
|
22
|
-
* @property {Intent} intent - The information required for purchaseing or vaulting an instrument
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Mount library with configurations.
|
|
27
|
-
* @param {string | HTMLElement} form - The CSS class or HTML element were the form will be mounted.
|
|
28
|
-
* @param {string | HTMLElement} summary - The CSS class or HTML element were the summary will be mounted.
|
|
29
|
-
* @param {Options} options - The configurations that are to be passed to the library for use.
|
|
30
|
-
*/
|
|
31
|
-
export async function Mount (
|
|
32
|
-
{
|
|
33
|
-
form = '.rebilly-instruments',
|
|
34
|
-
summary = '.rebilly-instruments-summary',
|
|
35
|
-
_dev = {
|
|
36
|
-
framePayScriptLink: null,
|
|
37
|
-
framePayStyleLink: null,
|
|
38
|
-
paymentMethodsUrl: null
|
|
39
|
-
},
|
|
40
|
-
options = {},
|
|
41
|
-
} = {},
|
|
42
|
-
) {
|
|
43
|
-
this.form = form;
|
|
44
|
-
this.summary = summary;
|
|
45
|
-
|
|
46
|
-
const framePayUrls = {
|
|
47
|
-
script: _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js',
|
|
48
|
-
style: _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css'
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const _computed = {
|
|
52
|
-
paymentMethodsUrl: _dev.paymentMethodsUrl || 'https://forms.secure-payments.app',
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const OPTIONS_DEFAULTS = {
|
|
56
|
-
intent: {
|
|
57
|
-
countryCode: 'US'
|
|
58
|
-
},
|
|
59
|
-
locale: 'auto',
|
|
60
|
-
paymentInstruments: {
|
|
61
|
-
compactExpressInstruments: true,
|
|
62
|
-
googlePay: {
|
|
63
|
-
displayOptions: {
|
|
64
|
-
buttonColor: 'black',
|
|
65
|
-
buttonType: 'short',
|
|
66
|
-
buttonHeight: '44px'
|
|
67
|
-
}
|
|
68
|
-
},
|
|
69
|
-
paymentCard: {
|
|
70
|
-
popup: false
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
flowFlags: {
|
|
74
|
-
autoConfirmation: true,
|
|
75
|
-
autoResult: true
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// TODO: Only add _dev in dev enviroment
|
|
80
|
-
this.options = merge(OPTIONS_DEFAULTS, {...options, _dev, _computed});
|
|
81
|
-
this.form = processPropertyAsDOMElement({prop: this.form, propName: 'form'});
|
|
82
|
-
this.summary = processPropertyAsDOMElement({prop: this.summary, propName: 'summary', isRequired: false});
|
|
83
|
-
|
|
84
|
-
// Setup loader
|
|
85
|
-
this.loader.addDOMElement({el: this.form});
|
|
86
|
-
this.loader.addDOMElement({section: 'summary', el: this.summary});
|
|
87
|
-
|
|
88
|
-
// Adds base stylesheet
|
|
89
|
-
addDOMElement(
|
|
90
|
-
{
|
|
91
|
-
element: 'style',
|
|
92
|
-
attributes: {type: 'text/css'},
|
|
93
|
-
content: MAIN_STYLE(this.configs?.theme || {}),
|
|
94
|
-
target: 'head'
|
|
95
|
-
}
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
// Adds configs CSS to override any styles
|
|
99
|
-
if (this.configs.css) {
|
|
100
|
-
addDOMElement(
|
|
101
|
-
{
|
|
102
|
-
element: 'style',
|
|
103
|
-
attributes: {type: 'text/css'},
|
|
104
|
-
content: this.configs.css,
|
|
105
|
-
target: 'head'
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Adds FramePay
|
|
111
|
-
if (!document.querySelectorAll(`[framepay*="script"]`).length) {
|
|
112
|
-
addDOMElement(
|
|
113
|
-
{
|
|
114
|
-
element: 'script',
|
|
115
|
-
attributes: {
|
|
116
|
-
'framepay': 'script',
|
|
117
|
-
src: framePayUrls.script
|
|
118
|
-
},
|
|
119
|
-
target: 'head'
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if(!document.querySelectorAll(`[framepay*="stylesheet"]`).length) {
|
|
125
|
-
addDOMElement(
|
|
126
|
-
{
|
|
127
|
-
element: 'link',
|
|
128
|
-
attributes: {
|
|
129
|
-
'framepay': 'stylesheet',
|
|
130
|
-
href: framePayUrls.style,
|
|
131
|
-
rel: 'stylesheet'
|
|
132
|
-
},
|
|
133
|
-
target: 'head'
|
|
134
|
-
}
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
this.loader.startLoading({section: 'summary', id: 'initSummary'});
|
|
140
|
-
this.loader.startLoading({id: 'initForm'});
|
|
141
|
-
|
|
142
|
-
const {riskMetadata} = await collectData();
|
|
143
|
-
|
|
144
|
-
if (this.options.locale === 'auto' && riskMetadata?.browserData?.language) {
|
|
145
|
-
const {browserData: {language}} = riskMetadata;
|
|
146
|
-
this.options.locale = language;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
const i18n = this.configs?.i18n || {};
|
|
150
|
-
this.translate.init(this.options.locale, i18n);
|
|
151
|
-
|
|
152
|
-
const [
|
|
153
|
-
readyToPayData,
|
|
154
|
-
summaryData,
|
|
155
|
-
] = await Promise.all([
|
|
156
|
-
this._fetchReadyToPay(riskMetadata),
|
|
157
|
-
this._fetchSummary()
|
|
158
|
-
]);
|
|
159
|
-
|
|
160
|
-
const plansData = await this._fetchPlans({data: summaryData});
|
|
161
|
-
const productsData = await this._fetchProducts({data: plansData});
|
|
162
|
-
|
|
163
|
-
if (this.form) {
|
|
164
|
-
this.formOptions = {
|
|
165
|
-
readyToPay: readyToPayData,
|
|
166
|
-
summary: summaryData,
|
|
167
|
-
plans: plansData,
|
|
168
|
-
products: productsData
|
|
169
|
-
};
|
|
170
|
-
this._mountForm(this.formOptions);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (this.summary) {
|
|
174
|
-
this._mountSummary({
|
|
175
|
-
summary: summaryData,
|
|
176
|
-
plans: plansData,
|
|
177
|
-
products: productsData,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
} catch(error) {
|
|
181
|
-
throw error;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const i18n = this.configs?.i18n || {};
|
|
185
|
-
this.translate.init(this.options.locale, i18n);
|
|
186
|
-
this.translate.translateItems();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (this.options.flowFlags.autoConfirmation) {
|
|
190
|
-
this.on('instrument-ready', (instrument) => {
|
|
191
|
-
this.show('confirmation', {
|
|
192
|
-
instrument
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (this.options.flowFlags.autoResult) {
|
|
198
|
-
this.on('purchase-complete', (purchase) => {
|
|
199
|
-
this.show('result', {
|
|
200
|
-
purchase
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
};
|