@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10
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 +23 -5
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +361 -2
- package/dist/events/base-event.js +51 -37
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +11 -8
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +60 -41
- package/dist/functions/initialize.spec.js +13 -13
- package/dist/functions/mount/fetch-summary-data.js +46 -0
- package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
- package/dist/functions/mount/index.js +346 -0
- package/dist/functions/mount/mount.spec.js +135 -0
- package/dist/functions/on.js +26 -18
- package/dist/functions/on.spec.js +45 -63
- package/dist/functions/purchase.js +41 -154
- package/dist/functions/purchase.spec.js +60 -76
- package/dist/functions/show.js +39 -43
- package/dist/functions/show.spec.js +57 -0
- package/dist/functions/update.js +60 -5
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/i18n.spec.js +6 -23
- package/dist/i18n/index.js +44 -67
- package/dist/index.js +70 -71
- package/dist/index.spec.js +24 -44
- package/dist/loader/index.js +63 -62
- package/dist/loader/loader.spec.js +14 -11
- package/dist/storefront/index.js +28 -39
- package/dist/storefront/models/plan-model.js +37 -54
- package/dist/storefront/models/product-model.js +25 -36
- package/dist/storefront/models/ready-to-pay-model.js +38 -42
- package/dist/storefront/models/summary-model.js +72 -99
- package/dist/storefront/plans.js +37 -84
- package/dist/storefront/plans.spec.js +61 -151
- package/dist/storefront/products.js +35 -83
- package/dist/storefront/products.spec.js +60 -150
- package/dist/storefront/purchase.js +27 -64
- package/dist/storefront/purchase.spec.js +51 -87
- package/dist/storefront/ready-to-pay.js +45 -107
- package/dist/storefront/ready-to-pay.spec.js +72 -147
- package/dist/storefront/storefront.spec.js +6 -6
- package/dist/storefront/summary.js +37 -84
- package/dist/storefront/summary.spec.js +135 -240
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/style/payment-instruments/payment-card.js +35 -0
- package/dist/style/utils/color-values.js +22 -0
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/add-dom-element.js +12 -34
- package/dist/utils/format-currency.js +4 -4
- package/dist/utils/has-valid-css-selector.js +2 -2
- package/dist/utils/index.js +15 -31
- package/dist/utils/is-dom-element.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +12 -17
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/views/method-selector/get-payment-methods.js +55 -0
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/views/summary.js +162 -0
- package/dist/views/summary.spec.js +148 -0
- package/package.json +12 -6
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +43 -20
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +29 -0
- package/src/functions/mount/fetch-summary-data.spec.js +41 -0
- package/src/functions/mount/index.js +312 -0
- package/src/functions/mount/mount.spec.js +171 -0
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +27 -7
- package/src/functions/show.spec.js +61 -0
- package/src/functions/update.js +50 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +20 -12
- package/src/index.js +43 -49
- package/src/index.spec.js +11 -42
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +90 -21
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -103
- package/dist/components/form/form.js +0 -110
- package/dist/components/form/form.spec.js +0 -135
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/get-payment-methods.js +0 -42
- package/dist/components/form/method-selector.js +0 -61
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -20
- package/dist/components/form/zoid-helpers.js +0 -130
- package/dist/components/result.js +0 -66
- package/dist/components/summary.js +0 -60
- package/dist/components/summary.spec.js +0 -144
- package/dist/events/instrument-ready.js +0 -51
- package/dist/events/purchase-complete.js +0 -51
- package/dist/functions/mount.js +0 -311
- package/dist/functions/mount.spec.js +0 -203
- package/dist/styles/base-styles.js +0 -12
- package/dist/styles/flat-theme-object.js +0 -42
- package/dist/styles/framepay.js +0 -15
- package/dist/styles/main.js +0 -25
- package/dist/styles/payment-card.js +0 -12
- package/dist/styles/shade-tint-values-helper.js +0 -28
- package/dist/styles/style-variables.js +0 -43
- package/dist/utils/camel-case.js +0 -12
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -77
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -88
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -114
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/functions/mount.js +0 -204
- package/src/functions/mount.spec.js +0 -172
- package/src/styles/base-styles.js +0 -741
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
|
@@ -2,27 +2,21 @@ import { MockStorefront } from 'tests/mocks/storefront-mock';
|
|
|
2
2
|
import { ok, get } from 'msw-when-then';
|
|
3
3
|
import { when } from 'tests/msw/server';
|
|
4
4
|
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import {
|
|
5
|
+
import { fetchProducts } from './products';
|
|
6
6
|
import ProductModel from './models/product-model';
|
|
7
|
+
import { expectConfigurationError } from 'tests/async-utilities';
|
|
7
8
|
|
|
8
9
|
describe('Storefront API Plan', () => {
|
|
9
10
|
class TestProductsInstance {
|
|
10
|
-
constructor({
|
|
11
|
-
configs = {},
|
|
12
|
-
options = {}
|
|
13
|
-
} = {}) {
|
|
11
|
+
constructor({ configs = {}, options = {} } = {}) {
|
|
14
12
|
this.configs = configs;
|
|
15
13
|
this.options = options;
|
|
16
14
|
this.storefront = MockStorefront();
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
FetchProducts(...args) {
|
|
20
|
-
return FetchProducts.apply(this, args);
|
|
21
|
-
}
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
it
|
|
25
|
-
const testProduct = {name: 'Test Product', id: 'test-product-id-1'};
|
|
17
|
+
|
|
18
|
+
it('can fetch products', async () => {
|
|
19
|
+
const testProduct = { name: 'Test Product', id: 'test-product-id-1' };
|
|
26
20
|
|
|
27
21
|
when(get(`${storefrontURL}/products`)).thenReturn(ok([testProduct]));
|
|
28
22
|
|
|
@@ -30,7 +24,7 @@ describe('Storefront API Plan', () => {
|
|
|
30
24
|
|
|
31
25
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
32
26
|
|
|
33
|
-
const response = await
|
|
27
|
+
const response = await fetchProducts({ state: instance });
|
|
34
28
|
|
|
35
29
|
expect(instance.storefront.products.getAll).toBeCalledTimes(1);
|
|
36
30
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
@@ -41,20 +35,21 @@ describe('Storefront API Plan', () => {
|
|
|
41
35
|
expect(response).toEqual([new ProductModel(testProduct)]);
|
|
42
36
|
});
|
|
43
37
|
|
|
44
|
-
it
|
|
38
|
+
it('can fetch products with filter', async () => {
|
|
45
39
|
const instance = new TestProductsInstance();
|
|
46
40
|
|
|
47
41
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
48
42
|
|
|
49
|
-
await
|
|
43
|
+
await fetchProducts({
|
|
44
|
+
state: instance,
|
|
50
45
|
data: [
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
]
|
|
46
|
+
{
|
|
47
|
+
productId: 'test-product-1'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
productId: 'test-product-2'
|
|
51
|
+
}
|
|
52
|
+
]
|
|
58
53
|
});
|
|
59
54
|
|
|
60
55
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
@@ -62,31 +57,25 @@ describe('Storefront API Plan', () => {
|
|
|
62
57
|
});
|
|
63
58
|
});
|
|
64
59
|
|
|
65
|
-
it
|
|
66
|
-
const NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
60
|
+
it('should throw errors with no configs or options', async () => {
|
|
67
61
|
const noConfigOrOptionsInstance = new TestProductsInstance({
|
|
68
62
|
configs: null,
|
|
69
|
-
options: null
|
|
63
|
+
options: null
|
|
70
64
|
});
|
|
65
|
+
await expectConfigurationError(
|
|
66
|
+
fetchProducts({ state: noConfigOrOptionsInstance })
|
|
67
|
+
);
|
|
68
|
+
|
|
71
69
|
const noConfigInstance = new TestProductsInstance({
|
|
72
70
|
configs: null,
|
|
73
|
-
options: {}
|
|
71
|
+
options: {}
|
|
74
72
|
});
|
|
73
|
+
await expectConfigurationError(fetchProducts({ state: noConfigInstance }));
|
|
74
|
+
|
|
75
75
|
const noOptionsInstance = new TestProductsInstance({
|
|
76
76
|
configs: {},
|
|
77
|
-
options: null
|
|
77
|
+
options: null
|
|
78
78
|
});
|
|
79
|
-
|
|
80
|
-
expect(async () => {
|
|
81
|
-
await noConfigOrOptionsInstance.FetchProducts();
|
|
82
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
83
|
-
|
|
84
|
-
expect(async () => {
|
|
85
|
-
await noConfigInstance.FetchProducts();
|
|
86
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
87
|
-
|
|
88
|
-
expect(async () => {
|
|
89
|
-
await noOptionsInstance.FetchProducts();
|
|
90
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
79
|
+
await expectConfigurationError(fetchProducts({ state: noOptionsInstance }));
|
|
91
80
|
});
|
|
92
81
|
});
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
export async function
|
|
2
|
-
if (!
|
|
1
|
+
export async function postPurchase({ data, state }) {
|
|
2
|
+
if (!state.storefront) {
|
|
3
3
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
if (!
|
|
7
|
-
throw new Error(
|
|
6
|
+
if (!state.configs || !state.options) {
|
|
7
|
+
throw new Error(
|
|
8
|
+
'Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data'
|
|
9
|
+
);
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
try {
|
|
11
13
|
if (data._raw) {
|
|
12
14
|
delete data._raw;
|
|
13
15
|
}
|
|
14
|
-
const resp = await
|
|
16
|
+
const resp = await state.storefront.purchase.purchase({ data });
|
|
15
17
|
return resp;
|
|
16
18
|
} catch (error) {
|
|
17
19
|
throw error;
|
|
18
20
|
}
|
|
19
|
-
}
|
|
21
|
+
}
|
|
@@ -2,39 +2,38 @@ import { MockStorefront } from 'tests/mocks/storefront-mock';
|
|
|
2
2
|
import { ok, post } from 'msw-when-then';
|
|
3
3
|
import { when } from 'tests/msw/server';
|
|
4
4
|
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import {
|
|
5
|
+
import { postPurchase } from './purchase';
|
|
6
6
|
|
|
7
7
|
describe('Storefront API Purchase', () => {
|
|
8
8
|
class TestPurchaseInstance {
|
|
9
|
-
constructor({
|
|
10
|
-
configs = {},
|
|
11
|
-
options = {}
|
|
12
|
-
} = {}) {
|
|
9
|
+
constructor({ configs = {}, options = {} } = {}) {
|
|
13
10
|
this.configs = configs;
|
|
14
11
|
this.options = options;
|
|
15
12
|
this.storefront = MockStorefront();
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
postPurchase(...args) {
|
|
19
|
-
return
|
|
16
|
+
return postPurchase({ state: this, data: args });
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
it
|
|
20
|
+
it('can make purchase', async () => {
|
|
24
21
|
const instance = new TestPurchaseInstance();
|
|
25
22
|
const payload = {
|
|
26
23
|
websiteId: 'test-website-id',
|
|
27
|
-
items: [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
items: [
|
|
25
|
+
{
|
|
26
|
+
planId: 'test-plan-id-1',
|
|
27
|
+
quantity: 1
|
|
28
|
+
}
|
|
29
|
+
],
|
|
31
30
|
billingAddress: {
|
|
32
31
|
firstName: 'Test',
|
|
33
32
|
lastName: 'Customer'
|
|
34
33
|
},
|
|
35
34
|
paymentInstruction: {
|
|
36
|
-
token: 'test-token'
|
|
37
|
-
}
|
|
35
|
+
token: 'test-token'
|
|
36
|
+
}
|
|
38
37
|
};
|
|
39
38
|
const fields = {
|
|
40
39
|
orderId: 'test-order-id',
|
|
@@ -44,17 +43,19 @@ describe('Storefront API Purchase', () => {
|
|
|
44
43
|
transaction: {
|
|
45
44
|
id: 'test-transaction-id'
|
|
46
45
|
}
|
|
47
|
-
}
|
|
46
|
+
};
|
|
48
47
|
|
|
49
48
|
when(post(`${storefrontURL}/purchase`)).thenReturn(ok(fields));
|
|
50
49
|
|
|
51
50
|
jest.spyOn(instance.storefront.purchase, 'purchase');
|
|
52
51
|
|
|
53
|
-
const requestResponse = await instance.storefront.purchase.purchase(
|
|
52
|
+
const requestResponse = await instance.storefront.purchase.purchase(
|
|
53
|
+
payload
|
|
54
|
+
);
|
|
54
55
|
|
|
55
56
|
expect(instance.storefront.purchase.purchase).toBeCalledTimes(1);
|
|
56
57
|
expect(instance.storefront.purchase.purchase).toBeCalledWith(payload);
|
|
57
|
-
|
|
58
|
+
|
|
58
59
|
expect(requestResponse.config).toBeInstanceOf(Object);
|
|
59
60
|
expect(requestResponse.fields).toBeInstanceOf(Object);
|
|
60
61
|
expect(requestResponse.response).toBeInstanceOf(Object);
|
|
@@ -62,4 +63,4 @@ describe('Storefront API Purchase', () => {
|
|
|
62
63
|
expect(requestResponse.fields).toEqual(fields);
|
|
63
64
|
expect(requestResponse.fields).toMatchObject(fields);
|
|
64
65
|
});
|
|
65
|
-
});
|
|
66
|
+
});
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import { collectData } from '@rebilly/risk-data-collector';
|
|
2
2
|
import ReadyToPayModel from './models/ready-to-pay-model';
|
|
3
3
|
|
|
4
|
-
export async function
|
|
5
|
-
if (!
|
|
4
|
+
export async function fetchReadyToPay({ state, riskMetadata = null }) {
|
|
5
|
+
if (!state.storefront) {
|
|
6
6
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
if (!
|
|
10
|
-
throw new Error(
|
|
9
|
+
if (!state.configs || !state.options) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
'Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data'
|
|
12
|
+
);
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
try {
|
|
14
16
|
if (!riskMetadata) {
|
|
15
|
-
const {riskMetadata: data} = await collectData();
|
|
17
|
+
const { riskMetadata: data } = await collectData();
|
|
16
18
|
riskMetadata = data;
|
|
17
19
|
}
|
|
18
|
-
const websiteId =
|
|
19
|
-
const items =
|
|
20
|
+
const websiteId = state.configs?.websiteId || null;
|
|
21
|
+
const items = state.options?.intent?.items || [];
|
|
20
22
|
|
|
21
23
|
const data = {
|
|
22
24
|
items,
|
|
@@ -24,13 +26,17 @@ export async function FetchReadyToPay (riskMetadata = null) {
|
|
|
24
26
|
riskMetadata
|
|
25
27
|
};
|
|
26
28
|
|
|
27
|
-
const {fields: readyToPayFields} =
|
|
29
|
+
const { fields: readyToPayFields } =
|
|
30
|
+
await state.storefront.purchase.readyToPay({ data });
|
|
28
31
|
|
|
29
|
-
return Object.values(readyToPayFields).map(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
return Object.values(readyToPayFields).map(
|
|
33
|
+
(fields, index) =>
|
|
34
|
+
new ReadyToPayModel({
|
|
35
|
+
index,
|
|
36
|
+
...fields
|
|
37
|
+
})
|
|
38
|
+
);
|
|
33
39
|
} catch (error) {
|
|
34
40
|
throw error;
|
|
35
41
|
}
|
|
36
|
-
}
|
|
42
|
+
}
|
|
@@ -2,32 +2,28 @@ import { MockStorefront } from 'tests/mocks/storefront-mock';
|
|
|
2
2
|
import { ok, post } from 'msw-when-then';
|
|
3
3
|
import { when } from 'tests/msw/server';
|
|
4
4
|
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import {
|
|
5
|
+
import { fetchReadyToPay } from './ready-to-pay';
|
|
6
6
|
import ReadyToPayModel from './models/ready-to-pay-model';
|
|
7
|
+
import { expectConfigurationError } from 'tests/async-utilities';
|
|
7
8
|
|
|
8
9
|
describe('Storefront API Ready to Pay', () => {
|
|
9
10
|
class TestReadyToPayInstance {
|
|
10
|
-
constructor({
|
|
11
|
-
configs = {},
|
|
12
|
-
options = {}
|
|
13
|
-
} = {}) {
|
|
11
|
+
constructor({ configs = {}, options = {} } = {}) {
|
|
14
12
|
this.configs = configs;
|
|
15
13
|
this.options = options;
|
|
16
14
|
this.storefront = MockStorefront();
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
fetchReadyToPay(...args) {
|
|
20
|
-
return FetchReadyToPay.apply(this, args);
|
|
21
|
-
}
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
it
|
|
25
|
-
const readyToPayPayload = [
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
17
|
+
|
|
18
|
+
it('can fetch ready to pay', async () => {
|
|
19
|
+
const readyToPayPayload = [
|
|
20
|
+
{
|
|
21
|
+
method: 'payment-card',
|
|
22
|
+
feature: null,
|
|
23
|
+
brands: ['Visa'],
|
|
24
|
+
filters: []
|
|
25
|
+
}
|
|
26
|
+
];
|
|
31
27
|
const configs = {
|
|
32
28
|
websiteId: 'test-website-id'
|
|
33
29
|
};
|
|
@@ -42,17 +38,20 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
42
38
|
}
|
|
43
39
|
};
|
|
44
40
|
|
|
45
|
-
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
41
|
+
when(post(`${storefrontURL}/ready-to-pay`)).thenReturn(
|
|
42
|
+
ok(readyToPayPayload)
|
|
43
|
+
);
|
|
46
44
|
|
|
47
45
|
const instance = new TestReadyToPayInstance({
|
|
48
46
|
configs,
|
|
49
|
-
options
|
|
47
|
+
options
|
|
50
48
|
});
|
|
51
49
|
|
|
52
50
|
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
53
51
|
|
|
54
|
-
const
|
|
55
|
-
|
|
52
|
+
const riskMetadata = null;
|
|
53
|
+
const response = await fetchReadyToPay({ state: instance, riskMetadata });
|
|
54
|
+
|
|
56
55
|
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
57
56
|
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
58
57
|
data: {
|
|
@@ -63,38 +62,39 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
63
62
|
});
|
|
64
63
|
expect(response).toBeInstanceOf(Array);
|
|
65
64
|
expect(response[0]).toBeInstanceOf(ReadyToPayModel);
|
|
66
|
-
expect(response)
|
|
67
|
-
|
|
65
|
+
expect(response).toEqual([
|
|
66
|
+
new ReadyToPayModel({
|
|
68
67
|
index: 0,
|
|
69
68
|
...readyToPayPayload[0]
|
|
70
|
-
})
|
|
69
|
+
})
|
|
70
|
+
]);
|
|
71
71
|
});
|
|
72
72
|
|
|
73
|
-
it
|
|
74
|
-
const
|
|
73
|
+
it('should throw errors with no configs or options', async () => {
|
|
74
|
+
const riskMetadata = null;
|
|
75
|
+
|
|
75
76
|
const noConfigOrOptionsInstance = new TestReadyToPayInstance({
|
|
76
77
|
configs: null,
|
|
77
|
-
options: null
|
|
78
|
+
options: null
|
|
78
79
|
});
|
|
80
|
+
await expectConfigurationError(
|
|
81
|
+
fetchReadyToPay({ riskMetadata, state: noConfigOrOptionsInstance })
|
|
82
|
+
);
|
|
83
|
+
|
|
79
84
|
const noConfigInstance = new TestReadyToPayInstance({
|
|
80
85
|
configs: null,
|
|
81
|
-
options: {}
|
|
86
|
+
options: {}
|
|
82
87
|
});
|
|
88
|
+
await expectConfigurationError(
|
|
89
|
+
fetchReadyToPay({ riskMetadata, state: noConfigInstance })
|
|
90
|
+
);
|
|
91
|
+
|
|
83
92
|
const noOptionsInstance = new TestReadyToPayInstance({
|
|
84
93
|
configs: {},
|
|
85
|
-
options: null
|
|
94
|
+
options: null
|
|
86
95
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
91
|
-
|
|
92
|
-
expect(async () => {
|
|
93
|
-
await noConfigInstance.fetchReadyToPay();
|
|
94
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
95
|
-
|
|
96
|
-
expect(async () => {
|
|
97
|
-
await noOptionsInstance.fetchReadyToPay();
|
|
98
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
96
|
+
await expectConfigurationError(
|
|
97
|
+
fetchReadyToPay({ riskMetadata, state: noOptionsInstance })
|
|
98
|
+
);
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -1,37 +1,39 @@
|
|
|
1
1
|
import SummaryModel from './models/summary-model';
|
|
2
2
|
|
|
3
|
-
export async function
|
|
4
|
-
|
|
5
|
-
} = {}) {
|
|
6
|
-
if (!this.storefront) {
|
|
3
|
+
export async function fetchSummary({ data = null, state = null } = {}) {
|
|
4
|
+
if (!state.storefront) {
|
|
7
5
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
8
6
|
}
|
|
9
7
|
|
|
10
|
-
if (!
|
|
11
|
-
throw new Error(
|
|
8
|
+
if (!state.configs || !state.options) {
|
|
9
|
+
throw new Error(
|
|
10
|
+
'Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data'
|
|
11
|
+
);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
try {
|
|
15
|
-
const websiteId =
|
|
16
|
-
const items =
|
|
15
|
+
const websiteId = state.configs?.websiteId || null;
|
|
16
|
+
const items = state.options?.intent?.items || [];
|
|
17
17
|
|
|
18
18
|
const payload = {
|
|
19
19
|
data: {
|
|
20
20
|
websiteId,
|
|
21
21
|
items
|
|
22
22
|
}
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
if (data?.billingAddress) {
|
|
25
25
|
payload.data.billingAddress = data.billingAddress;
|
|
26
26
|
}
|
|
27
|
-
if(data?.deliveryAddress) {
|
|
27
|
+
if (data?.deliveryAddress) {
|
|
28
28
|
payload.data.deliveryAddress = data.deliveryAddress;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const {fields: summaryFields} = await
|
|
31
|
+
const { fields: summaryFields } = await state.storefront.purchase.preview(
|
|
32
|
+
payload
|
|
33
|
+
);
|
|
32
34
|
|
|
33
35
|
return new SummaryModel(summaryFields);
|
|
34
36
|
} catch (error) {
|
|
35
37
|
throw error;
|
|
36
38
|
}
|
|
37
|
-
}
|
|
39
|
+
}
|
|
@@ -2,27 +2,20 @@ import { MockStorefront } from 'tests/mocks/storefront-mock';
|
|
|
2
2
|
import { ok, post } from 'msw-when-then';
|
|
3
3
|
import { when } from 'tests/msw/server';
|
|
4
4
|
import { storefrontURL } from 'tests/mocks/storefront-api-mock';
|
|
5
|
-
import {
|
|
5
|
+
import { fetchSummary } from './summary';
|
|
6
6
|
import SummaryModel from '@/storefront/models/summary-model';
|
|
7
|
+
import { expectConfigurationError } from 'tests/async-utilities';
|
|
7
8
|
|
|
8
9
|
describe('Storefront API Summary', () => {
|
|
9
10
|
class TestSummaryInstance {
|
|
10
|
-
constructor({
|
|
11
|
-
configs = {},
|
|
12
|
-
options = {},
|
|
13
|
-
storefront = null,
|
|
14
|
-
} = {}) {
|
|
11
|
+
constructor({ configs = {}, options = {}, storefront = null } = {}) {
|
|
15
12
|
this.configs = configs;
|
|
16
13
|
this.options = options;
|
|
17
14
|
this.storefront = storefront === null ? MockStorefront() : storefront;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
|
-
fetchSummary(...args) {
|
|
21
|
-
return FetchSummary.apply(this, args);
|
|
22
|
-
}
|
|
23
16
|
}
|
|
24
|
-
|
|
25
|
-
it
|
|
17
|
+
|
|
18
|
+
it('can fetch preview', async () => {
|
|
26
19
|
const configs = {
|
|
27
20
|
websiteId: 'test-website-id'
|
|
28
21
|
};
|
|
@@ -42,7 +35,7 @@ describe('Storefront API Summary', () => {
|
|
|
42
35
|
{
|
|
43
36
|
description: 'test-plan-id-1',
|
|
44
37
|
planId: 'test-plan-id-1',
|
|
45
|
-
quantity: 1
|
|
38
|
+
quantity: 1
|
|
46
39
|
}
|
|
47
40
|
]
|
|
48
41
|
};
|
|
@@ -51,26 +44,25 @@ describe('Storefront API Summary', () => {
|
|
|
51
44
|
|
|
52
45
|
const instance = new TestSummaryInstance({
|
|
53
46
|
configs,
|
|
54
|
-
options
|
|
47
|
+
options
|
|
55
48
|
});
|
|
56
49
|
|
|
57
50
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
58
51
|
|
|
59
|
-
const response = await
|
|
60
|
-
|
|
52
|
+
const response = await fetchSummary({ state: instance });
|
|
53
|
+
|
|
61
54
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
62
55
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
63
56
|
data: {
|
|
64
57
|
items: options.intent.items,
|
|
65
|
-
websiteId: configs.websiteId
|
|
58
|
+
websiteId: configs.websiteId
|
|
66
59
|
}
|
|
67
60
|
});
|
|
68
61
|
expect(response).toBeInstanceOf(SummaryModel);
|
|
69
62
|
expect(response).toEqual(new SummaryModel(testSummary));
|
|
70
|
-
|
|
71
63
|
});
|
|
72
64
|
|
|
73
|
-
it
|
|
65
|
+
it('Adds billing address to preview payload', async () => {
|
|
74
66
|
const configs = {
|
|
75
67
|
websiteId: 'test-website-id'
|
|
76
68
|
};
|
|
@@ -90,28 +82,29 @@ describe('Storefront API Summary', () => {
|
|
|
90
82
|
};
|
|
91
83
|
const instance = new TestSummaryInstance({
|
|
92
84
|
configs,
|
|
93
|
-
options
|
|
85
|
+
options
|
|
94
86
|
});
|
|
95
87
|
|
|
96
88
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
97
89
|
|
|
98
|
-
await
|
|
90
|
+
await fetchSummary({
|
|
99
91
|
data: {
|
|
100
|
-
billingAddress
|
|
101
|
-
}
|
|
92
|
+
billingAddress
|
|
93
|
+
},
|
|
94
|
+
state: instance
|
|
102
95
|
});
|
|
103
|
-
|
|
96
|
+
|
|
104
97
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
105
98
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
106
99
|
data: {
|
|
107
100
|
items: options.intent.items,
|
|
108
101
|
websiteId: configs.websiteId,
|
|
109
|
-
billingAddress
|
|
102
|
+
billingAddress
|
|
110
103
|
}
|
|
111
104
|
});
|
|
112
105
|
});
|
|
113
106
|
|
|
114
|
-
it
|
|
107
|
+
it('Adds delivery address to preview payload', async () => {
|
|
115
108
|
const configs = {
|
|
116
109
|
websiteId: 'test-website-id'
|
|
117
110
|
};
|
|
@@ -131,53 +124,47 @@ describe('Storefront API Summary', () => {
|
|
|
131
124
|
};
|
|
132
125
|
const instance = new TestSummaryInstance({
|
|
133
126
|
configs,
|
|
134
|
-
options
|
|
127
|
+
options
|
|
135
128
|
});
|
|
136
129
|
|
|
137
130
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
138
131
|
|
|
139
|
-
await
|
|
132
|
+
await fetchSummary({
|
|
140
133
|
data: {
|
|
141
|
-
deliveryAddress
|
|
142
|
-
}
|
|
134
|
+
deliveryAddress
|
|
135
|
+
},
|
|
136
|
+
state: instance
|
|
143
137
|
});
|
|
144
|
-
|
|
138
|
+
|
|
145
139
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
146
140
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
147
141
|
data: {
|
|
148
142
|
items: options.intent.items,
|
|
149
143
|
websiteId: configs.websiteId,
|
|
150
|
-
deliveryAddress
|
|
144
|
+
deliveryAddress
|
|
151
145
|
}
|
|
152
146
|
});
|
|
153
|
-
|
|
154
147
|
});
|
|
155
148
|
|
|
156
|
-
it
|
|
157
|
-
const NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
149
|
+
it('should throw errors with no configs or options', async () => {
|
|
158
150
|
const noConfigOrOptionsInstance = new TestSummaryInstance({
|
|
159
151
|
configs: null,
|
|
160
|
-
options: null
|
|
152
|
+
options: null
|
|
161
153
|
});
|
|
154
|
+
await expectConfigurationError(
|
|
155
|
+
fetchSummary({ state: noConfigOrOptionsInstance })
|
|
156
|
+
);
|
|
157
|
+
|
|
162
158
|
const noConfigInstance = new TestSummaryInstance({
|
|
163
159
|
configs: null,
|
|
164
|
-
options: {}
|
|
160
|
+
options: {}
|
|
165
161
|
});
|
|
162
|
+
await expectConfigurationError(fetchSummary({ state: noConfigInstance }));
|
|
163
|
+
|
|
166
164
|
const noOptionsInstance = new TestSummaryInstance({
|
|
167
165
|
configs: {},
|
|
168
|
-
options: null
|
|
166
|
+
options: null
|
|
169
167
|
});
|
|
170
|
-
|
|
171
|
-
expect(async () => {
|
|
172
|
-
await noConfigOrOptionsInstance.fetchSummary();
|
|
173
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
174
|
-
|
|
175
|
-
expect(async () => {
|
|
176
|
-
await noConfigInstance.fetchSummary();
|
|
177
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
178
|
-
|
|
179
|
-
expect(async () => {
|
|
180
|
-
await noOptionsInstance.fetchSummary();
|
|
181
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
168
|
+
await expectConfigurationError(fetchSummary({ state: noOptionsInstance }));
|
|
182
169
|
});
|
|
183
170
|
});
|