@rebilly/instruments 4.8.0 → 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 +14 -0
  2. package/dist/index.js +3 -3
  3. package/dist/index.min.js +3 -3
  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 -234
  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 -80
  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 -48
  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,216 +0,0 @@
1
- import { generateFramepayConfig } from './generate-framepay-config';
2
- import state from '@/state';
3
-
4
- describe('Generate FramePay Config', () => {
5
- beforeEach(() => {
6
- state.options = {
7
- themeFramepay: {},
8
- locale: 'en-CA',
9
- organizationId: 'test-organization-id',
10
- websiteId: 'test-website-id',
11
- };
12
- state.data = {
13
- readyToPay: [],
14
- };
15
- });
16
-
17
- it('should generate default config', () => {
18
- const config = generateFramepayConfig({
19
- state,
20
- methodIds: [],
21
- });
22
-
23
- const { options, data } = state;
24
-
25
- expect(config).toEqual(
26
- expect.objectContaining({
27
- style: options.themeFramepay,
28
- locale: options.locale,
29
- organizationId: options.organizationId,
30
- websiteId: options.websiteId,
31
- methods: data.readyToPay,
32
- }),
33
- );
34
- });
35
-
36
- it('should add publishableKey', () => {
37
- state.options.publishableKey = 'test-publishable-key';
38
-
39
- const config = generateFramepayConfig({
40
- state,
41
- methodIds: [],
42
- });
43
-
44
- expect(config).toEqual(
45
- expect.objectContaining({
46
- publishableKey: state.options.publishableKey,
47
- }),
48
- );
49
- });
50
-
51
- it('should add jwt', () => {
52
- state.options.jwt = 'test-jwt';
53
- state.options.apiMode = 'sandbox';
54
-
55
- const config = generateFramepayConfig({
56
- state,
57
- methodIds: [],
58
- });
59
-
60
- expect(config).toEqual(
61
- expect.objectContaining({
62
- jwt: state.options.jwt,
63
- sandbox: true,
64
- }),
65
- );
66
- });
67
-
68
- it('should add configurations for PayPal', () => {
69
- state.data.amountAndCurrency = {
70
- amount: 10,
71
- currency: 'CAD',
72
- };
73
- state.options.paymentInstruments = {
74
- paypal: {
75
- test: 'key',
76
- },
77
- };
78
-
79
- const config = generateFramepayConfig({
80
- state,
81
- methodIds: ['pay-pal-billing-agreement'],
82
- });
83
-
84
- expect(config).toEqual(
85
- expect.objectContaining({
86
- transactionData: expect.objectContaining(
87
- state.data.amountAndCurrency,
88
- ),
89
- paypal: state.options.paymentInstruments.paypal,
90
- }),
91
- );
92
- });
93
-
94
- it('should add configurations for Google Pay', () => {
95
- state.options.digitalWallet = {
96
- googlePay: {
97
- transactionData: {
98
- test: 'key',
99
- },
100
- googlePayDisplayOptions: {
101
- test: 'key',
102
- },
103
- },
104
- };
105
-
106
- const config = generateFramepayConfig({
107
- state,
108
- methodIds: ['google-pay'],
109
- });
110
-
111
- expect(config).toEqual(
112
- expect.objectContaining({
113
- transactionData: expect.objectContaining(
114
- state.options.digitalWallet.googlePay.transactionData,
115
- ),
116
- googlePay:
117
- state.options.digitalWallet.googlePay
118
- .googlePayDisplayOptions,
119
- }),
120
- );
121
- });
122
-
123
- it('should add configurations for Apple Pay', () => {
124
- state.options.digitalWallet = {
125
- applePay: {
126
- transactionData: {
127
- test: 'key',
128
- },
129
- applePayDisplayOptions: {
130
- test: 'key',
131
- },
132
- },
133
- };
134
-
135
- const config = generateFramepayConfig({
136
- state,
137
- methodIds: ['apple-pay'],
138
- });
139
-
140
- expect(config).toEqual(
141
- expect.objectContaining({
142
- transactionData: expect.objectContaining(
143
- state.options.digitalWallet.applePay.transactionData,
144
- ),
145
- applePay:
146
- state.options.digitalWallet.applePay.applePayDisplayOptions,
147
- }),
148
- );
149
- });
150
-
151
- it('should add all instrument methods together', () => {
152
- state.data.amountAndCurrency = {
153
- test: 'key',
154
- };
155
- state.options = {
156
- paymentInstruments: {
157
- paypal: {
158
- test: 'key',
159
- },
160
- },
161
- digitalWallet: {
162
- googlePay: {
163
- transactionData: {
164
- test: 'key',
165
- },
166
- googlePayDisplayOptions: {
167
- test: 'key',
168
- },
169
- },
170
- applePay: {
171
- transactionData: {
172
- test: 'key',
173
- },
174
- applePayDisplayOptions: {
175
- test: 'key',
176
- },
177
- },
178
- },
179
- };
180
-
181
- const config = generateFramepayConfig({
182
- state,
183
- methodIds: ['pay-pal-billing-agreement', 'google-pay', 'apple-pay'],
184
- });
185
-
186
- expect(config).toEqual(
187
- expect.objectContaining({
188
- transactionData: expect.objectContaining(
189
- state.data.amountAndCurrency,
190
- ),
191
- paypal: state.options.paymentInstruments.paypal,
192
- }),
193
- );
194
-
195
- expect(config).toEqual(
196
- expect.objectContaining({
197
- transactionData: expect.objectContaining(
198
- state.options.digitalWallet.googlePay.transactionData,
199
- ),
200
- googlePay:
201
- state.options.digitalWallet.googlePay
202
- .googlePayDisplayOptions,
203
- }),
204
- );
205
-
206
- expect(config).toEqual(
207
- expect.objectContaining({
208
- transactionData: expect.objectContaining(
209
- state.options.digitalWallet.applePay.transactionData,
210
- ),
211
- applePay:
212
- state.options.digitalWallet.applePay.applePayDisplayOptions,
213
- }),
214
- );
215
- });
216
- });
@@ -1,11 +0,0 @@
1
- import kebabCase from 'lodash.kebabcase';
2
- import camelCase from 'lodash.camelcase';
3
-
4
- export const getMethodData = (method) => {
5
- const METHOD_ID = kebabCase(method.feature?.name || method.method);
6
- const METHOD_TYPE = camelCase(
7
- method.feature?.name || method.method,
8
- ).replace('-', '');
9
-
10
- return { METHOD_ID, METHOD_TYPE };
11
- };
@@ -1,25 +0,0 @@
1
- import state from '../../state';
2
-
3
- export function getPaymentMethods() {
4
- const result = {
5
- expressMethods: [],
6
- methods: [],
7
- };
8
-
9
- state.data.readyToPay?.forEach((method) => {
10
- if (method.metadata.isExpressMethod) {
11
- result.expressMethods.push(method);
12
- } else {
13
- result.methods.push(method);
14
- }
15
- });
16
-
17
- if (!window.ApplePaySession) {
18
- result.expressMethods = result.expressMethods.filter(
19
- (method) => method?.feature?.name !== 'Apple Pay',
20
- );
21
- state.loader.stopLoading({ id: 'applePay-express' });
22
- }
23
-
24
- return result;
25
- }
@@ -1,41 +0,0 @@
1
- import { StorefontTestingInstance } from 'tests/mocks/storefront-mock';
2
- import { getPaymentMethods } from './get-payment-methods';
3
- import { ok, post } from 'msw-when-then';
4
- import { when } from 'tests/msw/server';
5
- import { storefrontURL } from 'tests/mocks/storefront-api-mock';
6
- import { fetchReadyToPay } from '@/storefront/ready-to-pay';
7
- import state from '@/state';
8
-
9
- it('should only return the allowed methods', async () => {
10
- StorefontTestingInstance();
11
- when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
12
- ok([
13
- {
14
- method: 'payment-card',
15
- feature: {
16
- name: 'Google Pay',
17
- merchantName: 'google-pay-merchant-name',
18
- merchantOrigin: 'google-pay-merchant-origin',
19
- },
20
- brands: ['Visa'],
21
- filters: [],
22
- },
23
- {
24
- method: 'fake-method',
25
- filters: [],
26
- },
27
- {
28
- method: 'payment-card',
29
- brands: ['Visa'],
30
- filters: [],
31
- },
32
- ]),
33
- );
34
- state.data.readyToPay = await fetchReadyToPay({});
35
-
36
- const results = getPaymentMethods();
37
-
38
- expect(results.hasOwnProperty('expressMethods')).toEqual(true);
39
- expect(results['expressMethods'].length).toEqual(1);
40
- expect(results['methods'].length).toEqual(1);
41
- });
@@ -1,223 +0,0 @@
1
- /* eslint-disable no-undef */
2
- import { collectData } from '@rebilly/risk-data-collector';
3
- import state from '../../state';
4
- import iframes from '../../state/iframes';
5
- import { getPaymentMethods } from './get-payment-methods';
6
- import { fetchData } from '../../functions/mount/fetch-data';
7
- import { mountForm } from '../form';
8
-
9
- import { mountExpressMethods } from './mount-express-methods';
10
- import { mountBumpOffer } from './mount-bump-offer';
11
- import { generateDigitalWallet } from './generate-digital-wallet';
12
- import { updateSummary } from '../summary';
13
- import { mountAmountSelector } from '../amount-selector';
14
-
15
- function getElement(id, rootElement = state.form) {
16
- return rootElement.querySelector(`[data-rebilly-instruments="${id}"]`);
17
- }
18
-
19
- const getBumpOfferElement = () => {
20
- const rootDiv = document.createElement('div');
21
- rootDiv.classList.add('rebilly-instruments-bump-offers');
22
- rootDiv.setAttribute('data-rebilly-instruments', 'bump-offer');
23
- return rootDiv;
24
- };
25
-
26
- export function hideExtraUI() {
27
- const { expressMethods } = getPaymentMethods();
28
-
29
- if (state.options?.deposit) {
30
- const linkElement = getElement('deposit-back');
31
- if (linkElement) {
32
- linkElement.style.height = '0px';
33
- linkElement.style.overflow = 'hidden';
34
- }
35
- }
36
-
37
- if (expressMethods.length) {
38
- const expressMethodsElement = getElement('express-methods');
39
- if (expressMethodsElement) {
40
- expressMethodsElement.style.height = '0px';
41
- expressMethodsElement.style.overflow = 'hidden';
42
- }
43
- }
44
-
45
- if (state.options?.bumpOffer?.length) {
46
- const bumpOfferElement = getElement('bump-offer');
47
- if (bumpOfferElement) {
48
- bumpOfferElement.style.height = '0px';
49
- bumpOfferElement.style.overflow = 'hidden';
50
- bumpOfferElement.style.marginBottom = '0px';
51
- }
52
- }
53
- }
54
-
55
- const backToAmountElement = () => {
56
- const template = `
57
- <div class="rebilly-instruments-confirmation-go-back-link" style="display: inline-block;margin-bottom: var(--rebilly-spacingM);margin-left: calc(var(--rebilly-spacingXs) * -1);">
58
- <a
59
- class="rebilly-instruments-link has-icon-left"
60
- style="display: inline-flex;color: var(--rebilly-colorPrimary);cursor: pointer;"
61
- >
62
- <svg
63
- class="rebilly-instruments-icon"
64
- style="margin-right: var(--rebilly-spacingXs);fill: var(--rebilly-colorPrimary)"
65
- viewBox="0 0 24 24"
66
- xmlns="http://www.w3.org/2000/svg"
67
- >
68
- <path
69
- d="M6.2929 11.2929l5-5c.3905-.3905 1.0237-.3905 1.4142 0 .3905.3905.3905 1.0237 0 1.4142L9.4142 11H17c.5523 0 1 .4477 1 1s-.4477 1-1 1H9.4142l3.293 3.2929c.3904.3905.3904 1.0237 0 1.4142-.3906.3905-1.0238.3905-1.4143 0l-5-5A.9969.9969 0 016 12c0-.2761.112-.5261.2929-.7071z"
70
- fill-rule="nonzero"
71
- />
72
- </svg>
73
- <span data-rebilly-i18n="deposit.goBack"></span>
74
- </a>
75
- </div>
76
- `;
77
- const rootDiv = document.createElement('div');
78
- rootDiv.setAttribute('data-rebilly-instruments', 'deposit-back');
79
- rootDiv.innerHTML += template;
80
-
81
- const link = rootDiv.querySelector('.rebilly-instruments-link');
82
- link.addEventListener('click', () => {
83
- hideExtraUI();
84
- mountAmountSelector();
85
- });
86
-
87
- return rootDiv;
88
- };
89
-
90
- const expressMethodsElement = ({ expressMethods }) => {
91
- const rootDiv = document.createElement('div');
92
- rootDiv.classList.add('rebilly-instruments-method-selector');
93
- rootDiv.setAttribute('data-rebilly-instruments', 'express-methods');
94
- rootDiv.innerHTML = `
95
- <div class="rebilly-instruments-express-methods ">
96
- <span data-rebilly-i18n="form.expressCheckout" class="rebilly-instruments-express-methods-label">Express checkout</span>
97
- <div class="rebilly-instruments-express-methods-container" data-rebilly-instruments="express-methods-container"></div>
98
- </div>
99
- <div data-rebilly-instruments="divider" class="rebilly-instruments-divider">
100
- <span class="rebilly-instruments-divider-label" data-rebilly-i18n="form.or">Or</span>
101
- </div>
102
- `;
103
- const expressMethodsContainer = getElement(
104
- 'express-methods-container',
105
- rootDiv,
106
- );
107
-
108
- const useCompactExpressInstruments =
109
- state.options.paymentInstruments.compactExpressInstruments &&
110
- expressMethods.length;
111
- if (useCompactExpressInstruments) {
112
- rootDiv.classList.add('has-express-compact');
113
- expressMethodsContainer.classList.add('is-compact');
114
- }
115
-
116
- return rootDiv;
117
- };
118
-
119
- export async function mountMethodSelector() {
120
- const contentEl = getElement('content');
121
- const formEl = getElement('form');
122
-
123
- const { expressMethods, methods } = getPaymentMethods();
124
-
125
- if (state.options?.deposit) {
126
- const existingDepositBackElement = getElement('deposit-back');
127
- if (existingDepositBackElement) {
128
- existingDepositBackElement.style.height = 'auto';
129
- } else {
130
- contentEl.insertBefore(backToAmountElement(), formEl);
131
- }
132
- }
133
-
134
- if (expressMethods.length) {
135
- const existingExpressMethodElement = getElement('express-methods');
136
- if (existingExpressMethodElement) {
137
- existingExpressMethodElement.style.height = 'auto';
138
- } else {
139
- contentEl.insertBefore(
140
- expressMethodsElement({ expressMethods }),
141
- formEl,
142
- );
143
- state.options.digitalWallet = generateDigitalWallet({
144
- expressMethods,
145
- });
146
- const container = document.querySelector(
147
- '[data-rebilly-instruments="express-methods-container"]',
148
- );
149
- mountExpressMethods({
150
- methods: expressMethods,
151
- container,
152
- });
153
- }
154
- }
155
-
156
- if (state.options?.bumpOffer?.length) {
157
- const existingExpressMethodElement = getElement('bump-offer');
158
- if (existingExpressMethodElement) {
159
- existingExpressMethodElement.style.height = 'auto';
160
- existingExpressMethodElement.style.marginBottom =
161
- 'calc(var(--rebilly-spacingM) + var(--rebilly-fontSizeS))';
162
- } else {
163
- contentEl.insertBefore(getBumpOfferElement(), formEl);
164
- const container = getElement('bump-offer');
165
- mountBumpOffer({
166
- container,
167
- });
168
- }
169
- }
170
-
171
- if (methods.length) {
172
- const iframe = iframes.form;
173
- if (!iframe) {
174
- await mountForm();
175
- }
176
-
177
- const modelSafeState = state.toModel();
178
- const model = {
179
- options: modelSafeState.options,
180
- data: modelSafeState.data,
181
- mainStyleVars: modelSafeState.mainStyleVars,
182
- };
183
-
184
- iframe?.component?.call('route', {
185
- name: 'method-switch',
186
- });
187
-
188
- iframe?.component?.call('update', model);
189
-
190
- iframe?.component?.on('choose-another-method', () => {
191
- if (state.data.isPurchase) {
192
- updateSummary();
193
- }
194
- mountMethodSelector();
195
- });
196
- } else {
197
- state.loader.stopLoading({ id: 'rebilly-instruments-form' });
198
- state.form.querySelector(
199
- '[data-rebilly-instruments="form"]',
200
- ).style.display = 'none';
201
- document
202
- .querySelectorAll('[data-rebilly-instruments="divider"]')
203
- .forEach((el) => {
204
- el.style.display = 'none';
205
- });
206
- }
207
-
208
- state.translate.translateItems();
209
- }
210
-
211
- export async function updateMethodSelector() {
212
- state.loader.startLoading({ id: 'rebilly-instruments-methods' });
213
-
214
- const { riskMetadata } = await collectData();
215
- state.data = await fetchData({ riskMetadata });
216
- state.updateModel();
217
-
218
- if (state.data.transaction && state.data.transaction?.type === 'setup') {
219
- state.options.transactionType = 'setup';
220
- }
221
-
222
- mountMethodSelector();
223
- }
@@ -1,20 +0,0 @@
1
- import { RenderMockRebillyInstruments } from 'tests/mocks/rebilly-instruments-mock';
2
- import { updateMethodSelector } from './index';
3
-
4
- describe('Methods Selector Component', () => {
5
- it('should inject the proper HTML for express methods', async () => {
6
- await RenderMockRebillyInstruments({
7
- form: '.rebilly-instruments-form',
8
- });
9
-
10
- const form = document.querySelector('.rebilly-instruments-form');
11
- expect(form).toMatchSnapshot();
12
- });
13
-
14
- it('should allow updating method selector', async () => {
15
- await RenderMockRebillyInstruments();
16
- await updateMethodSelector({
17
- mainStyleVars: 'any main style',
18
- });
19
- });
20
- });
@@ -1,120 +0,0 @@
1
- import state from '../../state';
2
- import formatCurrency from '../../utils/format-currency';
3
- import { fetchSummary } from '../../storefront/summary';
4
-
5
- function lineItem({ offer }) {
6
- const plan = state.data.plans.find((item) => item.id === offer.planId);
7
- const product = state.data.products.find(
8
- (item) => item.id === plan.productId,
9
- );
10
-
11
- const rif = (condition, template) => (condition ? template : '');
12
-
13
- function unitPrice() {
14
- const planPricing = plan.pricing.isBracket
15
- ? plan.pricing.brackets[0].price
16
- : plan.pricing.price;
17
-
18
- const basePrice = formatCurrency(planPricing, plan.currency);
19
- return plan.pricing.isBracket
20
- ? state.translate
21
- .getTranslation('form.bumpOffer.startingAt')
22
- .replace('{basePrice}', basePrice)
23
- : basePrice;
24
- }
25
-
26
- const thumbnail = (item) =>
27
- rif(
28
- item.thumbnail,
29
- `
30
- <figure class="rebilly-instruments-bump-offer-line-item-figure">
31
- <img src="${item.thumbnail}" :alt="${item.name}"/>
32
- </figure>
33
- `,
34
- );
35
-
36
- const synopsis = (item) => `
37
- <div class="rebilly-instruments-bump-offer-line-item-synopsis">
38
- <p class="rebilly-instruments-bump-offer-line-item-synopsis-title">
39
- ${item.name}
40
- </p>
41
- ${rif(
42
- item.description,
43
- `
44
- <p class="rebilly-instruments-bump-offer-line-item-synopsis-description">
45
- ${item.description}
46
- </p>
47
- `,
48
- )}
49
- </div>
50
- `;
51
-
52
- const breakdown = (item) => `
53
- <div class="rebilly-instruments-bump-offer-line-item-price-breakdown">
54
- ${rif(
55
- item.quantity,
56
- `
57
- <p class="rebilly-instruments-bump-offer-line-item-price-breakdown-quantity">
58
- ${item.quantity}
59
- </p>
60
- <svg class="rebilly-instruments-icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
61
- <path d="M12 10.5858l2.8284-2.8284c.3906-.3906 1.0237-.3906 1.4142 0 .3906.3905.3906 1.0236 0 1.4142L13.4142 12l2.8284 2.8284c.3906.3906.3906 1.0237 0 1.4142-.3905.3906-1.0236.3906-1.4142 0L12 13.4142l-2.8284 2.8284c-.3906.3906-1.0237.3906-1.4142 0-.3906-.3905-.3906-1.0236 0-1.4142L10.5858 12 7.7574 9.1716c-.3906-.3906-.3906-1.0237 0-1.4142.3905-.3906 1.0236-.3906 1.4142 0L12 10.5858z" fill-rule="nonzero"/>
62
- </svg>
63
- `,
64
- )}
65
- <p class="rebilly-instruments-bump-offer-line-item-price-breakdown-unit-price">
66
- ${item.unitPrice}
67
- </p>
68
- <div>
69
- `;
70
-
71
- const line = {
72
- ...offer,
73
- quantity: plan.pricing.isBracket ? null : offer.quantity,
74
- name: product.name,
75
- description: plan.name,
76
- unitPrice: unitPrice(),
77
- };
78
-
79
- return `
80
- <div class="rebilly-instruments-bump-offer-line-item">
81
- ${thumbnail(line)}
82
- ${synopsis(line)}
83
- ${breakdown(line)}
84
- </div>
85
- `;
86
- }
87
-
88
- export function mountBumpOffer({ container }) {
89
- container.insertAdjacentHTML(
90
- 'beforeEnd',
91
- `
92
- <label for="rebilly-instruments-bump-offer" class="rebilly-instruments-form-field-checkbox">
93
- <div class="rebilly-instruments-bump-offer-label" data-rebilly-i18n="form.bumpOffer.title">
94
- ${state.translate.getTranslation('form.bumpOffer.title')}
95
- </div>
96
- <input
97
- type="checkbox"
98
- id="rebilly-instruments-bump-offer"
99
- />
100
- <span></span>
101
- </label>
102
- `,
103
- );
104
-
105
- const checkbox = document.getElementById('rebilly-instruments-bump-offer');
106
- checkbox.addEventListener('click', async () => {
107
- state.data.acceptBumpOffer = checkbox.checked;
108
- await fetchSummary();
109
- state.updateModel();
110
- });
111
-
112
- checkbox.checked = state.data.acceptBumpOffer;
113
-
114
- state.options.bumpOffer.forEach((offer) => {
115
- const node = document.createElement('div');
116
- node.classList.add('rebilly-instruments-bump-offer');
117
- node.insertAdjacentHTML('beforeEnd', lineItem({ offer }));
118
- container.appendChild(node);
119
- });
120
- }