@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.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 +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +183 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +158 -251
- package/dist/functions/mount/mount.spec.js +24 -121
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +96 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +4 -1
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/theme.js +3 -3
- package/dist/style/components/methods.js +43 -42
- package/dist/style/utils/color-values.js +1 -3
- package/dist/style/views/confirmation.js +0 -4
- package/dist/style/views/method-selector.js +1 -1
- package/dist/style/views/modal.js +3 -1
- package/dist/style/views/summary.js +5 -1
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +44 -3
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +28 -8
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +21 -15
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +170 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +5 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +148 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +129 -244
- package/src/functions/mount/mount.spec.js +35 -139
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +100 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +4 -1
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/theme.js +10 -8
- package/src/style/base/theme.spec.js +4 -2
- package/src/style/browserslist.js +1 -3
- package/src/style/components/button.js +3 -1
- package/src/style/components/forms/checkbox.js +3 -1
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +3 -1
- package/src/style/components/methods.js +43 -42
- package/src/style/helpers/index.js +1 -1
- package/src/style/index.js +2 -1
- package/src/style/utils/color-values.js +4 -4
- package/src/style/vendor/framepay.js +1 -1
- package/src/style/vendor/postmate.js +1 -1
- package/src/style/views/confirmation.js +0 -4
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +1 -1
- package/src/style/views/modal.js +4 -2
- package/src/style/views/summary.js +5 -1
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- 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 +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +103 -113
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +42 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -29
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +37 -23
- package/src/views/result.js +12 -15
- package/src/views/summary.js +169 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
|
@@ -1,36 +1,22 @@
|
|
|
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', () => {
|
|
18
|
-
class TestReadyToPayInstance {
|
|
19
|
-
constructor({
|
|
20
|
-
configs = {},
|
|
21
|
-
options = {}
|
|
22
|
-
} = {}) {
|
|
23
|
-
this.configs = configs;
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
fetchReadyToPay(...args) {
|
|
29
|
-
return _readyToPay.FetchReadyToPay.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
20
|
it('can fetch ready to pay', async () => {
|
|
35
21
|
const readyToPayPayload = [{
|
|
36
22
|
method: 'payment-card',
|
|
@@ -38,29 +24,28 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
38
24
|
brands: ['Visa'],
|
|
39
25
|
filters: []
|
|
40
26
|
}];
|
|
41
|
-
const configs = {
|
|
42
|
-
websiteId: 'test-website-id'
|
|
43
|
-
};
|
|
44
27
|
const options = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
28
|
+
websiteId: 'test-website-id',
|
|
29
|
+
items: [{
|
|
30
|
+
planId: 'test-plan-id',
|
|
31
|
+
quantity: 1
|
|
32
|
+
}]
|
|
51
33
|
};
|
|
52
34
|
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
|
|
53
|
-
const instance =
|
|
54
|
-
configs,
|
|
35
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
55
36
|
options
|
|
56
37
|
});
|
|
57
38
|
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
58
|
-
const
|
|
39
|
+
const riskMetadata = null;
|
|
40
|
+
const response = await (0, _readyToPay.fetchReadyToPay)({
|
|
41
|
+
state: instance,
|
|
42
|
+
riskMetadata
|
|
43
|
+
});
|
|
59
44
|
expect(instance.storefront.purchase.readyToPay).toBeCalledTimes(1);
|
|
60
45
|
expect(instance.storefront.purchase.readyToPay).toBeCalledWith({
|
|
61
46
|
data: {
|
|
62
|
-
items: options.
|
|
63
|
-
websiteId:
|
|
47
|
+
items: options.items,
|
|
48
|
+
websiteId: options.websiteId,
|
|
64
49
|
riskMetadata: {}
|
|
65
50
|
}
|
|
66
51
|
});
|
|
@@ -71,28 +56,14 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
71
56
|
...readyToPayPayload[0]
|
|
72
57
|
})]);
|
|
73
58
|
});
|
|
74
|
-
it('should throw errors with no
|
|
75
|
-
const
|
|
76
|
-
const noConfigOrOptionsInstance = new
|
|
77
|
-
configs: null,
|
|
78
|
-
options: null
|
|
79
|
-
});
|
|
80
|
-
const noConfigInstance = new TestReadyToPayInstance({
|
|
81
|
-
configs: null,
|
|
82
|
-
options: {}
|
|
83
|
-
});
|
|
84
|
-
const noOptionsInstance = new TestReadyToPayInstance({
|
|
85
|
-
configs: {},
|
|
59
|
+
it('should throw errors with no options', async () => {
|
|
60
|
+
const riskMetadata = null;
|
|
61
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
86
62
|
options: null
|
|
87
63
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
await noConfigInstance.fetchReadyToPay();
|
|
93
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
94
|
-
expect(async () => {
|
|
95
|
-
await noOptionsInstance.fetchReadyToPay();
|
|
96
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
64
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
65
|
+
riskMetadata,
|
|
66
|
+
state: noConfigOrOptionsInstance
|
|
67
|
+
}));
|
|
97
68
|
});
|
|
98
69
|
});
|
|
@@ -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,35 +3,40 @@
|
|
|
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
|
+
var _index = require("./index");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
|
-
async function
|
|
13
|
-
data = null
|
|
14
|
+
async function fetchSummary({
|
|
15
|
+
data = null,
|
|
16
|
+
state = null
|
|
14
17
|
} = {}) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!this.configs || !this.options) {
|
|
20
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
var _this$configs, _this$options, _this$options$intent;
|
|
18
|
+
return (0, _index.Endpoint)({
|
|
19
|
+
state
|
|
20
|
+
}, async () => {
|
|
21
|
+
var _state$options, _state$options2, _state$data;
|
|
25
22
|
|
|
26
|
-
const websiteId = ((
|
|
27
|
-
const items = ((_this$options = this.options) === null || _this$options === void 0 ? void 0 : (_this$options$intent = _this$options.intent) === null || _this$options$intent === void 0 ? void 0 : _this$options$intent.items) || [];
|
|
23
|
+
const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
|
|
28
24
|
const payload = {
|
|
29
25
|
data: {
|
|
30
|
-
websiteId
|
|
31
|
-
items
|
|
26
|
+
websiteId
|
|
32
27
|
}
|
|
33
28
|
};
|
|
34
29
|
|
|
30
|
+
if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
|
|
31
|
+
payload.data.items = state.options.items;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
|
|
35
|
+
payload.data = { ...payload.data,
|
|
36
|
+
...state.data.amountAndCurrency
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
if (data !== null && data !== void 0 && data.billingAddress) {
|
|
36
41
|
payload.data.billingAddress = data.billingAddress;
|
|
37
42
|
}
|
|
@@ -42,11 +47,9 @@ async function FetchSummary({
|
|
|
42
47
|
|
|
43
48
|
const {
|
|
44
49
|
fields: summaryFields
|
|
45
|
-
} = await
|
|
46
|
-
return new _summaryModel.default(summaryFields);
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw error;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
50
|
+
} = await state.storefront.purchase.preview(payload); // In case of preview purchase gets call again for updating the values
|
|
51
51
|
|
|
52
|
-
;
|
|
52
|
+
state.data.previewPurchase = summaryFields;
|
|
53
|
+
return new _summaryModel.default(summaryFields);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -1,48 +1,29 @@
|
|
|
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
|
|
|
17
19
|
describe('Storefront API Summary', () => {
|
|
18
|
-
class TestSummaryInstance {
|
|
19
|
-
constructor({
|
|
20
|
-
configs = {},
|
|
21
|
-
options = {},
|
|
22
|
-
storefront = null
|
|
23
|
-
} = {}) {
|
|
24
|
-
this.configs = configs;
|
|
25
|
-
this.options = options;
|
|
26
|
-
this.storefront = storefront === null ? (0, _storefrontMock.MockStorefront)() : storefront;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
fetchSummary(...args) {
|
|
30
|
-
return _summary.FetchSummary.apply(this, args);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
20
|
it('can fetch preview', async () => {
|
|
36
|
-
const configs = {
|
|
37
|
-
websiteId: 'test-website-id'
|
|
38
|
-
};
|
|
39
21
|
const options = {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
22
|
+
websiteId: 'test-website-id',
|
|
23
|
+
items: [{
|
|
24
|
+
planId: 'test-plan-id',
|
|
25
|
+
quantity: 1
|
|
26
|
+
}]
|
|
46
27
|
};
|
|
47
28
|
const testSummary = {
|
|
48
29
|
currency: 'USD',
|
|
@@ -53,114 +34,91 @@ describe('Storefront API Summary', () => {
|
|
|
53
34
|
}]
|
|
54
35
|
};
|
|
55
36
|
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((0, _mswWhenThen.ok)(testSummary));
|
|
56
|
-
const instance =
|
|
57
|
-
configs,
|
|
37
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
58
38
|
options
|
|
59
39
|
});
|
|
60
40
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
61
|
-
const response = await
|
|
41
|
+
const response = await (0, _summary.fetchSummary)({
|
|
42
|
+
state: instance
|
|
43
|
+
});
|
|
62
44
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
63
45
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
64
46
|
data: {
|
|
65
|
-
items: options.
|
|
66
|
-
websiteId:
|
|
47
|
+
items: options.items,
|
|
48
|
+
websiteId: options.websiteId
|
|
67
49
|
}
|
|
68
50
|
});
|
|
69
51
|
expect(response).toBeInstanceOf(_summaryModel.default);
|
|
70
52
|
expect(response).toEqual(new _summaryModel.default(testSummary));
|
|
71
53
|
});
|
|
72
54
|
it('Adds billing address to preview payload', async () => {
|
|
73
|
-
const configs = {
|
|
74
|
-
websiteId: 'test-website-id'
|
|
75
|
-
};
|
|
76
55
|
const options = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
56
|
+
websiteId: 'test-website-id',
|
|
57
|
+
items: [{
|
|
58
|
+
planId: 'test-plan-id',
|
|
59
|
+
quantity: 1
|
|
60
|
+
}]
|
|
83
61
|
};
|
|
84
62
|
const billingAddress = {
|
|
85
63
|
firstName: 'Test',
|
|
86
64
|
lastName: 'Customer'
|
|
87
65
|
};
|
|
88
|
-
const instance =
|
|
89
|
-
configs,
|
|
66
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
90
67
|
options
|
|
91
68
|
});
|
|
92
69
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
93
|
-
await
|
|
70
|
+
await (0, _summary.fetchSummary)({
|
|
94
71
|
data: {
|
|
95
72
|
billingAddress
|
|
96
|
-
}
|
|
73
|
+
},
|
|
74
|
+
state: instance
|
|
97
75
|
});
|
|
98
76
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
99
77
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
100
78
|
data: {
|
|
101
|
-
items: options.
|
|
102
|
-
websiteId:
|
|
79
|
+
items: options.items,
|
|
80
|
+
websiteId: options.websiteId,
|
|
103
81
|
billingAddress
|
|
104
82
|
}
|
|
105
83
|
});
|
|
106
84
|
});
|
|
107
85
|
it('Adds delivery address to preview payload', async () => {
|
|
108
|
-
const configs = {
|
|
109
|
-
websiteId: 'test-website-id'
|
|
110
|
-
};
|
|
111
86
|
const options = {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
87
|
+
websiteId: 'test-website-id',
|
|
88
|
+
items: [{
|
|
89
|
+
planId: 'test-plan-id',
|
|
90
|
+
quantity: 1
|
|
91
|
+
}]
|
|
118
92
|
};
|
|
119
93
|
const deliveryAddress = {
|
|
120
94
|
firstName: 'Test',
|
|
121
95
|
lastName: 'Customer'
|
|
122
96
|
};
|
|
123
|
-
const instance =
|
|
124
|
-
configs,
|
|
97
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
125
98
|
options
|
|
126
99
|
});
|
|
127
100
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
128
|
-
await
|
|
101
|
+
await (0, _summary.fetchSummary)({
|
|
129
102
|
data: {
|
|
130
103
|
deliveryAddress
|
|
131
|
-
}
|
|
104
|
+
},
|
|
105
|
+
state: instance
|
|
132
106
|
});
|
|
133
107
|
expect(instance.storefront.purchase.preview).toBeCalledTimes(1);
|
|
134
108
|
expect(instance.storefront.purchase.preview).toBeCalledWith({
|
|
135
109
|
data: {
|
|
136
|
-
items: options.
|
|
137
|
-
websiteId:
|
|
110
|
+
items: options.items,
|
|
111
|
+
websiteId: options.websiteId,
|
|
138
112
|
deliveryAddress
|
|
139
113
|
}
|
|
140
114
|
});
|
|
141
115
|
});
|
|
142
|
-
it('should throw errors with no
|
|
143
|
-
const
|
|
144
|
-
const noConfigOrOptionsInstance = new TestSummaryInstance({
|
|
145
|
-
configs: null,
|
|
146
|
-
options: null
|
|
147
|
-
});
|
|
148
|
-
const noConfigInstance = new TestSummaryInstance({
|
|
149
|
-
configs: null,
|
|
150
|
-
options: {}
|
|
151
|
-
});
|
|
152
|
-
const noOptionsInstance = new TestSummaryInstance({
|
|
153
|
-
configs: {},
|
|
116
|
+
it('should throw errors with no options', async () => {
|
|
117
|
+
const noConfigOrOptionsInstance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
154
118
|
options: null
|
|
155
119
|
});
|
|
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);
|
|
120
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
|
|
121
|
+
state: noConfigOrOptionsInstance
|
|
122
|
+
}));
|
|
165
123
|
});
|
|
166
124
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fetchTransaction = fetchTransaction;
|
|
7
|
+
|
|
8
|
+
var _transactionModel = _interopRequireDefault(require("./models/transaction-model"));
|
|
9
|
+
|
|
10
|
+
var _index = require("./index");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
async function fetchTransaction({
|
|
15
|
+
data = null,
|
|
16
|
+
state = null
|
|
17
|
+
}) {
|
|
18
|
+
return (0, _index.Endpoint)({
|
|
19
|
+
state
|
|
20
|
+
}, async () => {
|
|
21
|
+
state.storefront.setSessionToken(state.options.customerJwt);
|
|
22
|
+
const {
|
|
23
|
+
fields
|
|
24
|
+
} = await state.storefront.transactions.get(data);
|
|
25
|
+
return new _transactionModel.default(fields);
|
|
26
|
+
});
|
|
27
|
+
}
|
package/dist/style/base/theme.js
CHANGED
|
@@ -63,12 +63,12 @@ class Theme {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
build() {
|
|
66
|
-
return { ...(0, _lodash.default)(this.theme
|
|
66
|
+
return { ...(0, _lodash.default)({ ...this.theme
|
|
67
|
+
}, this.overrides),
|
|
67
68
|
getComputed: this.getComputed
|
|
68
69
|
};
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
exports.Theme = Theme;
|
|
74
|
-
;
|
|
74
|
+
exports.Theme = Theme;
|
|
@@ -13,73 +13,60 @@ const expressMethods = theme => `
|
|
|
13
13
|
* Express methods
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.rebilly-instruments-express-methods *:nth-child(2) {
|
|
21
|
-
margin-top: 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.rebilly-instruments-express-methods.is-compact * + * {
|
|
25
|
-
margin-top: 0;
|
|
16
|
+
@keyframes rebillyExpressShine {
|
|
17
|
+
to {
|
|
18
|
+
background-position-x: -200%;
|
|
19
|
+
}
|
|
26
20
|
}
|
|
27
21
|
|
|
28
22
|
.rebilly-instruments-express-methods.is-compact {
|
|
29
|
-
display: flex;
|
|
30
|
-
justify-content: center;
|
|
31
|
-
padding: calc(${theme.space.xs} + ${theme.space.s}) ${theme.space.s} ${theme.space.s};
|
|
32
23
|
border: 1px solid ${theme.getComputed.color.mutedBorder};
|
|
24
|
+
padding: calc(${theme.space.xs} + ${theme.space.s}) ${theme.space.s} ${theme.space.s};
|
|
33
25
|
border-radius: ${theme.borderRadius};
|
|
34
26
|
position: relative;
|
|
35
|
-
flex-wrap: wrap;
|
|
36
27
|
}
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.rebilly-instruments-express-methods.is-compact > * {
|
|
45
|
-
flex: 1 1;
|
|
46
|
-
margin: ${theme.space.xs} ${theme.space.xs};
|
|
47
|
-
max-width: 260px;
|
|
29
|
+
.rebilly-instruments-express-methods .rebilly-instruments-iframe {
|
|
30
|
+
display: block;
|
|
31
|
+
margin-bottom: 0;
|
|
48
32
|
height: 44px;
|
|
49
|
-
background: linear-gradient(110deg, ${theme.getComputed.color.mutedBorder} 0%, ${theme.color.background} 25%, ${theme.getComputed.color.mutedBorder} 50%);
|
|
50
|
-
border-radius: 6px;
|
|
51
|
-
background-size: 200% 100%;
|
|
52
|
-
animation: 1.5s rebillyExpressShine linear infinite;
|
|
53
|
-
position: relative;
|
|
54
33
|
}
|
|
55
34
|
|
|
56
|
-
.rebilly-instruments-express-methods > * {
|
|
57
|
-
margin: ${theme.space.xs} 0;
|
|
58
|
-
height: 44px;
|
|
59
|
-
background: linear-gradient(110deg, ${theme.getComputed.color.mutedBorder} 0%, ${theme.color.background} 25%, ${theme.getComputed.color.mutedBorder} 50%);
|
|
35
|
+
.rebilly-instruments-express-methods .rebilly-instruments-express-methods-container > * {
|
|
60
36
|
border-radius: 6px;
|
|
37
|
+
margin-bottom: ${theme.space.xs};
|
|
38
|
+
background: linear-gradient(110deg, ${theme.getComputed.color.mutedBorder} 0%, ${theme.color.background} 25%, ${theme.getComputed.color.mutedBorder} 50%);
|
|
61
39
|
background-size: 200% 100%;
|
|
62
40
|
animation: 1.5s rebillyExpressShine linear infinite;
|
|
63
41
|
}
|
|
42
|
+
.rebilly-instruments-express-methods .rebilly-instruments-express-methods-container > *:last-child {
|
|
43
|
+
margin: 0;
|
|
44
|
+
}
|
|
64
45
|
|
|
65
|
-
.rebilly-instruments-express-methods
|
|
66
|
-
|
|
46
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container {
|
|
47
|
+
display: flex;
|
|
48
|
+
justify-content: center;
|
|
67
49
|
}
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
51
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container > * {
|
|
52
|
+
flex: 1 1 0px;
|
|
53
|
+
max-width: 260px;
|
|
54
|
+
margin: 0 ${theme.space.xs};
|
|
55
|
+
}
|
|
56
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container > *:first-child {
|
|
57
|
+
margin-left: 0;
|
|
58
|
+
}
|
|
59
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container > *:last-child {
|
|
60
|
+
margin-right: 0;
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
.rebilly-instruments-express-methods .rebilly-instruments-express-methods-label {
|
|
77
64
|
display: none;
|
|
78
65
|
}
|
|
79
|
-
|
|
80
66
|
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-label {
|
|
81
67
|
position: absolute;
|
|
82
|
-
top: -12px;
|
|
68
|
+
top: -12px; left: 50%;
|
|
69
|
+
transform: translateX(-50%);
|
|
83
70
|
color: ${theme.color.text};
|
|
84
71
|
padding: 0 ${theme.space.s};
|
|
85
72
|
line-height: ${theme.typography.lineHeight};
|
|
@@ -88,6 +75,20 @@ const expressMethods = theme => `
|
|
|
88
75
|
font-weight: 500;
|
|
89
76
|
min-height: auto;
|
|
90
77
|
margin: 0;
|
|
78
|
+
border: 1px soplid red;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@media (max-width: 600px) {
|
|
82
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container {
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
}
|
|
85
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container > * {
|
|
86
|
+
max-width: 100%;
|
|
87
|
+
margin: 0 0 ${theme.space.xs};
|
|
88
|
+
}
|
|
89
|
+
.rebilly-instruments-express-methods.is-compact .rebilly-instruments-express-methods-container > *:last-child {
|
|
90
|
+
margin: 0;
|
|
91
|
+
}
|
|
91
92
|
}
|
|
92
93
|
`;
|
|
93
94
|
|
|
@@ -22,10 +22,6 @@ const confirmation = theme => `
|
|
|
22
22
|
margin-left: -${theme.space.xs};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
.rebilly-instruments-confirmation .rebilly-instruments-h2 {
|
|
26
|
-
margin: 0 0 ${theme.space.s};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
25
|
.rebilly-instruments-confirmation-address-title {
|
|
30
26
|
display: flex;
|
|
31
27
|
justify-content: flex-start;
|
|
@@ -38,6 +38,7 @@ const modal = theme => `
|
|
|
38
38
|
transition: all .24s ease-in-out;
|
|
39
39
|
position: relative;
|
|
40
40
|
max-width: 800px;
|
|
41
|
+
background: ${theme.color.background};
|
|
41
42
|
margin: 50px auto 20px;
|
|
42
43
|
box-shadow: 0 19px 38px rgba(0,0,0,0.20), 0 15px 12px rgba(0,0,0,0.12);
|
|
43
44
|
border-radius: ${theme.borderRadius};
|
|
@@ -66,7 +67,8 @@ const modal = theme => `
|
|
|
66
67
|
|
|
67
68
|
.rebilly-instruments-modal-content .rebilly-instruments-iframe {
|
|
68
69
|
transition: all .15s;
|
|
69
|
-
height:
|
|
70
|
+
height: auto;
|
|
71
|
+
min-height: 360px;
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
.rebilly-instruments-modal-container.is-redirect .rebilly-instruments-modal-content {
|
|
@@ -93,10 +93,14 @@ const summary = theme => `
|
|
|
93
93
|
font-weight: 500;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
.rebilly-instruments-summary-breakdown table {
|
|
97
|
+
border-bottom: 1px solid ${theme.getComputed.color.mutedBorder};
|
|
98
|
+
padding-bottom: ${theme.space.xs};
|
|
99
|
+
}
|
|
100
|
+
|
|
96
101
|
.rebilly-instruments-summary-breakdown-total {
|
|
97
102
|
padding-top: ${theme.space.xs};
|
|
98
103
|
display: flex;
|
|
99
|
-
border-top: 1px solid ${theme.getComputed.color.mutedBorder};
|
|
100
104
|
align-items: center;
|
|
101
105
|
}
|
|
102
106
|
|
|
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = formatCurrency;
|
|
7
7
|
|
|
8
|
-
function formatCurrency(number, currency
|
|
8
|
+
function formatCurrency(number, currency) {
|
|
9
|
+
const converToNumber = Number(number);
|
|
10
|
+
if (Number.isNaN(converToNumber) || number === null) return '-';
|
|
9
11
|
return new Intl.NumberFormat('en-US', {
|
|
10
12
|
style: 'currency',
|
|
11
|
-
currency
|
|
13
|
+
currency: currency || 'USD'
|
|
12
14
|
}).format(number);
|
|
13
15
|
}
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = hasValidCSSSelector;
|
|
7
7
|
|
|
8
8
|
function hasValidCSSSelector(selector) {
|
|
9
|
-
const REGEX_CSS_SELECTOR = /([.#][_a-z]+[_a-z0-9-:\\]*)/
|
|
9
|
+
const REGEX_CSS_SELECTOR = /([.#][_a-z]+[_a-z0-9-:\\]*)/gi;
|
|
10
10
|
return typeof selector === 'string' && selector.match(REGEX_CSS_SELECTOR);
|
|
11
11
|
}
|