@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
|
@@ -6,70 +6,75 @@ import { fetchReadyToPay } from './ready-to-pay';
|
|
|
6
6
|
import ReadyToPayModel from './models/ready-to-pay-model';
|
|
7
7
|
import { expectConfigurationError } from 'tests/async-utilities';
|
|
8
8
|
import PaymentMetadataModel from './models/payment-metadata';
|
|
9
|
-
import { paymentMethods } from '@rebilly/api-metadata'
|
|
9
|
+
import { paymentMethods } from '@rebilly/api-metadata';
|
|
10
10
|
|
|
11
11
|
describe('Storefront API Ready to Pay', () => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
12
|
+
it('can fetch ready to pay', async () => {
|
|
13
|
+
const readyToPayPayload = [
|
|
14
|
+
{
|
|
15
|
+
method: 'payment-card',
|
|
16
|
+
feature: null,
|
|
17
|
+
brands: ['Visa'],
|
|
18
|
+
filters: [],
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
const options = {
|
|
22
|
+
websiteId: 'test-website-id',
|
|
23
|
+
items: [
|
|
24
|
+
{
|
|
25
|
+
planId: 'test-plan-id',
|
|
26
|
+
quantity: 1,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
const paymentCardMetadata = [...paymentMethods].find(
|
|
32
|
+
(method) => method.apiName === 'payment-card',
|
|
33
|
+
);
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
36
|
+
ok(readyToPayPayload),
|
|
37
|
+
);
|
|
36
38
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const instance = StorefontTestingInstance({
|
|
40
|
+
options,
|
|
41
|
+
});
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
vi.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
const riskMetadata = null;
|
|
46
|
+
const response = await fetchReadyToPay({
|
|
47
|
+
state: instance,
|
|
48
|
+
riskMetadata,
|
|
49
|
+
});
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
52
|
+
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
53
|
+
data: expect.objectContaining({
|
|
54
|
+
items: options.items,
|
|
55
|
+
websiteId: options.websiteId,
|
|
56
|
+
riskMetadata: expect.anything(),
|
|
57
|
+
}),
|
|
58
|
+
});
|
|
59
|
+
expect(response).toBeInstanceOf(Array);
|
|
60
|
+
expect(response[0]).toBeInstanceOf(ReadyToPayModel);
|
|
61
|
+
expect(response).toEqual([
|
|
62
|
+
new ReadyToPayModel({
|
|
63
|
+
index: 0,
|
|
64
|
+
...readyToPayPayload[0],
|
|
65
|
+
metadata: new PaymentMetadataModel(paymentCardMetadata),
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
53
68
|
});
|
|
54
|
-
expect(response).toBeInstanceOf(Array);
|
|
55
|
-
expect(response[0]).toBeInstanceOf(ReadyToPayModel);
|
|
56
|
-
expect(response).toEqual([
|
|
57
|
-
new ReadyToPayModel({
|
|
58
|
-
index: 0,
|
|
59
|
-
...readyToPayPayload[0],
|
|
60
|
-
metadata: new PaymentMetadataModel(paymentCardMetadata),
|
|
61
|
-
})
|
|
62
|
-
]);
|
|
63
|
-
});
|
|
64
69
|
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
it('should throw errors with no options', async () => {
|
|
71
|
+
const riskMetadata = null;
|
|
67
72
|
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
const noConfigOrOptionsInstance = new StorefontTestingInstance({
|
|
74
|
+
options: null,
|
|
75
|
+
});
|
|
76
|
+
await expectConfigurationError(
|
|
77
|
+
fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance }),
|
|
78
|
+
);
|
|
70
79
|
});
|
|
71
|
-
await expectConfigurationError(
|
|
72
|
-
fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance })
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
80
|
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { MockStorefront } from 'tests/mocks/storefront-mock';
|
|
2
2
|
|
|
3
3
|
describe('Storefront application programming interface', () => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
it('can create rebilly-js-sdk instance', () => {
|
|
5
|
+
const storefront = MockStorefront();
|
|
6
|
+
expect(storefront).toHaveProperty('setPublishableKey');
|
|
7
|
+
});
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
it('has required endpoints', () => {
|
|
10
|
+
const storefront = MockStorefront();
|
|
11
|
+
expect(storefront).toHaveProperty('purchase');
|
|
12
|
+
expect(storefront.purchase).toHaveProperty('readyToPay');
|
|
13
|
+
});
|
|
14
14
|
});
|
|
@@ -2,87 +2,113 @@ import cloneDeep from 'lodash.clonedeep';
|
|
|
2
2
|
import state from '../state';
|
|
3
3
|
import SummaryModel from './models/summary-model';
|
|
4
4
|
import { Endpoint } from './index';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
mapItemsQuantities,
|
|
7
|
+
createQuantitiesMap,
|
|
8
|
+
updateItemQuantityFromMap,
|
|
9
|
+
} from '../utils/quantity';
|
|
6
10
|
|
|
7
11
|
export async function fetchSummary({ data = null } = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
return Endpoint(async () => {
|
|
13
|
+
const items = state.options?.items;
|
|
14
|
+
const websiteId = state.options?.websiteId || null;
|
|
15
|
+
const bumpOfferProductsIds =
|
|
16
|
+
state.options?.bumpOffer?.map(({ planId }) => planId) || [];
|
|
12
17
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
const payload = {
|
|
19
|
+
data: {
|
|
20
|
+
websiteId,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
const isBumpOfferSummary = () =>
|
|
25
|
+
state.data.summaryLineItems.every((item) =>
|
|
26
|
+
bumpOfferProductsIds.includes(item.planId),
|
|
27
|
+
);
|
|
28
|
+
if (!isBumpOfferSummary() && !state.data.acceptBumpOffer) {
|
|
29
|
+
payload.data.items = mapItemsQuantities(
|
|
30
|
+
state.data.summaryLineItems,
|
|
31
|
+
);
|
|
32
|
+
} else if (items) {
|
|
33
|
+
if (state.data.acceptBumpOffer) {
|
|
34
|
+
payload.data.items = state.options.bumpOffer;
|
|
35
|
+
} else {
|
|
36
|
+
payload.data.items = mapItemsQuantities(items);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
payload.data.items = mapItemsQuantities(
|
|
40
|
+
state.data.summaryLineItems,
|
|
41
|
+
);
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
43
|
+
if (state.data?.addons.length > 0) {
|
|
44
|
+
payload.data.items = payload.data.items.concat(
|
|
45
|
+
state.data.addons.map(mapItemsQuantities),
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
37
49
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
if (
|
|
51
|
+
!state.data.acceptBumpOffer &&
|
|
52
|
+
state.data?.previewPurchase?.addonLineItems?.length > 0
|
|
53
|
+
) {
|
|
54
|
+
payload.data.items = payload.data.items.concat(
|
|
55
|
+
state.data.previewPurchase.addonLineItems,
|
|
56
|
+
);
|
|
57
|
+
}
|
|
41
58
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
59
|
+
if (state.data?.amountAndCurrency) {
|
|
60
|
+
payload.data = {
|
|
61
|
+
...payload.data,
|
|
62
|
+
...state.data.amountAndCurrency,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
48
65
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
66
|
+
if (data?.billingAddress) {
|
|
67
|
+
payload.data.billingAddress = data.billingAddress;
|
|
68
|
+
}
|
|
52
69
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
if (data?.deliveryAddress) {
|
|
71
|
+
payload.data.deliveryAddress = data.deliveryAddress;
|
|
72
|
+
}
|
|
56
73
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
if (state.data?.couponIds) {
|
|
75
|
+
payload.data.couponIds = state.data.couponIds;
|
|
76
|
+
}
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
);
|
|
78
|
+
const { fields: summaryFields } =
|
|
79
|
+
await state.storefront.purchase.preview(payload);
|
|
64
80
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
81
|
+
let transformedFields = summaryFields;
|
|
82
|
+
if (!state.data.acceptBumpOffer) {
|
|
83
|
+
const quantitiesByPlanId = createQuantitiesMap(items);
|
|
68
84
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
transformedFields = cloneDeep(summaryFields);
|
|
86
|
+
if (transformedFields.lineItems) {
|
|
87
|
+
if (state.data?.previewPurchase?.addonLineItems) {
|
|
88
|
+
const addonsMap =
|
|
89
|
+
state.data.previewPurchase.addonLineItems.reduce(
|
|
90
|
+
(map, curr) => {
|
|
91
|
+
map.set(curr.planId, curr);
|
|
92
|
+
return map;
|
|
93
|
+
},
|
|
94
|
+
new Map(),
|
|
95
|
+
);
|
|
96
|
+
transformedFields.lineItems =
|
|
97
|
+
transformedFields.lineItems.filter(
|
|
98
|
+
(item) => !addonsMap.has(item.planId),
|
|
99
|
+
);
|
|
100
|
+
transformedFields.addonLineItems =
|
|
101
|
+
state.data.previewPurchase.addonLineItems;
|
|
102
|
+
}
|
|
103
|
+
transformedFields.lineItems.forEach(
|
|
104
|
+
updateItemQuantityFromMap(quantitiesByPlanId),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
78
107
|
}
|
|
79
|
-
transformedFields.lineItems.forEach(updateItemQuantityFromMap(quantitiesByPlanId))
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
108
|
|
|
83
|
-
|
|
84
|
-
|
|
109
|
+
// In case of preview purchase gets call again for updating the values
|
|
110
|
+
state.data.previewPurchase = transformedFields;
|
|
85
111
|
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
return new SummaryModel(transformedFields);
|
|
113
|
+
});
|
|
88
114
|
}
|
|
@@ -7,128 +7,130 @@ import { expectConfigurationError } from 'tests/async-utilities';
|
|
|
7
7
|
import { fetchSummary } from './summary';
|
|
8
8
|
|
|
9
9
|
describe('Storefront API Summary', () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
10
|
+
it('can fetch preview', async () => {
|
|
11
|
+
const options = {
|
|
12
|
+
websiteId: 'test-website-id',
|
|
13
|
+
items: [
|
|
14
|
+
{
|
|
15
|
+
planId: 'test-plan-id',
|
|
16
|
+
quantity: 1,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
const testSummary = {
|
|
21
|
+
currency: 'USD',
|
|
22
|
+
lineItems: [
|
|
23
|
+
{
|
|
24
|
+
description: 'test-plan-id-1',
|
|
25
|
+
planId: 'test-plan-id-1',
|
|
26
|
+
quantity: 1,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
when(post(`${storefrontURL}/preview-purchase`)).thenReturn(
|
|
32
|
+
ok(testSummary),
|
|
33
|
+
);
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const instance = StorefontTestingInstance({
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
vi.spyOn(instance.storefront.purchase, 'preview');
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
const response = await fetchSummary({ state: instance });
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
44
|
+
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
45
|
+
data: expect.objectContaining({
|
|
46
|
+
items: options.items,
|
|
47
|
+
websiteId: options.websiteId,
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
expect(response).toBeInstanceOf(SummaryModel);
|
|
51
|
+
expect(response).toEqual(new SummaryModel(testSummary));
|
|
47
52
|
});
|
|
48
|
-
expect(response).toBeInstanceOf(SummaryModel);
|
|
49
|
-
expect(response).toEqual(new SummaryModel(testSummary));
|
|
50
|
-
});
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
it('Adds billing address to preview payload', async () => {
|
|
55
|
+
const options = {
|
|
56
|
+
websiteId: 'test-website-id',
|
|
57
|
+
items: [
|
|
58
|
+
{
|
|
59
|
+
planId: 'test-plan-id',
|
|
60
|
+
quantity: 1,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
};
|
|
64
|
+
const billingAddress = {
|
|
65
|
+
firstName: 'Test',
|
|
66
|
+
lastName: 'Customer',
|
|
67
|
+
};
|
|
68
|
+
const instance = StorefontTestingInstance({
|
|
69
|
+
options,
|
|
70
|
+
});
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
vi.spyOn(instance.storefront.purchase, 'preview');
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
await fetchSummary({
|
|
75
|
+
data: {
|
|
76
|
+
billingAddress,
|
|
77
|
+
},
|
|
78
|
+
state: instance,
|
|
79
|
+
});
|
|
78
80
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
81
|
+
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
82
|
+
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
83
|
+
data: expect.objectContaining({
|
|
84
|
+
items: options.items,
|
|
85
|
+
websiteId: options.websiteId,
|
|
86
|
+
billingAddress,
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
86
89
|
});
|
|
87
|
-
});
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
91
|
+
it('Adds delivery address to preview payload', async () => {
|
|
92
|
+
const options = {
|
|
93
|
+
websiteId: 'test-website-id',
|
|
94
|
+
items: [
|
|
95
|
+
{
|
|
96
|
+
planId: 'test-plan-id',
|
|
97
|
+
quantity: 1,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
101
|
+
const deliveryAddress = {
|
|
102
|
+
firstName: 'Test',
|
|
103
|
+
lastName: 'Customer',
|
|
104
|
+
};
|
|
105
|
+
const instance = StorefontTestingInstance({
|
|
106
|
+
options,
|
|
107
|
+
});
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
vi.spyOn(instance.storefront.purchase, 'preview');
|
|
108
110
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
await fetchSummary({
|
|
112
|
+
data: {
|
|
113
|
+
deliveryAddress,
|
|
114
|
+
},
|
|
115
|
+
state: instance,
|
|
116
|
+
});
|
|
115
117
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
119
|
+
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
120
|
+
data: expect.objectContaining({
|
|
121
|
+
items: options.items,
|
|
122
|
+
websiteId: options.websiteId,
|
|
123
|
+
deliveryAddress,
|
|
124
|
+
}),
|
|
125
|
+
});
|
|
123
126
|
});
|
|
124
|
-
});
|
|
125
127
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
it('should throw errors with no options', async () => {
|
|
129
|
+
const noConfigOrOptionsInstance = StorefontTestingInstance({
|
|
130
|
+
options: null,
|
|
131
|
+
});
|
|
132
|
+
await expectConfigurationError(
|
|
133
|
+
fetchSummary({ state: noConfigOrOptionsInstance }),
|
|
134
|
+
);
|
|
129
135
|
});
|
|
130
|
-
await expectConfigurationError(
|
|
131
|
-
fetchSummary({ state: noConfigOrOptionsInstance })
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
136
|
});
|
|
@@ -3,10 +3,10 @@ import { Endpoint } from './index';
|
|
|
3
3
|
import state from '../state';
|
|
4
4
|
|
|
5
5
|
export async function fetchTransaction({ data = null }) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
return Endpoint(async () => {
|
|
7
|
+
state.storefront.setSessionToken(state.options.jwt);
|
|
8
|
+
const { fields } = await state.storefront.transactions.get(data);
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
10
|
+
return new TransactionModel(fields);
|
|
11
|
+
});
|
|
12
|
+
}
|