@rebilly/instruments 4.8.1 → 4.8.2

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.
Files changed (139) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/index.js +1 -1
  3. package/dist/index.min.js +1 -1
  4. package/package.json +5 -1
  5. package/.babelrc +0 -26
  6. package/project.json +0 -31
  7. package/rollup.config.mjs +0 -79
  8. package/src/data/options-schema/index.js +0 -112
  9. package/src/data/options-schema/schemas/options-schema.js +0 -448
  10. package/src/events/base-event.js +0 -47
  11. package/src/events/events.spec.js +0 -11
  12. package/src/events/index.js +0 -15
  13. package/src/functions/destroy.js +0 -29
  14. package/src/functions/destroy.spec.js +0 -63
  15. package/src/functions/mount/fetch-data.js +0 -236
  16. package/src/functions/mount/fetch-data.spec.js +0 -317
  17. package/src/functions/mount/get-lead-source-data.js +0 -46
  18. package/src/functions/mount/get-lead-source-data.spec.js +0 -38
  19. package/src/functions/mount/index.js +0 -105
  20. package/src/functions/mount/mount.spec.js +0 -96
  21. package/src/functions/mount/setup-element.js +0 -29
  22. package/src/functions/mount/setup-framepay-theme.js +0 -104
  23. package/src/functions/mount/setup-framepay.js +0 -26
  24. package/src/functions/mount/setup-i18n.js +0 -21
  25. package/src/functions/mount/setup-options.js +0 -100
  26. package/src/functions/mount/setup-options.spec.js +0 -353
  27. package/src/functions/mount/setup-storefront.js +0 -23
  28. package/src/functions/mount/setup-styles-vars.js +0 -30
  29. package/src/functions/mount/setup-user-flow.js +0 -60
  30. package/src/functions/on.js +0 -22
  31. package/src/functions/on.spec.js +0 -75
  32. package/src/functions/purchase.js +0 -173
  33. package/src/functions/purchase.spec.js +0 -80
  34. package/src/functions/setup.js +0 -66
  35. package/src/functions/setup.spec.js +0 -111
  36. package/src/functions/show.js +0 -30
  37. package/src/functions/show.spec.js +0 -62
  38. package/src/functions/update.js +0 -40
  39. package/src/functions/update.spec.js +0 -104
  40. package/src/i18n/en.json +0 -35
  41. package/src/i18n/es.json +0 -32
  42. package/src/i18n/i18n.spec.js +0 -27
  43. package/src/i18n/index.js +0 -59
  44. package/src/index.js +0 -3
  45. package/src/instance.js +0 -48
  46. package/src/instance.spec.js +0 -44
  47. package/src/loader/index.js +0 -145
  48. package/src/loader/loader.spec.js +0 -74
  49. package/src/state/iframes.js +0 -23
  50. package/src/state/index.js +0 -64
  51. package/src/storefront/account-and-website.js +0 -18
  52. package/src/storefront/account-and-website.spec.js +0 -73
  53. package/src/storefront/deposit-requests.js +0 -12
  54. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +0 -30
  55. package/src/storefront/fetch-products-from-plans.js +0 -59
  56. package/src/storefront/fetch-products-from-plans.spec.js +0 -113
  57. package/src/storefront/index.js +0 -78
  58. package/src/storefront/invoices.js +0 -23
  59. package/src/storefront/invoices.spec.js +0 -92
  60. package/src/storefront/models/account-model.js +0 -36
  61. package/src/storefront/models/base-model.js +0 -7
  62. package/src/storefront/models/deposit-request-model.js +0 -24
  63. package/src/storefront/models/invoice-model.js +0 -20
  64. package/src/storefront/models/payment-metadata.js +0 -7
  65. package/src/storefront/models/plan-model.js +0 -94
  66. package/src/storefront/models/product-model.js +0 -3
  67. package/src/storefront/models/ready-to-pay-model.js +0 -76
  68. package/src/storefront/models/summary-model.js +0 -56
  69. package/src/storefront/models/transaction-model.js +0 -16
  70. package/src/storefront/models/website-model.js +0 -3
  71. package/src/storefront/payment-instruments.js +0 -47
  72. package/src/storefront/payment-instruments.spec.js +0 -88
  73. package/src/storefront/purchase.js +0 -60
  74. package/src/storefront/purchase.spec.js +0 -53
  75. package/src/storefront/ready-to-pay.js +0 -96
  76. package/src/storefront/ready-to-pay.spec.js +0 -76
  77. package/src/storefront/storefront.spec.js +0 -14
  78. package/src/storefront/summary.js +0 -114
  79. package/src/storefront/summary.spec.js +0 -136
  80. package/src/storefront/transactions.js +0 -12
  81. package/src/style/base/__snapshots__/theme.spec.js.snap +0 -143
  82. package/src/style/base/default-theme.js +0 -955
  83. package/src/style/base/index.js +0 -688
  84. package/src/style/base/theme.js +0 -30
  85. package/src/style/base/theme.spec.js +0 -19
  86. package/src/style/index.js +0 -11
  87. package/src/style/utils/border.js +0 -47
  88. package/src/style/utils/color-values.js +0 -35
  89. package/src/style/utils/minifyCss.js +0 -14
  90. package/src/utils/add-dom-element.js +0 -17
  91. package/src/utils/format-currency.js +0 -8
  92. package/src/utils/has-valid-css-selector.js +0 -4
  93. package/src/utils/index.js +0 -15
  94. package/src/utils/is-dom-element.js +0 -3
  95. package/src/utils/process-property-as-dom-element.js +0 -31
  96. package/src/utils/quantity.js +0 -47
  97. package/src/utils/sleep.js +0 -5
  98. package/src/views/amount-selector.js +0 -46
  99. package/src/views/common/iframe/base-iframe.js +0 -66
  100. package/src/views/common/iframe/events/change-iframe-src-handler.js +0 -6
  101. package/src/views/common/iframe/events/dispatch-event-handler.js +0 -8
  102. package/src/views/common/iframe/events/resize-component-handler.js +0 -9
  103. package/src/views/common/iframe/events/show-error-handler.js +0 -5
  104. package/src/views/common/iframe/events/stop-loader-handler.js +0 -9
  105. package/src/views/common/iframe/events/update-addons-handler.js +0 -23
  106. package/src/views/common/iframe/events/update-coupons-handler.js +0 -12
  107. package/src/views/common/iframe/events/update-items-handler.js +0 -34
  108. package/src/views/common/iframe/index.js +0 -5
  109. package/src/views/common/iframe/modal-iframe.js +0 -82
  110. package/src/views/common/iframe/view-iframe.js +0 -23
  111. package/src/views/common/render-utilities.js +0 -4
  112. package/src/views/confirmation.js +0 -45
  113. package/src/views/errors.js +0 -115
  114. package/src/views/form.js +0 -61
  115. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -135
  116. package/src/views/method-selector/express-methods.js +0 -52
  117. package/src/views/method-selector/generate-digital-wallet.js +0 -53
  118. package/src/views/method-selector/generate-digital-wallet.spec.js +0 -121
  119. package/src/views/method-selector/generate-framepay-config.js +0 -56
  120. package/src/views/method-selector/generate-framepay-config.spec.js +0 -216
  121. package/src/views/method-selector/get-method-data.js +0 -11
  122. package/src/views/method-selector/get-payment-methods.js +0 -25
  123. package/src/views/method-selector/get-payment-methods.spec.js +0 -41
  124. package/src/views/method-selector/index.js +0 -223
  125. package/src/views/method-selector/method-selector.spec.js +0 -20
  126. package/src/views/method-selector/mount-bump-offer.js +0 -120
  127. package/src/views/method-selector/mount-express-methods.js +0 -107
  128. package/src/views/modal.js +0 -103
  129. package/src/views/result.js +0 -24
  130. package/src/views/summary.js +0 -38
  131. package/tests/async-utilities.js +0 -22
  132. package/tests/mocks/framepay-mock.js +0 -15
  133. package/tests/mocks/rebilly-api-mock.js +0 -11
  134. package/tests/mocks/rebilly-instruments-mock.js +0 -141
  135. package/tests/mocks/storefront-api-mock.js +0 -62
  136. package/tests/mocks/storefront-mock.js +0 -20
  137. package/tests/msw/server.js +0 -14
  138. package/tests/setup-test.js +0 -30
  139. package/vitest.config.js +0 -18
@@ -1,19 +0,0 @@
1
- import { Theme } from './theme';
2
-
3
- describe('RebillyInstruments theme', () => {
4
- it('builds the theme object', () => {
5
- const theme = new Theme().build();
6
-
7
- expect(theme).toMatchSnapshot();
8
- });
9
-
10
- it('properly overrides the default properties', () => {
11
- const overrides = {
12
- colorPrimary: 'red',
13
- buttonBorderRadius: '30px',
14
- };
15
- const theme = new Theme(overrides).build();
16
- expect(theme.cssVars).toMatch('--rebilly-colorPrimary: red;');
17
- expect(theme.cssVars).toMatch('--rebilly-buttonBorderRadius: 30px;');
18
- });
19
- });
@@ -1,11 +0,0 @@
1
- import { Theme } from './base/theme';
2
- import { vars } from './base';
3
-
4
- export const mainStyleVars = (themeOverride) => {
5
- const resolvedTheme = new Theme(themeOverride).build();
6
- const style = `
7
- ${vars(resolvedTheme)}
8
- `;
9
-
10
- return style;
11
- };
@@ -1,47 +0,0 @@
1
- export default class Border {
2
- allStyles = [
3
- 'none',
4
- 'hidden',
5
- 'dotted',
6
- 'dashed',
7
- 'solid',
8
- 'double',
9
- 'groove',
10
- 'ridge',
11
- 'inset',
12
- 'outset',
13
- 'initial',
14
- 'inherit',
15
- ];
16
-
17
- constructor(str) {
18
- this.str = str || '';
19
-
20
- const style = this.allStyles.find((s) => this.str.includes(s));
21
- const borderProps = this.str.split(style).map((a) => a.trim());
22
- this.border = [borderProps[0], style, borderProps[1]];
23
- }
24
-
25
- get stylePosition() {
26
- let stylePosition = 0;
27
- if (this.border.length === 3) {
28
- stylePosition = 1;
29
- } else if (this.border.length === 2) {
30
- if (this.allStyles.includes(this.border[0])) {
31
- stylePosition = 0;
32
- } else {
33
- stylePosition = 1;
34
- }
35
- }
36
- return stylePosition;
37
- }
38
-
39
- updateColor(color) {
40
- this.border[this.stylePosition + 1] = color;
41
- return this;
42
- }
43
-
44
- get value() {
45
- return this.border.join(' ');
46
- }
47
- }
@@ -1,35 +0,0 @@
1
- import Values from 'values.js';
2
-
3
- export const colorValues = (color) => new Values(color);
4
-
5
- export function alphaColor(color, alphaValue = 1) {
6
- if (color === null) {
7
- return color;
8
- }
9
-
10
- const _alphaColor = colorValues(color);
11
- _alphaColor.alpha = alphaValue;
12
- return _alphaColor.rgbString();
13
- }
14
-
15
- export const mutedTextColor = (color) => alphaColor(color, 0.5);
16
-
17
- export const mutedBorderColor = (color) => alphaColor(color, 0.25);
18
-
19
- export const darken = (color, percent) => {
20
- if (color === null) {
21
- return color;
22
- }
23
-
24
- const _color = colorValues(color);
25
- return _color.shade(percent).hexString();
26
- };
27
-
28
- export const lighten = (color, percent) => {
29
- if (color === null) {
30
- return color;
31
- }
32
-
33
- const _color = colorValues(color);
34
- return _color.tint(percent).hexString();
35
- };
@@ -1,14 +0,0 @@
1
- export function minifyCss(_content) {
2
- let content = _content;
3
- // Remove all comments and new lines
4
- content = content.replace(/\/\*(?:(?!\*\/)[\s\S])*\*\/|[\r\n\t]+/g, '');
5
- // Remove spaces between selectors
6
- content = content.replace(/\s{2,}/g, ' ');
7
- // Remove spaces of nested { }
8
- content = content.replace(/\s([{:}])\s/g, '$1');
9
- // Remove spaces between , and ;
10
- content = content.replace(/([;,])\s/g, '$1');
11
- // Remove important! spaces
12
- content = content.replace(/\s!/g, '!');
13
- return content;
14
- }
@@ -1,17 +0,0 @@
1
- export default function addDOMElement({
2
- element = 'div',
3
- attributes = {},
4
- content = null,
5
- target = 'body',
6
- insertMethod = 'append',
7
- } = {}) {
8
- const ELEMENT = document.createElement(element);
9
- const ELEMENT_ATTRIBUTES = Object.entries(attributes);
10
- ELEMENT_ATTRIBUTES.forEach(([attribute, value]) => {
11
- ELEMENT.setAttribute(attribute, value);
12
- });
13
- if (content) {
14
- ELEMENT.innerHTML = content;
15
- }
16
- document[target][insertMethod](ELEMENT);
17
- }
@@ -1,8 +0,0 @@
1
- export default function formatCurrency(number, currency) {
2
- const converToNumber = Number(number);
3
- if (Number.isNaN(converToNumber) || number === null) return '-';
4
- return new Intl.NumberFormat('en-US', {
5
- style: 'currency',
6
- currency: currency || 'USD',
7
- }).format(number);
8
- }
@@ -1,4 +0,0 @@
1
- export default function hasValidCSSSelector(selector) {
2
- const REGEX_CSS_SELECTOR = /([.#][_a-z]+[_a-z0-9-:\\]*)/gi;
3
- return typeof selector === 'string' && selector.match(REGEX_CSS_SELECTOR);
4
- }
@@ -1,15 +0,0 @@
1
- import addDOMElement from './add-dom-element';
2
- import processPropertyAsDOMElement from './process-property-as-dom-element';
3
- import isDOMElement from './is-dom-element';
4
- import hasValidCSSSelector from './has-valid-css-selector';
5
- import formatCurrency from './format-currency';
6
- import sleep from './sleep';
7
-
8
- export {
9
- addDOMElement,
10
- processPropertyAsDOMElement,
11
- isDOMElement,
12
- hasValidCSSSelector,
13
- formatCurrency,
14
- sleep,
15
- };
@@ -1,3 +0,0 @@
1
- export default function isDOMElement(element) {
2
- return element instanceof Element || element instanceof HTMLDocument;
3
- }
@@ -1,31 +0,0 @@
1
- import hasValidCSSSelector from './has-valid-css-selector';
2
- import isDOMElement from './is-dom-element';
3
-
4
- export default function processPropertyAsDOMElement({
5
- prop,
6
- propName = 'Mounting',
7
- isRequired = true,
8
- } = {}) {
9
- let DOMElement;
10
-
11
- if (typeof prop === 'undefined') {
12
- throw new Error('processPropertyDOMElement: Missing argument "prop"');
13
- }
14
-
15
- if (hasValidCSSSelector(prop)) {
16
- DOMElement = document.querySelector(prop);
17
- } else if (isDOMElement(prop)) {
18
- DOMElement = prop;
19
- } else {
20
- throw new Error(
21
- `Please provide a valid CSS class, id or DOM element for "${propName}" property`,
22
- );
23
- }
24
-
25
- if (!DOMElement && isRequired) {
26
- throw new Error(
27
- `Could not find DOM element with CSS class or id "${prop}" to mount ${propName}`,
28
- );
29
- }
30
- return DOMElement;
31
- }
@@ -1,47 +0,0 @@
1
- import { toRaw } from 'vue';
2
-
3
- const defaultOptions = {
4
- minimum: 1,
5
- maximum: Number.MAX_SAFE_INTEGER,
6
- multipleOf: 1,
7
- };
8
- export const isObject = (val) => typeof val === 'object';
9
-
10
- export function parseQuantity({ quantity }) {
11
- return isObject(quantity) ? { ...defaultOptions, ...quantity } : quantity;
12
- }
13
-
14
- export function mergeOptionsItemsQuantity(items) {
15
- return items.map((item) => ({
16
- ...item,
17
- quantity: parseQuantity(item),
18
- }));
19
- }
20
-
21
- export function getQuantityValue(quantity) {
22
- return isObject(quantity) ? quantity.default : quantity;
23
- }
24
-
25
- export function mapItemsQuantities(items) {
26
- return items.map(({ planId, quantity }) => ({
27
- planId,
28
- quantity: getQuantityValue(quantity),
29
- }));
30
- }
31
-
32
- export function createQuantitiesMap(items) {
33
- return items.reduce((map, item) => {
34
- map.set(item.planId, toRaw(item.quantity));
35
- return map;
36
- }, new Map());
37
- }
38
-
39
- export function updateItemQuantityFromMap(quantitiesByPlanId) {
40
- return function updateQuantity(item) {
41
- const quantity = quantitiesByPlanId.get(item.planId) || item.quantity;
42
- if (isObject(quantity)) {
43
- quantity.default = getQuantityValue(item.quantity);
44
- item.quantity = quantity;
45
- }
46
- };
47
- }
@@ -1,5 +0,0 @@
1
- export default function sleep(ms) {
2
- return new Promise((resolve) => {
3
- setTimeout(resolve, ms);
4
- });
5
- }
@@ -1,46 +0,0 @@
1
- import state from '../state';
2
- import iframes from '../state/iframes';
3
- import { mountMethodSelector } from './method-selector';
4
- import { fetchReadyToPay } from '../storefront/ready-to-pay';
5
- import { mountForm } from './form';
6
-
7
- export async function mountAmountSelector() {
8
- if (state.data.money) {
9
- state.data.money.amount = null;
10
- state.data.money.currency = null;
11
- state.updateModel();
12
- }
13
-
14
- const iframe = iframes.form;
15
- if (!iframe) {
16
- await mountForm();
17
- }
18
-
19
- const modelSafeState = state.toModel();
20
- const model = {
21
- options: modelSafeState.options,
22
- data: modelSafeState.data,
23
- mainStyleVars: modelSafeState.mainStyleVars,
24
- };
25
-
26
- iframe.component?.call('route', {
27
- name: 'amount-selector',
28
- });
29
-
30
- iframe.component?.call('update', model);
31
-
32
- iframe?.component?.on('confirm-amount', async (data) => {
33
- const { amount, currency } = data;
34
- state.data.money = {
35
- amount,
36
- currency,
37
- };
38
-
39
- const readyToPayUpdated = await fetchReadyToPay();
40
-
41
- state.data.readyToPay = readyToPayUpdated;
42
-
43
- state.updateModel();
44
- mountMethodSelector();
45
- });
46
- }
@@ -1,66 +0,0 @@
1
- import Postmate from 'popostmate';
2
-
3
- export default class BaseIframe {
4
- constructor({
5
- name = '',
6
- url = '',
7
- model = {},
8
- container = null,
9
- classListArray = [],
10
- route = null,
11
- } = {}) {
12
- classListArray = Array.isArray(classListArray) ? classListArray : [];
13
- if (!classListArray.includes('rebilly-instruments-iframe')) {
14
- classListArray.push('rebilly-instruments-iframe');
15
- }
16
-
17
- this.container = container;
18
- this.classListArray = classListArray;
19
- this.name = name;
20
- this.url = url;
21
- this.model = model;
22
- this.component = null;
23
-
24
- // eslint-disable-next-line no-constructor-return
25
- return (async () => {
26
- this.component = await this.createComponent();
27
-
28
- if (route) {
29
- this.component.call('route', route);
30
- }
31
-
32
- return this;
33
- })();
34
- }
35
-
36
- async destroy() {
37
- if (this.component.frame.parentNode) {
38
- await this.component.destroy();
39
- }
40
- }
41
-
42
- async createComponent() {
43
- // Use a fake container so we can capture the appendChild call
44
- // and immediately apply the feature-policy flags to the iframe
45
- // before Postmate tries to load the iframe. The feature policy
46
- // would otherwise not apply until the frame was reloaded.
47
- const container = {
48
- appendChild: (iframe) => {
49
- iframe.setAttribute('loading', 'lazy');
50
- iframe.setAttribute('allow', 'payment');
51
- iframe.allowPaymentRequest = true;
52
- this.container.appendChild(iframe);
53
- },
54
- };
55
-
56
- const component = await new Postmate({
57
- name: this.name,
58
- url: this.url,
59
- container,
60
- classListArray: this.classListArray,
61
- model: this.model,
62
- });
63
-
64
- return component;
65
- }
66
- }
@@ -1,6 +0,0 @@
1
- export function changeIframeSrcHandler(iframe) {
2
- iframe.component.on(`${iframe.name}-change-iframe-src`, (url = null) => {
3
- iframe.component.frame.src = url;
4
- iframe.component.frame.style.height = '75vh';
5
- });
6
- }
@@ -1,8 +0,0 @@
1
- import camelCase from 'lodash.camelcase';
2
- import Events from '../../../../events';
3
-
4
- export function dispatchEventHandler(iframe) {
5
- iframe.component.on(`${iframe.name}-dispatch`, ({ event, detail }) => {
6
- Events[camelCase(event).replace(/-/, '')].dispatch(detail);
7
- });
8
- }
@@ -1,9 +0,0 @@
1
- export function resizeComponentHandler(iframe) {
2
- let prevHeight = '';
3
- iframe.component.on(`${iframe.name}-resize-frame`, (height) => {
4
- if (height !== prevHeight) {
5
- prevHeight = height;
6
- iframe.component.frame.style.height = height;
7
- }
8
- });
9
- }
@@ -1,5 +0,0 @@
1
- import { showError } from '../../../errors';
2
-
3
- export function showErrorHandler(iframe) {
4
- iframe.component.on(`${iframe.name}-show-error`, showError);
5
- }
@@ -1,9 +0,0 @@
1
- export function stopLoaderHandler(iframe, data) {
2
- iframe.component.on(`${iframe.name}-stop-loading`, (id) => {
3
- let { section } = data;
4
- if (!section) {
5
- section = id.includes('summary') ? 'summary' : 'form';
6
- }
7
- data.loader?.stopLoading({ section, id });
8
- });
9
- }
@@ -1,23 +0,0 @@
1
- import state from '../../../../state';
2
-
3
- export function updateAddonsHandler(iframe) {
4
- iframe.component.on(
5
- `${iframe.name}-update-addons`,
6
- async ({ addons, previewPurchase }) => {
7
- const addonPlanIds = addons.map((addon) => addon.planId);
8
- state.data.addons = addonPlanIds;
9
- state.data.previewPurchase = previewPurchase;
10
-
11
- state.data.previewPurchase.addonLineItems =
12
- state.data.previewPurchase.lineItems.filter((item) =>
13
- addonPlanIds.includes(item.planId),
14
- );
15
- state.data.previewPurchase.lineItems =
16
- state.data.previewPurchase.lineItems.filter(
17
- (item) => !addonPlanIds.includes(item.planId),
18
- );
19
-
20
- state.updateModel();
21
- },
22
- );
23
- }
@@ -1,12 +0,0 @@
1
- import state from '../../../../state';
2
-
3
- export function updateCouponsHandler(iframe) {
4
- iframe.component.on(
5
- `${iframe.name}-update-coupon`,
6
- async ({ couponIds, previewPurchase } = {}) => {
7
- state.data.couponIds = couponIds;
8
- state.data.previewPurchase = previewPurchase;
9
- state.updateModel();
10
- },
11
- );
12
- }
@@ -1,34 +0,0 @@
1
- import state from '../../../../state';
2
- import { fetchSummary } from '../../../../storefront/summary';
3
- import {
4
- createQuantitiesMap,
5
- getQuantityValue,
6
- isObject,
7
- } from '../../../../utils/quantity';
8
-
9
- let loading = false;
10
- export async function itemsUpdatedHandler(iframe) {
11
- iframe.component.on(`${iframe.name}-update-items`, async (lineItems) => {
12
- try {
13
- if (loading) return;
14
- loading = true;
15
- const mappedItems = createQuantitiesMap(lineItems);
16
-
17
- state.data.summaryLineItems.forEach((item) => {
18
- const quantity = getQuantityValue(mappedItems.get(item.planId));
19
- if (isObject(item.quantity)) {
20
- item.quantity.default = quantity;
21
- } else {
22
- item.quantity = quantity;
23
- }
24
- });
25
-
26
- await fetchSummary();
27
- state.updateModel();
28
- loading = false;
29
- } catch (err) {
30
- console.error(err);
31
- loading = false;
32
- }
33
- });
34
- }
@@ -1,5 +0,0 @@
1
- import { ViewIframe as view } from './view-iframe';
2
- import { ModalIframe as modal } from './modal-iframe';
3
-
4
- export const ViewIframe = view;
5
- export const ModalIframe = modal;
@@ -1,82 +0,0 @@
1
- import BaseIframe from './base-iframe';
2
- import state from '../../../state';
3
-
4
- import { changeIframeSrcHandler } from './events/change-iframe-src-handler';
5
- import { resizeComponentHandler } from './events/resize-component-handler';
6
- import { dispatchEventHandler } from './events/dispatch-event-handler';
7
- import { showErrorHandler } from './events/show-error-handler';
8
- import { stopLoaderHandler } from './events/stop-loader-handler';
9
-
10
- export class ModalIframe extends BaseIframe {
11
- constructor(args = {}) {
12
- super(args);
13
- }
14
-
15
- bindEventListeners({ close = () => {}, loader } = {}) {
16
- dispatchEventHandler(this);
17
- resizeComponentHandler(this);
18
- changeIframeSrcHandler(this);
19
- stopLoaderHandler(this, {
20
- loader,
21
- section: 'modal',
22
- id: this.name,
23
- });
24
- showErrorHandler(this);
25
-
26
- // Close modal via postmate
27
- this.component.on(`${this.name}-close`, (...args) => {
28
- close(...args);
29
- });
30
-
31
- // Close modal via postMessage (specifically during approval url flow)
32
- window.addEventListener(
33
- 'message',
34
- async (event) => {
35
- if (event.data === 'rebilly-instruments-approval-url-close') {
36
- if (state.options.transactionType === 'purchase') {
37
- state.storefront.setSessionToken(
38
- state.data.token || state.options.jwt,
39
- );
40
-
41
- const [{ fields: transaction }, { fields: invoice }] =
42
- await Promise.all([
43
- state.storefront.transactions.get({
44
- id: state.data.transaction.id,
45
- }),
46
- state.data.invoice?.id
47
- ? state.storefront.invoices.get({
48
- id: state.data.invoice.id,
49
- })
50
- : { fields: null },
51
- ]);
52
-
53
- const updatedPurchase = {
54
- orderId: state.data.orderId,
55
- token: state.data.token,
56
- transaction,
57
- };
58
- if (invoice) {
59
- updatedPurchase.invoice = invoice;
60
- }
61
- close(updatedPurchase);
62
- } else if (state.options.transactionType === 'setup') {
63
- state.storefront.setSessionToken(
64
- state.data.instrument.token || state.options.jwt,
65
- );
66
- const { fields: transaction } =
67
- await state.storefront.transactions.get({
68
- id: state.data.transaction.id,
69
- });
70
- close({
71
- transaction,
72
- instrument: state.data.instrument,
73
- });
74
- } else {
75
- close();
76
- }
77
- }
78
- },
79
- false,
80
- );
81
- }
82
- }
@@ -1,23 +0,0 @@
1
- import BaseIframe from './base-iframe';
2
-
3
- import { resizeComponentHandler } from './events/resize-component-handler';
4
- import { dispatchEventHandler } from './events/dispatch-event-handler';
5
- import { updateCouponsHandler } from './events/update-coupons-handler';
6
- import { updateAddonsHandler } from './events/update-addons-handler';
7
- import { showErrorHandler } from './events/show-error-handler';
8
- import { stopLoaderHandler } from './events/stop-loader-handler';
9
-
10
- export class ViewIframe extends BaseIframe {
11
- constructor(args = {}) {
12
- super(args);
13
- }
14
-
15
- bindEventListeners({ loader } = {}) {
16
- dispatchEventHandler(this);
17
- resizeComponentHandler(this);
18
- stopLoaderHandler(this, { loader });
19
- showErrorHandler(this);
20
- updateCouponsHandler(this);
21
- updateAddonsHandler(this);
22
- }
23
- }
@@ -1,4 +0,0 @@
1
- export function replaceContent(form, newContent) {
2
- const contentElement = form.querySelector('.rebilly-instruments-content');
3
- contentElement.innerHTML = newContent;
4
- }
@@ -1,45 +0,0 @@
1
- import state from '../state';
2
- import iframes from '../state/iframes';
3
- import { mountForm } from './form';
4
- import { updateSummary } from './summary';
5
- import { purchase } from '../functions/purchase';
6
- import { setup } from '../functions/setup';
7
-
8
- export async function mountConfirmation({ payload: instrument }) {
9
- if (instrument.billingAddress && state.summary && state.data.isPurchase) {
10
- updateSummary({ instrument });
11
- }
12
-
13
- const iframe = iframes.form;
14
- if (!iframe) {
15
- await mountForm();
16
- }
17
-
18
- const modelSafeState = state.toModel();
19
- const model = {
20
- options: modelSafeState.options,
21
- data: modelSafeState.data,
22
- mainStyleVars: modelSafeState.mainStyleVars,
23
- instrument,
24
- };
25
-
26
- iframe?.component?.call('update', model);
27
-
28
- iframe?.component?.call('route', {
29
- name: 'confirmation',
30
- });
31
-
32
- iframe?.component?.on(
33
- `${iframe.name}-confirm-purchase`,
34
- (confirmedInstrument) => {
35
- purchase({ payload: confirmedInstrument });
36
- },
37
- );
38
-
39
- iframe?.component?.on(
40
- `${iframe.name}-confirm-setup`,
41
- (confirmedInstrument) => {
42
- setup({ payload: confirmedInstrument });
43
- },
44
- );
45
- }