@rebilly/instruments 3.1.0-beta.0 → 3.1.4-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/index.js +88 -107
- package/dist/index.min.js +88 -0
- package/package.json +17 -6
- package/rollup.config.js +84 -0
- package/src/functions/mount/fetch-data.js +13 -1
- package/src/functions/mount/index.js +6 -42
- package/src/functions/mount/setup-framepay-theme.js +2 -2
- package/src/functions/mount/setup-options.js +3 -0
- package/src/functions/mount/setup-user-flow.js +49 -0
- package/src/functions/purchase.js +1 -1
- package/src/functions/setup.js +1 -1
- package/src/functions/show.spec.js +1 -1
- package/src/i18n/en.json +3 -0
- package/src/index.js +1 -61
- package/src/instance.js +65 -0
- package/src/{index.spec.js → instance.spec.js} +2 -1
- package/src/loader/index.js +21 -1
- package/src/storefront/models/ready-to-pay-model.js +13 -2
- package/src/storefront/plans.js +8 -4
- package/src/storefront/plans.spec.js +8 -2
- package/src/storefront/products.js +8 -4
- package/src/storefront/products.spec.js +8 -2
- package/src/storefront/ready-to-pay.js +5 -4
- package/src/style/components/button.js +1 -0
- package/src/style/components/loader.js +2 -1
- package/src/style/payment-instruments/payment-card.js +2 -1
- package/src/style/utils/remove-empty-null.js +9 -9
- package/src/style/vendor/postmate.js +13 -0
- package/src/style/views/confirmation.js +2 -1
- package/src/views/common/iframe/base-iframe.js +2 -0
- package/src/views/common/iframe/event-listeners.js +10 -0
- package/src/views/common/iframe/method-iframe.js +3 -1
- package/src/views/confirmation.js +1 -0
- package/src/views/method-selector/express-methods/{google-pay.js → index.js} +3 -2
- package/src/views/method-selector/mount-express-methods.js +6 -18
- package/src/views/result.js +1 -0
- package/tests/mocks/rebilly-instruments-mock.js +2 -2
- package/dist/events/base-event.js +0 -66
- package/dist/events/events.spec.js +0 -18
- package/dist/events/index.js +0 -22
- package/dist/functions/destroy.js +0 -34
- package/dist/functions/destroy.spec.js +0 -69
- package/dist/functions/mount/fetch-data.js +0 -187
- package/dist/functions/mount/fetch-data.spec.js +0 -189
- package/dist/functions/mount/index.js +0 -218
- package/dist/functions/mount/mount.spec.js +0 -64
- package/dist/functions/mount/setup-element.js +0 -40
- package/dist/functions/mount/setup-framepay-theme.js +0 -95
- package/dist/functions/mount/setup-framepay.js +0 -46
- package/dist/functions/mount/setup-i18n.js +0 -33
- package/dist/functions/mount/setup-options.js +0 -99
- package/dist/functions/mount/setup-options.spec.js +0 -66
- package/dist/functions/mount/setup-storefront.js +0 -34
- package/dist/functions/mount/setup-styles.js +0 -43
- package/dist/functions/on.js +0 -40
- package/dist/functions/on.spec.js +0 -55
- package/dist/functions/purchase.js +0 -158
- package/dist/functions/purchase.spec.js +0 -74
- package/dist/functions/setup.js +0 -85
- package/dist/functions/setup.spec.js +0 -87
- package/dist/functions/show.js +0 -55
- package/dist/functions/show.spec.js +0 -61
- package/dist/functions/update.js +0 -74
- package/dist/functions/update.spec.js +0 -86
- package/dist/i18n/en.json +0 -22
- package/dist/i18n/es.json +0 -22
- package/dist/i18n/i18n.spec.js +0 -22
- package/dist/i18n/index.js +0 -72
- package/dist/index.spec.js +0 -35
- package/dist/loader/index.js +0 -94
- package/dist/loader/loader.spec.js +0 -69
- package/dist/storefront/index.js +0 -73
- package/dist/storefront/invoices.js +0 -27
- package/dist/storefront/models/base-model.js +0 -18
- package/dist/storefront/models/invoice-model.js +0 -14
- package/dist/storefront/models/plan-model.js +0 -14
- package/dist/storefront/models/product-model.js +0 -14
- package/dist/storefront/models/ready-to-pay-model.js +0 -46
- package/dist/storefront/models/summary-model.js +0 -79
- package/dist/storefront/models/transaction-model.js +0 -31
- package/dist/storefront/payment-instruments.js +0 -47
- package/dist/storefront/payment-instruments.spec.js +0 -55
- package/dist/storefront/plans.js +0 -37
- package/dist/storefront/plans.spec.js +0 -64
- package/dist/storefront/products.js +0 -40
- package/dist/storefront/products.spec.js +0 -65
- package/dist/storefront/purchase.js +0 -43
- package/dist/storefront/purchase.spec.js +0 -48
- package/dist/storefront/ready-to-pay.js +0 -58
- package/dist/storefront/ready-to-pay.spec.js +0 -69
- package/dist/storefront/storefront.spec.js +0 -15
- package/dist/storefront/summary.js +0 -55
- package/dist/storefront/summary.spec.js +0 -124
- package/dist/storefront/transactions.js +0 -27
- package/dist/style/base/__snapshots__/theme.spec.js.snap +0 -227
- package/dist/style/base/default-theme.js +0 -804
- package/dist/style/base/index.js +0 -104
- package/dist/style/base/theme.js +0 -41
- package/dist/style/base/theme.spec.js +0 -19
- package/dist/style/browserslist.js +0 -8
- package/dist/style/components/address.js +0 -64
- package/dist/style/components/button.js +0 -87
- package/dist/style/components/divider.js +0 -48
- package/dist/style/components/forms/checkbox.js +0 -86
- package/dist/style/components/forms/field.js +0 -65
- package/dist/style/components/forms/form.js +0 -28
- package/dist/style/components/forms/input.js +0 -86
- package/dist/style/components/forms/label.js +0 -64
- package/dist/style/components/forms/select.js +0 -95
- package/dist/style/components/forms/validation.js +0 -81
- package/dist/style/components/icons.js +0 -22
- package/dist/style/components/index.js +0 -57
- package/dist/style/components/loader.js +0 -50
- package/dist/style/components/methods.js +0 -108
- package/dist/style/components/overlay.js +0 -33
- package/dist/style/helpers/index.js +0 -59
- package/dist/style/index.js +0 -50
- package/dist/style/payment-instruments/content.js +0 -17
- package/dist/style/payment-instruments/index.js +0 -20
- package/dist/style/payment-instruments/payment-card.js +0 -35
- package/dist/style/utils/border.js +0 -47
- package/dist/style/utils/color-values.js +0 -58
- package/dist/style/utils/remove-empty-null.js +0 -20
- package/dist/style/vendor/framepay.js +0 -37
- package/dist/style/vendor/postmate.js +0 -17
- package/dist/style/views/confirmation.js +0 -85
- package/dist/style/views/index.js +0 -29
- package/dist/style/views/method-selector.js +0 -20
- package/dist/style/views/modal.js +0 -93
- package/dist/style/views/result.js +0 -61
- package/dist/style/views/summary.js +0 -127
- package/dist/utils/add-dom-element.js +0 -26
- package/dist/utils/format-currency.js +0 -15
- package/dist/utils/has-valid-css-selector.js +0 -11
- package/dist/utils/index.js +0 -55
- package/dist/utils/is-dom-element.js +0 -10
- package/dist/utils/process-property-as-dom-element.js +0 -38
- package/dist/utils/sleep.js +0 -10
- package/dist/views/__snapshots__/summary.spec.js.snap +0 -246
- package/dist/views/common/iframe/base-iframe.js +0 -59
- package/dist/views/common/iframe/event-listeners.js +0 -50
- package/dist/views/common/iframe/index.js +0 -19
- package/dist/views/common/iframe/method-iframe.js +0 -33
- package/dist/views/common/iframe/modal-iframe.js +0 -84
- package/dist/views/common/iframe/view-iframe.js +0 -31
- package/dist/views/common/render-utilities.js +0 -11
- package/dist/views/confirmation.js +0 -92
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +0 -3
- package/dist/views/method-selector/express-methods/apple-pay.js +0 -92
- package/dist/views/method-selector/express-methods/google-pay.js +0 -31
- package/dist/views/method-selector/express-methods/paypal.js +0 -19
- package/dist/views/method-selector/generate-digital-wallet.js +0 -68
- package/dist/views/method-selector/generate-digital-wallet.spec.js +0 -135
- package/dist/views/method-selector/get-method-data.js +0 -25
- package/dist/views/method-selector/get-payment-methods.js +0 -66
- package/dist/views/method-selector/get-payment-methods.spec.js +0 -46
- package/dist/views/method-selector/index.js +0 -122
- package/dist/views/method-selector/method-selector.spec.js +0 -124
- package/dist/views/method-selector/mount-express-methods.js +0 -69
- package/dist/views/method-selector/mount-methods.js +0 -74
- package/dist/views/modal.js +0 -88
- package/dist/views/result.js +0 -40
- package/dist/views/summary.js +0 -215
- package/dist/views/summary.spec.js +0 -134
- package/src/views/method-selector/express-methods/paypal.js +0 -7
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = require("./index");
|
|
4
|
-
|
|
5
|
-
describe('Loader Class', () => {
|
|
6
|
-
let loader;
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
loader = new _index.Loader();
|
|
9
|
-
document.body.innerHTML = `
|
|
10
|
-
<div class="form-selector"></div>
|
|
11
|
-
<div class="summary-selector"></div>
|
|
12
|
-
`;
|
|
13
|
-
loader.addDOMElement({
|
|
14
|
-
el: document.querySelector('.form-selector')
|
|
15
|
-
});
|
|
16
|
-
loader.addDOMElement({
|
|
17
|
-
section: 'summary',
|
|
18
|
-
el: document.querySelector('.summary-selector')
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
it('manage state of loading ids', () => {
|
|
22
|
-
loader.startLoading({
|
|
23
|
-
id: 'loadForm'
|
|
24
|
-
});
|
|
25
|
-
loader.startLoading({
|
|
26
|
-
id: 'updateForm'
|
|
27
|
-
}); // Start loading state
|
|
28
|
-
|
|
29
|
-
loader.startLoading({
|
|
30
|
-
section: 'summary',
|
|
31
|
-
id: 'loadSummary'
|
|
32
|
-
});
|
|
33
|
-
loader.startLoading({
|
|
34
|
-
section: 'summary',
|
|
35
|
-
id: 'updateSummary'
|
|
36
|
-
}); // Stop one loading state
|
|
37
|
-
|
|
38
|
-
loader.stopLoading({
|
|
39
|
-
id: 'loadForm'
|
|
40
|
-
});
|
|
41
|
-
expect(loader.form.length).toEqual(1);
|
|
42
|
-
expect(loader.summary.length).toEqual(2);
|
|
43
|
-
});
|
|
44
|
-
it('adds the loader HTML on element and removes the active class when stoped', () => {
|
|
45
|
-
loader.startLoading({
|
|
46
|
-
id: 'loadForm'
|
|
47
|
-
});
|
|
48
|
-
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
49
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
50
|
-
loader.stopLoading({
|
|
51
|
-
id: 'loadForm'
|
|
52
|
-
});
|
|
53
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(false);
|
|
54
|
-
});
|
|
55
|
-
it('keeps loading when there are Ids on the element array', () => {
|
|
56
|
-
loader.startLoading({
|
|
57
|
-
id: 'loadForm'
|
|
58
|
-
});
|
|
59
|
-
loader.startLoading({
|
|
60
|
-
id: 'updateForm'
|
|
61
|
-
});
|
|
62
|
-
expect(loader.DOM.form.innerHTML).toMatch('rebilly-instruments-loader');
|
|
63
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
64
|
-
loader.stopLoading({
|
|
65
|
-
id: 'loadForm'
|
|
66
|
-
});
|
|
67
|
-
expect(loader.DOM.form.querySelector('.rebilly-instruments-loader').classList.contains('is-active')).toEqual(true);
|
|
68
|
-
});
|
|
69
|
-
});
|
package/dist/storefront/index.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.validateStateForStorefront = validateStateForStorefront;
|
|
7
|
-
exports.Endpoint = Endpoint;
|
|
8
|
-
exports.default = exports.StorefrontInstance = void 0;
|
|
9
|
-
|
|
10
|
-
var _rebillyJsSdk = require("rebilly-js-sdk");
|
|
11
|
-
|
|
12
|
-
function validateStateForStorefront({
|
|
13
|
-
state
|
|
14
|
-
}) {
|
|
15
|
-
if (!state.storefront) {
|
|
16
|
-
throw new Error('Could not access rebilly-js-sdk instance');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (!state.options) {
|
|
20
|
-
throw new Error('Could not use Rebilly Instruments mount options to fetch Rebilly data');
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async function Endpoint({
|
|
25
|
-
state
|
|
26
|
-
} = {}, callback) {
|
|
27
|
-
try {
|
|
28
|
-
validateStateForStorefront({
|
|
29
|
-
state
|
|
30
|
-
});
|
|
31
|
-
return await callback();
|
|
32
|
-
} catch (error) {
|
|
33
|
-
// TODO: standard error handling for all endpoints
|
|
34
|
-
// console.error(error);
|
|
35
|
-
if (error.status === 422) {
|
|
36
|
-
error.details.forEach(e => console.error(e));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
class StorefrontInstance {
|
|
44
|
-
constructor({
|
|
45
|
-
publishableKey = null,
|
|
46
|
-
organizationId = null,
|
|
47
|
-
mode = 'live',
|
|
48
|
-
timeout = 10000,
|
|
49
|
-
liveUrl = null,
|
|
50
|
-
sandboxUrl = null
|
|
51
|
-
} = {}) {
|
|
52
|
-
const urls = {
|
|
53
|
-
live: liveUrl || 'https://api.rebilly.com',
|
|
54
|
-
sandbox: sandboxUrl || 'https://api-sandbox.rebilly.com'
|
|
55
|
-
};
|
|
56
|
-
const api = (0, _rebillyJsSdk.RebillyStorefrontAPI)({
|
|
57
|
-
organizationId,
|
|
58
|
-
sandbox: mode === 'sandbox',
|
|
59
|
-
timeout: Number.isNaN(parseInt(timeout, 10)) ? 10000 : parseInt(timeout, 10),
|
|
60
|
-
urls
|
|
61
|
-
});
|
|
62
|
-
api.setPublishableKey(publishableKey);
|
|
63
|
-
this.api = api;
|
|
64
|
-
return this.api;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.StorefrontInstance = StorefrontInstance;
|
|
70
|
-
|
|
71
|
-
var _default = (config = {}) => new StorefrontInstance(config);
|
|
72
|
-
|
|
73
|
-
exports.default = _default;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchInvoice = fetchInvoice;
|
|
7
|
-
|
|
8
|
-
var _invoiceModel = _interopRequireDefault(require("./models/invoice-model"));
|
|
9
|
-
|
|
10
|
-
var _index = require("./index");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
async function fetchInvoice({
|
|
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.invoices.get(data);
|
|
25
|
-
return new _invoiceModel.default(fields);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
class BaseModel {
|
|
9
|
-
constructor({ ...fields
|
|
10
|
-
} = {}) {
|
|
11
|
-
Object.entries(fields).forEach(([key, value]) => {
|
|
12
|
-
this[key] = value;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
exports.default = BaseModel;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseModel = _interopRequireDefault(require("./base-model"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class InvoiceModel extends _baseModel.default {}
|
|
13
|
-
|
|
14
|
-
exports.default = InvoiceModel;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseModel = _interopRequireDefault(require("./base-model"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class PlanModel extends _baseModel.default {}
|
|
13
|
-
|
|
14
|
-
exports.default = PlanModel;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseModel = _interopRequireDefault(require("./base-model"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class ProductModel extends _baseModel.default {}
|
|
13
|
-
|
|
14
|
-
exports.default = ProductModel;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.ReadyToPayFeatureModel = void 0;
|
|
7
|
-
|
|
8
|
-
class ReadyToPayFeatureModel {
|
|
9
|
-
constructor({
|
|
10
|
-
name = '',
|
|
11
|
-
// Google Pay fields
|
|
12
|
-
merchantName = '',
|
|
13
|
-
merchantOrigin = '',
|
|
14
|
-
// Plaid fields
|
|
15
|
-
linkToken = '',
|
|
16
|
-
expirationTime = ''
|
|
17
|
-
} = {}) {
|
|
18
|
-
this.name = name;
|
|
19
|
-
this.merchantName = merchantName;
|
|
20
|
-
this.merchantOrigin = merchantOrigin;
|
|
21
|
-
this.linkToken = linkToken;
|
|
22
|
-
this.expirationTime = expirationTime;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.ReadyToPayFeatureModel = ReadyToPayFeatureModel;
|
|
28
|
-
|
|
29
|
-
class ReadyToPayModel {
|
|
30
|
-
constructor({
|
|
31
|
-
index = null,
|
|
32
|
-
method = '',
|
|
33
|
-
feature = null,
|
|
34
|
-
brands = [],
|
|
35
|
-
filters = []
|
|
36
|
-
} = {}) {
|
|
37
|
-
this.index = index;
|
|
38
|
-
this.method = method;
|
|
39
|
-
this.feature = feature ? new ReadyToPayFeatureModel(feature) : null;
|
|
40
|
-
this.brands = brands;
|
|
41
|
-
this.filters = filters;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
exports.default = ReadyToPayModel;
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.SummaryDiscountModel = exports.SummaryTaxModel = exports.SummaryLineItemModel = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseModel = _interopRequireDefault(require("./base-model"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class SummaryLineItemModel extends _baseModel.default {
|
|
13
|
-
constructor({
|
|
14
|
-
unitPrice = 0.0,
|
|
15
|
-
quantity = 0,
|
|
16
|
-
price = 0.0,
|
|
17
|
-
...fields
|
|
18
|
-
} = {}) {
|
|
19
|
-
super(fields);
|
|
20
|
-
this.unitPrice = unitPrice;
|
|
21
|
-
this.quantity = quantity;
|
|
22
|
-
this.price = price;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.SummaryLineItemModel = SummaryLineItemModel;
|
|
28
|
-
|
|
29
|
-
class SummaryTaxModel extends _baseModel.default {}
|
|
30
|
-
|
|
31
|
-
exports.SummaryTaxModel = SummaryTaxModel;
|
|
32
|
-
|
|
33
|
-
class SummaryDiscountModel extends _baseModel.default {
|
|
34
|
-
constructor({
|
|
35
|
-
amount = 0,
|
|
36
|
-
...fields
|
|
37
|
-
}) {
|
|
38
|
-
super(fields);
|
|
39
|
-
this.amount = amount;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
exports.SummaryDiscountModel = SummaryDiscountModel;
|
|
45
|
-
|
|
46
|
-
class SummaryModel {
|
|
47
|
-
constructor({
|
|
48
|
-
currency = '',
|
|
49
|
-
lineItems = [],
|
|
50
|
-
taxes = [],
|
|
51
|
-
discounts = [],
|
|
52
|
-
subtotalAmount = 0.0,
|
|
53
|
-
taxAmount = 0.0,
|
|
54
|
-
shippingAmount = 0.0,
|
|
55
|
-
discountsAmount = 0.0,
|
|
56
|
-
total = 0.0
|
|
57
|
-
} = {}) {
|
|
58
|
-
function map(array) {
|
|
59
|
-
const list = Array.isArray(array) ? array : [];
|
|
60
|
-
return {
|
|
61
|
-
// eslint-disable-next-line new-cap
|
|
62
|
-
to: instance => list.map(item => new instance(item))
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
this.currency = currency;
|
|
67
|
-
this.lineItems = map(lineItems).to(SummaryLineItemModel);
|
|
68
|
-
this.taxes = map(taxes).to(SummaryTaxModel);
|
|
69
|
-
this.discounts = map(discounts).to(SummaryDiscountModel);
|
|
70
|
-
this.subtotalAmount = subtotalAmount;
|
|
71
|
-
this.taxAmount = taxAmount;
|
|
72
|
-
this.shippingAmount = shippingAmount;
|
|
73
|
-
this.discountsAmount = discountsAmount;
|
|
74
|
-
this.total = total;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
exports.default = SummaryModel;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _baseModel = _interopRequireDefault(require("./base-model"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class TransactionModel extends _baseModel.default {
|
|
13
|
-
constructor({
|
|
14
|
-
invoiceIds = [],
|
|
15
|
-
...fields
|
|
16
|
-
}) {
|
|
17
|
-
super(fields);
|
|
18
|
-
this.invoiceIds = invoiceIds || [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get invoiceId() {
|
|
22
|
-
return this.invoiceIds[0] || null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
get hasInvoice() {
|
|
26
|
-
return !!this.invoiceId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
exports.default = TransactionModel;
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchPlans = fetchPlans;
|
|
7
|
-
|
|
8
|
-
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
9
|
-
|
|
10
|
-
var _index = require("./index");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
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;
|
|
22
|
-
const filterByPlanId = {
|
|
23
|
-
filter: ''
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
if (lineItems.length) {
|
|
27
|
-
filterByPlanId.filter = `id:${lineItems.map(item => item.planId).join(',')}`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
items: planItems
|
|
32
|
-
} = await state.storefront.plans.getAll(filterByPlanId);
|
|
33
|
-
return planItems.map(({
|
|
34
|
-
fields
|
|
35
|
-
}) => new _planModel.default(fields));
|
|
36
|
-
});
|
|
37
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
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
|
-
var _plans = require("./plans");
|
|
12
|
-
|
|
13
|
-
var _planModel = _interopRequireDefault(require("./models/plan-model"));
|
|
14
|
-
|
|
15
|
-
var _asyncUtilities = require("../../tests/async-utilities");
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
-
|
|
19
|
-
describe('Storefront API Plan', () => {
|
|
20
|
-
it('can fetch plans', async () => {
|
|
21
|
-
const testPlan = {
|
|
22
|
-
name: 'Test Plan',
|
|
23
|
-
id: 'test-plan-id-1'
|
|
24
|
-
};
|
|
25
|
-
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((0, _mswWhenThen.ok)([testPlan]));
|
|
26
|
-
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
27
|
-
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
28
|
-
const response = await (0, _plans.fetchPlans)({
|
|
29
|
-
state: instance
|
|
30
|
-
});
|
|
31
|
-
expect(instance.storefront.plans.getAll).toBeCalledTimes(1);
|
|
32
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
33
|
-
filter: ''
|
|
34
|
-
});
|
|
35
|
-
expect(response).toBeInstanceOf(Array);
|
|
36
|
-
expect(response[0]).toBeInstanceOf(_planModel.default);
|
|
37
|
-
expect(response).toEqual([new _planModel.default(testPlan)]);
|
|
38
|
-
});
|
|
39
|
-
it('can fetch plans with filter', async () => {
|
|
40
|
-
const instance = new _storefrontMock.StorefontTestingInstance();
|
|
41
|
-
jest.spyOn(instance.storefront.plans, 'getAll');
|
|
42
|
-
await (0, _plans.fetchPlans)({
|
|
43
|
-
state: instance,
|
|
44
|
-
data: {
|
|
45
|
-
lineItems: [{
|
|
46
|
-
planId: 'test-plan-id-1'
|
|
47
|
-
}, {
|
|
48
|
-
planId: 'test-plan-id-2'
|
|
49
|
-
}]
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
expect(instance.storefront.plans.getAll).toBeCalledWith({
|
|
53
|
-
filter: 'id:test-plan-id-1,test-plan-id-2'
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
it('should throw errors with no options', async () => {
|
|
57
|
-
const noConfigOrOptionsInstance = new _storefrontMock.StorefontTestingInstance({
|
|
58
|
-
options: null
|
|
59
|
-
});
|
|
60
|
-
await (0, _asyncUtilities.expectConfigurationError)((0, _plans.fetchPlans)({
|
|
61
|
-
state: noConfigOrOptionsInstance
|
|
62
|
-
}));
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.fetchProducts = fetchProducts;
|
|
7
|
-
|
|
8
|
-
var _productModel = _interopRequireDefault(require("./models/product-model"));
|
|
9
|
-
|
|
10
|
-
var _index = require("./index");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
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
|
-
}
|
|
23
|
-
|
|
24
|
-
const plansData = state.data.plans || [];
|
|
25
|
-
const filterByProductId = {
|
|
26
|
-
filter: ''
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
if (plansData.length) {
|
|
30
|
-
filterByProductId.filter = `id:${plansData.map(item => item.productId).join(',')}`;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const {
|
|
34
|
-
items: productItems
|
|
35
|
-
} = await state.storefront.products.getAll(filterByProductId);
|
|
36
|
-
return productItems.map(({
|
|
37
|
-
fields
|
|
38
|
-
}) => new _productModel.default(fields));
|
|
39
|
-
});
|
|
40
|
-
}
|