@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
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setupPaymentInstrument = setupPaymentInstrument;
|
|
7
|
+
|
|
8
|
+
var _index = require("./index");
|
|
9
|
+
|
|
10
|
+
async function setupPaymentInstrument({
|
|
11
|
+
data,
|
|
12
|
+
state
|
|
13
|
+
}) {
|
|
14
|
+
return (0, _index.Endpoint)({
|
|
15
|
+
state
|
|
16
|
+
}, async () => {
|
|
17
|
+
// Create payment instrument
|
|
18
|
+
const {
|
|
19
|
+
fields: instrument
|
|
20
|
+
} = await state.storefront.paymentInstruments.create({
|
|
21
|
+
data
|
|
22
|
+
}); // Setup the payment instrument
|
|
23
|
+
|
|
24
|
+
state.storefront.setSessionToken(instrument.token);
|
|
25
|
+
const setupPayload = {
|
|
26
|
+
id: instrument.id,
|
|
27
|
+
data: {
|
|
28
|
+
websiteId: state.options.websiteId,
|
|
29
|
+
...data
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (state.data.getAmountAndCurrency) {
|
|
34
|
+
setupPayload.data = { ...setupPayload.data,
|
|
35
|
+
...state.data.getAmountAndCurrency
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const {
|
|
40
|
+
fields: transaction
|
|
41
|
+
} = await state.storefront.paymentInstruments.setup(setupPayload);
|
|
42
|
+
return {
|
|
43
|
+
instrument,
|
|
44
|
+
transaction
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -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
|
@@ -3,44 +3,35 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchPlans = fetchPlans;
|
|
7
7
|
|
|
8
8
|
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
async function FetchPlans({
|
|
13
|
-
data = null
|
|
14
|
-
} = {}) {
|
|
15
|
-
if (!this.storefront) {
|
|
16
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
|
-
}
|
|
10
|
+
var _index = require("./index");
|
|
18
11
|
|
|
19
|
-
|
|
20
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
|
-
}
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
13
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
async function fetchPlans({
|
|
15
|
+
state = {},
|
|
16
|
+
data = {}
|
|
17
|
+
}) {
|
|
18
|
+
return (0, _index.Endpoint)({
|
|
19
|
+
state
|
|
20
|
+
}, async () => {
|
|
21
|
+
const lineItems = data.lineItems || state.data.summaryLineItems;
|
|
27
22
|
const filterByPlanId = {
|
|
28
23
|
filter: ''
|
|
29
24
|
};
|
|
30
25
|
|
|
31
|
-
if (lineItems) {
|
|
26
|
+
if (lineItems.length) {
|
|
32
27
|
filterByPlanId.filter = `id:${lineItems.map(item => item.planId).join(',')}`;
|
|
33
28
|
}
|
|
34
29
|
|
|
35
30
|
const {
|
|
36
31
|
items: planItems
|
|
37
|
-
} = await
|
|
32
|
+
} = await state.storefront.plans.getAll(filterByPlanId);
|
|
38
33
|
return planItems.map(({
|
|
39
34
|
fields
|
|
40
35
|
}) => new _planModel.default(fields));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -1,45 +1,33 @@
|
|
|
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 _plans = require("./plans");
|
|
12
12
|
|
|
13
13
|
var _planModel = _interopRequireDefault(require("./models/plan-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', () => {
|
|
18
|
-
class TestPlansInstance {
|
|
19
|
-
constructor({
|
|
20
|
-
configs = {},
|
|
21
|
-
options = {}
|
|
22
|
-
} = {}) {
|
|
23
|
-
this.configs = configs;
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
fetchPlans(...args) {
|
|
29
|
-
return _plans.FetchPlans.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
20
|
it('can fetch plans', async () => {
|
|
35
21
|
const testPlan = {
|
|
36
22
|
name: 'Test Plan',
|
|
37
23
|
id: 'test-plan-id-1'
|
|
38
24
|
};
|
|
39
25
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
|
|
40
|
-
const instance = new
|
|
26
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
41
27
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
42
|
-
const response = await
|
|
28
|
+
const response = await (0, _plans.fetchPlans)({
|
|
29
|
+
state: instance
|
|
30
|
+
});
|
|
43
31
|
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
44
32
|
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
45
33
|
filter: ''
|
|
@@ -49,9 +37,10 @@ describe('Storefront API Plan', () => {
|
|
|
49
37
|
expect(response).toEqual([new _planModel.default(testPlan)]);
|
|
50
38
|
});
|
|
51
39
|
it('can fetch plans with filter', async () => {
|
|
52
|
-
const instance = new
|
|
40
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
53
41
|
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
54
|
-
await
|
|
42
|
+
await (0, _plans.fetchPlans)({
|
|
43
|
+
state: instance,
|
|
55
44
|
data: {
|
|
56
45
|
lineItems: [{
|
|
57
46
|
planId: 'test-plan-id-1'
|
|
@@ -64,28 +53,12 @@ describe('Storefront API Plan', () => {
|
|
|
64
53
|
filter: 'id:test-plan-id-1,test-plan-id-2'
|
|
65
54
|
});
|
|
66
55
|
});
|
|
67
|
-
it('should throw errors with no
|
|
68
|
-
const
|
|
69
|
-
const noConfigOrOptionsInstance = new TestPlansInstance({
|
|
70
|
-
configs: null,
|
|
71
|
-
options: null
|
|
72
|
-
});
|
|
73
|
-
const noConfigInstance = new TestPlansInstance({
|
|
74
|
-
configs: null,
|
|
75
|
-
options: {}
|
|
76
|
-
});
|
|
77
|
-
const noOptionsInstance = new TestPlansInstance({
|
|
78
|
-
configs: {},
|
|
56
|
+
it('should throw errors with no options', async () => {
|
|
57
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
79
58
|
options: null
|
|
80
59
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
})
|
|
84
|
-
expect(async () => {
|
|
85
|
-
await noConfigInstance.fetchPlans();
|
|
86
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
87
|
-
expect(async () => {
|
|
88
|
-
await noOptionsInstance.fetchPlans();
|
|
89
|
-
}).rejects.toEqual(NoConfigOrOptionsError);
|
|
60
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
61
|
+
state: noConfigOrOptionsInstance
|
|
62
|
+
}));
|
|
90
63
|
});
|
|
91
64
|
});
|
|
@@ -3,25 +3,25 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.fetchProducts = fetchProducts;
|
|
7
7
|
|
|
8
8
|
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var _index = require("./index");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
data = null
|
|
14
|
-
} = {}) {
|
|
15
|
-
if (!this.storefront) {
|
|
16
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
|
-
}
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
async function fetchProducts({
|
|
15
|
+
state
|
|
16
|
+
}) {
|
|
17
|
+
return (0, _index.Endpoint)({
|
|
18
|
+
state
|
|
19
|
+
}, async () => {
|
|
20
|
+
if (state.data.plans === null) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
const plansData = data || [];
|
|
24
|
+
const plansData = state.data.plans || [];
|
|
25
25
|
const filterByProductId = {
|
|
26
26
|
filter: ''
|
|
27
27
|
};
|
|
@@ -32,13 +32,9 @@ async function FetchProducts({
|
|
|
32
32
|
|
|
33
33
|
const {
|
|
34
34
|
items: productItems
|
|
35
|
-
} = await
|
|
35
|
+
} = await state.storefront.products.getAll(filterByProductId);
|
|
36
36
|
return productItems.map(({
|
|
37
37
|
fields
|
|
38
38
|
}) => new _productModel.default(fields));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -1,45 +1,33 @@
|
|
|
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', () => {
|
|
18
|
-
class TestProductsInstance {
|
|
19
|
-
constructor({
|
|
20
|
-
configs = {},
|
|
21
|
-
options = {}
|
|
22
|
-
} = {}) {
|
|
23
|
-
this.configs = configs;
|
|
24
|
-
this.options = options;
|
|
25
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
FetchProducts(...args) {
|
|
29
|
-
return _products.FetchProducts.apply(this, args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
20
|
it('can fetch products', async () => {
|
|
35
21
|
const testProduct = {
|
|
36
22
|
name: 'Test Product',
|
|
37
23
|
id: 'test-product-id-1'
|
|
38
24
|
};
|
|
39
25
|
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((0, _mswWhenThen.ok)([testProduct]));
|
|
40
|
-
const instance = new
|
|
26
|
+
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
41
27
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
42
|
-
const response = await
|
|
28
|
+
const response = await (0, _products.fetchProducts)({
|
|
29
|
+
state: instance
|
|
30
|
+
});
|
|
43
31
|
expect(instance.storefront.products.getAll).toBeCalledTimes(1);
|
|
44
32
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
45
33
|
filter: ''
|
|
@@ -49,41 +37,29 @@ describe('Storefront API Plan', () => {
|
|
|
49
37
|
expect(response).toEqual([new _productModel.default(testProduct)]);
|
|
50
38
|
});
|
|
51
39
|
it('can fetch products with filter', async () => {
|
|
52
|
-
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
|
+
});
|
|
53
49
|
jest.spyOn(instance.storefront.products, 'getAll');
|
|
54
|
-
await
|
|
55
|
-
|
|
56
|
-
productId: 'test-product-1'
|
|
57
|
-
}, {
|
|
58
|
-
productId: 'test-product-2'
|
|
59
|
-
}]
|
|
50
|
+
await (0, _products.fetchProducts)({
|
|
51
|
+
state: instance
|
|
60
52
|
});
|
|
61
53
|
expect(instance.storefront.products.getAll).toBeCalledWith({
|
|
62
54
|
filter: 'id:test-product-1,test-product-2'
|
|
63
55
|
});
|
|
64
56
|
});
|
|
65
|
-
it('should throw errors with no
|
|
66
|
-
const
|
|
67
|
-
const noConfigOrOptionsInstance = new TestProductsInstance({
|
|
68
|
-
configs: null,
|
|
69
|
-
options: null
|
|
70
|
-
});
|
|
71
|
-
const noConfigInstance = new TestProductsInstance({
|
|
72
|
-
configs: null,
|
|
73
|
-
options: {}
|
|
74
|
-
});
|
|
75
|
-
const noOptionsInstance = new TestProductsInstance({
|
|
76
|
-
configs: {},
|
|
57
|
+
it('should throw errors with no options', async () => {
|
|
58
|
+
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
77
59
|
options: null
|
|
78
60
|
});
|
|
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);
|
|
61
|
+
await (0, _asyncUtilities.expectConfigurationError)((0, _products.fetchProducts)({
|
|
62
|
+
state: noConfigOrOptionsInstance
|
|
63
|
+
}));
|
|
88
64
|
});
|
|
89
65
|
});
|
|
@@ -3,29 +3,41 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.postPurchase = postPurchase;
|
|
7
|
+
exports.postPayment = postPayment;
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
if (!this.storefront) {
|
|
10
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
11
|
-
}
|
|
9
|
+
var _index = require("./index");
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
async function postPurchase({
|
|
12
|
+
data,
|
|
13
|
+
state
|
|
14
|
+
}) {
|
|
15
|
+
return (0, _index.Endpoint)({
|
|
16
|
+
state
|
|
17
|
+
}, async () => {
|
|
18
18
|
if (data._raw) {
|
|
19
19
|
delete data._raw;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
return state.storefront.purchase.purchase({
|
|
23
23
|
data
|
|
24
24
|
});
|
|
25
|
-
|
|
26
|
-
} catch (error) {
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
25
|
+
});
|
|
29
26
|
}
|
|
30
27
|
|
|
31
|
-
|
|
28
|
+
async function postPayment({
|
|
29
|
+
data,
|
|
30
|
+
state
|
|
31
|
+
}) {
|
|
32
|
+
return (0, _index.Endpoint)({
|
|
33
|
+
state
|
|
34
|
+
}, async () => {
|
|
35
|
+
if (data._raw) {
|
|
36
|
+
delete data._raw;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return state.storefront.purchase.payment({
|
|
40
|
+
data
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -1,34 +1,16 @@
|
|
|
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");
|
|
10
|
-
|
|
11
|
-
var _purchase = require("./purchase");
|
|
9
|
+
var _storefrontApiMock = require("../../tests/mocks/storefront-api-mock");
|
|
12
10
|
|
|
13
11
|
describe('Storefront API Purchase', () => {
|
|
14
|
-
class TestPurchaseInstance {
|
|
15
|
-
constructor({
|
|
16
|
-
configs = {},
|
|
17
|
-
options = {}
|
|
18
|
-
} = {}) {
|
|
19
|
-
this.configs = configs;
|
|
20
|
-
this.options = options;
|
|
21
|
-
this.storefront = (0, _storefrontMock.MockStorefront)();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
postPurchase(...args) {
|
|
25
|
-
return _purchase.PostPurchase.apply(this, args);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
12
|
it('can make purchase', async () => {
|
|
31
|
-
const instance =
|
|
13
|
+
const instance = (0, _storefrontMock.StorefontTestingInstance)();
|
|
32
14
|
const payload = {
|
|
33
15
|
websiteId: 'test-website-id',
|
|
34
16
|
items: [{
|
|
@@ -3,25 +3,24 @@
|
|
|
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
|
|
|
10
10
|
var _readyToPayModel = _interopRequireDefault(require("./models/ready-to-pay-model"));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
async function FetchReadyToPay(riskMetadata = null) {
|
|
15
|
-
if (!this.storefront) {
|
|
16
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
|
-
}
|
|
12
|
+
var _index = require("./index");
|
|
18
13
|
|
|
19
|
-
|
|
20
|
-
throw new Error('Could not use Rebilly Instruments configurations or mount options to fetch Rebilly data');
|
|
21
|
-
}
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
15
|
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
async function fetchReadyToPay({
|
|
17
|
+
state,
|
|
18
|
+
riskMetadata = null
|
|
19
|
+
}) {
|
|
20
|
+
return (0, _index.Endpoint)({
|
|
21
|
+
state
|
|
22
|
+
}, async () => {
|
|
23
|
+
var _state$options, _state$options2, _state$data;
|
|
25
24
|
|
|
26
25
|
if (!riskMetadata) {
|
|
27
26
|
const {
|
|
@@ -30,25 +29,30 @@ async function FetchReadyToPay(riskMetadata = null) {
|
|
|
30
29
|
riskMetadata = data;
|
|
31
30
|
}
|
|
32
31
|
|
|
33
|
-
const websiteId = ((
|
|
34
|
-
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) || [];
|
|
32
|
+
const websiteId = ((_state$options = state.options) === null || _state$options === void 0 ? void 0 : _state$options.websiteId) || null;
|
|
35
33
|
const data = {
|
|
36
|
-
items,
|
|
37
34
|
websiteId,
|
|
38
35
|
riskMetadata
|
|
39
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
|
+
|
|
40
48
|
const {
|
|
41
49
|
fields: readyToPayFields
|
|
42
|
-
} = await
|
|
50
|
+
} = await state.storefront.purchase.readyToPay({
|
|
43
51
|
data
|
|
44
52
|
});
|
|
45
53
|
return Object.values(readyToPayFields).map((fields, index) => new _readyToPayModel.default({
|
|
46
54
|
index,
|
|
47
55
|
...fields
|
|
48
56
|
}));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
;
|
|
57
|
+
});
|
|
58
|
+
}
|