@rebilly/instruments 4.4.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 +14 -0
  3. package/dist/index.js +14 -40
  4. package/dist/index.min.js +14 -40
  5. package/package.json +16 -5
  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 +420 -408
  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 +325 -289
  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 +149 -134
  33. package/src/functions/purchase.spec.js +59 -56
  34. package/src/functions/setup.js +53 -49
  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
@@ -7,71 +7,74 @@ import Events from '../events';
7
7
  import { mapItemsQuantities } from '../utils/quantity';
8
8
 
9
9
  describe('RebillyInstruments purchase', () => {
10
- it('should be able to make a purchase', async () => {
11
- const options = {
12
- websiteId: 'test-website-id',
13
- items: [{ planId: 'test-plan-id', quantity: 1 }]
14
- };
10
+ it('should be able to make a purchase', async () => {
11
+ const options = {
12
+ websiteId: 'test-website-id',
13
+ items: [{ planId: 'test-plan-id', quantity: 1 }],
14
+ };
15
15
 
16
- const token = {
17
- id: 'test-token-id'
18
- };
19
- const billingAddress = {
20
- billing: 'address'
21
- };
22
- const deliveryAddress = {
23
- delivery: 'address'
24
- };
16
+ const token = {
17
+ id: 'test-token-id',
18
+ };
19
+ const billingAddress = {
20
+ billing: 'address',
21
+ };
22
+ const deliveryAddress = {
23
+ delivery: 'address',
24
+ };
25
25
 
26
- const fields = {
27
- orderId: 'test-order-id',
28
- invoice: {
29
- id: 'test-invoice-id'
30
- },
31
- transaction: {
32
- id: 'test-transaction-id'
33
- }
34
- };
26
+ const fields = {
27
+ orderId: 'test-order-id',
28
+ invoice: {
29
+ id: 'test-invoice-id',
30
+ },
31
+ transaction: {
32
+ id: 'test-transaction-id',
33
+ },
34
+ };
35
35
 
36
- when(post(`${storefrontURL}/purchase`)).thenReturn(ok(fields));
37
- const rebillyInstruments = await RenderMockRebillyInstruments(options);
38
- const spyStorefrontPurchase = vi.spyOn(rebillyInstruments.state.storefront.purchase, 'purchase');
39
- vi.spyOn(Events.purchaseCompleted, 'dispatch');
36
+ when(post(`${storefrontURL}/purchase`)).thenReturn(ok(fields));
37
+ const rebillyInstruments = await RenderMockRebillyInstruments(options);
38
+ const spyStorefrontPurchase = vi.spyOn(
39
+ rebillyInstruments.state.storefront.purchase,
40
+ 'purchase',
41
+ );
42
+ vi.spyOn(Events.purchaseCompleted, 'dispatch');
40
43
 
41
- const purchaseCompletedListener = vi.fn();
44
+ const purchaseCompletedListener = vi.fn();
42
45
 
43
- rebillyInstruments.on('purchase-completed', purchaseCompletedListener);
46
+ rebillyInstruments.on('purchase-completed', purchaseCompletedListener);
44
47
 
45
- const purchasePayload = {
46
- billingAddress,
47
- deliveryAddress,
48
- _raw: token
49
- };
48
+ const purchasePayload = {
49
+ billingAddress,
50
+ deliveryAddress,
51
+ _raw: token,
52
+ };
50
53
 
51
- const purchasePayloadParsed = {
52
- websiteId: rebillyInstruments.state.options.websiteId,
53
- items: mapItemsQuantities(rebillyInstruments.state.options.items),
54
- billingAddress,
55
- deliveryAddress,
56
- couponIds: [],
57
- paymentInstruction: {
58
- token: token.id
59
- }
60
- };
54
+ const purchasePayloadParsed = {
55
+ websiteId: rebillyInstruments.state.options.websiteId,
56
+ items: mapItemsQuantities(rebillyInstruments.state.options.items),
57
+ billingAddress,
58
+ deliveryAddress,
59
+ couponIds: [],
60
+ paymentInstruction: {
61
+ token: token.id,
62
+ },
63
+ };
61
64
 
62
- await rebillyInstruments.purchase(purchasePayload);
65
+ await rebillyInstruments.purchase(purchasePayload);
63
66
 
64
- expect(spyStorefrontPurchase).toBeCalledTimes(1);
65
- expect(spyStorefrontPurchase).toBeCalledWith({
66
- data: expect.objectContaining(purchasePayloadParsed)
67
- });
67
+ expect(spyStorefrontPurchase).toBeCalledTimes(1);
68
+ expect(spyStorefrontPurchase).toBeCalledWith({
69
+ data: expect.objectContaining(purchasePayloadParsed),
70
+ });
68
71
 
69
- expect(Events.purchaseCompleted.dispatch).toBeCalledTimes(1);
72
+ expect(Events.purchaseCompleted.dispatch).toBeCalledTimes(1);
70
73
 
71
- expect(purchaseCompletedListener).toBeCalledTimes(1);
72
- expect(purchaseCompletedListener).toBeCalledWith(
73
- expect.objectContaining(fields)
74
- );
75
- await avoidUnhandledPromises();
76
- });
74
+ expect(purchaseCompletedListener).toBeCalledTimes(1);
75
+ expect(purchaseCompletedListener).toBeCalledWith(
76
+ expect.objectContaining(fields),
77
+ );
78
+ await avoidUnhandledPromises();
79
+ });
77
80
  });
@@ -4,59 +4,63 @@ import Events from '../events';
4
4
  import { mountModal } from '../views/modal';
5
5
  import { DataInstance } from './mount/fetch-data';
6
6
  import { showError } from '../views/errors';
7
-
7
+
8
8
  export async function setup({ payload }) {
9
- try {
10
- const {
11
- _raw: {
12
- id
13
- },
14
- isExistingInstrument
15
- } = payload;
16
- delete payload.isExistingInstrument;
17
- delete payload._raw;
18
-
19
- const data = {
20
- ...payload
21
- };
22
-
23
- if (isExistingInstrument) {
24
- data.paymentInstrumentId = id;
25
- } else {
26
- data.token = id;
27
- }
9
+ try {
10
+ const {
11
+ _raw: { id },
12
+ isExistingInstrument,
13
+ } = payload;
14
+ delete payload.isExistingInstrument;
15
+ delete payload._raw;
28
16
 
29
- const {instrument, transaction} = await setupPaymentInstrument({
30
- data: {
31
- websiteId: state.options?.websiteId,
32
- ...data
33
- }
34
- });
17
+ const data = {
18
+ ...payload,
19
+ };
20
+
21
+ if (isExistingInstrument) {
22
+ data.paymentInstrumentId = id;
23
+ } else {
24
+ data.token = id;
25
+ }
35
26
 
36
- state.data = new DataInstance({instrument, transaction});
27
+ const { instrument, transaction } = await setupPaymentInstrument({
28
+ data: {
29
+ websiteId: state.options?.websiteId,
30
+ ...data,
31
+ },
32
+ });
37
33
 
38
- if (transaction.approvalUrl && transaction.result === 'unknown') {
39
- const { paymentMethodsUrl } = state.options._computed;
40
- mountModal({
41
- name: 'rebilly-instruments-approval-url',
42
- url: `${paymentMethodsUrl}/approval-url`,
43
- model: {
44
- setup: {transaction}
45
- },
46
- close: ({transaction: updatedTransaction = transaction}) => {
47
- Events.setupCompleted.dispatch({
48
- instrument,
49
- transaction: updatedTransaction
50
- });
34
+ state.data = new DataInstance({ instrument, transaction });
35
+
36
+ if (transaction.approvalUrl && transaction.result === 'unknown') {
37
+ if (state.options.features.fullPageRedirect) {
38
+ window.location = transaction.approvalUrl;
39
+ } else {
40
+ const { paymentMethodsUrl } = state.options._computed;
41
+ mountModal({
42
+ name: 'rebilly-instruments-approval-url',
43
+ url: `${paymentMethodsUrl}/approval-url`,
44
+ model: {
45
+ setup: { transaction },
46
+ },
47
+ close: ({
48
+ transaction: updatedTransaction = transaction,
49
+ }) => {
50
+ Events.setupCompleted.dispatch({
51
+ instrument,
52
+ transaction: updatedTransaction,
53
+ });
54
+ },
55
+ });
56
+ }
57
+ } else {
58
+ Events.setupCompleted.dispatch({ instrument, transaction });
51
59
  }
52
- });
53
- } else {
54
- Events.setupCompleted.dispatch({instrument, transaction});
55
- }
56
60
 
57
- return {instrument, transaction};
58
- } catch (error) {
59
- showError(error);
60
- return error;
61
- }
61
+ return { instrument, transaction };
62
+ } catch (error) {
63
+ showError(error);
64
+ return error;
65
+ }
62
66
  }
@@ -6,93 +6,106 @@ import Events from '../events';
6
6
  import { avoidUnhandledPromises } from 'tests/async-utilities';
7
7
 
8
8
  describe('RebillyInstruments setup', () => {
9
- it('should be able to setup a payment instrument', async () => {
10
- const options = {
11
- websiteId: 'test-website-id',
12
- money: {
13
- amount: 30,
14
- currency: 'USD'
15
- },
16
- transactionType: 'setup'
17
- };
9
+ it('should be able to setup a payment instrument', async () => {
10
+ const options = {
11
+ websiteId: 'test-website-id',
12
+ money: {
13
+ amount: 30,
14
+ currency: 'USD',
15
+ },
16
+ transactionType: 'setup',
17
+ };
18
18
 
19
- const token = {
20
- id: 'test-token-id'
21
- };
22
- const billingAddress = {
23
- billing: 'address'
24
- };
25
- const deliveryAddress = {
26
- delivery: 'address'
27
- };
19
+ const token = {
20
+ id: 'test-token-id',
21
+ };
22
+ const billingAddress = {
23
+ billing: 'address',
24
+ };
25
+ const deliveryAddress = {
26
+ delivery: 'address',
27
+ };
28
28
 
29
- const paymentInstrumentFields = {
30
- id: 'payment-instrument-id'
31
- };
29
+ const paymentInstrumentFields = {
30
+ id: 'payment-instrument-id',
31
+ };
32
32
 
33
- const paymentInstrumentSetupFields = {
34
- id: 'payment-instrument-id',
35
- approvalUrl: null,
36
- };
33
+ const paymentInstrumentSetupFields = {
34
+ id: 'payment-instrument-id',
35
+ approvalUrl: null,
36
+ };
37
37
 
38
- when(post(`${storefrontURL}/payment-instruments`)).thenReturn(ok(paymentInstrumentFields));
39
- when(post(`${storefrontURL}/payment-instruments/*/setup`)).thenReturn(ok(paymentInstrumentSetupFields));
40
- const rebillyInstruments = await RenderMockRebillyInstruments(options);
38
+ when(post(`${storefrontURL}/payment-instruments`)).thenReturn(
39
+ ok(paymentInstrumentFields),
40
+ );
41
+ when(post(`${storefrontURL}/payment-instruments/*/setup`)).thenReturn(
42
+ ok(paymentInstrumentSetupFields),
43
+ );
44
+ const rebillyInstruments = await RenderMockRebillyInstruments(options);
41
45
 
42
- const spyCreatePaymentInstrument = vi.spyOn(rebillyInstruments.state.storefront.paymentInstruments, 'create');
43
- const spySetupPaymentInstrument = vi.spyOn(rebillyInstruments.state.storefront.paymentInstruments, 'setup');
44
- const spyDispatchSetupCompleted = vi.spyOn(Events.setupCompleted, 'dispatch');
46
+ const spyCreatePaymentInstrument = vi.spyOn(
47
+ rebillyInstruments.state.storefront.paymentInstruments,
48
+ 'create',
49
+ );
50
+ const spySetupPaymentInstrument = vi.spyOn(
51
+ rebillyInstruments.state.storefront.paymentInstruments,
52
+ 'setup',
53
+ );
54
+ const spyDispatchSetupCompleted = vi.spyOn(
55
+ Events.setupCompleted,
56
+ 'dispatch',
57
+ );
45
58
 
46
- const setupCompletedListener = vi.fn();
59
+ const setupCompletedListener = vi.fn();
47
60
 
48
- rebillyInstruments.on('setup-completed', setupCompletedListener);
61
+ rebillyInstruments.on('setup-completed', setupCompletedListener);
49
62
 
50
- const setupPayload = {
51
- billingAddress,
52
- deliveryAddress,
53
- ...options.money,
54
- _raw: token
55
- };
63
+ const setupPayload = {
64
+ billingAddress,
65
+ deliveryAddress,
66
+ ...options.money,
67
+ _raw: token,
68
+ };
56
69
 
57
- rebillyInstruments.mock.data({
58
- previewPurchase: {
59
- currency: 'USD',
60
- total: 30
61
- }
62
- });
70
+ rebillyInstruments.mock.data({
71
+ previewPurchase: {
72
+ currency: 'USD',
73
+ total: 30,
74
+ },
75
+ });
63
76
 
64
- await rebillyInstruments.setup(setupPayload);
77
+ await rebillyInstruments.setup(setupPayload);
65
78
 
66
- expect(spyCreatePaymentInstrument).toBeCalledTimes(1);
67
- expect(spyCreatePaymentInstrument).toBeCalledWith(
68
- expect.objectContaining({
69
- data: expect.objectContaining ({
70
- token: token.id
71
- })
72
- })
73
- );
79
+ expect(spyCreatePaymentInstrument).toBeCalledTimes(1);
80
+ expect(spyCreatePaymentInstrument).toBeCalledWith(
81
+ expect.objectContaining({
82
+ data: expect.objectContaining({
83
+ token: token.id,
84
+ }),
85
+ }),
86
+ );
74
87
 
75
- expect(spySetupPaymentInstrument).toBeCalledTimes(1);
76
- expect(spySetupPaymentInstrument).toBeCalledWith(
77
- expect.objectContaining({
78
- id: expect.stringContaining(paymentInstrumentFields.id),
79
- data: expect.objectContaining ({
80
- websiteId: rebillyInstruments.state.options.websiteId,
81
- currency: 'USD',
82
- amount: 30
83
- })
84
- })
85
- );
88
+ expect(spySetupPaymentInstrument).toBeCalledTimes(1);
89
+ expect(spySetupPaymentInstrument).toBeCalledWith(
90
+ expect.objectContaining({
91
+ id: expect.stringContaining(paymentInstrumentFields.id),
92
+ data: expect.objectContaining({
93
+ websiteId: rebillyInstruments.state.options.websiteId,
94
+ currency: 'USD',
95
+ amount: 30,
96
+ }),
97
+ }),
98
+ );
86
99
 
87
- expect(spyDispatchSetupCompleted).toBeCalledTimes(1);
100
+ expect(spyDispatchSetupCompleted).toBeCalledTimes(1);
88
101
 
89
- expect(setupCompletedListener).toBeCalledTimes(1);
90
- expect(setupCompletedListener).toBeCalledWith(
91
- expect.objectContaining({
92
- instrument: paymentInstrumentFields,
93
- transaction: paymentInstrumentSetupFields
94
- })
95
- );
96
- await avoidUnhandledPromises();
97
- });
102
+ expect(setupCompletedListener).toBeCalledTimes(1);
103
+ expect(setupCompletedListener).toBeCalledWith(
104
+ expect.objectContaining({
105
+ instrument: paymentInstrumentFields,
106
+ transaction: paymentInstrumentSetupFields,
107
+ }),
108
+ );
109
+ await avoidUnhandledPromises();
110
+ });
98
111
  });
@@ -1,7 +1,6 @@
1
- import iframes from '../state/iframes';
2
1
  import { mountConfirmation } from '../views/confirmation';
3
2
  import { mountResult } from '../views/result';
4
- import { hideExtraUI as hideMethodSelectorUI} from '../views/method-selector'
3
+ import { hideExtraUI as hideMethodSelectorUI } from '../views/method-selector';
5
4
 
6
5
  /**
7
6
  @typedef ShowParams
@@ -16,16 +15,16 @@ import { hideExtraUI as hideMethodSelectorUI} from '../views/method-selector'
16
15
  * @param {ShowParams} params
17
16
  */
18
17
  export async function show({ componentName, payload }) {
19
- switch (componentName) {
20
- case 'result':
21
- hideMethodSelectorUI();
22
- mountResult({ payload });
23
- break;
24
- case 'confirmation':
25
- hideMethodSelectorUI();
26
- mountConfirmation({ payload });
27
- break;
28
- default:
29
- throw new Error(`'${componentName}' not a supported component`);
30
- }
18
+ switch (componentName) {
19
+ case 'result':
20
+ hideMethodSelectorUI();
21
+ mountResult({ payload });
22
+ break;
23
+ case 'confirmation':
24
+ hideMethodSelectorUI();
25
+ mountConfirmation({ payload });
26
+ break;
27
+ default:
28
+ throw new Error(`'${componentName}' not a supported component`);
29
+ }
31
30
  }
@@ -6,57 +6,57 @@ import iframes from '@/state/iframes';
6
6
  const iframeMock = { destroy: vi.fn() };
7
7
 
8
8
  describe('RebillyInstruments show', () => {
9
- it('should show result component', async () => {
10
- const mountResult = vi
11
- .spyOn(result, 'mountResult')
12
- .mockReturnValue(Promise.resolve());
13
-
14
- const instance = new RebillyInstrumentsInstance();
15
-
16
- const payload = {
17
- test: 'value'
18
- };
19
-
20
- await instance.show('result', payload);
21
-
22
- expect(mountResult).toBeCalledTimes(1);
23
- expect(mountResult).toBeCalledWith(
24
- expect.objectContaining({ payload })
25
- );
26
- });
27
-
28
- it('should show confirmation component', async () => {
29
- const mountConfirmation = vi
30
- .spyOn(confirmation, 'mountConfirmation')
31
- .mockReturnValue(Promise.resolve());
32
-
33
- const instance = new RebillyInstrumentsInstance();
34
- iframes.form = iframeMock;
35
-
36
- const payload = {
37
- test: 'value'
38
- };
39
-
40
- await instance.show('confirmation', payload);
41
-
42
- expect(mountConfirmation).toBeCalledTimes(1);
43
- expect(mountConfirmation).toBeCalledWith(
44
- expect.objectContaining({payload})
45
- );
46
- expect(iframes.form).toEqual(iframeMock);
47
- });
48
-
49
- it('should fail for non supported component', async () => {
50
- const rebillyInstruments = new RebillyInstrumentsInstance();
51
-
52
- let error;
53
- try {
54
- await rebillyInstruments.show('not-a-component', 'any payload');
55
- } catch (e) {
56
- error = e;
57
- }
58
- expect(error.toString()).toBe(
59
- `Error: 'not-a-component' not a supported component`
60
- );
61
- });
9
+ it('should show result component', async () => {
10
+ const mountResult = vi
11
+ .spyOn(result, 'mountResult')
12
+ .mockReturnValue(Promise.resolve());
13
+
14
+ const instance = new RebillyInstrumentsInstance();
15
+
16
+ const payload = {
17
+ test: 'value',
18
+ };
19
+
20
+ await instance.show('result', payload);
21
+
22
+ expect(mountResult).toBeCalledTimes(1);
23
+ expect(mountResult).toBeCalledWith(
24
+ expect.objectContaining({ payload }),
25
+ );
26
+ });
27
+
28
+ it('should show confirmation component', async () => {
29
+ const mountConfirmation = vi
30
+ .spyOn(confirmation, 'mountConfirmation')
31
+ .mockReturnValue(Promise.resolve());
32
+
33
+ const instance = new RebillyInstrumentsInstance();
34
+ iframes.form = iframeMock;
35
+
36
+ const payload = {
37
+ test: 'value',
38
+ };
39
+
40
+ await instance.show('confirmation', payload);
41
+
42
+ expect(mountConfirmation).toBeCalledTimes(1);
43
+ expect(mountConfirmation).toBeCalledWith(
44
+ expect.objectContaining({ payload }),
45
+ );
46
+ expect(iframes.form).toEqual(iframeMock);
47
+ });
48
+
49
+ it('should fail for non supported component', async () => {
50
+ const rebillyInstruments = new RebillyInstrumentsInstance();
51
+
52
+ let error;
53
+ try {
54
+ await rebillyInstruments.show('not-a-component', 'any payload');
55
+ } catch (e) {
56
+ error = e;
57
+ }
58
+ expect(error.toString()).toBe(
59
+ `Error: 'not-a-component' not a supported component`,
60
+ );
61
+ });
62
62
  });
@@ -3,36 +3,38 @@ import state from '../state';
3
3
  import { destroy } from './destroy';
4
4
  import { mount } from './mount';
5
5
 
6
- export async function update({newOptions = {}}) {
7
- if (!state.hasMounted) {
8
- throw Error('Update method cannot be called before mounting instruments');
9
- }
6
+ export async function update({ newOptions = {} }) {
7
+ if (!state.hasMounted) {
8
+ throw Error(
9
+ 'Update method cannot be called before mounting instruments',
10
+ );
11
+ }
10
12
 
11
- /**
12
- * Framepay locale option is almost but not fully updatable yet:
13
- * https://github.com/Rebilly/framepay/issues/450
14
- * That's why this toggle disables real time locale update until that issue is fixed.
15
- */
16
- // const updatingJustLocale =
17
- // newOptions?.options && isEqual(Object.keys(newOptions), ['locale']);
18
- // if (updatingJustLocale) {
19
- // const updatedOptions = merge(state.options, newOptions);
20
- // const newLocale = newOptions?.locale;
21
- // state.options = updatedOptions;
22
- // state.translate.updateTranslationsToNewLocale(newLocale);
23
- // state.iframeComponents.forEach((iframe) =>
24
- // iframe.component.call('changeLocale', newLocale)
25
- // );
26
- // return;
27
- // }
13
+ /**
14
+ * Framepay locale option is almost but not fully updatable yet:
15
+ * https://github.com/Rebilly/framepay/issues/450
16
+ * That's why this toggle disables real time locale update until that issue is fixed.
17
+ */
18
+ // const updatingJustLocale =
19
+ // newOptions?.options && isEqual(Object.keys(newOptions), ['locale']);
20
+ // if (updatingJustLocale) {
21
+ // const updatedOptions = merge(state.options, newOptions);
22
+ // const newLocale = newOptions?.locale;
23
+ // state.options = updatedOptions;
24
+ // state.translate.updateTranslationsToNewLocale(newLocale);
25
+ // state.iframeComponents.forEach((iframe) =>
26
+ // iframe.component.call('changeLocale', newLocale)
27
+ // );
28
+ // return;
29
+ // }
28
30
 
29
- const updatedOptions = merge({...state.options}, newOptions);
31
+ const updatedOptions = merge({ ...state.options }, newOptions);
30
32
 
31
- await destroy();
33
+ await destroy();
32
34
 
33
- mount({
34
- form: state.form,
35
- summary: state.summary,
36
- ...updatedOptions,
37
- });
35
+ mount({
36
+ form: state.form,
37
+ summary: state.summary,
38
+ ...updatedOptions,
39
+ });
38
40
  }