@rebilly/instruments 4.5.0 → 4.6.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.
Files changed (134) hide show
  1. package/.babelrc +24 -26
  2. package/CHANGELOG.md +7 -0
  3. package/dist/index.js +8 -8
  4. package/dist/index.min.js +8 -8
  5. package/package.json +14 -3
  6. package/project.json +9 -0
  7. package/rollup.config.mjs +21 -26
  8. package/src/data/options-schema/index.js +94 -78
  9. package/src/data/options-schema/schemas/options-schema.js +419 -411
  10. package/src/events/base-event.js +34 -34
  11. package/src/events/events.spec.js +6 -6
  12. package/src/events/index.js +5 -5
  13. package/src/functions/destroy.js +19 -19
  14. package/src/functions/destroy.spec.js +41 -41
  15. package/src/functions/mount/fetch-data.js +200 -193
  16. package/src/functions/mount/fetch-data.spec.js +287 -285
  17. package/src/functions/mount/get-lead-source-data.js +31 -31
  18. package/src/functions/mount/get-lead-source-data.spec.js +19 -19
  19. package/src/functions/mount/index.js +73 -65
  20. package/src/functions/mount/mount.spec.js +77 -66
  21. package/src/functions/mount/setup-element.js +23 -23
  22. package/src/functions/mount/setup-framepay-theme.js +86 -68
  23. package/src/functions/mount/setup-framepay.js +9 -5
  24. package/src/functions/mount/setup-i18n.js +15 -15
  25. package/src/functions/mount/setup-options.js +74 -74
  26. package/src/functions/mount/setup-options.spec.js +323 -287
  27. package/src/functions/mount/setup-storefront.js +15 -20
  28. package/src/functions/mount/setup-styles-vars.js +19 -22
  29. package/src/functions/mount/setup-user-flow.js +51 -47
  30. package/src/functions/on.js +5 -5
  31. package/src/functions/on.spec.js +60 -51
  32. package/src/functions/purchase.js +151 -146
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -53
  35. package/src/functions/setup.spec.js +88 -75
  36. package/src/functions/show.js +13 -14
  37. package/src/functions/show.spec.js +53 -53
  38. package/src/functions/update.js +30 -28
  39. package/src/functions/update.spec.js +94 -93
  40. package/src/i18n/en.json +32 -32
  41. package/src/i18n/es.json +29 -29
  42. package/src/i18n/i18n.spec.js +18 -18
  43. package/src/i18n/index.js +48 -48
  44. package/src/instance.js +36 -36
  45. package/src/instance.spec.js +29 -27
  46. package/src/loader/index.js +95 -70
  47. package/src/loader/loader.spec.js +63 -63
  48. package/src/state/iframes.js +21 -21
  49. package/src/state/index.js +56 -54
  50. package/src/storefront/account-and-website.js +10 -8
  51. package/src/storefront/account-and-website.spec.js +55 -55
  52. package/src/storefront/deposit-requests.js +6 -6
  53. package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
  54. package/src/storefront/fetch-products-from-plans.js +52 -51
  55. package/src/storefront/fetch-products-from-plans.spec.js +90 -87
  56. package/src/storefront/index.js +56 -49
  57. package/src/storefront/invoices.js +15 -15
  58. package/src/storefront/invoices.spec.js +69 -65
  59. package/src/storefront/models/account-model.js +29 -32
  60. package/src/storefront/models/base-model.js +6 -9
  61. package/src/storefront/models/deposit-request-model.js +22 -13
  62. package/src/storefront/models/invoice-model.js +16 -16
  63. package/src/storefront/models/payment-metadata.js +4 -4
  64. package/src/storefront/models/plan-model.js +73 -64
  65. package/src/storefront/models/ready-to-pay-model.js +59 -59
  66. package/src/storefront/models/summary-model.js +43 -46
  67. package/src/storefront/models/transaction-model.js +11 -14
  68. package/src/storefront/payment-instruments.js +38 -35
  69. package/src/storefront/payment-instruments.spec.js +81 -62
  70. package/src/storefront/purchase.js +50 -44
  71. package/src/storefront/purchase.spec.js +40 -40
  72. package/src/storefront/ready-to-pay.js +75 -77
  73. package/src/storefront/ready-to-pay.spec.js +59 -54
  74. package/src/storefront/storefront.spec.js +9 -9
  75. package/src/storefront/summary.js +93 -67
  76. package/src/storefront/summary.spec.js +108 -106
  77. package/src/storefront/transactions.js +6 -6
  78. package/src/style/base/default-theme.js +928 -923
  79. package/src/style/base/theme.js +21 -21
  80. package/src/style/base/theme.spec.js +13 -13
  81. package/src/style/index.js +3 -3
  82. package/src/style/utils/border.js +40 -27
  83. package/src/style/utils/color-values.js +18 -18
  84. package/src/style/utils/minifyCss.js +6 -6
  85. package/src/utils/add-dom-element.js +14 -14
  86. package/src/utils/format-currency.js +6 -5
  87. package/src/utils/has-valid-css-selector.js +2 -2
  88. package/src/utils/index.js +6 -6
  89. package/src/utils/is-dom-element.js +1 -1
  90. package/src/utils/process-property-as-dom-element.js +22 -22
  91. package/src/utils/quantity.js +26 -28
  92. package/src/utils/sleep.js +3 -1
  93. package/src/views/amount-selector.js +37 -36
  94. package/src/views/common/iframe/base-iframe.js +53 -52
  95. package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
  96. package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
  97. package/src/views/common/iframe/events/resize-component-handler.js +8 -8
  98. package/src/views/common/iframe/events/show-error-handler.js +2 -2
  99. package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
  100. package/src/views/common/iframe/events/update-addons-handler.js +20 -13
  101. package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
  102. package/src/views/common/iframe/events/update-items-handler.js +26 -22
  103. package/src/views/common/iframe/modal-iframe.js +67 -56
  104. package/src/views/common/iframe/view-iframe.js +11 -11
  105. package/src/views/common/render-utilities.js +2 -2
  106. package/src/views/confirmation.js +33 -30
  107. package/src/views/errors.js +89 -79
  108. package/src/views/form.js +41 -37
  109. package/src/views/method-selector/express-methods.js +46 -46
  110. package/src/views/method-selector/generate-digital-wallet.js +46 -45
  111. package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
  112. package/src/views/method-selector/generate-framepay-config.js +53 -51
  113. package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
  114. package/src/views/method-selector/get-method-data.js +5 -6
  115. package/src/views/method-selector/get-payment-methods.js +18 -16
  116. package/src/views/method-selector/get-payment-methods.spec.js +29 -27
  117. package/src/views/method-selector/index.js +154 -139
  118. package/src/views/method-selector/method-selector.spec.js +13 -13
  119. package/src/views/method-selector/mount-bump-offer.js +65 -49
  120. package/src/views/method-selector/mount-express-methods.js +89 -85
  121. package/src/views/modal.js +74 -67
  122. package/src/views/result.js +14 -14
  123. package/src/views/summary.js +25 -26
  124. package/tests/async-utilities.js +13 -13
  125. package/tests/mocks/framepay-mock.js +9 -8
  126. package/tests/mocks/rebilly-api-mock.js +5 -3
  127. package/tests/mocks/rebilly-instruments-mock.js +121 -117
  128. package/tests/mocks/storefront-api-mock.js +55 -48
  129. package/tests/mocks/storefront-mock.js +10 -14
  130. package/tests/msw/server.js +6 -6
  131. package/tests/setup-test.js +14 -16
  132. package/vitest.config.js +14 -14
  133. package/.eslintrc.js +0 -34
  134. package/.prettierrc.js +0 -11
@@ -1,65 +1,66 @@
1
1
  import Postmate from 'popostmate';
2
2
 
3
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
- }
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
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;
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
23
 
24
- return (async () => {
25
- this.component = await this.createComponent();
24
+ // eslint-disable-next-line no-constructor-return
25
+ return (async () => {
26
+ this.component = await this.createComponent();
26
27
 
27
- if (route) {
28
- this.component.call('route', route);
29
- }
28
+ if (route) {
29
+ this.component.call('route', route);
30
+ }
30
31
 
31
- return this;
32
- })();
33
- }
32
+ return this;
33
+ })();
34
+ }
34
35
 
35
- async destroy() {
36
- if (this.component.frame.parentNode) {
37
- await this.component.destroy();
36
+ async destroy() {
37
+ if (this.component.frame.parentNode) {
38
+ await this.component.destroy();
39
+ }
38
40
  }
39
- }
40
41
 
41
- async createComponent() {
42
- // Use a fake container so we can capture the appendChild call
43
- // and immediately apply the feature-policy flags to the iframe
44
- // before Postmate tries to load the iframe. The feature policy
45
- // would otherwise not apply until the frame was reloaded.
46
- const container = {
47
- appendChild: (iframe) => {
48
- iframe.setAttribute('loading', 'lazy');
49
- iframe.setAttribute('allow', 'payment');
50
- iframe.allowPaymentRequest = true;
51
- this.container.appendChild(iframe);
52
- },
53
- };
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
+ };
54
55
 
55
- const component = await new Postmate({
56
- name: this.name,
57
- url: this.url,
58
- container,
59
- classListArray: this.classListArray,
60
- model: this.model
61
- });
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
+ });
62
63
 
63
- return component;
64
- }
64
+ return component;
65
+ }
65
66
  }
@@ -1,6 +1,6 @@
1
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
- }
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
+ }
@@ -2,7 +2,7 @@ import camelCase from 'lodash.camelcase';
2
2
  import Events from '../../../../events';
3
3
 
4
4
  export function dispatchEventHandler(iframe) {
5
- iframe.component.on(`${iframe.name}-dispatch`, ({ event, detail }) => {
6
- Events[camelCase(event).replace(/-/, '')].dispatch(detail);
7
- });
8
- }
5
+ iframe.component.on(`${iframe.name}-dispatch`, ({ event, detail }) => {
6
+ Events[camelCase(event).replace(/-/, '')].dispatch(detail);
7
+ });
8
+ }
@@ -1,9 +1,9 @@
1
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
- }
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 +1,5 @@
1
1
  import { showError } from '../../../errors';
2
2
 
3
3
  export function showErrorHandler(iframe) {
4
- iframe.component.on(`${iframe.name}-show-error`, showError);
5
- }
4
+ iframe.component.on(`${iframe.name}-show-error`, showError);
5
+ }
@@ -1,9 +1,9 @@
1
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
- }
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,16 +1,23 @@
1
1
  import state from '../../../../state';
2
2
 
3
3
  export function updateAddonsHandler(iframe) {
4
- iframe.component.on(`${iframe.name}-update-addons`, async ({addons, previewPurchase}) => {
5
- const addonPlanIds = addons.map(addon => addon.planId);
6
- state.data.addons = addonPlanIds;
7
- state.data.previewPurchase = previewPurchase;
8
-
9
- state.data.previewPurchase.addonLineItems = state.data.previewPurchase.lineItems
10
- .filter(item => addonPlanIds.includes(item.planId));
11
- state.data.previewPurchase.lineItems = state.data.previewPurchase.lineItems
12
- .filter(item => !addonPlanIds.includes(item.planId));
13
-
14
- state.updateModel();
15
- });
16
- }
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 +1,12 @@
1
1
  import state from '../../../../state';
2
2
 
3
3
  export function updateCouponsHandler(iframe) {
4
- iframe.component.on(`${iframe.name}-update-coupon`, async ({
5
- couponIds,
6
- previewPurchase
7
- } = {}) => {
8
- state.data.couponIds = couponIds;
9
- state.data.previewPurchase = previewPurchase;
10
- state.updateModel();
11
- });
12
- }
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,30 +1,34 @@
1
1
  import state from '../../../../state';
2
2
  import { fetchSummary } from '../../../../storefront/summary';
3
- import { createQuantitiesMap, getQuantityValue, isObject } from '../../../../utils/quantity';
3
+ import {
4
+ createQuantitiesMap,
5
+ getQuantityValue,
6
+ isObject,
7
+ } from '../../../../utils/quantity';
4
8
 
5
9
  let loading = false;
6
10
  export async function itemsUpdatedHandler(iframe) {
7
- iframe.component.on(`${iframe.name}-update-items`, async (lineItems) => {
8
- try {
9
- if (loading) return;
10
- loading = true;
11
- const mappedItems = createQuantitiesMap(lineItems);
11
+ iframe.component.on(`${iframe.name}-update-items`, async (lineItems) => {
12
+ try {
13
+ if (loading) return;
14
+ loading = true;
15
+ const mappedItems = createQuantitiesMap(lineItems);
12
16
 
13
- state.data.summaryLineItems.forEach(item => {
14
- const quantity = getQuantityValue(mappedItems.get(item.planId));
15
- if(isObject(item.quantity)) {
16
- item.quantity.default = quantity;
17
- } else {
18
- item.quantity = quantity;
19
- }
20
- })
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
+ });
21
25
 
22
- await fetchSummary();
23
- state.updateModel();
24
- loading = false;
25
- } catch (err) {
26
- console.error(err);
27
- loading = false;
28
- }
29
- });
26
+ await fetchSummary();
27
+ state.updateModel();
28
+ loading = false;
29
+ } catch (err) {
30
+ console.error(err);
31
+ loading = false;
32
+ }
33
+ });
30
34
  }
@@ -8,64 +8,75 @@ import { showErrorHandler } from './events/show-error-handler';
8
8
  import { stopLoaderHandler } from './events/stop-loader-handler';
9
9
 
10
10
  export class ModalIframe extends BaseIframe {
11
- constructor(args = {}) {
12
- super(args);
13
- }
11
+ constructor(args = {}) {
12
+ super(args);
13
+ }
14
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);
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
25
 
26
- // Close modal via postmate
27
- this.component.on(`${this.name}-close`, (...args) => {
28
- close(...args);
29
- });
26
+ // Close modal via postmate
27
+ this.component.on(`${this.name}-close`, (...args) => {
28
+ close(...args);
29
+ });
30
30
 
31
- // Close modal via postMessage (specifically during approval url flow)
32
- window.addEventListener('message', async (event) => {
33
- if(event.data === 'rebilly-instruments-approval-url-close') {
34
- if (state.options.transactionType === 'purchase') {
35
- state.storefront.setSessionToken(state.data.token || state.options.jwt);
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
+ );
36
40
 
37
- const [
38
- {fields: transaction},
39
- {fields: invoice}
40
- ] = await Promise.all([
41
- state.storefront.transactions.get({id: state.data.transaction.id}),
42
- state.data.invoice?.id
43
- ? state.storefront.invoices.get({id: state.data.invoice.id})
44
- : {fields: null}
45
- ]);
46
-
47
- const updatedPurchase = {
48
- orderId: state.data.orderId,
49
- token: state.data.token,
50
- transaction,
51
- };
52
- if (invoice) {
53
- updatedPurchase.invoice = invoice;
54
- }
55
- close(updatedPurchase);
56
- } else if (state.options.transactionType === 'setup') {
57
- state.storefront.setSessionToken(state.data.instrument.token || state.options.jwt);
58
- const {
59
- fields: transaction
60
- } = await state.storefront.transactions.get({id: state.data.transaction.id});
61
- close({
62
- transaction,
63
- instrument: state.data.instrument
64
- });
65
- } else {
66
- close();
67
- }
68
- }
69
- }, false);
70
- }
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
+ }
71
82
  }
@@ -8,16 +8,16 @@ import { showErrorHandler } from './events/show-error-handler';
8
8
  import { stopLoaderHandler } from './events/stop-loader-handler';
9
9
 
10
10
  export class ViewIframe extends BaseIframe {
11
- constructor(args = {}) {
12
- super(args);
13
- }
11
+ constructor(args = {}) {
12
+ super(args);
13
+ }
14
14
 
15
- bindEventListeners({ loader } = {}) {
16
- dispatchEventHandler(this);
17
- resizeComponentHandler(this);
18
- stopLoaderHandler(this, { loader });
19
- showErrorHandler(this);
20
- updateCouponsHandler(this);
21
- updateAddonsHandler(this);
22
- }
15
+ bindEventListeners({ loader } = {}) {
16
+ dispatchEventHandler(this);
17
+ resizeComponentHandler(this);
18
+ stopLoaderHandler(this, { loader });
19
+ showErrorHandler(this);
20
+ updateCouponsHandler(this);
21
+ updateAddonsHandler(this);
22
+ }
23
23
  }
@@ -1,4 +1,4 @@
1
1
  export function replaceContent(form, newContent) {
2
- const contentElement = form.querySelector('.rebilly-instruments-content');
3
- contentElement.innerHTML = newContent;
2
+ const contentElement = form.querySelector('.rebilly-instruments-content');
3
+ contentElement.innerHTML = newContent;
4
4
  }
@@ -2,41 +2,44 @@ import state from '../state';
2
2
  import iframes from '../state/iframes';
3
3
  import { mountForm } from './form';
4
4
  import { updateSummary } from './summary';
5
- import { purchase} from '../functions/purchase';
5
+ import { purchase } from '../functions/purchase';
6
6
  import { setup } from '../functions/setup';
7
7
 
8
8
  export async function mountConfirmation({ payload: instrument }) {
9
- if (
10
- (instrument.billingAddress && state.summary) &&
11
- state.data.isPurchase
12
- ) {
13
- updateSummary({ instrument });
14
- }
9
+ if (instrument.billingAddress && state.summary && state.data.isPurchase) {
10
+ updateSummary({ instrument });
11
+ }
15
12
 
16
- const iframe = iframes.form;
17
- if (!iframe) {
18
- await mountForm();
19
- }
20
-
21
- const modelSafeState = state.toModel();
22
- const model = {
23
- options: modelSafeState.options,
24
- data: modelSafeState.data,
25
- mainStyleVars: modelSafeState.mainStyleVars,
26
- instrument
27
- };
28
-
29
- iframe?.component?.call('update', model);
13
+ const iframe = iframes.form;
14
+ if (!iframe) {
15
+ await mountForm();
16
+ }
30
17
 
31
- iframe?.component?.call('route', {
32
- name: 'confirmation'
33
- });
18
+ const modelSafeState = state.toModel();
19
+ const model = {
20
+ options: modelSafeState.options,
21
+ data: modelSafeState.data,
22
+ mainStyleVars: modelSafeState.mainStyleVars,
23
+ instrument,
24
+ };
34
25
 
35
- iframe?.component?.on(`${iframe.name}-confirm-purchase`, (confirmedInstrument) => {
36
- purchase({ payload: confirmedInstrument });
37
- });
26
+ iframe?.component?.call('update', model);
38
27
 
39
- iframe?.component?.on(`${iframe.name}-confirm-setup`, (confirmedInstrument) => {
40
- setup({ payload: confirmedInstrument });
41
- });
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
+ );
42
45
  }