@rebilly/instruments 1.0.2-beta.1 → 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 +13 -4
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +350 -0
- package/dist/events/base-event.js +40 -11
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +10 -7
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +24 -20
- package/dist/functions/initialize.spec.js +4 -4
- package/dist/functions/mount/fetch-summary-data.js +26 -11
- package/dist/functions/mount/fetch-summary-data.spec.js +15 -16
- package/dist/functions/mount/index.js +168 -106
- package/dist/functions/mount/mount.spec.js +14 -36
- package/dist/functions/on.js +25 -17
- package/dist/functions/on.spec.js +36 -18
- package/dist/functions/purchase.js +33 -74
- package/dist/functions/purchase.spec.js +17 -14
- package/dist/functions/show.js +31 -8
- package/dist/functions/show.spec.js +42 -17
- package/dist/functions/update.js +60 -4
- 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/index.js +5 -0
- package/dist/index.js +67 -55
- package/dist/index.spec.js +6 -10
- package/dist/loader/index.js +24 -4
- package/dist/loader/loader.spec.js +4 -4
- package/dist/storefront/models/ready-to-pay-model.js +7 -1
- package/dist/storefront/plans.js +9 -10
- package/dist/storefront/plans.spec.js +20 -20
- package/dist/storefront/products.js +9 -10
- package/dist/storefront/products.spec.js +20 -20
- package/dist/storefront/purchase.js +9 -8
- package/dist/storefront/purchase.spec.js +7 -4
- package/dist/storefront/ready-to-pay.js +12 -11
- package/dist/storefront/ready-to-pay.spec.js +24 -19
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +11 -12
- package/dist/storefront/summary.spec.js +25 -24
- 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/{styles → style/payment-instruments}/payment-card.js +14 -6
- package/dist/{styles/shade-tint-values-helper.js → style/utils/color-values.js} +5 -9
- 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/format-currency.js +1 -0
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/index.js +3 -19
- package/dist/utils/process-property-as-dom-element.js +0 -2
- 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/{components/form → views/method-selector}/get-payment-methods.js +22 -6
- 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/{components → views}/summary.js +36 -25
- package/dist/{components → views}/summary.spec.js +49 -22
- package/package.json +11 -5
- 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 +23 -18
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +16 -13
- package/src/functions/mount/fetch-summary-data.spec.js +22 -27
- package/src/functions/mount/index.js +194 -133
- package/src/functions/mount/mount.spec.js +83 -84
- 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 +26 -6
- package/src/functions/show.spec.js +41 -19
- package/src/functions/update.js +49 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +19 -11
- package/src/index.js +42 -51
- package/src/index.spec.js +11 -20
- 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 +65 -33
- 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 -113
- package/dist/components/form/form.js +0 -143
- package/dist/components/form/form.spec.js +0 -111
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/method-selector.js +0 -60
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -24
- package/dist/components/form/zoid-helpers.js +0 -131
- package/dist/components/result.js +0 -68
- package/dist/events/instrument-ready.js +0 -24
- package/dist/events/purchase-complete.js +0 -24
- package/dist/styles/base-styles.js +0 -793
- package/dist/styles/flat-theme-object.js +0 -23
- package/dist/styles/framepay.js +0 -38
- package/dist/styles/main.js +0 -29
- package/dist/styles/style-variables.js +0 -44
- package/dist/utils/camel-case.js +0 -10
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -81
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -117
- 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 -117
- 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/styles/base-styles.js +0 -784
- 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
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _products = require("./products");
|
|
12
12
|
|
|
13
13
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
14
14
|
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
|
+
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
|
|
17
19
|
describe('Storefront API Plan', () => {
|
|
@@ -25,10 +27,6 @@ describe('Storefront API Plan', () => {
|
|
|
25
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
FetchProducts(...args) {
|
|
29
|
-
return _products.FetchProducts.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
it('can fetch products', async () => {
|
|
@@ -39,7 +37,9 @@ describe('Storefront API Plan', () => {
|
|
|
39
37
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
|
|
40
38
|
const instance = new TestProductsInstance();
|
|
41
39
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
42
|
-
const response = await
|
|
40
|
+
const response = await (0, _products.fetchProducts)({
|
|
41
|
+
state: instance
|
|
42
|
+
});
|
|
43
43
|
expect(instance.storefront.products.getAll).toBeCalledTimes(1);
|
|
44
44
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
45
45
|
filter: ''
|
|
@@ -51,7 +51,8 @@ describe('Storefront API Plan', () => {
|
|
|
51
51
|
it('can fetch products with filter', async () => {
|
|
52
52
|
const instance = new TestProductsInstance();
|
|
53
53
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
54
|
-
await
|
|
54
|
+
await (0, _products.fetchProducts)({
|
|
55
|
+
state: instance,
|
|
55
56
|
data: [{
|
|
56
57
|
productId: 'test-product-1'
|
|
57
58
|
}, {
|
|
@@ -62,28 +63,27 @@ describe('Storefront API Plan', () => {
|
|
|
62
63
|
filter: 'id:test-product-1,test-product-2'
|
|
63
64
|
});
|
|
64
65
|
});
|
|
65
|
-
it('should throw errors with no configs or options', () => {
|
|
66
|
-
const NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
66
|
+
it('should throw errors with no configs or options', async () => {
|
|
67
67
|
const noConfigOrOptionsInstance = new TestProductsInstance({
|
|
68
68
|
configs: null,
|
|
69
69
|
options: null
|
|
70
70
|
});
|
|
71
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
72
|
+
state: noConfigOrOptionsInstance
|
|
73
|
+
}));
|
|
71
74
|
const noConfigInstance = new TestProductsInstance({
|
|
72
75
|
configs: null,
|
|
73
76
|
options: {}
|
|
74
77
|
});
|
|
78
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
79
|
+
state: noConfigInstance
|
|
80
|
+
}));
|
|
75
81
|
const noOptionsInstance = new TestProductsInstance({
|
|
76
82
|
configs: {},
|
|
77
83
|
options: null
|
|
78
84
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
})
|
|
82
|
-
expect(async () => {
|
|
83
|
-
await noConfigInstance.FetchProducts();
|
|
84
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
85
|
-
expect(async () => {
|
|
86
|
-
await noOptionsInstance.FetchProducts();
|
|
87
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
85
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
86
|
+
state: noOptionsInstance
|
|
87
|
+
}));
|
|
88
88
|
});
|
|
89
89
|
});
|
|
@@ -3,14 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.postPurchase = postPurchase;
|
|
7
7
|
|
|
8
|
-
async function
|
|
9
|
-
|
|
8
|
+
async function postPurchase({
|
|
9
|
+
data,
|
|
10
|
+
state
|
|
11
|
+
}) {
|
|
12
|
+
if (!state.storefront) {
|
|
10
13
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
if (!
|
|
16
|
+
if (!state.configs || !state.options) {
|
|
14
17
|
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
15
18
|
}
|
|
16
19
|
|
|
@@ -19,13 +22,11 @@ async function PostPurchase(data) {
|
|
|
19
22
|
delete data._raw;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
const resp = await
|
|
25
|
+
const resp = await state.storefront.purchase.purchase({
|
|
23
26
|
data
|
|
24
27
|
});
|
|
25
28
|
return resp;
|
|
26
29
|
} catch (error) {
|
|
27
30
|
throw error;
|
|
28
31
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
;
|
|
32
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _purchase = require("./purchase");
|
|
12
12
|
|
|
@@ -22,7 +22,10 @@ describe('Storefront API Purchase', () => {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
postPurchase(...args) {
|
|
25
|
-
return
|
|
25
|
+
return (0, _purchase.postPurchase)({
|
|
26
|
+
state: this,
|
|
27
|
+
data: args
|
|
28
|
+
});
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchReadyToPay = fetchReadyToPay;
|
|
7
7
|
|
|
8
8
|
var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
9
9
|
|
|
@@ -11,17 +11,20 @@ var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-mod
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
async function
|
|
15
|
-
|
|
14
|
+
async function fetchReadyToPay({
|
|
15
|
+
state,
|
|
16
|
+
riskMetadata = null
|
|
17
|
+
}) {
|
|
18
|
+
if (!state.storefront) {
|
|
16
19
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
if (!
|
|
22
|
+
if (!state.configs || !state.options) {
|
|
20
23
|
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
try {
|
|
24
|
-
var
|
|
27
|
+
var _state$configs, _state$options, _state$options$intent;
|
|
25
28
|
|
|
26
29
|
if (!riskMetadata) {
|
|
27
30
|
const {
|
|
@@ -30,8 +33,8 @@ async function FetchReadyToPay(riskMetadata = null) {
|
|
|
30
33
|
riskMetadata = data;
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
const websiteId = ((
|
|
34
|
-
const items = ((
|
|
36
|
+
const websiteId = ((_state$configs = state.configs) === null || _state$configs === void 0 ? void 0 : _state$configs.websiteId) || null;
|
|
37
|
+
const items = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : (_state$options$intent = _state$options.intent) === null || _state$options$intent === void 0 ? void 0 : _state$options$intent.items) || [];
|
|
35
38
|
const data = {
|
|
36
39
|
items,
|
|
37
40
|
websiteId,
|
|
@@ -39,7 +42,7 @@ async function FetchReadyToPay(riskMetadata = null) {
|
|
|
39
42
|
};
|
|
40
43
|
const {
|
|
41
44
|
fields: readyToPayFields
|
|
42
|
-
} = await
|
|
45
|
+
} = await state.storefront.purchase.readyToPay({
|
|
43
46
|
data
|
|
44
47
|
});
|
|
45
48
|
return Object.values(readyToPayFields).map((fields, index) => new _readyToPayModel.default({
|
|
@@ -49,6 +52,4 @@ async function FetchReadyToPay(riskMetadata = null) {
|
|
|
49
52
|
} catch (error) {
|
|
50
53
|
throw error;
|
|
51
54
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
;
|
|
55
|
+
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _readyToPay = require("./ready-to-pay");
|
|
12
12
|
|
|
13
13
|
var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
|
|
14
14
|
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
|
+
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
|
|
17
19
|
describe('Storefront API Ready to Pay', () => {
|
|
@@ -25,10 +27,6 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
25
27
|
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
fetchReadyToPay(...args) {
|
|
29
|
-
return _readyToPay.FetchReadyToPay.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
30
|
}
|
|
33
31
|
|
|
34
32
|
it('can fetch ready to pay', async () => {
|
|
@@ -55,7 +53,11 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
55
53
|
options
|
|
56
54
|
});
|
|
57
55
|
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
58
|
-
const
|
|
56
|
+
const riskMetadata = null;
|
|
57
|
+
const response = await (0, _readyToPay.fetchReadyToPay)({
|
|
58
|
+
state: instance,
|
|
59
|
+
riskMetadata
|
|
60
|
+
});
|
|
59
61
|
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
60
62
|
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
61
63
|
data: {
|
|
@@ -71,28 +73,31 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
71
73
|
...readyToPayPayload[0]
|
|
72
74
|
})]);
|
|
73
75
|
});
|
|
74
|
-
it('should throw errors with no configs or options', () => {
|
|
75
|
-
const
|
|
76
|
+
it('should throw errors with no configs or options', async () => {
|
|
77
|
+
const riskMetadata = null;
|
|
76
78
|
const noConfigOrOptionsInstance = new TestReadyToPayInstance({
|
|
77
79
|
configs: null,
|
|
78
80
|
options: null
|
|
79
81
|
});
|
|
82
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
83
|
+
riskMetadata,
|
|
84
|
+
state: noConfigOrOptionsInstance
|
|
85
|
+
}));
|
|
80
86
|
const noConfigInstance = new TestReadyToPayInstance({
|
|
81
87
|
configs: null,
|
|
82
88
|
options: {}
|
|
83
89
|
});
|
|
90
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
91
|
+
riskMetadata,
|
|
92
|
+
state: noConfigInstance
|
|
93
|
+
}));
|
|
84
94
|
const noOptionsInstance = new TestReadyToPayInstance({
|
|
85
95
|
configs: {},
|
|
86
96
|
options: null
|
|
87
97
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await noConfigInstance.fetchReadyToPay();
|
|
93
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
94
|
-
expect(async () => {
|
|
95
|
-
await noOptionsInstance.fetchReadyToPay();
|
|
96
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
98
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
99
|
+
riskMetadata,
|
|
100
|
+
state: noOptionsInstance
|
|
101
|
+
}));
|
|
97
102
|
});
|
|
98
103
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
describe('Storefront application programming interface', () => {
|
|
6
6
|
it('can create rebilly-js-sdk instance', () => {
|
|
@@ -3,28 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchSummary = fetchSummary;
|
|
7
7
|
|
|
8
8
|
var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
|
|
9
9
|
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
|
|
12
|
-
async function
|
|
13
|
-
data = null
|
|
12
|
+
async function fetchSummary({
|
|
13
|
+
data = null,
|
|
14
|
+
state = null
|
|
14
15
|
} = {}) {
|
|
15
|
-
if (!
|
|
16
|
+
if (!state.storefront) {
|
|
16
17
|
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
if (!
|
|
20
|
+
if (!state.configs || !state.options) {
|
|
20
21
|
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
try {
|
|
24
|
-
var
|
|
25
|
+
var _state$configs, _state$options, _state$options$intent;
|
|
25
26
|
|
|
26
|
-
const websiteId = ((
|
|
27
|
-
const items = ((
|
|
27
|
+
const websiteId = ((_state$configs = state.configs) === null || _state$configs === void 0 ? void 0 : _state$configs.websiteId) || null;
|
|
28
|
+
const items = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : (_state$options$intent = _state$options.intent) === null || _state$options$intent === void 0 ? void 0 : _state$options$intent.items) || [];
|
|
28
29
|
const payload = {
|
|
29
30
|
data: {
|
|
30
31
|
websiteId,
|
|
@@ -42,11 +43,9 @@ async function FetchSummary({
|
|
|
42
43
|
|
|
43
44
|
const {
|
|
44
45
|
fields: summaryFields
|
|
45
|
-
} = await
|
|
46
|
+
} = await state.storefront.purchase.preview(payload);
|
|
46
47
|
return new _summaryModel.default(summaryFields);
|
|
47
48
|
} catch (error) {
|
|
48
49
|
throw error;
|
|
49
50
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
;
|
|
51
|
+
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _storefrontMock = require("tests/mocks/storefront-mock");
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
4
|
|
|
5
5
|
var _mswWhenThen = require("msw-when-then");
|
|
6
6
|
|
|
7
|
-
var _server = require("tests/msw/server");
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
8
|
|
|
9
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
11
|
var _summary = require("./summary");
|
|
12
12
|
|
|
13
|
-
var _summaryModel = _interopRequireDefault(require("
|
|
13
|
+
var _summaryModel = _interopRequireDefault(require("./models/summary-model"));
|
|
14
|
+
|
|
15
|
+
var _asyncUtilities = require("../../tests/async-utilities");
|
|
14
16
|
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
18
|
|
|
@@ -26,10 +28,6 @@ describe('Storefront API Summary', () => {
|
|
|
26
28
|
this.storefront = storefront === null ? (0, _storefrontMock.MockStorefront)() : storefront;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
fetchSummary(...args) {
|
|
30
|
-
return _summary.FetchSummary.apply(this, args);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
it('can fetch preview', async () => {
|
|
@@ -58,7 +56,9 @@ describe('Storefront API Summary', () => {
|
|
|
58
56
|
options
|
|
59
57
|
});
|
|
60
58
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
61
|
-
const response = await
|
|
59
|
+
const response = await (0, _summary.fetchSummary)({
|
|
60
|
+
state: instance
|
|
61
|
+
});
|
|
62
62
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
63
63
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
64
64
|
data: {
|
|
@@ -90,10 +90,11 @@ describe('Storefront API Summary', () => {
|
|
|
90
90
|
options
|
|
91
91
|
});
|
|
92
92
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
93
|
-
await
|
|
93
|
+
await (0, _summary.fetchSummary)({
|
|
94
94
|
data: {
|
|
95
95
|
billingAddress
|
|
96
|
-
}
|
|
96
|
+
},
|
|
97
|
+
state: instance
|
|
97
98
|
});
|
|
98
99
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
99
100
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
@@ -125,10 +126,11 @@ describe('Storefront API Summary', () => {
|
|
|
125
126
|
options
|
|
126
127
|
});
|
|
127
128
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
128
|
-
await
|
|
129
|
+
await (0, _summary.fetchSummary)({
|
|
129
130
|
data: {
|
|
130
131
|
deliveryAddress
|
|
131
|
-
}
|
|
132
|
+
},
|
|
133
|
+
state: instance
|
|
132
134
|
});
|
|
133
135
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
134
136
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
@@ -139,28 +141,27 @@ describe('Storefront API Summary', () => {
|
|
|
139
141
|
}
|
|
140
142
|
});
|
|
141
143
|
});
|
|
142
|
-
it('should throw errors with no configs or options', () => {
|
|
143
|
-
const NoConfigOrOptionsError = new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
144
|
+
it('should throw errors with no configs or options', async () => {
|
|
144
145
|
const noConfigOrOptionsInstance = new TestSummaryInstance({
|
|
145
146
|
configs: null,
|
|
146
147
|
options: null
|
|
147
148
|
});
|
|
149
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
|
|
150
|
+
state: noConfigOrOptionsInstance
|
|
151
|
+
}));
|
|
148
152
|
const noConfigInstance = new TestSummaryInstance({
|
|
149
153
|
configs: null,
|
|
150
154
|
options: {}
|
|
151
155
|
});
|
|
156
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
|
|
157
|
+
state: noConfigInstance
|
|
158
|
+
}));
|
|
152
159
|
const noOptionsInstance = new TestSummaryInstance({
|
|
153
160
|
configs: {},
|
|
154
161
|
options: null
|
|
155
162
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
})
|
|
159
|
-
expect(async () => {
|
|
160
|
-
await noConfigInstance.fetchSummary();
|
|
161
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
162
|
-
expect(async () => {
|
|
163
|
-
await noOptionsInstance.fetchSummary();
|
|
164
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
163
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
|
|
164
|
+
state: noOptionsInstance
|
|
165
|
+
}));
|
|
165
166
|
});
|
|
166
167
|
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`RebillyInstruments theme builds the theme object 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"borderRadius": "4px",
|
|
6
|
+
"color": Object {
|
|
7
|
+
"background": "#ffffff",
|
|
8
|
+
"buttonText": "#ffffff",
|
|
9
|
+
"errorText": "#cd5c5c",
|
|
10
|
+
"primary": "#0044d4",
|
|
11
|
+
"text": "#0D2B3E",
|
|
12
|
+
},
|
|
13
|
+
"getComputed": Object {
|
|
14
|
+
"color": Object {
|
|
15
|
+
"mutedBorder": "rgba(13, 43, 62, 0.25)",
|
|
16
|
+
"mutedText": "rgba(13, 43, 62, 0.6)",
|
|
17
|
+
"primaryValues": Values {
|
|
18
|
+
"alpha": 1,
|
|
19
|
+
"rgb": Array [
|
|
20
|
+
0,
|
|
21
|
+
68,
|
|
22
|
+
212,
|
|
23
|
+
],
|
|
24
|
+
"type": "base",
|
|
25
|
+
"weight": 0,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
"space": Object {
|
|
30
|
+
"form": Object {
|
|
31
|
+
"horizontalPadding": "16px",
|
|
32
|
+
"minHeight": "44px",
|
|
33
|
+
"padding": "8px 16px",
|
|
34
|
+
"verticalPadding": "8px",
|
|
35
|
+
},
|
|
36
|
+
"l": "48px",
|
|
37
|
+
"m": "24px",
|
|
38
|
+
"s": "12px",
|
|
39
|
+
"xl": "96px",
|
|
40
|
+
"xs": "6px",
|
|
41
|
+
"xxl": "112px",
|
|
42
|
+
"xxs": "4px",
|
|
43
|
+
},
|
|
44
|
+
"typography": Object {
|
|
45
|
+
"captionFontSize": "12px",
|
|
46
|
+
"captionLineHeight": "12px",
|
|
47
|
+
"fontFamily": "Avenir, Helvetica, Arial, sans-serif",
|
|
48
|
+
"fontSize": "16px",
|
|
49
|
+
"lineHeight": "24px",
|
|
50
|
+
},
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.base = void 0;
|
|
7
|
+
|
|
8
|
+
const base = theme => `
|
|
9
|
+
/* Base, Typography
|
|
10
|
+
------------------------------------------------------------ */
|
|
11
|
+
/* Base setup for top level elements */
|
|
12
|
+
.rebilly-instruments-content,
|
|
13
|
+
.rebilly-instruments-method-content,
|
|
14
|
+
.rebilly-instruments-confirmation,
|
|
15
|
+
.rebilly-instruments-results {
|
|
16
|
+
color: ${theme.color.text};
|
|
17
|
+
background: ${theme.color.background};
|
|
18
|
+
font-size: ${theme.typography.fontSize};
|
|
19
|
+
line-height: ${theme.typography.lineHeight};
|
|
20
|
+
font-family: ${theme.typography.fontFamily};
|
|
21
|
+
-webkit-font-smoothing: antialiased;
|
|
22
|
+
-moz-osx-font-smoothing: grayscale;
|
|
23
|
+
text-align: left;
|
|
24
|
+
transition: all 200ms;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.rebilly-instruments-link {
|
|
28
|
+
color: ${theme.color.primary};
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.rebilly-instruments-link:hover {
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.rebilly-instruments-link .rebilly-instruments-icon {
|
|
37
|
+
fill: ${theme.color.primary};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rebilly-instruments-link.has-icon-left,
|
|
41
|
+
.rebilly-instruments-link.has-icon-right {
|
|
42
|
+
display: inline-flex;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.rebilly-instruments-link.has-icon-left .rebilly-instruments-icon {
|
|
46
|
+
margin-right: ${theme.space.xs};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.rebilly-instruments-link.has-icon-right .rebilly-instruments-icon {
|
|
50
|
+
margin-left: ${theme.space.xs};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Typography */
|
|
54
|
+
.rebilly-instruments-h1,
|
|
55
|
+
.rebilly-instruments-h2 {
|
|
56
|
+
font-weight: 500;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.rebilly-instruments-h1 {
|
|
60
|
+
font-size: calc(${theme.typography.fontSize} * 1.5);
|
|
61
|
+
line-height: calc(${theme.typography.lineHeight} * 1.5);
|
|
62
|
+
margin: 0 0 calc(${theme.space.m} * 1.5) 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.rebilly-instruments-h2 {
|
|
66
|
+
font-size: calc(${theme.typography.fontSize} * 1.12);
|
|
67
|
+
line-height: ${theme.typography.lineHeight};
|
|
68
|
+
margin: 0 0 ${theme.space.m} 0;
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
exports.base = base;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Theme = void 0;
|
|
7
|
+
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
9
|
+
|
|
10
|
+
var _colorValues = require("../utils/color-values");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
class Theme {
|
|
15
|
+
constructor(overrides = {}) {
|
|
16
|
+
this.overrides = overrides;
|
|
17
|
+
this.theme = {
|
|
18
|
+
color: {
|
|
19
|
+
primary: '#0044d4',
|
|
20
|
+
errorText: '#cd5c5c',
|
|
21
|
+
text: '#0D2B3E',
|
|
22
|
+
buttonText: '#ffffff',
|
|
23
|
+
background: '#ffffff'
|
|
24
|
+
},
|
|
25
|
+
typography: {
|
|
26
|
+
fontFamily: 'Avenir, Helvetica, Arial, sans-serif',
|
|
27
|
+
fontSize: '16px',
|
|
28
|
+
lineHeight: '24px',
|
|
29
|
+
captionFontSize: '12px',
|
|
30
|
+
captionLineHeight: '12px'
|
|
31
|
+
},
|
|
32
|
+
space: {
|
|
33
|
+
xxs: '4px',
|
|
34
|
+
xs: '6px',
|
|
35
|
+
s: '12px',
|
|
36
|
+
m: '24px',
|
|
37
|
+
l: '48px',
|
|
38
|
+
xl: '96px',
|
|
39
|
+
xxl: '112px',
|
|
40
|
+
form: {
|
|
41
|
+
padding: '8px 16px',
|
|
42
|
+
verticalPadding: '8px',
|
|
43
|
+
horizontalPadding: '16px',
|
|
44
|
+
minHeight: '44px'
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
borderRadius: '4px'
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
get getComputed() {
|
|
52
|
+
return this.computed();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
computed() {
|
|
56
|
+
return {
|
|
57
|
+
color: {
|
|
58
|
+
primaryValues: (0, _colorValues.colorValues)(this.theme.color.primary),
|
|
59
|
+
mutedText: (0, _colorValues.alphaColor)(this.theme.color.text, 0.6),
|
|
60
|
+
mutedBorder: (0, _colorValues.alphaColor)(this.theme.color.text, 0.25)
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
build() {
|
|
66
|
+
return { ...(0, _lodash.default)(this.theme, this.overrides),
|
|
67
|
+
getComputed: this.getComputed
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
exports.Theme = Theme;
|