@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.
- package/.babelrc +24 -26
- package/CHANGELOG.md +7 -0
- package/dist/index.js +8 -8
- package/dist/index.min.js +8 -8
- package/package.json +14 -3
- package/project.json +9 -0
- package/rollup.config.mjs +21 -26
- package/src/data/options-schema/index.js +94 -78
- package/src/data/options-schema/schemas/options-schema.js +419 -411
- package/src/events/base-event.js +34 -34
- package/src/events/events.spec.js +6 -6
- package/src/events/index.js +5 -5
- package/src/functions/destroy.js +19 -19
- package/src/functions/destroy.spec.js +41 -41
- package/src/functions/mount/fetch-data.js +200 -193
- package/src/functions/mount/fetch-data.spec.js +287 -285
- package/src/functions/mount/get-lead-source-data.js +31 -31
- package/src/functions/mount/get-lead-source-data.spec.js +19 -19
- package/src/functions/mount/index.js +73 -65
- package/src/functions/mount/mount.spec.js +77 -66
- package/src/functions/mount/setup-element.js +23 -23
- package/src/functions/mount/setup-framepay-theme.js +86 -68
- package/src/functions/mount/setup-framepay.js +9 -5
- package/src/functions/mount/setup-i18n.js +15 -15
- package/src/functions/mount/setup-options.js +74 -74
- package/src/functions/mount/setup-options.spec.js +323 -287
- package/src/functions/mount/setup-storefront.js +15 -20
- package/src/functions/mount/setup-styles-vars.js +19 -22
- package/src/functions/mount/setup-user-flow.js +51 -47
- package/src/functions/on.js +5 -5
- package/src/functions/on.spec.js +60 -51
- package/src/functions/purchase.js +151 -146
- package/src/functions/purchase.spec.js +59 -56
- package/src/functions/setup.js +53 -53
- package/src/functions/setup.spec.js +88 -75
- package/src/functions/show.js +13 -14
- package/src/functions/show.spec.js +53 -53
- package/src/functions/update.js +30 -28
- package/src/functions/update.spec.js +94 -93
- package/src/i18n/en.json +32 -32
- package/src/i18n/es.json +29 -29
- package/src/i18n/i18n.spec.js +18 -18
- package/src/i18n/index.js +48 -48
- package/src/instance.js +36 -36
- package/src/instance.spec.js +29 -27
- package/src/loader/index.js +95 -70
- package/src/loader/loader.spec.js +63 -63
- package/src/state/iframes.js +21 -21
- package/src/state/index.js +56 -54
- package/src/storefront/account-and-website.js +10 -8
- package/src/storefront/account-and-website.spec.js +55 -55
- package/src/storefront/deposit-requests.js +6 -6
- package/src/storefront/fetch-plans-from-addons-bumpOffer.js +21 -19
- package/src/storefront/fetch-products-from-plans.js +52 -51
- package/src/storefront/fetch-products-from-plans.spec.js +90 -87
- package/src/storefront/index.js +56 -49
- package/src/storefront/invoices.js +15 -15
- package/src/storefront/invoices.spec.js +69 -65
- package/src/storefront/models/account-model.js +29 -32
- package/src/storefront/models/base-model.js +6 -9
- package/src/storefront/models/deposit-request-model.js +22 -13
- package/src/storefront/models/invoice-model.js +16 -16
- package/src/storefront/models/payment-metadata.js +4 -4
- package/src/storefront/models/plan-model.js +73 -64
- package/src/storefront/models/ready-to-pay-model.js +59 -59
- package/src/storefront/models/summary-model.js +43 -46
- package/src/storefront/models/transaction-model.js +11 -14
- package/src/storefront/payment-instruments.js +38 -35
- package/src/storefront/payment-instruments.spec.js +81 -62
- package/src/storefront/purchase.js +50 -44
- package/src/storefront/purchase.spec.js +40 -40
- package/src/storefront/ready-to-pay.js +75 -77
- package/src/storefront/ready-to-pay.spec.js +59 -54
- package/src/storefront/storefront.spec.js +9 -9
- package/src/storefront/summary.js +93 -67
- package/src/storefront/summary.spec.js +108 -106
- package/src/storefront/transactions.js +6 -6
- package/src/style/base/default-theme.js +928 -923
- package/src/style/base/theme.js +21 -21
- package/src/style/base/theme.spec.js +13 -13
- package/src/style/index.js +3 -3
- package/src/style/utils/border.js +40 -27
- package/src/style/utils/color-values.js +18 -18
- package/src/style/utils/minifyCss.js +6 -6
- package/src/utils/add-dom-element.js +14 -14
- package/src/utils/format-currency.js +6 -5
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +6 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +22 -22
- package/src/utils/quantity.js +26 -28
- package/src/utils/sleep.js +3 -1
- package/src/views/amount-selector.js +37 -36
- package/src/views/common/iframe/base-iframe.js +53 -52
- package/src/views/common/iframe/events/change-iframe-src-handler.js +5 -5
- package/src/views/common/iframe/events/dispatch-event-handler.js +4 -4
- package/src/views/common/iframe/events/resize-component-handler.js +8 -8
- package/src/views/common/iframe/events/show-error-handler.js +2 -2
- package/src/views/common/iframe/events/stop-loader-handler.js +8 -8
- package/src/views/common/iframe/events/update-addons-handler.js +20 -13
- package/src/views/common/iframe/events/update-coupons-handler.js +9 -9
- package/src/views/common/iframe/events/update-items-handler.js +26 -22
- package/src/views/common/iframe/modal-iframe.js +67 -56
- package/src/views/common/iframe/view-iframe.js +11 -11
- package/src/views/common/render-utilities.js +2 -2
- package/src/views/confirmation.js +33 -30
- package/src/views/errors.js +89 -79
- package/src/views/form.js +41 -37
- package/src/views/method-selector/express-methods.js +46 -46
- package/src/views/method-selector/generate-digital-wallet.js +46 -45
- package/src/views/method-selector/generate-digital-wallet.spec.js +104 -102
- package/src/views/method-selector/generate-framepay-config.js +53 -51
- package/src/views/method-selector/generate-framepay-config.spec.js +197 -173
- package/src/views/method-selector/get-method-data.js +5 -6
- package/src/views/method-selector/get-payment-methods.js +18 -16
- package/src/views/method-selector/get-payment-methods.spec.js +29 -27
- package/src/views/method-selector/index.js +154 -139
- package/src/views/method-selector/method-selector.spec.js +13 -13
- package/src/views/method-selector/mount-bump-offer.js +65 -49
- package/src/views/method-selector/mount-express-methods.js +89 -85
- package/src/views/modal.js +74 -67
- package/src/views/result.js +14 -14
- package/src/views/summary.js +25 -26
- package/tests/async-utilities.js +13 -13
- package/tests/mocks/framepay-mock.js +9 -8
- package/tests/mocks/rebilly-api-mock.js +5 -3
- package/tests/mocks/rebilly-instruments-mock.js +121 -117
- package/tests/mocks/storefront-api-mock.js +55 -48
- package/tests/mocks/storefront-mock.js +10 -14
- package/tests/msw/server.js +6 -6
- package/tests/setup-test.js +14 -16
- package/vitest.config.js +14 -14
- package/.eslintrc.js +0 -34
- 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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
44
|
+
const purchaseCompletedListener = vi.fn();
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
rebillyInstruments.on('purchase-completed', purchaseCompletedListener);
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const purchasePayload = {
|
|
49
|
+
billingAddress,
|
|
50
|
+
deliveryAddress,
|
|
51
|
+
_raw: token,
|
|
52
|
+
};
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
65
|
+
await rebillyInstruments.purchase(purchasePayload);
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
expect(spyStorefrontPurchase).toBeCalledTimes(1);
|
|
68
|
+
expect(spyStorefrontPurchase).toBeCalledWith({
|
|
69
|
+
data: expect.objectContaining(purchasePayloadParsed),
|
|
70
|
+
});
|
|
68
71
|
|
|
69
|
-
|
|
72
|
+
expect(Events.purchaseCompleted.dispatch).toBeCalledTimes(1);
|
|
70
73
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
expect(purchaseCompletedListener).toBeCalledTimes(1);
|
|
75
|
+
expect(purchaseCompletedListener).toBeCalledWith(
|
|
76
|
+
expect.objectContaining(fields),
|
|
77
|
+
);
|
|
78
|
+
await avoidUnhandledPromises();
|
|
79
|
+
});
|
|
77
80
|
});
|
package/src/functions/setup.js
CHANGED
|
@@ -4,63 +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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
...data
|
|
33
|
-
}
|
|
34
|
-
});
|
|
17
|
+
const data = {
|
|
18
|
+
...payload,
|
|
19
|
+
};
|
|
35
20
|
|
|
36
|
-
|
|
21
|
+
if (isExistingInstrument) {
|
|
22
|
+
data.paymentInstrumentId = id;
|
|
23
|
+
} else {
|
|
24
|
+
data.token = id;
|
|
25
|
+
}
|
|
37
26
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
mountModal({
|
|
44
|
-
name: 'rebilly-instruments-approval-url',
|
|
45
|
-
url: `${paymentMethodsUrl}/approval-url`,
|
|
46
|
-
model: {
|
|
47
|
-
setup: {transaction}
|
|
48
|
-
},
|
|
49
|
-
close: ({transaction: updatedTransaction = transaction}) => {
|
|
50
|
-
Events.setupCompleted.dispatch({
|
|
51
|
-
instrument,
|
|
52
|
-
transaction: updatedTransaction
|
|
53
|
-
});
|
|
54
|
-
}
|
|
27
|
+
const { instrument, transaction } = await setupPaymentInstrument({
|
|
28
|
+
data: {
|
|
29
|
+
websiteId: state.options?.websiteId,
|
|
30
|
+
...data,
|
|
31
|
+
},
|
|
55
32
|
});
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
Events.setupCompleted.dispatch({instrument, transaction});
|
|
59
|
-
}
|
|
60
33
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 });
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { instrument, transaction };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
showError(error);
|
|
64
|
+
return error;
|
|
65
|
+
}
|
|
66
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const paymentInstrumentFields = {
|
|
30
|
+
id: 'payment-instrument-id',
|
|
31
|
+
};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
const paymentInstrumentSetupFields = {
|
|
34
|
+
id: 'payment-instrument-id',
|
|
35
|
+
approvalUrl: null,
|
|
36
|
+
};
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
59
|
+
const setupCompletedListener = vi.fn();
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
rebillyInstruments.on('setup-completed', setupCompletedListener);
|
|
49
62
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const setupPayload = {
|
|
64
|
+
billingAddress,
|
|
65
|
+
deliveryAddress,
|
|
66
|
+
...options.money,
|
|
67
|
+
_raw: token,
|
|
68
|
+
};
|
|
56
69
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
rebillyInstruments.mock.data({
|
|
71
|
+
previewPurchase: {
|
|
72
|
+
currency: 'USD',
|
|
73
|
+
total: 30,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
63
76
|
|
|
64
|
-
|
|
77
|
+
await rebillyInstruments.setup(setupPayload);
|
|
65
78
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
100
|
+
expect(spyDispatchSetupCompleted).toBeCalledTimes(1);
|
|
88
101
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
});
|
package/src/functions/show.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
});
|
package/src/functions/update.js
CHANGED
|
@@ -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
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
+
const updatedOptions = merge({ ...state.options }, newOptions);
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
await destroy();
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
mount({
|
|
36
|
+
form: state.form,
|
|
37
|
+
summary: state.summary,
|
|
38
|
+
...updatedOptions,
|
|
39
|
+
});
|
|
38
40
|
}
|