@rebilly/instruments 3.23.0-beta.0 → 3.23.0-beta.1

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 (54) hide show
  1. package/dist/index.js +17 -10
  2. package/dist/index.min.js +56 -49
  3. package/package.json +1 -3
  4. package/src/functions/destroy.js +9 -11
  5. package/src/functions/mount/fetch-data.js +16 -14
  6. package/src/functions/mount/fetch-data.spec.js +93 -140
  7. package/src/functions/mount/index.js +10 -9
  8. package/src/functions/mount/mount.spec.js +7 -5
  9. package/src/functions/mount/setup-framepay-theme.js +1 -2
  10. package/src/functions/mount/setup-framepay.js +1 -3
  11. package/src/functions/mount/setup-i18n.js +2 -4
  12. package/src/functions/mount/setup-options.js +4 -6
  13. package/src/functions/on.spec.js +2 -3
  14. package/src/functions/purchase.js +5 -16
  15. package/src/functions/setup.js +4 -3
  16. package/src/functions/show.js +6 -7
  17. package/src/functions/show.spec.js +7 -11
  18. package/src/functions/update.js +3 -3
  19. package/src/functions/update.spec.js +3 -4
  20. package/src/instance.js +31 -11
  21. package/src/storefront/account-and-website.js +2 -3
  22. package/src/storefront/{fetch-plans-from-addons-bumpOffer.js → fetch-plans-from-addons-bumpOffers.js} +4 -5
  23. package/src/storefront/fetch-products-from-plans.js +4 -5
  24. package/src/storefront/index.js +4 -3
  25. package/src/storefront/invoices.js +4 -6
  26. package/src/storefront/payment-instruments.js +4 -5
  27. package/src/storefront/purchase.js +4 -5
  28. package/src/storefront/ready-to-pay.js +2 -2
  29. package/src/storefront/summary.js +3 -8
  30. package/src/storefront/transactions.js +2 -3
  31. package/src/style/base/index.js +0 -243
  32. package/src/views/common/iframe/base-iframe.js +2 -0
  33. package/src/views/common/iframe/events/update-addons-handler.js +13 -8
  34. package/src/views/common/iframe/events/update-coupons-handler.js +11 -5
  35. package/src/views/confirmation.js +6 -16
  36. package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +1 -182
  37. package/src/views/method-selector/generate-digital-wallet.js +1 -2
  38. package/src/views/method-selector/generate-digital-wallet.spec.js +37 -32
  39. package/src/views/method-selector/generate-framepay-config.js +1 -1
  40. package/src/views/method-selector/generate-framepay-config.spec.js +12 -9
  41. package/src/views/method-selector/get-payment-methods.js +1 -3
  42. package/src/views/method-selector/get-payment-methods.spec.js +34 -25
  43. package/src/views/method-selector/index.js +20 -39
  44. package/src/views/method-selector/method-selector.spec.js +109 -9
  45. package/src/views/method-selector/mount-express-methods.js +2 -1
  46. package/src/views/modal.js +3 -3
  47. package/src/views/result.js +5 -7
  48. package/src/views/summary.js +16 -12
  49. package/tests/mocks/rebilly-instruments-mock.js +19 -17
  50. package/tests/mocks/storefront-mock.js +9 -10
  51. package/tests/setup-jest.js +0 -2
  52. package/src/state/iframes.js +0 -23
  53. package/src/state/index.js +0 -61
  54. package/src/views/method-selector/mount-bump-offer.js +0 -99
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rebilly/instruments",
3
- "version": "3.23.0-beta.0",
3
+ "version": "3.23.0-beta.1",
4
4
  "author": "Rebilly",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -17,8 +17,6 @@
17
17
  "@babel/core": "^7.14.6",
18
18
  "@babel/preset-env": "^7.14.7",
19
19
  "@rebilly/risk-data-collector": "^2.3.0",
20
- "@vue-reactivity/watch": "^0.2.0",
21
- "@vue/reactivity": "^3.2.39",
22
20
  "jwt-decode": "^3.1.2",
23
21
  "lodash.camelcase": "^4.3.0",
24
22
  "lodash.isequal": "^4.5.0",
@@ -1,23 +1,21 @@
1
1
  import { cancellation } from 'rebilly-js-sdk';
2
2
  import { registeredListeners } from '../events/base-event';
3
3
  import { sleep } from '../utils';
4
- import state from '../state';
5
- import iframes from '../state/iframes';
6
4
 
7
- export async function destroy() {
5
+ export async function destroy({ state }) {
8
6
  // wait to allow for cancellation to catch any pending api requests
9
7
  const sleepMilliseconds = 1000;
10
8
  await sleep(sleepMilliseconds);
11
-
12
- Object.keys(iframes).forEach(frame => {
13
- if (iframes.hasFrame(frame)) {
14
- iframes[frame].destroy();
15
- iframes[frame] = null;
16
- }
17
- });
9
+
10
+ Object.values(state.iframeComponents)
11
+ .forEach(iframe => iframe?.destroy())
18
12
 
19
13
  registeredListeners.removeAll(document);
20
-
14
+
15
+ state.iframeComponents = {
16
+ summary: null,
17
+ form: null,
18
+ };
21
19
  state.hasMounted = false;
22
20
 
23
21
  if (state.summary) {
@@ -1,7 +1,6 @@
1
1
  import { collectData } from '@rebilly/risk-data-collector';
2
- import state from '../../state';
3
2
  import { fetchProductsFromPlans } from '../../storefront/fetch-products-from-plans';
4
- import { fetchPlansFromAddonsBumpOffer } from '../../storefront/fetch-plans-from-addons-bumpOffer';
3
+ import { fetchPlansFromAddonsBumpOffers } from '../../storefront/fetch-plans-from-addons-bumpOffers';
5
4
  import { fetchReadyToPay } from '../../storefront/ready-to-pay';
6
5
  import { fetchSummary } from '../../storefront/summary';
7
6
  import { fetchInvoiceAndProducts as FetchInvoiceAndProducts } from '../../storefront/invoices';
@@ -11,6 +10,7 @@ import { fetchPaymentInstrument as FetchInstruments } from '../../storefront/pay
11
10
 
12
11
  export class DataInstance {
13
12
  constructor({
13
+ state = {},
14
14
  ...fields
15
15
  } = {}) {
16
16
  Object.entries({
@@ -23,14 +23,12 @@ export class DataInstance {
23
23
  this.money = state.options?.money || null;
24
24
  this.couponIds = [];
25
25
  this.addons = [];
26
- this.acceptBumpOffer = false;
27
26
  }
28
27
 
29
28
  get amountAndCurrency() {
30
29
  let currency;
31
30
  let amount;
32
31
  let amountDue;
33
-
34
32
  if (this.previewPurchase) {
35
33
  currency = this.previewPurchase.currency;
36
34
  amount = this.previewPurchase.total;
@@ -120,6 +118,7 @@ export class DataInstance {
120
118
  }
121
119
 
122
120
  export async function fetchData({
121
+ state = null,
123
122
  riskMetadata = null,
124
123
 
125
124
  // Dependency injectable functions
@@ -127,9 +126,11 @@ export async function fetchData({
127
126
  fetchTransaction = FetchTransaction,
128
127
  fetchAccountAndWebsite = FetchAccountAndWebsite,
129
128
  fetchInstruments = FetchInstruments
130
- } = {}) {
129
+ }) {
131
130
  try {
132
- state.data = new DataInstance();
131
+ state.data = new DataInstance({
132
+ state
133
+ });
133
134
 
134
135
  let readyToPayPromise = Promise.resolve(null);
135
136
 
@@ -152,12 +153,12 @@ export async function fetchData({
152
153
  }
153
154
 
154
155
  let productsPromise;
155
- const invoiceId = state.options?.invoiceId || state.data?.transaction?.invoiceId;
156
- if (invoiceId) {
156
+ if (state.options?.invoiceId || state.data?.transaction?.hasInvoice) {
157
157
  const { invoice, products } = await fetchInvoiceAndProducts({
158
158
  data: {
159
- id: invoiceId
160
- }
159
+ id: state.options?.invoiceId || state.data?.transaction?.invoiceId
160
+ },
161
+ state,
161
162
  });
162
163
  productsPromise = Promise.resolve(products);
163
164
  state.data.invoice = invoice;
@@ -169,17 +170,17 @@ export async function fetchData({
169
170
  }
170
171
 
171
172
  const previewPurchasePromise = state.options.items ?
172
- fetchSummary() : null;
173
+ fetchSummary({ state }) : null;
173
174
 
174
175
  if (!state.options?.jwt) {
175
- // There is no invoice, only pla ns through the static options,
176
+ // There is no invoice, only plans through the static options,
176
177
  // so we should fetch the products from the provided plan names.
177
178
  productsPromise = fetchProductsFromPlans({ state });
178
179
  }
179
180
 
180
181
  let plansPromise = new Promise((resolve) => resolve([]));
181
- if (state.options?.addons || state.options?.bumpOffer) {
182
- plansPromise = fetchPlansFromAddonsBumpOffer({ state });
182
+ if (state.options?.addons || state.options?.bumpOffers) {
183
+ plansPromise = fetchPlansFromAddonsBumpOffers({ state });
183
184
  }
184
185
 
185
186
  const [
@@ -197,6 +198,7 @@ export async function fetchData({
197
198
  ]);
198
199
 
199
200
  return new DataInstance({
201
+ state,
200
202
  readyToPay,
201
203
  previewPurchase,
202
204
  products,
@@ -3,16 +3,17 @@ import { fetchData, DataInstance } from './fetch-data';
3
3
  import TransactionModel from '../../storefront/models/transaction-model';
4
4
 
5
5
  describe('fetchData function', () => {
6
- it ('Should use correct invoice id for invoiceId', async () => {
6
+ it('Should use correct invoice id for invoiceId', async () => {
7
7
  const mockFetchInvoiceAndProducts = jest.fn();
8
8
  const invoiceId = 'test-invoice-id';
9
- StorefontTestingInstance({
9
+ const state = new StorefontTestingInstance({
10
10
  options: {
11
11
  invoiceId
12
12
  }
13
- });
13
+ })
14
14
 
15
15
  await fetchData({
16
+ state,
16
17
  fetchInvoiceAndProducts: mockFetchInvoiceAndProducts
17
18
  });
18
19
 
@@ -26,10 +27,11 @@ describe('fetchData function', () => {
26
27
  );
27
28
  });
28
29
 
29
- it ('Should use correct invoice id for transaction with invoiceIds', async () => {
30
+ it('Should use correct invoice id for transaction with invoiceIds', async () => {
30
31
  const mockFetchInvoiceAndProducts = jest.fn();
31
32
  const invoiceId = 'test-invoice-id';
32
- StorefontTestingInstance({
33
+ const state = new StorefontTestingInstance({
34
+ options: {},
33
35
  data: {
34
36
  transaction: new TransactionModel({
35
37
  invoiceIds: [invoiceId]
@@ -38,6 +40,7 @@ describe('fetchData function', () => {
38
40
  });
39
41
 
40
42
  await fetchData({
43
+ state,
41
44
  fetchInvoiceAndProducts: mockFetchInvoiceAndProducts
42
45
  });
43
46
 
@@ -51,18 +54,19 @@ describe('fetchData function', () => {
51
54
  );
52
55
  });
53
56
 
54
- it ('Should not fetch invoice for transaction with no invoice Ids', async () => {
57
+ it('Should not fetch invoice for transaction with no invoice Ids', async () => {
55
58
  const mockFetchInvoiceAndProducts = jest.fn();
56
- StorefontTestingInstance({
59
+ const invoiceState = {
57
60
  options: {},
58
61
  data: {
59
62
  transaction: new TransactionModel({
60
63
  invoiceIds: []
61
64
  }),
62
65
  }
63
- });
66
+ }
64
67
 
65
68
  fetchData({
69
+ state: invoiceState,
66
70
  fetchInvoiceAndProducts: mockFetchInvoiceAndProducts
67
71
  });
68
72
 
@@ -70,28 +74,29 @@ describe('fetchData function', () => {
70
74
 
71
75
  });
72
76
 
73
- it ('Should fetch account when JWT is supplied', async () => {
77
+ it('Should fetch account when JWT is supplied', async () => {
74
78
  const mockFetchAccountAndWebsite = jest.fn();
75
- StorefontTestingInstance({
79
+ const accountState = {
76
80
  options: {
77
81
  jwt: 'TEST_JWT'
78
82
  }
79
- });
83
+ }
80
84
 
81
85
  await fetchData({
86
+ state: accountState,
82
87
  fetchAccountAndWebsite: mockFetchAccountAndWebsite,
83
88
  });
84
89
 
85
90
  expect(mockFetchAccountAndWebsite).toBeCalledTimes(1);
86
91
  });
87
92
 
88
- it ('Should not fetch account when there JWT is not supplied', async () => {
93
+ it('Should not fetch account when there JWT is not supplied', async () => {
89
94
  const mockFetchAccountAndWebsite = jest.fn();
90
- StorefontTestingInstance({
91
- options: {}
92
- });
93
95
 
94
96
  await fetchData({
97
+ state: {
98
+ options: {}
99
+ },
95
100
  fetchAccountAndWebsite: mockFetchAccountAndWebsite,
96
101
  });
97
102
 
@@ -100,169 +105,117 @@ describe('fetchData function', () => {
100
105
  });
101
106
 
102
107
  describe('DataInstance', () => {
103
- describe('Determining amountAndCurrency', () => {
104
- it ('should use money option', () => {
105
- const expectedAmountAndCurrency = {
106
- amount: 10,
107
- currency: 'USD'
108
- }
109
- StorefontTestingInstance({
108
+ it ('Should correctly determine amountAndCurrency', () => {
109
+ const expectedAmountAndCurrency = {
110
+ amount: 10,
111
+ currency: 'USD'
112
+ }
113
+ let fetchedData = new DataInstance({
114
+ state: {
110
115
  options: {
111
- money: expectedAmountAndCurrency
116
+ money: {
117
+ ...expectedAmountAndCurrency
118
+ }
112
119
  }
113
- });
114
- const fetchedData = new DataInstance();
115
-
116
- expect(fetchedData.amountAndCurrency).toEqual(expectedAmountAndCurrency);
120
+ }
117
121
  });
122
+ expect(fetchedData.amountAndCurrency).toEqual(
123
+ expect.objectContaining(expectedAmountAndCurrency)
124
+ );
118
125
 
119
- it ('should use preview Purchase', () => {
120
- const expectedAmountAndCurrency = {
121
- amount: 10,
122
- currency: 'USD'
126
+ fetchedData = new DataInstance({
127
+ previewPurchase: {
128
+ total: expectedAmountAndCurrency.amount,
129
+ currency: expectedAmountAndCurrency.currency
123
130
  }
124
- StorefontTestingInstance();
125
-
126
- const fetchedData = new DataInstance({
127
- previewPurchase: {
128
- total: expectedAmountAndCurrency.amount,
129
- currency: expectedAmountAndCurrency.currency
130
- }
131
- });
132
- expect(fetchedData.amountAndCurrency).toEqual(
133
- expect.objectContaining(expectedAmountAndCurrency)
134
- );
135
131
  });
132
+ expect(fetchedData.amountAndCurrency).toEqual(
133
+ expect.objectContaining(expectedAmountAndCurrency)
134
+ );
136
135
 
137
- it ('should use invoice', () => {
138
- const expectedAmountAndCurrency = {
139
- amount: 10,
140
- currency: 'USD'
136
+ fetchedData = new DataInstance({
137
+ invoice: {
138
+ ...expectedAmountAndCurrency
141
139
  }
142
- StorefontTestingInstance();
143
-
144
- const fetchedData = new DataInstance({
145
- invoice: {
146
- ...expectedAmountAndCurrency
147
- }
148
- });
149
- expect(fetchedData.amountAndCurrency).toEqual(
150
- expect.objectContaining(expectedAmountAndCurrency)
151
- );
152
140
  });
141
+ expect(fetchedData.amountAndCurrency).toEqual(
142
+ expect.objectContaining(expectedAmountAndCurrency)
143
+ );
153
144
 
154
- it ('should use transaction', () => {
155
- const expectedAmountAndCurrency = {
156
- amount: 10,
157
- currency: 'USD'
145
+ fetchedData = new DataInstance({
146
+ transaction: {
147
+ ...expectedAmountAndCurrency
158
148
  }
159
- StorefontTestingInstance();
160
-
161
- const fetchedData = new DataInstance({
162
- transaction: {
163
- ...expectedAmountAndCurrency
164
- }
165
- });
166
- expect(fetchedData.amountAndCurrency).toEqual(
167
- expect.objectContaining(expectedAmountAndCurrency)
168
- );
169
149
  });
150
+ expect(fetchedData.amountAndCurrency).toEqual(
151
+ expect.objectContaining(expectedAmountAndCurrency)
152
+ );
170
153
 
171
- it ('should handle empty value', () => {
172
- StorefontTestingInstance();
173
-
174
- const fetchedData = new DataInstance();
175
- expect(fetchedData.amountAndCurrency).toEqual(
176
- expect.objectContaining({
177
- amount: undefined,
178
- currency: undefined
179
- })
180
- );
181
- })
154
+ fetchedData = new DataInstance();
155
+ expect(fetchedData.amountAndCurrency).toEqual(
156
+ expect.objectContaining({
157
+ amount: undefined,
158
+ currency: undefined
159
+ })
160
+ );
182
161
  });
183
162
 
184
- describe('isPayment', () => {
185
- it ('money is truthy', () => {
186
- StorefontTestingInstance({
163
+ it ('Should correctly determine isPayment', () => {
164
+ let fetchedData = new DataInstance({
165
+ state: {
187
166
  options: {
188
167
  money: true
189
168
  }
190
- });
191
- const fetchedData = new DataInstance();
192
- expect(fetchedData.isPayment).toBeTruthy();
169
+ }
193
170
  });
171
+ expect(fetchedData.isPayment).toBeTruthy();
194
172
 
195
- it ('invoice is truthy', () => {
196
- StorefontTestingInstance();
197
- const fetchedData = new DataInstance({
198
- invoice: true
199
- });
200
- expect(fetchedData.isPayment).toBeTruthy();
173
+ fetchedData = new DataInstance({
174
+ invoice: true
201
175
  });
176
+ expect(fetchedData.isPayment).toBeTruthy();
202
177
 
203
- it ('transaction is truthy', () => {
204
- StorefontTestingInstance();
205
- const fetchedData = new DataInstance({
206
- transaction: true
207
- });
208
- expect(fetchedData.isPayment).toBeTruthy();
178
+ fetchedData = new DataInstance({
179
+ transaction: true
209
180
  });
181
+ expect(fetchedData.isPayment).toBeTruthy();
210
182
 
211
- it ('previewPurchase is falsy', () => {
212
- StorefontTestingInstance();
213
- const fetchedData = new DataInstance({
214
- previewPurchase: true
215
- });
216
- expect(fetchedData.isPayment).toBeFalsy();
183
+ fetchedData = new DataInstance({
184
+ previewPurchase: true
217
185
  });
186
+ expect(fetchedData.isPayment).toBeFalsy();
218
187
 
219
- it ('empty is falsy', () => {
220
- StorefontTestingInstance();
221
- const fetchedData = new DataInstance({});
222
- expect(fetchedData.isPayment).toBeFalsy();
223
- });
188
+ fetchedData = new DataInstance({});
189
+ expect(fetchedData.isPayment).toBeFalsy();
224
190
  });
225
191
 
226
- describe('isPurchase', () => {
227
- it ('previewPurchase is truthy', () => {
228
- StorefontTestingInstance();
229
- const fetchedData = new DataInstance({
230
- previewPurchase: true
231
- });
232
- expect(fetchedData.isPurchase).toBeTruthy();
192
+ it ('Should correctly determine isPurchase', () => {
193
+ let fetchedData = new DataInstance({
194
+ previewPurchase: true
233
195
  });
234
-
235
- it ('money is falsy', () => {
236
- StorefontTestingInstance({
196
+ expect(fetchedData.isPurchase).toBeTruthy();
197
+
198
+ fetchedData = new DataInstance({
199
+ state: {
237
200
  options: {
238
201
  money: true
239
202
  }
240
- });
241
- const fetchedData = new DataInstance();
242
- expect(fetchedData.isPurchase).toBeFalsy();
203
+ }
243
204
  });
205
+ expect(fetchedData.isPurchase).toBeFalsy();
244
206
 
245
- it ('invoice is falsy', () => {
246
- StorefontTestingInstance();
247
- const fetchedData = new DataInstance({
248
- invoice: true
249
- });
250
- expect(fetchedData.isPurchase).toBeFalsy();
207
+ fetchedData = new DataInstance({
208
+ invoice: true
251
209
  });
210
+ expect(fetchedData.isPurchase).toBeFalsy();
252
211
 
253
- it ('transaction is falsy', () => {
254
- StorefontTestingInstance();
255
- const fetchedData = new DataInstance({
256
- transaction: true
257
- });
258
- expect(fetchedData.isPurchase).toBeFalsy();
212
+ fetchedData = new DataInstance({
213
+ transaction: true
259
214
  });
215
+ expect(fetchedData.isPurchase).toBeFalsy();
260
216
 
261
- it ('empty is falsy', () => {
262
- StorefontTestingInstance();
263
- const fetchedData = new DataInstance({});
264
- expect(fetchedData.isPurchase).toBeFalsy();
265
- });
217
+ fetchedData = new DataInstance({});
218
+ expect(fetchedData.isPurchase).toBeFalsy();
266
219
  });
267
220
 
268
221
  it ('Should get summaryItems', () => {
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable max-len */
2
- import state from '../../state';
3
2
  import { mountSummary } from '../../views/summary';
4
3
  import { mountMethodSelector } from '../../views/method-selector';
5
4
  import { fetchData } from './fetch-data';
@@ -65,6 +64,7 @@ import { showError } from '../../views/errors';
65
64
  /**
66
65
  * Mount library with configurations.
67
66
  * @param {object} options - The options object
67
+ * @param {object} options.state - Global state
68
68
  * @param {function} options.setupFramepayInstance - Helper for adding FramePay scripts to the DOM
69
69
  * @param {string | HTMLElement} options.form - The CSS class or HTML element were the form will be mounted.
70
70
  * @param {string | HTMLElement} options.summary - The CSS class or HTML element were the summary will be mounted.
@@ -77,6 +77,7 @@ import { showError } from '../../views/errors';
77
77
  * @param {string} options.locale - default: auto. Language to render component text
78
78
  */
79
79
  export async function mount({
80
+ state,
80
81
  setupFramepay = setupFramepayInstance,
81
82
  ...options
82
83
  } = {}) {
@@ -98,22 +99,22 @@ export async function mount({
98
99
  state.options = setupOptions({ options });
99
100
  state.storefront = setupStorefront({ options });
100
101
  state.mainStyleVars = setupStylesVars({ options });
101
- state.options.themeFramepay = setupFramepayTheme({ options });
102
+ state.options.themeFramepay = setupFramepayTheme({ state, options });
102
103
 
103
104
  // Setup loader
104
105
  state.loader.addDOMElement({ el: state.form });
105
106
  state.loader.addDOMElement({ section: 'summary', el: state.summary });
106
- state.loader.startLoading({ section: 'summary', id: 'rebilly-instruments-summary' });
107
- state.loader.startLoading({ id: 'rebilly-instruments-form' });
107
+ state.loader.startLoading({ state, section: 'summary', id: 'rebilly-instruments-summary' });
108
+ state.loader.startLoading({ state, id: 'rebilly-instruments-form' });
108
109
 
109
110
  const [data] = await Promise.all([
110
- fetchData(),
111
- setupFramepay()
111
+ fetchData({ state }),
112
+ setupFramepay(state)
112
113
  ]);
113
114
  state.data = data;
114
115
  Events.dataReady.dispatch(state.data);
115
116
 
116
- state.i18n = setupI18n();
117
+ state.i18n = setupI18n({ state });
117
118
 
118
119
  // Update state options from data
119
120
  if ((!state.options.websiteId) && state.data.transaction?.websiteId) {
@@ -127,10 +128,10 @@ export async function mount({
127
128
 
128
129
  // Mount content
129
130
  if (state.form) {
130
- mountMethodSelector();
131
+ mountMethodSelector({ state });
131
132
  }
132
133
  if (state.summary) {
133
- mountSummary();
134
+ mountSummary({ state });
134
135
  }
135
136
  state.i18n({state});
136
137
  state.hasMounted = true;
@@ -1,5 +1,4 @@
1
1
  import {RenderMockRebillyInstruments} from 'tests/mocks/rebilly-instruments-mock';
2
- import { sleep } from '@/utils';
3
2
 
4
3
  describe('RebillyInstruments instance', () => {
5
4
  it('should inject HTML to the merchant\'s website', async () => {
@@ -29,13 +28,16 @@ describe('RebillyInstruments instance', () => {
29
28
  },
30
29
  };
31
30
  await RenderMockRebillyInstruments(options);
32
-
33
- const sleepMilliseconds = 1000;
34
- await sleep(sleepMilliseconds);
31
+
32
+ await new Promise((resolve) => {
33
+ setTimeout(() => {
34
+ resolve();
35
+ }, 100);
36
+ })
35
37
 
36
38
  // Mounts form and summary
37
39
  const summarySelector = document.querySelector('.summary-selector');
38
- expect(summarySelector.innerHTML).toContain('<iframe name="rebilly-instruments-summary" class="rebilly-instruments-iframe" loading="lazy" allow="payment" src="https://forms.test.rebilly.dev/summary"></iframe>');
40
+ expect(summarySelector.innerHTML).toContain('<iframe name="rebilly-instruments-summary" class="rebilly-instruments-iframe" loading="lazy" allow="payment" src="https://forms.local.rebilly.dev:3000/summary"></iframe>');
39
41
 
40
42
  // Theme config overrides initial styles
41
43
  const STYLE_VARS = document.querySelectorAll('style[type="text/css"]')[0];
@@ -1,5 +1,3 @@
1
- import state from '../../state';
2
-
3
1
  function processCSS(rawCss) {
4
2
  const cssMap = {};
5
3
  [...rawCss.matchAll(/(--rebilly.*(?=:))[:\s](.*(?=;))/g)]
@@ -46,6 +44,7 @@ const getStyleProps = (obj, particle = '') => {
46
44
  }
47
45
 
48
46
  export default ({
47
+ state,
49
48
  options = {}
50
49
  }) => {
51
50
  const fullCss = `
@@ -1,6 +1,4 @@
1
- import state from '../../state';
2
-
3
- export default async function setupFramepay () {
1
+ export default async function setupFramepay (state = {}) {
4
2
  const {_dev} = state.options || {};
5
3
  const urls = {
6
4
  script: _dev?.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js',
@@ -1,11 +1,9 @@
1
- import state from '../../state';
2
-
3
- const triggerTranslations = () => {
1
+ const triggerTranslations = ({state}) => {
4
2
  state.translate.init(state.options.locale, state.options.i18n);
5
3
  state.translate.translateItems();
6
4
  }
7
5
 
8
- export default () => {
6
+ export default ({state = {}}) => {
9
7
  if (
10
8
  state.options.locale === 'auto' &&
11
9
  state.data.riskMetadata?.browserData?.language
@@ -8,7 +8,7 @@ export const defaults = {
8
8
  labels: 'stacked'
9
9
  },
10
10
  addons: [],
11
- bumpOffer: [],
11
+ bumpOffers: [],
12
12
  paymentInstruments: {
13
13
  address: {
14
14
  name: 'default',
@@ -82,6 +82,7 @@ export function validateOptions(options) {
82
82
  export default ({
83
83
  options = {}
84
84
  } = {}) => {
85
+
85
86
  const sanitizedOptions = sanitizeOptions(options)
86
87
 
87
88
  validateOptions(sanitizedOptions);
@@ -137,6 +138,7 @@ export default ({
137
138
  // Add optional key's
138
139
  [
139
140
  'items',
141
+ 'bumpOffers',
140
142
  'money',
141
143
  'invoiceId',
142
144
  'transactionId',
@@ -148,15 +150,11 @@ export default ({
148
150
  }
149
151
  });
150
152
 
151
- // only add "addons" or "bumpOffer" if items are available
153
+ // only add "addons" if items are available
152
154
  if (combinedOptions.items) {
153
155
  if (options.addons) {
154
156
  combinedOptions.addons = options.addons;
155
157
  }
156
-
157
- if (options.bumpOffer) {
158
- combinedOptions.bumpOffer = options.bumpOffer;
159
- }
160
158
  }
161
159
 
162
160
  return combinedOptions;