@rebilly/instruments 3.1.0-beta.0 → 3.1.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +88 -107
- package/dist/index.min.js +88 -0
- package/package.json +17 -6
- package/rollup.config.js +84 -0
- package/src/functions/mount/fetch-data.js +13 -1
- package/src/functions/mount/index.js +6 -42
- package/src/functions/mount/setup-framepay-theme.js +2 -2
- package/src/functions/mount/setup-options.js +3 -0
- package/src/functions/mount/setup-user-flow.js +49 -0
- package/src/functions/purchase.js +1 -1
- package/src/functions/setup.js +1 -1
- package/src/functions/show.spec.js +1 -1
- package/src/i18n/en.json +3 -0
- package/src/index.js +1 -61
- package/src/instance.js +65 -0
- package/src/{index.spec.js → instance.spec.js} +2 -1
- package/src/loader/index.js +21 -1
- package/src/storefront/models/ready-to-pay-model.js +13 -2
- package/src/storefront/plans.js +8 -4
- package/src/storefront/plans.spec.js +8 -2
- package/src/storefront/products.js +8 -4
- package/src/storefront/products.spec.js +8 -2
- package/src/storefront/ready-to-pay.js +5 -4
- package/src/style/components/button.js +1 -0
- package/src/style/components/loader.js +2 -1
- package/src/style/payment-instruments/payment-card.js +2 -1
- package/src/style/utils/remove-empty-null.js +9 -9
- package/src/style/vendor/postmate.js +13 -0
- package/src/style/views/confirmation.js +2 -1
- package/src/views/common/iframe/base-iframe.js +2 -0
- package/src/views/common/iframe/event-listeners.js +10 -0
- package/src/views/common/iframe/method-iframe.js +3 -1
- package/src/views/confirmation.js +1 -0
- package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
- package/src/views/method-selector/mount-express-methods.js +6 -18
- package/src/views/result.js +1 -0
- package/tests/mocks/rebilly-instruments-mock.js +2 -2
- package/dist/events/base-event.js +0 -66
- package/dist/events/events.spec.js +0 -18
- package/dist/events/index.js +0 -22
- package/dist/functions/destroy.js +0 -34
- package/dist/functions/destroy.spec.js +0 -69
- package/dist/functions/mount/fetch-data.js +0 -187
- package/dist/functions/mount/fetch-data.spec.js +0 -189
- package/dist/functions/mount/index.js +0 -218
- package/dist/functions/mount/mount.spec.js +0 -64
- package/dist/functions/mount/setup-element.js +0 -40
- package/dist/functions/mount/setup-framepay-theme.js +0 -95
- package/dist/functions/mount/setup-framepay.js +0 -46
- package/dist/functions/mount/setup-i18n.js +0 -33
- package/dist/functions/mount/setup-options.js +0 -99
- package/dist/functions/mount/setup-options.spec.js +0 -66
- package/dist/functions/mount/setup-storefront.js +0 -34
- package/dist/functions/mount/setup-styles.js +0 -43
- package/dist/functions/on.js +0 -40
- package/dist/functions/on.spec.js +0 -55
- package/dist/functions/purchase.js +0 -158
- package/dist/functions/purchase.spec.js +0 -74
- package/dist/functions/setup.js +0 -85
- package/dist/functions/setup.spec.js +0 -87
- package/dist/functions/show.js +0 -55
- package/dist/functions/show.spec.js +0 -61
- package/dist/functions/update.js +0 -74
- package/dist/functions/update.spec.js +0 -86
- package/dist/i18n/en.json +0 -22
- package/dist/i18n/es.json +0 -22
- package/dist/i18n/i18n.spec.js +0 -22
- package/dist/i18n/index.js +0 -72
- package/dist/index.spec.js +0 -35
- package/dist/loader/index.js +0 -94
- package/dist/loader/loader.spec.js +0 -69
- package/dist/storefront/index.js +0 -73
- package/dist/storefront/invoices.js +0 -27
- package/dist/storefront/models/base-model.js +0 -18
- package/dist/storefront/models/invoice-model.js +0 -14
- package/dist/storefront/models/plan-model.js +0 -14
- package/dist/storefront/models/product-model.js +0 -14
- package/dist/storefront/models/ready-to-pay-model.js +0 -46
- package/dist/storefront/models/summary-model.js +0 -79
- package/dist/storefront/models/transaction-model.js +0 -31
- package/dist/storefront/payment-instruments.js +0 -47
- package/dist/storefront/payment-instruments.spec.js +0 -55
- package/dist/storefront/plans.js +0 -37
- package/dist/storefront/plans.spec.js +0 -64
- package/dist/storefront/products.js +0 -40
- package/dist/storefront/products.spec.js +0 -65
- package/dist/storefront/purchase.js +0 -43
- package/dist/storefront/purchase.spec.js +0 -48
- package/dist/storefront/ready-to-pay.js +0 -58
- package/dist/storefront/ready-to-pay.spec.js +0 -69
- package/dist/storefront/storefront.spec.js +0 -15
- package/dist/storefront/summary.js +0 -55
- package/dist/storefront/summary.spec.js +0 -124
- package/dist/storefront/transactions.js +0 -27
- package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -227
- package/dist/style/base/default-theme.js +0 -804
- package/dist/style/base/index.js +0 -104
- package/dist/style/base/theme.js +0 -41
- package/dist/style/base/theme.spec.js +0 -19
- package/dist/style/browserslist.js +0 -8
- package/dist/style/components/address.js +0 -64
- package/dist/style/components/button.js +0 -87
- package/dist/style/components/divider.js +0 -48
- package/dist/style/components/forms/checkbox.js +0 -86
- package/dist/style/components/forms/field.js +0 -65
- package/dist/style/components/forms/form.js +0 -28
- package/dist/style/components/forms/input.js +0 -86
- package/dist/style/components/forms/label.js +0 -64
- package/dist/style/components/forms/select.js +0 -95
- package/dist/style/components/forms/validation.js +0 -81
- package/dist/style/components/icons.js +0 -22
- package/dist/style/components/index.js +0 -57
- package/dist/style/components/loader.js +0 -50
- package/dist/style/components/methods.js +0 -108
- package/dist/style/components/overlay.js +0 -33
- package/dist/style/helpers/index.js +0 -59
- package/dist/style/index.js +0 -50
- package/dist/style/payment-instruments/content.js +0 -17
- package/dist/style/payment-instruments/index.js +0 -20
- package/dist/style/payment-instruments/payment-card.js +0 -35
- package/dist/style/utils/border.js +0 -47
- package/dist/style/utils/color-values.js +0 -58
- package/dist/style/utils/remove-empty-null.js +0 -20
- package/dist/style/vendor/framepay.js +0 -37
- package/dist/style/vendor/postmate.js +0 -17
- package/dist/style/views/confirmation.js +0 -85
- package/dist/style/views/index.js +0 -29
- package/dist/style/views/method-selector.js +0 -20
- package/dist/style/views/modal.js +0 -93
- package/dist/style/views/result.js +0 -61
- package/dist/style/views/summary.js +0 -127
- package/dist/utils/add-dom-element.js +0 -26
- package/dist/utils/format-currency.js +0 -15
- package/dist/utils/has-valid-css-selector.js +0 -11
- package/dist/utils/index.js +0 -55
- package/dist/utils/is-dom-element.js +0 -10
- package/dist/utils/process-property-as-dom-element.js +0 -38
- package/dist/utils/sleep.js +0 -10
- package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
- package/dist/views/common/iframe/base-iframe.js +0 -59
- package/dist/views/common/iframe/event-listeners.js +0 -50
- package/dist/views/common/iframe/index.js +0 -19
- package/dist/views/common/iframe/method-iframe.js +0 -33
- package/dist/views/common/iframe/modal-iframe.js +0 -84
- package/dist/views/common/iframe/view-iframe.js +0 -31
- package/dist/views/common/render-utilities.js +0 -11
- package/dist/views/confirmation.js +0 -92
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
- package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
- package/dist/views/method-selector/express-methods/google-pay.js +0 -31
- package/dist/views/method-selector/express-methods/paypal.js +0 -19
- package/dist/views/method-selector/generate-digital-wallet.js +0 -68
- package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
- package/dist/views/method-selector/get-method-data.js +0 -25
- package/dist/views/method-selector/get-payment-methods.js +0 -66
- package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
- package/dist/views/method-selector/index.js +0 -122
- package/dist/views/method-selector/method-selector.spec.js +0 -124
- package/dist/views/method-selector/mount-express-methods.js +0 -69
- package/dist/views/method-selector/mount-methods.js +0 -74
- package/dist/views/modal.js +0 -88
- package/dist/views/result.js +0 -40
- package/dist/views/summary.js +0 -215
- package/dist/views/summary.spec.js +0 -134
- package/src/views/method-selector/express-methods/paypal.js +0 -7
|
@@ -57,6 +57,7 @@ export const button = () => `
|
|
|
57
57
|
|
|
58
58
|
.rebilly-instruments-button.rebilly-instruments-button-secondary:not([disabled]):hover,
|
|
59
59
|
.rebilly-instruments-button.rebilly-instruments-button-secondary:not([disabled]):active {
|
|
60
|
+
color: var(--rebilly-buttonColorBackground);
|
|
60
61
|
background: var(--rebilly-colorBackground);
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export default () => ({
|
|
2
|
+
postcssPlugin: 'postcss-remove-empty-null',
|
|
3
|
+
Once (root) {
|
|
4
|
+
root.walkAtRules(decl => {
|
|
5
|
+
if ((decl.value === '\'\'' || decl.value === '""' || decl.value.includes('null')) && decl.prop !== 'content') {
|
|
6
|
+
decl.remove();
|
|
7
|
+
}
|
|
8
|
+
});
|
|
7
9
|
}
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
);
|
|
10
|
+
})
|
|
@@ -4,5 +4,18 @@ export const postmateStyle = () => `
|
|
|
4
4
|
width: 100%;
|
|
5
5
|
min-height: var(--rebilly-spacings-form-element-min-height);
|
|
6
6
|
transition: all 0.2s ease;
|
|
7
|
+
transition: width 0s ease;
|
|
8
|
+
transition: height 0s ease;
|
|
9
|
+
transition: position 0s ease;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.rebilly-instruments-iframe-overlay {
|
|
13
|
+
top: -2px;
|
|
14
|
+
left: -2px;
|
|
15
|
+
width: calc(100vw + 2px);
|
|
16
|
+
height: 100vh;
|
|
17
|
+
min-height: calc(100vh + 4px);
|
|
18
|
+
position: fixed;
|
|
19
|
+
z-index: 99999999999999;
|
|
7
20
|
}
|
|
8
21
|
`;
|
|
@@ -25,3 +25,13 @@ export function changeIframeSrcHandler(iframe) {
|
|
|
25
25
|
iframe.component.frame.style.height = '75vh';
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export function displayOverlay(iframe) {
|
|
30
|
+
iframe.component.on(`${iframe.name}-change-overlay`, (showOverlay = true) => {
|
|
31
|
+
if (showOverlay) {
|
|
32
|
+
iframe.component.frame.classList.add('rebilly-instruments-iframe-overlay');
|
|
33
|
+
} else {
|
|
34
|
+
iframe.component.frame.classList.remove('rebilly-instruments-iframe-overlay');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -2,7 +2,8 @@ import BaseIframe from './base-iframe';
|
|
|
2
2
|
import {
|
|
3
3
|
dispatchRebillyInsturmentEventHandler,
|
|
4
4
|
resizeComponentHandler,
|
|
5
|
-
stopLoaderHandler
|
|
5
|
+
stopLoaderHandler,
|
|
6
|
+
displayOverlay
|
|
6
7
|
} from './event-listeners';
|
|
7
8
|
|
|
8
9
|
export class MethodIframe extends BaseIframe {
|
|
@@ -17,5 +18,6 @@ export class MethodIframe extends BaseIframe {
|
|
|
17
18
|
loader,
|
|
18
19
|
id
|
|
19
20
|
});
|
|
21
|
+
displayOverlay(this);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { MethodIframe } from '../../common/iframe';
|
|
2
2
|
|
|
3
|
-
export default async function
|
|
3
|
+
export default async function mountExpressMethod({ state, METHOD_ID }) {
|
|
4
4
|
const container = document.querySelector(`.rebilly-instruments-${METHOD_ID}-method`);
|
|
5
5
|
|
|
6
6
|
const { paymentMethodsUrl } = state.options._computed;
|
|
7
7
|
|
|
8
8
|
const model = {
|
|
9
|
-
options: state.options
|
|
9
|
+
options: state.options,
|
|
10
|
+
data: state.data.toPostmatesModel()
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
const iframe = await new MethodIframe({
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import mountGooglePay from './express-methods/google-pay';
|
|
1
|
+
import mountExpressMethod from './express-methods';
|
|
3
2
|
import mountApplePay from './express-methods/apple-pay';
|
|
4
|
-
import mountPaypal from './express-methods/paypal';
|
|
5
3
|
import { getMethodData } from './get-method-data';
|
|
6
4
|
|
|
7
5
|
export function mountExpressMethods({
|
|
@@ -22,16 +20,9 @@ export function mountExpressMethods({
|
|
|
22
20
|
|
|
23
21
|
|
|
24
22
|
EXPRESS_METHODS.forEach((expressMethod) => {
|
|
25
|
-
const {
|
|
23
|
+
const { feature } = expressMethod;
|
|
26
24
|
const { METHOD_ID, METHOD_TYPE } = getMethodData(expressMethod);
|
|
27
25
|
|
|
28
|
-
if (feature?.name === 'Google Pay') {
|
|
29
|
-
mountGooglePay({
|
|
30
|
-
state,
|
|
31
|
-
METHOD_ID
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
26
|
if (feature?.name === 'Apple Pay') {
|
|
36
27
|
mountApplePay({
|
|
37
28
|
state,
|
|
@@ -40,14 +31,11 @@ export function mountExpressMethods({
|
|
|
40
31
|
EXPRESS_METHODS,
|
|
41
32
|
EXPRESS_METHODS_CONTAINER
|
|
42
33
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (method === 'paypal') {
|
|
46
|
-
mountPaypal({
|
|
34
|
+
} else {
|
|
35
|
+
mountExpressMethod({
|
|
47
36
|
state,
|
|
48
|
-
METHOD_ID
|
|
49
|
-
|
|
50
|
-
});
|
|
37
|
+
METHOD_ID
|
|
38
|
+
})
|
|
51
39
|
}
|
|
52
40
|
});
|
|
53
41
|
}
|
package/src/views/result.js
CHANGED
|
@@ -6,6 +6,7 @@ export async function mountResult({ payload, state }) {
|
|
|
6
6
|
replaceContent(state.form, `<div class="${resultContainerClassName}"></div>`);
|
|
7
7
|
|
|
8
8
|
state.loader.startLoading({ id: 'result' });
|
|
9
|
+
state.loader.stopLoading({ id: 'express-purchase' });
|
|
9
10
|
|
|
10
11
|
const container = document.querySelector(`.${resultContainerClassName}`);
|
|
11
12
|
const { paymentMethodsUrl } = state.options._computed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import RebillyInstrumentsInstance from '@rebilly/instruments';
|
|
2
2
|
import { createFramepayMock } from 'tests/mocks/framepay-mock';
|
|
3
3
|
import { get, ok, post } from 'msw-when-then';
|
|
4
4
|
import { when } from 'tests/msw/server';
|
|
@@ -103,7 +103,7 @@ export async function RenderMockRebillyInstruments(options = {}) {
|
|
|
103
103
|
const framepayMock = createFramepayMock();
|
|
104
104
|
global.Rebilly = framepayMock;
|
|
105
105
|
|
|
106
|
-
const rebillyInstruments =
|
|
106
|
+
const rebillyInstruments = RebillyInstrumentsInstance;
|
|
107
107
|
|
|
108
108
|
document.body.innerHTML = `
|
|
109
109
|
<div class="${mergedOptions.form.replace('.', '')}"></div>
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.registeredListeners = exports.RegisteredListeners = void 0;
|
|
7
|
-
|
|
8
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
-
|
|
10
|
-
class RegisteredListeners {
|
|
11
|
-
constructor() {
|
|
12
|
-
_defineProperty(this, "_listeners", {});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
add(eventName, callback) {
|
|
16
|
-
document.addEventListener(eventName, callback, false);
|
|
17
|
-
|
|
18
|
-
if (!(eventName in this._listeners)) {
|
|
19
|
-
this._listeners[eventName] = [];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
this._listeners[eventName].push(callback);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
removeAll() {
|
|
26
|
-
Object.keys(this._listeners).forEach(eventName => {
|
|
27
|
-
this._listeners[eventName].forEach(callback => document.removeEventListener(eventName, callback, false));
|
|
28
|
-
});
|
|
29
|
-
this._listeners = {};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
exports.RegisteredListeners = RegisteredListeners;
|
|
35
|
-
const registeredListeners = new RegisteredListeners();
|
|
36
|
-
exports.registeredListeners = registeredListeners;
|
|
37
|
-
|
|
38
|
-
class BaseEvent {
|
|
39
|
-
/**
|
|
40
|
-
* @param {string} name
|
|
41
|
-
*/
|
|
42
|
-
constructor(name) {
|
|
43
|
-
// Using namespaced internal name as a protection mechanism
|
|
44
|
-
const PREFIX = 'rebilly-instruments-';
|
|
45
|
-
this.internalName = PREFIX + name;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
addEventListener(callback) {
|
|
49
|
-
const innerCallback = ({
|
|
50
|
-
detail
|
|
51
|
-
}) => callback(detail);
|
|
52
|
-
|
|
53
|
-
registeredListeners.add(this.internalName, innerCallback);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
dispatch(detail) {
|
|
57
|
-
const event = new CustomEvent(this.internalName, {
|
|
58
|
-
bubbles: true,
|
|
59
|
-
detail
|
|
60
|
-
});
|
|
61
|
-
document.dispatchEvent(event);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
exports.default = BaseEvent;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
|
|
4
|
-
|
|
5
|
-
var _ = _interopRequireWildcard(require("./"));
|
|
6
|
-
|
|
7
|
-
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); }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
|
|
13
|
-
it('Should export all public event names', async () => {
|
|
14
|
-
Object.keys(_.default).forEach(internalEventName => {
|
|
15
|
-
expect(_.default[internalEventName].internalName).toEqual(`rebilly-instruments-${(0, _lodash.default)(internalEventName)}`);
|
|
16
|
-
expect((0, _lodash.default)(internalEventName) in _.publicEventNames);
|
|
17
|
-
});
|
|
18
|
-
});
|
package/dist/events/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.publicEventNames = exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.kebabcase"));
|
|
9
|
-
|
|
10
|
-
var _baseEvent = _interopRequireDefault(require("./base-event"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
const events = {
|
|
15
|
-
instrumentReady: new _baseEvent.default('instrument-ready'),
|
|
16
|
-
purchaseCompleted: new _baseEvent.default('purchase-completed'),
|
|
17
|
-
setupCompleted: new _baseEvent.default('setup-completed')
|
|
18
|
-
};
|
|
19
|
-
var _default = events;
|
|
20
|
-
exports.default = _default;
|
|
21
|
-
const publicEventNames = Object.keys(events).map(internalName => (0, _lodash.default)(internalName));
|
|
22
|
-
exports.publicEventNames = publicEventNames;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.destroy = destroy;
|
|
7
|
-
|
|
8
|
-
var _rebillyJsSdk = require("rebilly-js-sdk");
|
|
9
|
-
|
|
10
|
-
var _baseEvent = require("../events/base-event");
|
|
11
|
-
|
|
12
|
-
var _utils = require("../utils");
|
|
13
|
-
|
|
14
|
-
async function destroy({
|
|
15
|
-
state
|
|
16
|
-
}) {
|
|
17
|
-
// wait to allow for cancellation to catch any pending api requests
|
|
18
|
-
const sleepMilliseconds = 1000;
|
|
19
|
-
await (0, _utils.sleep)(sleepMilliseconds);
|
|
20
|
-
[...(state.iframeComponents || {})].forEach(iframe => {
|
|
21
|
-
iframe.destroy();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
_baseEvent.registeredListeners.removeAll(document);
|
|
25
|
-
|
|
26
|
-
state.iframeComponents = [];
|
|
27
|
-
state.hasMounted = false;
|
|
28
|
-
state.summary.textContent = '';
|
|
29
|
-
state.form.textContent = '';
|
|
30
|
-
|
|
31
|
-
_rebillyJsSdk.cancellation.cancelAll();
|
|
32
|
-
|
|
33
|
-
state.loader.clearAll();
|
|
34
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _events = _interopRequireWildcard(require("../events"));
|
|
4
|
-
|
|
5
|
-
var _baseEvent = _interopRequireDefault(require("../events/base-event"));
|
|
6
|
-
|
|
7
|
-
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
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); }
|
|
12
|
-
|
|
13
|
-
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; }
|
|
14
|
-
|
|
15
|
-
describe('RebillyInstruments Destroy', () => {
|
|
16
|
-
it('should be able to destroy instance', async () => {
|
|
17
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
18
|
-
const formElement = document.querySelector('.form-selector');
|
|
19
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
20
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
21
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
22
|
-
await rebillyInstruments.destroy();
|
|
23
|
-
expect(formElement.innerHTML).toEqual('');
|
|
24
|
-
expect(summaryElement.innerHTML).toEqual('');
|
|
25
|
-
});
|
|
26
|
-
it('should remove registered listeners', async () => {
|
|
27
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
28
|
-
const fakeEventListener = jest.fn();
|
|
29
|
-
_events.default.fakeEvent = new _baseEvent.default('fake-event');
|
|
30
|
-
|
|
31
|
-
_events.publicEventNames.push('fake-event');
|
|
32
|
-
|
|
33
|
-
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
34
|
-
|
|
35
|
-
_events.default.fakeEvent.dispatch();
|
|
36
|
-
|
|
37
|
-
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
38
|
-
fakeEventListener.mockClear();
|
|
39
|
-
await rebillyInstruments.destroy();
|
|
40
|
-
|
|
41
|
-
_events.default.fakeEvent.dispatch();
|
|
42
|
-
|
|
43
|
-
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
44
|
-
});
|
|
45
|
-
it('should remove multiple listeners on the same event', async () => {
|
|
46
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
47
|
-
const fakeEventListener = jest.fn();
|
|
48
|
-
const anotherFakeEventListener = jest.fn();
|
|
49
|
-
_events.default.fakeEvent = new _baseEvent.default('fake-event');
|
|
50
|
-
|
|
51
|
-
_events.publicEventNames.push('fake-event');
|
|
52
|
-
|
|
53
|
-
rebillyInstruments.on('fake-event', fakeEventListener);
|
|
54
|
-
rebillyInstruments.on('fake-event', anotherFakeEventListener);
|
|
55
|
-
|
|
56
|
-
_events.default.fakeEvent.dispatch();
|
|
57
|
-
|
|
58
|
-
expect(fakeEventListener).toHaveBeenCalledTimes(1);
|
|
59
|
-
expect(anotherFakeEventListener).toHaveBeenCalledTimes(1);
|
|
60
|
-
fakeEventListener.mockClear();
|
|
61
|
-
anotherFakeEventListener.mockClear();
|
|
62
|
-
await rebillyInstruments.destroy();
|
|
63
|
-
|
|
64
|
-
_events.default.fakeEvent.dispatch();
|
|
65
|
-
|
|
66
|
-
expect(fakeEventListener).not.toHaveBeenCalled();
|
|
67
|
-
expect(anotherFakeEventListener).not.toHaveBeenCalled();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchData = fetchData;
|
|
7
|
-
exports.DataInstance = void 0;
|
|
8
|
-
|
|
9
|
-
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
10
|
-
|
|
11
|
-
var _plans = require("../../storefront/plans");
|
|
12
|
-
|
|
13
|
-
var _products = require("../../storefront/products");
|
|
14
|
-
|
|
15
|
-
var _readyToPay = require("../../storefront/ready-to-pay");
|
|
16
|
-
|
|
17
|
-
var _summary = require("../../storefront/summary");
|
|
18
|
-
|
|
19
|
-
var _invoices = require("../../storefront/invoices");
|
|
20
|
-
|
|
21
|
-
var _transactions = require("../../storefront/transactions");
|
|
22
|
-
|
|
23
|
-
class DataInstance {
|
|
24
|
-
constructor({
|
|
25
|
-
state = {},
|
|
26
|
-
...fields
|
|
27
|
-
} = {}) {
|
|
28
|
-
var _state$options;
|
|
29
|
-
|
|
30
|
-
Object.entries({ ...(state.data || {}),
|
|
31
|
-
...fields
|
|
32
|
-
}).forEach(([key, value]) => {
|
|
33
|
-
this[key] = value;
|
|
34
|
-
});
|
|
35
|
-
this.money = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.money) || null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get amountAndCurrency() {
|
|
39
|
-
let currency;
|
|
40
|
-
let amount;
|
|
41
|
-
|
|
42
|
-
if (this.previewPurchase) {
|
|
43
|
-
currency = this.previewPurchase.currency;
|
|
44
|
-
amount = this.previewPurchase.total;
|
|
45
|
-
} else if (this.invoice) {
|
|
46
|
-
currency = this.invoice.currency;
|
|
47
|
-
amount = this.invoice.amount;
|
|
48
|
-
} else if (this.transaction) {
|
|
49
|
-
currency = this.transaction.currency;
|
|
50
|
-
amount = this.transaction.amount;
|
|
51
|
-
} else if (this.money) {
|
|
52
|
-
currency = this.money.currency;
|
|
53
|
-
amount = this.money.amount;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
amount,
|
|
58
|
-
currency
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get isPayment() {
|
|
63
|
-
return this.invoice || this.transaction || this.money;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get isPurchase() {
|
|
67
|
-
return this.previewPurchase;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get summaryItems() {
|
|
71
|
-
const {
|
|
72
|
-
discountsAmount = null,
|
|
73
|
-
shippingAmount = null,
|
|
74
|
-
subtotalAmount = null,
|
|
75
|
-
taxAmount = null
|
|
76
|
-
} = this.previewPurchase || this.invoice || {};
|
|
77
|
-
return {
|
|
78
|
-
discountsAmount,
|
|
79
|
-
shippingAmount,
|
|
80
|
-
subtotalAmount,
|
|
81
|
-
taxAmount
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get summaryLineItems() {
|
|
86
|
-
let lineItems = [];
|
|
87
|
-
|
|
88
|
-
if (this.invoice) {
|
|
89
|
-
({
|
|
90
|
-
items: lineItems = []
|
|
91
|
-
} = this.invoice);
|
|
92
|
-
} else {
|
|
93
|
-
({
|
|
94
|
-
lineItems = []
|
|
95
|
-
} = this.previewPurchase || {});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return lineItems;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get isShippingRequired() {
|
|
102
|
-
return this.products.some(product => product.requiresShipping);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
exports.DataInstance = DataInstance;
|
|
108
|
-
|
|
109
|
-
async function fetchData({
|
|
110
|
-
state = null,
|
|
111
|
-
riskMetadata = null,
|
|
112
|
-
summaryPayload = null,
|
|
113
|
-
// Dependancy injectable functions
|
|
114
|
-
fetchInvoice = _invoices.fetchInvoice,
|
|
115
|
-
fetchTransaction = _transactions.fetchTransaction
|
|
116
|
-
}) {
|
|
117
|
-
try {
|
|
118
|
-
var _state$options2, _state$options3, _state$data, _state$data$transacti, _state$data3;
|
|
119
|
-
|
|
120
|
-
let transaction = null;
|
|
121
|
-
|
|
122
|
-
if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.transactionId) {
|
|
123
|
-
transaction = await fetchTransaction({
|
|
124
|
-
data: {
|
|
125
|
-
id: state.options.transactionId
|
|
126
|
-
},
|
|
127
|
-
state
|
|
128
|
-
});
|
|
129
|
-
state.data.transaction = transaction;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
let invoice = null;
|
|
133
|
-
|
|
134
|
-
if ((_state$options3 = state.options) !== null && _state$options3 !== void 0 && _state$options3.invoiceId || (_state$data = state.data) !== null && _state$data !== void 0 && (_state$data$transacti = _state$data.transaction) !== null && _state$data$transacti !== void 0 && _state$data$transacti.hasInvoice) {
|
|
135
|
-
var _state$options4, _state$data2, _state$data2$transact;
|
|
136
|
-
|
|
137
|
-
invoice = await fetchInvoice({
|
|
138
|
-
data: {
|
|
139
|
-
id: ((_state$options4 = state.options) === null || _state$options4 === void 0 ? void 0 : _state$options4.invoiceId) || ((_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : (_state$data2$transact = _state$data2.transaction) === null || _state$data2$transact === void 0 ? void 0 : _state$data2$transact.invoiceId)
|
|
140
|
-
},
|
|
141
|
-
state
|
|
142
|
-
});
|
|
143
|
-
state.data.invoice = invoice;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (!riskMetadata) {
|
|
147
|
-
const {
|
|
148
|
-
riskMetadata: data
|
|
149
|
-
} = await (0, _riskDataCollector.collectData)();
|
|
150
|
-
riskMetadata = data;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
state.data = new DataInstance({
|
|
154
|
-
state,
|
|
155
|
-
invoice,
|
|
156
|
-
transaction,
|
|
157
|
-
riskMetadata
|
|
158
|
-
});
|
|
159
|
-
const [readyToPay, previewPurchase] = await Promise.all([((_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.readyToPay) || (0, _readyToPay.fetchReadyToPay)({
|
|
160
|
-
riskMetadata,
|
|
161
|
-
state
|
|
162
|
-
}), state.options.items ? (0, _summary.fetchSummary)({
|
|
163
|
-
data: summaryPayload,
|
|
164
|
-
state
|
|
165
|
-
}) : null]);
|
|
166
|
-
const plans = await (0, _plans.fetchPlans)({
|
|
167
|
-
state
|
|
168
|
-
});
|
|
169
|
-
state.data.plans = plans;
|
|
170
|
-
const products = await (0, _products.fetchProducts)({
|
|
171
|
-
state
|
|
172
|
-
});
|
|
173
|
-
return new DataInstance({
|
|
174
|
-
state,
|
|
175
|
-
readyToPay,
|
|
176
|
-
previewPurchase,
|
|
177
|
-
plans,
|
|
178
|
-
products,
|
|
179
|
-
invoice,
|
|
180
|
-
transaction,
|
|
181
|
-
riskMetadata
|
|
182
|
-
});
|
|
183
|
-
} catch (error) {// console.log(error);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return new DataInstance({});
|
|
187
|
-
}
|