@rebilly/instruments 2.0.0-beta → 3.0.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/dist/events/index.js +2 -1
- package/dist/functions/mount/fetch-data.js +187 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +132 -164
- package/dist/functions/mount/mount.spec.js +2 -4
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay-theme.js +95 -0
- package/dist/functions/mount/setup-framepay.js +5 -1
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +68 -47
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +6 -4
- package/dist/functions/mount/setup-styles.js +4 -2
- package/dist/functions/purchase.js +129 -24
- package/dist/functions/purchase.spec.js +13 -10
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +8 -4
- package/dist/functions/show.spec.js +9 -5
- package/dist/functions/update.js +39 -24
- package/dist/functions/update.spec.js +0 -4
- package/dist/i18n/en.json +5 -2
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +17 -3
- package/dist/index.spec.js +3 -16
- 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 +10 -18
- package/dist/storefront/plans.spec.js +3 -13
- package/dist/storefront/products.js +10 -13
- package/dist/storefront/products.spec.js +12 -19
- package/dist/storefront/purchase.js +23 -12
- package/dist/storefront/purchase.spec.js +1 -20
- package/dist/storefront/ready-to-pay.js +18 -15
- package/dist/storefront/ready-to-pay.spec.js +2 -12
- package/dist/storefront/summary.js +21 -17
- package/dist/storefront/summary.spec.js +4 -15
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/dist/style/base/default-theme.js +699 -0
- package/dist/style/base/index.js +48 -16
- package/dist/style/base/theme.js +16 -48
- package/dist/style/base/theme.spec.js +4 -15
- package/dist/style/components/address.js +3 -3
- package/dist/style/components/button.js +32 -22
- package/dist/style/components/divider.js +9 -9
- package/dist/style/components/forms/checkbox.js +12 -9
- package/dist/style/components/forms/field.js +18 -6
- package/dist/style/components/forms/form.js +2 -2
- package/dist/style/components/forms/input.js +54 -13
- package/dist/style/components/forms/label.js +39 -18
- package/dist/style/components/forms/select.js +54 -22
- package/dist/style/components/forms/validation.js +53 -6
- package/dist/style/components/icons.js +4 -4
- package/dist/style/components/loader.js +5 -3
- package/dist/style/components/methods.js +18 -15
- package/dist/style/components/overlay.js +5 -5
- package/dist/style/helpers/index.js +46 -46
- package/dist/style/index.js +3 -1
- package/dist/style/payment-instruments/payment-card.js +4 -4
- package/dist/style/utils/border.js +47 -0
- package/dist/style/utils/color-values.js +39 -3
- package/dist/style/utils/remove-empty-null.js +20 -0
- package/dist/style/vendor/framepay.js +11 -8
- package/dist/style/vendor/postmate.js +2 -2
- package/dist/style/views/confirmation.js +13 -13
- package/dist/style/views/method-selector.js +2 -2
- package/dist/style/views/modal.js +6 -6
- package/dist/style/views/result.js +4 -4
- package/dist/style/views/summary.js +26 -22
- package/dist/views/__snapshots__/summary.spec.js.snap +77 -119
- package/dist/views/common/iframe/base-iframe.js +2 -0
- package/dist/views/common/iframe/modal-iframe.js +50 -4
- package/dist/views/confirmation.js +19 -8
- package/dist/views/method-selector/generate-digital-wallet.js +12 -3
- package/dist/views/method-selector/generate-digital-wallet.spec.js +11 -0
- package/dist/views/method-selector/get-payment-methods.js +13 -2
- package/dist/views/method-selector/get-payment-methods.spec.js +21 -19
- package/dist/views/method-selector/index.js +23 -34
- package/dist/views/method-selector/method-selector.spec.js +50 -55
- package/dist/views/method-selector/mount-methods.js +5 -8
- package/dist/views/modal.js +8 -2
- package/dist/views/result.js +3 -4
- package/dist/views/summary.js +156 -97
- package/dist/views/summary.spec.js +53 -58
- package/package.json +4 -2
- package/src/events/index.js +2 -1
- package/src/functions/mount/fetch-data.js +152 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +101 -158
- package/src/functions/mount/mount.spec.js +3 -5
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay-theme.js +82 -0
- package/src/functions/mount/setup-framepay.js +5 -1
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +78 -48
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +6 -4
- package/src/functions/mount/setup-styles.js +4 -2
- package/src/functions/on.spec.js +1 -1
- package/src/functions/purchase.js +99 -23
- package/src/functions/purchase.spec.js +10 -10
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +2 -4
- package/src/functions/show.spec.js +3 -4
- package/src/functions/update.js +40 -25
- package/src/functions/update.spec.js +0 -4
- package/src/i18n/en.json +5 -2
- package/src/i18n/es.json +4 -1
- package/src/index.js +9 -3
- package/src/index.spec.js +3 -21
- package/src/loader/index.js +3 -3
- package/src/storefront/index.js +28 -0
- 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/summary-model.js +12 -19
- 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 +6 -17
- package/src/storefront/plans.spec.js +4 -11
- package/src/storefront/products.js +8 -16
- package/src/storefront/products.spec.js +16 -22
- package/src/storefront/purchase.js +14 -16
- package/src/storefront/purchase.spec.js +2 -14
- package/src/storefront/ready-to-pay.js +13 -16
- package/src/storefront/ready-to-pay.spec.js +3 -10
- package/src/storefront/summary.js +19 -17
- package/src/storefront/summary.spec.js +5 -12
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/__snapshots__/theme.spec.js.snap +188 -45
- package/src/style/base/default-theme.js +674 -0
- package/src/style/base/index.js +48 -16
- package/src/style/base/theme.js +17 -47
- package/src/style/base/theme.spec.js +4 -16
- package/src/style/components/address.js +3 -3
- package/src/style/components/button.js +32 -24
- package/src/style/components/divider.js +9 -9
- package/src/style/components/forms/checkbox.js +11 -11
- package/src/style/components/forms/field.js +18 -6
- package/src/style/components/forms/form.js +2 -2
- package/src/style/components/forms/input.js +54 -13
- package/src/style/components/forms/label.js +39 -18
- package/src/style/components/forms/select.js +54 -22
- package/src/style/components/forms/validation.js +53 -6
- package/src/style/components/icons.js +4 -4
- package/src/style/components/loader.js +4 -5
- package/src/style/components/methods.js +18 -15
- package/src/style/components/overlay.js +5 -5
- package/src/style/helpers/index.js +46 -46
- package/src/style/index.js +2 -1
- package/src/style/payment-instruments/payment-card.js +4 -4
- package/src/style/utils/border.js +34 -0
- package/src/style/utils/color-values.js +27 -1
- package/src/style/utils/remove-empty-null.js +10 -0
- package/src/style/vendor/framepay.js +11 -8
- package/src/style/vendor/postmate.js +2 -2
- package/src/style/views/confirmation.js +13 -13
- package/src/style/views/method-selector.js +2 -2
- package/src/style/views/modal.js +6 -6
- package/src/style/views/result.js +4 -4
- package/src/style/views/summary.js +26 -22
- package/src/views/__snapshots__/summary.spec.js.snap +77 -119
- package/src/views/common/iframe/base-iframe.js +2 -0
- package/src/views/common/iframe/modal-iframe.js +45 -3
- package/src/views/confirmation.js +15 -5
- package/src/views/method-selector/generate-digital-wallet.js +10 -3
- package/src/views/method-selector/generate-digital-wallet.spec.js +10 -0
- package/src/views/method-selector/get-payment-methods.js +7 -2
- package/src/views/method-selector/get-payment-methods.spec.js +26 -23
- package/src/views/method-selector/index.js +21 -28
- package/src/views/method-selector/method-selector.spec.js +49 -64
- package/src/views/method-selector/mount-methods.js +5 -8
- package/src/views/modal.js +6 -2
- package/src/views/result.js +4 -3
- package/src/views/summary.js +161 -117
- package/src/views/summary.spec.js +60 -75
- package/tests/mocks/rebilly-instruments-mock.js +37 -7
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/functions/mount/fetch-summary-data.js +0 -46
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -43
- package/src/functions/mount/fetch-summary-data.js +0 -29
- package/src/functions/mount/fetch-summary-data.spec.js +0 -40
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _storefrontMock = require("../../tests/mocks/storefront-mock");
|
|
4
|
+
|
|
5
|
+
var _mswWhenThen = require("msw-when-then");
|
|
6
|
+
|
|
7
|
+
var _server = require("../../tests/msw/server");
|
|
8
|
+
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
|
+
|
|
11
|
+
describe('Storefront API Setup', () => {
|
|
12
|
+
it('can make purchase', async () => {
|
|
13
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
14
|
+
const paymentInstrumentFields = {
|
|
15
|
+
id: 'payment-instrument-id'
|
|
16
|
+
};
|
|
17
|
+
const paymentInstrumentSetupFields = {
|
|
18
|
+
id: 'payment-instrument-id',
|
|
19
|
+
approvalUrl: null
|
|
20
|
+
};
|
|
21
|
+
const paymentInstrumentPayload = {
|
|
22
|
+
data: {
|
|
23
|
+
token: 'test-token'
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const paymentInstrumentSetupPayload = {
|
|
27
|
+
id: paymentInstrumentFields.id,
|
|
28
|
+
data: {
|
|
29
|
+
websiteId: 'website-id',
|
|
30
|
+
currency: 'USD',
|
|
31
|
+
amount: 30
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentFields));
|
|
35
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments/*/setup`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentSetupFields));
|
|
36
|
+
jest.spyOn(instance.storefront.paymentInstruments, 'create');
|
|
37
|
+
jest.spyOn(instance.storefront.paymentInstruments, 'setup');
|
|
38
|
+
const paymentInstrumentResponse = await instance.storefront.paymentInstruments.create(paymentInstrumentPayload);
|
|
39
|
+
const paymentInstrumentSetupResponse = await instance.storefront.paymentInstruments.setup(paymentInstrumentSetupPayload);
|
|
40
|
+
expect(instance.storefront.paymentInstruments.create).toBeCalledTimes(1);
|
|
41
|
+
expect(instance.storefront.paymentInstruments.create).toBeCalledWith(paymentInstrumentPayload);
|
|
42
|
+
expect(instance.storefront.paymentInstruments.setup).toBeCalledTimes(1);
|
|
43
|
+
expect(instance.storefront.paymentInstruments.setup).toBeCalledWith(paymentInstrumentSetupPayload);
|
|
44
|
+
expect(paymentInstrumentResponse.config).toBeInstanceOf(Object);
|
|
45
|
+
expect(paymentInstrumentResponse.fields).toBeInstanceOf(Object);
|
|
46
|
+
expect(paymentInstrumentResponse.response).toBeInstanceOf(Object);
|
|
47
|
+
expect(paymentInstrumentResponse.fields).toEqual(paymentInstrumentFields);
|
|
48
|
+
expect(paymentInstrumentResponse.fields).toMatchObject(paymentInstrumentFields);
|
|
49
|
+
expect(paymentInstrumentSetupResponse.config).toBeInstanceOf(Object);
|
|
50
|
+
expect(paymentInstrumentSetupResponse.fields).toBeInstanceOf(Object);
|
|
51
|
+
expect(paymentInstrumentSetupResponse.response).toBeInstanceOf(Object);
|
|
52
|
+
expect(paymentInstrumentSetupResponse.fields).toEqual(paymentInstrumentSetupFields);
|
|
53
|
+
expect(paymentInstrumentSetupResponse.fields).toMatchObject(paymentInstrumentSetupFields);
|
|
54
|
+
});
|
|
55
|
+
});
|
package/dist/storefront/plans.js
CHANGED
|
@@ -7,29 +7,23 @@ exports.fetchPlans = fetchPlans;
|
|
|
7
7
|
|
|
8
8
|
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
9
9
|
|
|
10
|
+
var _index = require("./index");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
async function fetchPlans({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
state = {},
|
|
16
|
+
data = {}
|
|
15
17
|
}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!state.options) {
|
|
21
|
-
throw new Error('Could not use Rebilly Instruments mount options to fetch Rebilly data');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
const {
|
|
26
|
-
lineItems
|
|
27
|
-
} = data || {};
|
|
18
|
+
return (0, _index.Endpoint)({
|
|
19
|
+
state
|
|
20
|
+
}, async () => {
|
|
21
|
+
const lineItems = data.lineItems || state.data.summaryLineItems;
|
|
28
22
|
const filterByPlanId = {
|
|
29
23
|
filter: ''
|
|
30
24
|
};
|
|
31
25
|
|
|
32
|
-
if (lineItems) {
|
|
26
|
+
if (lineItems.length) {
|
|
33
27
|
filterByPlanId.filter = `id:${lineItems.map(item => item.planId).join(',')}`;
|
|
34
28
|
}
|
|
35
29
|
|
|
@@ -39,7 +33,5 @@ async function fetchPlans({
|
|
|
39
33
|
return planItems.map(({
|
|
40
34
|
fields
|
|
41
35
|
}) => new _planModel.default(fields));
|
|
42
|
-
}
|
|
43
|
-
throw error;
|
|
44
|
-
}
|
|
36
|
+
});
|
|
45
37
|
}
|
|
@@ -17,23 +17,13 @@ var _asyncUtilities = require("../../tests/async-utilities");
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
19
|
describe('Storefront API Plan', () => {
|
|
20
|
-
class TestPlansInstance {
|
|
21
|
-
constructor({
|
|
22
|
-
options = {}
|
|
23
|
-
} = {}) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
it('can fetch plans', async () => {
|
|
31
21
|
const testPlan = {
|
|
32
22
|
name: 'Test Plan',
|
|
33
23
|
id: 'test-plan-id-1'
|
|
34
24
|
};
|
|
35
25
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
|
|
36
|
-
const instance = new
|
|
26
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
37
27
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
38
28
|
const response = await (0, _plans.fetchPlans)({
|
|
39
29
|
state: instance
|
|
@@ -47,7 +37,7 @@ describe('Storefront API Plan', () => {
|
|
|
47
37
|
expect(response).toEqual([new _planModel.default(testPlan)]);
|
|
48
38
|
});
|
|
49
39
|
it('can fetch plans with filter', async () => {
|
|
50
|
-
const instance = new
|
|
40
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
51
41
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
52
42
|
await (0, _plans.fetchPlans)({
|
|
53
43
|
state: instance,
|
|
@@ -64,7 +54,7 @@ describe('Storefront API Plan', () => {
|
|
|
64
54
|
});
|
|
65
55
|
});
|
|
66
56
|
it('should throw errors with no options', async () => {
|
|
67
|
-
const noConfigOrOptionsInstance = new
|
|
57
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
68
58
|
options: null
|
|
69
59
|
});
|
|
70
60
|
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
@@ -7,22 +7,21 @@ exports.fetchProducts = fetchProducts;
|
|
|
7
7
|
|
|
8
8
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
9
9
|
|
|
10
|
+
var _index = require("./index");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
async function fetchProducts({
|
|
13
|
-
data = null,
|
|
14
15
|
state
|
|
15
16
|
}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
17
|
+
return (0, _index.Endpoint)({
|
|
18
|
+
state
|
|
19
|
+
}, async () => {
|
|
20
|
+
if (state.data.plans === null) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
const plansData = data || [];
|
|
24
|
+
const plansData = state.data.plans || [];
|
|
26
25
|
const filterByProductId = {
|
|
27
26
|
filter: ''
|
|
28
27
|
};
|
|
@@ -37,7 +36,5 @@ async function fetchProducts({
|
|
|
37
36
|
return productItems.map(({
|
|
38
37
|
fields
|
|
39
38
|
}) => new _productModel.default(fields));
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
39
|
+
});
|
|
43
40
|
}
|
|
@@ -17,23 +17,13 @@ var _asyncUtilities = require("../../tests/async-utilities");
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
19
|
describe('Storefront API Plan', () => {
|
|
20
|
-
class TestProductsInstance {
|
|
21
|
-
constructor({
|
|
22
|
-
options = {}
|
|
23
|
-
} = {}) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
it('can fetch products', async () => {
|
|
31
21
|
const testProduct = {
|
|
32
22
|
name: 'Test Product',
|
|
33
23
|
id: 'test-product-id-1'
|
|
34
24
|
};
|
|
35
25
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
|
|
36
|
-
const instance = new
|
|
26
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
37
27
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
38
28
|
const response = await (0, _products.fetchProducts)({
|
|
39
29
|
state: instance
|
|
@@ -47,22 +37,25 @@ describe('Storefront API Plan', () => {
|
|
|
47
37
|
expect(response).toEqual([new _productModel.default(testProduct)]);
|
|
48
38
|
});
|
|
49
39
|
it('can fetch products with filter', async () => {
|
|
50
|
-
const instance = new
|
|
40
|
+
const instance = new _storefrontMock.StorefontTestingInstance({
|
|
41
|
+
data: {
|
|
42
|
+
plans: [{
|
|
43
|
+
productId: 'test-product-1'
|
|
44
|
+
}, {
|
|
45
|
+
productId: 'test-product-2'
|
|
46
|
+
}]
|
|
47
|
+
}
|
|
48
|
+
});
|
|
51
49
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
52
50
|
await (0, _products.fetchProducts)({
|
|
53
|
-
state: instance
|
|
54
|
-
data: [{
|
|
55
|
-
productId: 'test-product-1'
|
|
56
|
-
}, {
|
|
57
|
-
productId: 'test-product-2'
|
|
58
|
-
}]
|
|
51
|
+
state: instance
|
|
59
52
|
});
|
|
60
53
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
61
54
|
filter: 'id:test-product-1,test-product-2'
|
|
62
55
|
});
|
|
63
56
|
});
|
|
64
57
|
it('should throw errors with no options', async () => {
|
|
65
|
-
const noConfigOrOptionsInstance = new
|
|
58
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
66
59
|
options: null
|
|
67
60
|
});
|
|
68
61
|
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
@@ -4,29 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.postPurchase = postPurchase;
|
|
7
|
+
exports.postPayment = postPayment;
|
|
8
|
+
|
|
9
|
+
var _index = require("./index");
|
|
7
10
|
|
|
8
11
|
async function postPurchase({
|
|
9
12
|
data,
|
|
10
13
|
state
|
|
11
14
|
}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
+
return (0, _index.Endpoint)({
|
|
16
|
+
state
|
|
17
|
+
}, async () => {
|
|
18
|
+
if (data._raw) {
|
|
19
|
+
delete data._raw;
|
|
20
|
+
}
|
|
15
21
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
return state.storefront.purchase.purchase({
|
|
23
|
+
data
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
19
27
|
|
|
20
|
-
|
|
28
|
+
async function postPayment({
|
|
29
|
+
data,
|
|
30
|
+
state
|
|
31
|
+
}) {
|
|
32
|
+
return (0, _index.Endpoint)({
|
|
33
|
+
state
|
|
34
|
+
}, async () => {
|
|
21
35
|
if (data._raw) {
|
|
22
36
|
delete data._raw;
|
|
23
37
|
}
|
|
24
38
|
|
|
25
|
-
|
|
39
|
+
return state.storefront.purchase.payment({
|
|
26
40
|
data
|
|
27
41
|
});
|
|
28
|
-
|
|
29
|
-
} catch (error) {
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
42
|
+
});
|
|
32
43
|
}
|
|
@@ -8,28 +8,9 @@ var _server = require("../../tests/msw/server");
|
|
|
8
8
|
|
|
9
9
|
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
10
10
|
|
|
11
|
-
var _purchase = require("./purchase");
|
|
12
|
-
|
|
13
11
|
describe('Storefront API Purchase', () => {
|
|
14
|
-
class TestPurchaseInstance {
|
|
15
|
-
constructor({
|
|
16
|
-
options = {}
|
|
17
|
-
} = {}) {
|
|
18
|
-
this.options = options;
|
|
19
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
postPurchase(...args) {
|
|
23
|
-
return (0, _purchase.postPurchase)({
|
|
24
|
-
state: this,
|
|
25
|
-
data: args
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
12
|
it('can make purchase', async () => {
|
|
32
|
-
const instance =
|
|
13
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)();
|
|
33
14
|
const payload = {
|
|
34
15
|
websiteId: 'test-website-id',
|
|
35
16
|
items: [{
|
|
@@ -9,22 +9,18 @@ var _riskDataCollector = require("@rebilly/risk-data-collector");
|
|
|
9
9
|
|
|
10
10
|
var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
|
|
11
11
|
|
|
12
|
+
var _index = require("./index");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
14
16
|
async function fetchReadyToPay({
|
|
15
17
|
state,
|
|
16
18
|
riskMetadata = null
|
|
17
19
|
}) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!state.options) {
|
|
23
|
-
throw new Error('Could not use Rebilly Instruments mount options to fetch Rebilly data');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
var _state$options, _state$options2;
|
|
20
|
+
return (0, _index.Endpoint)({
|
|
21
|
+
state
|
|
22
|
+
}, async () => {
|
|
23
|
+
var _state$options, _state$options2, _state$data;
|
|
28
24
|
|
|
29
25
|
if (!riskMetadata) {
|
|
30
26
|
const {
|
|
@@ -34,12 +30,21 @@ async function fetchReadyToPay({
|
|
|
34
30
|
}
|
|
35
31
|
|
|
36
32
|
const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
|
|
37
|
-
const items = ((_state$options2 = state.options) === null || _state$options2 === void 0 ? void 0 : _state$options2.items) || [];
|
|
38
33
|
const data = {
|
|
39
|
-
items,
|
|
40
34
|
websiteId,
|
|
41
35
|
riskMetadata
|
|
42
36
|
};
|
|
37
|
+
|
|
38
|
+
if ((_state$options2 = state.options) !== null && _state$options2 !== void 0 && _state$options2.items) {
|
|
39
|
+
data.items = state.options.items;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ((_state$data = state.data) !== null && _state$data !== void 0 && _state$data.amountAndCurrency) {
|
|
43
|
+
const money = state.data.amountAndCurrency;
|
|
44
|
+
data.amount = money.amount;
|
|
45
|
+
data.currency = money.currency;
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
const {
|
|
44
49
|
fields: readyToPayFields
|
|
45
50
|
} = await state.storefront.purchase.readyToPay({
|
|
@@ -49,7 +54,5 @@ async function fetchReadyToPay({
|
|
|
49
54
|
index,
|
|
50
55
|
...fields
|
|
51
56
|
}));
|
|
52
|
-
}
|
|
53
|
-
throw error;
|
|
54
|
-
}
|
|
57
|
+
});
|
|
55
58
|
}
|
|
@@ -17,16 +17,6 @@ var _asyncUtilities = require("../../tests/async-utilities");
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
19
|
describe('Storefront API Ready to Pay', () => {
|
|
20
|
-
class TestReadyToPayInstance {
|
|
21
|
-
constructor({
|
|
22
|
-
options = {}
|
|
23
|
-
} = {}) {
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
20
|
it('can fetch ready to pay', async () => {
|
|
31
21
|
const readyToPayPayload = [{
|
|
32
22
|
method: 'payment-card',
|
|
@@ -42,7 +32,7 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
42
32
|
}]
|
|
43
33
|
};
|
|
44
34
|
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((0, _mswWhenThen.ok)(readyToPayPayload));
|
|
45
|
-
const instance =
|
|
35
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
46
36
|
options
|
|
47
37
|
});
|
|
48
38
|
jest.spyOn(instance.storefront.purchase, 'readyToPay');
|
|
@@ -68,7 +58,7 @@ describe('Storefront API Ready to Pay', () => {
|
|
|
68
58
|
});
|
|
69
59
|
it('should throw errors with no options', async () => {
|
|
70
60
|
const riskMetadata = null;
|
|
71
|
-
const noConfigOrOptionsInstance = new
|
|
61
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
72
62
|
options: null
|
|
73
63
|
});
|
|
74
64
|
await (0, _asyncUtilities.expectConfigurationError)((0, _readyToPay.fetchReadyToPay)({
|
|
@@ -7,32 +7,36 @@ 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
14
|
async function fetchSummary({
|
|
13
15
|
data = null,
|
|
14
16
|
state = null
|
|
15
17
|
} = {}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!state.options) {
|
|
21
|
-
throw new Error('Could not use Rebilly Instruments mount options to fetch Rebilly data');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
var _state$options, _state$options2;
|
|
18
|
+
return (0, _index.Endpoint)({
|
|
19
|
+
state
|
|
20
|
+
}, async () => {
|
|
21
|
+
var _state$options, _state$options2, _state$data;
|
|
26
22
|
|
|
27
23
|
const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
|
|
28
|
-
const items = ((_state$options2 = state.options) === null || _state$options2 === void 0 ? void 0 : _state$options2.items) || [];
|
|
29
24
|
const payload = {
|
|
30
25
|
data: {
|
|
31
|
-
websiteId
|
|
32
|
-
items
|
|
26
|
+
websiteId
|
|
33
27
|
}
|
|
34
28
|
};
|
|
35
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
|
+
|
|
36
40
|
if (data !== null && data !== void 0 && data.billingAddress) {
|
|
37
41
|
payload.data.billingAddress = data.billingAddress;
|
|
38
42
|
}
|
|
@@ -43,9 +47,9 @@ async function fetchSummary({
|
|
|
43
47
|
|
|
44
48
|
const {
|
|
45
49
|
fields: summaryFields
|
|
46
|
-
} = await state.storefront.purchase.preview(payload);
|
|
50
|
+
} = await state.storefront.purchase.preview(payload); // In case of preview purchase gets call again for updating the values
|
|
51
|
+
|
|
52
|
+
state.data.previewPurchase = summaryFields;
|
|
47
53
|
return new _summaryModel.default(summaryFields);
|
|
48
|
-
}
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
54
|
+
});
|
|
51
55
|
}
|
|
@@ -17,17 +17,6 @@ var _asyncUtilities = require("../../tests/async-utilities");
|
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
|
|
19
19
|
describe('Storefront API Summary', () => {
|
|
20
|
-
class TestSummaryInstance {
|
|
21
|
-
constructor({
|
|
22
|
-
options = {},
|
|
23
|
-
storefront = null
|
|
24
|
-
} = {}) {
|
|
25
|
-
this.options = options;
|
|
26
|
-
this.storefront = storefront === null ? (0, _storefrontMock.MockStorefront)() : storefront;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
20
|
it('can fetch preview', async () => {
|
|
32
21
|
const options = {
|
|
33
22
|
websiteId: 'test-website-id',
|
|
@@ -45,7 +34,7 @@ describe('Storefront API Summary', () => {
|
|
|
45
34
|
}]
|
|
46
35
|
};
|
|
47
36
|
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((0, _mswWhenThen.ok)(testSummary));
|
|
48
|
-
const instance =
|
|
37
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
49
38
|
options
|
|
50
39
|
});
|
|
51
40
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
@@ -74,7 +63,7 @@ describe('Storefront API Summary', () => {
|
|
|
74
63
|
firstName: 'Test',
|
|
75
64
|
lastName: 'Customer'
|
|
76
65
|
};
|
|
77
|
-
const instance =
|
|
66
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
78
67
|
options
|
|
79
68
|
});
|
|
80
69
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
@@ -105,7 +94,7 @@ describe('Storefront API Summary', () => {
|
|
|
105
94
|
firstName: 'Test',
|
|
106
95
|
lastName: 'Customer'
|
|
107
96
|
};
|
|
108
|
-
const instance =
|
|
97
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
109
98
|
options
|
|
110
99
|
});
|
|
111
100
|
jest.spyOn(instance.storefront.purchase, 'preview');
|
|
@@ -125,7 +114,7 @@ describe('Storefront API Summary', () => {
|
|
|
125
114
|
});
|
|
126
115
|
});
|
|
127
116
|
it('should throw errors with no options', async () => {
|
|
128
|
-
const noConfigOrOptionsInstance =
|
|
117
|
+
const noConfigOrOptionsInstance = (0, _storefrontMock.StorefontTestingInstance)({
|
|
129
118
|
options: null
|
|
130
119
|
});
|
|
131
120
|
await (0, _asyncUtilities.expectConfigurationError)((0, _summary.fetchSummary)({
|
|
@@ -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
|
+
}
|