@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,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-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 _events = _interopRequireDefault(require("../events"));
|
|
12
|
-
|
|
13
|
-
var _asyncUtilities = require("../../tests/async-utilities");
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
describe('RebillyInstruments setup', () => {
|
|
18
|
-
it('should be able to setup a payment instrument', async () => {
|
|
19
|
-
const options = {
|
|
20
|
-
websiteId: 'test-website-id',
|
|
21
|
-
money: {
|
|
22
|
-
amount: 30,
|
|
23
|
-
currency: 'USD'
|
|
24
|
-
},
|
|
25
|
-
transactionType: 'setup'
|
|
26
|
-
};
|
|
27
|
-
const token = {
|
|
28
|
-
id: 'test-token-id'
|
|
29
|
-
};
|
|
30
|
-
const billingAddress = {
|
|
31
|
-
billing: 'address'
|
|
32
|
-
};
|
|
33
|
-
const deliveryAddress = {
|
|
34
|
-
delivery: 'address'
|
|
35
|
-
};
|
|
36
|
-
const paymentInstrumentFields = {
|
|
37
|
-
id: 'payment-instrument-id'
|
|
38
|
-
};
|
|
39
|
-
const paymentInstrumentSetupFields = {
|
|
40
|
-
id: 'payment-instrument-id',
|
|
41
|
-
approvalUrl: null
|
|
42
|
-
};
|
|
43
|
-
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentFields));
|
|
44
|
-
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/payment-instruments/*/setup`)).thenReturn((0, _mswWhenThen.ok)(paymentInstrumentSetupFields));
|
|
45
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options);
|
|
46
|
-
const spyCreatePaymentInstrument = jest.spyOn(rebillyInstruments.state.storefront.paymentInstruments, 'create');
|
|
47
|
-
const spySetupPaymentInstrument = jest.spyOn(rebillyInstruments.state.storefront.paymentInstruments, 'setup');
|
|
48
|
-
const spyDispatchSetupCompleted = jest.spyOn(_events.default.setupCompleted, 'dispatch');
|
|
49
|
-
const setupCompletedListener = jest.fn();
|
|
50
|
-
rebillyInstruments.on('setup-completed', setupCompletedListener);
|
|
51
|
-
const setupPayload = {
|
|
52
|
-
billingAddress,
|
|
53
|
-
deliveryAddress,
|
|
54
|
-
...options.money,
|
|
55
|
-
_raw: token
|
|
56
|
-
};
|
|
57
|
-
rebillyInstruments.mock.data({
|
|
58
|
-
previewPurchase: {
|
|
59
|
-
currency: 'USD',
|
|
60
|
-
total: 30
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
await rebillyInstruments.setup(setupPayload);
|
|
64
|
-
expect(spyCreatePaymentInstrument).toBeCalledTimes(1);
|
|
65
|
-
expect(spyCreatePaymentInstrument).toBeCalledWith(expect.objectContaining({
|
|
66
|
-
data: expect.objectContaining({
|
|
67
|
-
token: token.id
|
|
68
|
-
})
|
|
69
|
-
}));
|
|
70
|
-
expect(spySetupPaymentInstrument).toBeCalledTimes(1);
|
|
71
|
-
expect(spySetupPaymentInstrument).toBeCalledWith(expect.objectContaining({
|
|
72
|
-
id: expect.stringContaining(paymentInstrumentFields.id),
|
|
73
|
-
data: expect.objectContaining({
|
|
74
|
-
websiteId: rebillyInstruments.state.options.websiteId,
|
|
75
|
-
currency: 'USD',
|
|
76
|
-
amount: 30
|
|
77
|
-
})
|
|
78
|
-
}));
|
|
79
|
-
expect(spyDispatchSetupCompleted).toBeCalledTimes(1);
|
|
80
|
-
expect(setupCompletedListener).toBeCalledTimes(1);
|
|
81
|
-
expect(setupCompletedListener).toBeCalledWith(expect.objectContaining({
|
|
82
|
-
instrument: paymentInstrumentFields,
|
|
83
|
-
transaction: paymentInstrumentSetupFields
|
|
84
|
-
}));
|
|
85
|
-
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
86
|
-
});
|
|
87
|
-
});
|
package/dist/functions/show.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.show = show;
|
|
7
|
-
|
|
8
|
-
var _confirmation = require("../views/confirmation");
|
|
9
|
-
|
|
10
|
-
var _result = require("../views/result");
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
@typedef ShowParams
|
|
14
|
-
@type {Object}
|
|
15
|
-
@property {string} componentName - The name of the component to render to the form.
|
|
16
|
-
@property {object} payload - The extra data to provide the component.
|
|
17
|
-
@property {object} state - The global state.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Register events that will be triggered
|
|
22
|
-
* @param {ShowParams} params
|
|
23
|
-
*/
|
|
24
|
-
async function show({
|
|
25
|
-
componentName,
|
|
26
|
-
payload,
|
|
27
|
-
state
|
|
28
|
-
}) {
|
|
29
|
-
switch (componentName) {
|
|
30
|
-
case 'result':
|
|
31
|
-
state.iframeComponents = state.iframeComponents.filter(iframe => {
|
|
32
|
-
iframe.destroy();
|
|
33
|
-
return false;
|
|
34
|
-
});
|
|
35
|
-
(0, _result.mountResult)({
|
|
36
|
-
payload,
|
|
37
|
-
state
|
|
38
|
-
});
|
|
39
|
-
break;
|
|
40
|
-
|
|
41
|
-
case 'confirmation':
|
|
42
|
-
state.iframeComponents = state.iframeComponents.filter(iframe => {
|
|
43
|
-
iframe.destroy();
|
|
44
|
-
return false;
|
|
45
|
-
});
|
|
46
|
-
(0, _confirmation.mountConfirmation)({
|
|
47
|
-
payload,
|
|
48
|
-
state
|
|
49
|
-
});
|
|
50
|
-
break;
|
|
51
|
-
|
|
52
|
-
default:
|
|
53
|
-
throw new Error(`'${componentName}' not a supported component`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var result = _interopRequireWildcard(require("../views/result"));
|
|
4
|
-
|
|
5
|
-
var confirmation = _interopRequireWildcard(require("../views/confirmation"));
|
|
6
|
-
|
|
7
|
-
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
8
|
-
|
|
9
|
-
var _index = require("../index");
|
|
10
|
-
|
|
11
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
-
|
|
13
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
14
|
-
|
|
15
|
-
const iframeMock = {
|
|
16
|
-
destroy: jest.fn()
|
|
17
|
-
};
|
|
18
|
-
describe('RebillyInstruments show', () => {
|
|
19
|
-
it('should show result component', async () => {
|
|
20
|
-
const mountResult = jest.spyOn(result, 'mountResult').mockReturnValue(Promise.resolve());
|
|
21
|
-
const instance = new _index.RebillyInstrumentsInstance();
|
|
22
|
-
instance.state.iframeComponents.push(iframeMock);
|
|
23
|
-
const payload = {
|
|
24
|
-
test: 'value'
|
|
25
|
-
};
|
|
26
|
-
await instance.show('result', payload);
|
|
27
|
-
expect(mountResult).toBeCalledTimes(1);
|
|
28
|
-
expect(mountResult).toBeCalledWith({
|
|
29
|
-
payload,
|
|
30
|
-
state: instance.state
|
|
31
|
-
});
|
|
32
|
-
expect(instance.state.iframeComponents).toEqual([]);
|
|
33
|
-
});
|
|
34
|
-
it('should show confirmation component', async () => {
|
|
35
|
-
const mountConfirmation = jest.spyOn(confirmation, 'mountConfirmation').mockReturnValue(Promise.resolve());
|
|
36
|
-
const instance = new _index.RebillyInstrumentsInstance();
|
|
37
|
-
instance.state.iframeComponents.push(iframeMock);
|
|
38
|
-
const payload = {
|
|
39
|
-
test: 'value'
|
|
40
|
-
};
|
|
41
|
-
await instance.show('confirmation', payload);
|
|
42
|
-
expect(mountConfirmation).toBeCalledTimes(1);
|
|
43
|
-
expect(mountConfirmation).toBeCalledWith({
|
|
44
|
-
payload,
|
|
45
|
-
state: instance.state
|
|
46
|
-
});
|
|
47
|
-
expect(instance.state.iframeComponents).toEqual([]);
|
|
48
|
-
});
|
|
49
|
-
it('should fail for non supported component', async () => {
|
|
50
|
-
const rebillyInstruments = new _index.RebillyInstrumentsInstance();
|
|
51
|
-
let error;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
await rebillyInstruments.show('not-a-component', 'any payload');
|
|
55
|
-
} catch (e) {
|
|
56
|
-
error = e;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
expect(error.toString()).toBe(`Error: 'not-a-component' not a supported component`);
|
|
60
|
-
});
|
|
61
|
-
});
|
package/dist/functions/update.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.update = update;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
9
|
-
|
|
10
|
-
var _destroy = require("./destroy");
|
|
11
|
-
|
|
12
|
-
var _mount = require("./mount");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
function sanitizeOldPurchaseData({
|
|
17
|
-
newOptions
|
|
18
|
-
}) {
|
|
19
|
-
let purchaseData = {};
|
|
20
|
-
const hasPurchaseDataKeys = Object.keys(newOptions).some(key => ['items', 'money', 'invoiceId', 'transactionId'].includes(key));
|
|
21
|
-
purchaseData = hasPurchaseDataKeys ? {
|
|
22
|
-
items: null,
|
|
23
|
-
money: null,
|
|
24
|
-
invoiceId: null,
|
|
25
|
-
transactionId: null
|
|
26
|
-
} : purchaseData;
|
|
27
|
-
return purchaseData;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
;
|
|
31
|
-
|
|
32
|
-
async function update({
|
|
33
|
-
state,
|
|
34
|
-
newOptions = {}
|
|
35
|
-
}) {
|
|
36
|
-
if (!state.hasMounted) {
|
|
37
|
-
throw Error('Update method cannot be called before mounting instruments');
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Framepay locale option is almost but not fully updatable yet:
|
|
41
|
-
* https://github.com/Rebilly/framepay/issues/450
|
|
42
|
-
* That's why this toggle disables real time locale update until that issue is fixed.
|
|
43
|
-
*/
|
|
44
|
-
// const updatingJustLocale =
|
|
45
|
-
// newOptions?.options && isEqual(Object.keys(newOptions), ['locale']);
|
|
46
|
-
// if (updatingJustLocale) {
|
|
47
|
-
// const updatedOptions = merge(state.options, newOptions);
|
|
48
|
-
// const newLocale = newOptions?.locale;
|
|
49
|
-
// state.options = updatedOptions;
|
|
50
|
-
// state.translate.updateTranslationsToNewLocale(newLocale);
|
|
51
|
-
// state.iframeComponents.forEach((iframe) =>
|
|
52
|
-
// iframe.component.call('changeLocale', newLocale)
|
|
53
|
-
// );
|
|
54
|
-
// return;
|
|
55
|
-
// }
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const oldOptions = { ...state.options,
|
|
59
|
-
...sanitizeOldPurchaseData({
|
|
60
|
-
newOptions
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
const updatedOptions = (0, _lodash.default)({ ...oldOptions
|
|
64
|
-
}, newOptions);
|
|
65
|
-
await (0, _destroy.destroy)({
|
|
66
|
-
state
|
|
67
|
-
});
|
|
68
|
-
(0, _mount.mount)({
|
|
69
|
-
state,
|
|
70
|
-
form: state.form,
|
|
71
|
-
summary: state.summary,
|
|
72
|
-
...updatedOptions
|
|
73
|
-
});
|
|
74
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
4
|
-
|
|
5
|
-
var _asyncUtilities = require("../../tests/async-utilities");
|
|
6
|
-
|
|
7
|
-
describe('RebillyInstruments Update', () => {
|
|
8
|
-
it('should throw an error when methods are not mounted', async () => {
|
|
9
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
10
|
-
rebillyInstruments.state.hasMounted = false;
|
|
11
|
-
let error;
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
await rebillyInstruments.update();
|
|
15
|
-
} catch (e) {
|
|
16
|
-
error = e;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
expect(error).toEqual(new Error('Update method cannot be called before mounting instruments'));
|
|
20
|
-
}); // TODO: Un skip this test when we activate real time update (currently disabled by feature toggle in update.js)
|
|
21
|
-
|
|
22
|
-
it.skip('should call changeLocale when updating locale options', async () => {
|
|
23
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
24
|
-
const call = jest.fn(); // Simulate mounted iframe
|
|
25
|
-
|
|
26
|
-
const fakeIFrameComponent = {
|
|
27
|
-
destroy: jest.fn(),
|
|
28
|
-
component: {
|
|
29
|
-
call
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
|
|
33
|
-
await rebillyInstruments.update({
|
|
34
|
-
locale: 'ja'
|
|
35
|
-
});
|
|
36
|
-
expect(call).toBeCalledWith('changeLocale', 'ja'); // It would be better to match real UI instead of implementation state
|
|
37
|
-
|
|
38
|
-
expect(rebillyInstruments.state.options.locale).toBe('ja');
|
|
39
|
-
expect(rebillyInstruments.state.translate.locale).toBe('ja');
|
|
40
|
-
});
|
|
41
|
-
it('should destroy and update when updating options different than locale', async () => {
|
|
42
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
43
|
-
const formElement = document.querySelector('.form-selector');
|
|
44
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
45
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
46
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
47
|
-
const call = jest.fn(); // Simulate mounted iframe
|
|
48
|
-
|
|
49
|
-
const fakeIFrameComponent = {
|
|
50
|
-
destroy: jest.fn(),
|
|
51
|
-
component: {
|
|
52
|
-
call
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
rebillyInstruments.state.iframeComponents = [fakeIFrameComponent];
|
|
56
|
-
await rebillyInstruments.update({
|
|
57
|
-
countryCode: 'ES'
|
|
58
|
-
});
|
|
59
|
-
expect(rebillyInstruments.state.options.countryCode).toEqual('ES');
|
|
60
|
-
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
61
|
-
});
|
|
62
|
-
it('should replace the items with different options', async () => {
|
|
63
|
-
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
64
|
-
const formElement = document.querySelector('.form-selector');
|
|
65
|
-
const summaryElement = document.querySelector('.summary-selector');
|
|
66
|
-
expect(formElement.innerHTML).not.toEqual('');
|
|
67
|
-
expect(summaryElement.innerHTML).not.toEqual('');
|
|
68
|
-
const call = jest.fn(); // Simulate mounted iframe
|
|
69
|
-
|
|
70
|
-
const fakeIFrameComponent = {
|
|
71
|
-
destroy: jest.fn(),
|
|
72
|
-
component: {
|
|
73
|
-
call
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
rebillyInstruments.iframeComponents = [fakeIFrameComponent];
|
|
77
|
-
await rebillyInstruments.update({
|
|
78
|
-
items: [{
|
|
79
|
-
planId: 'test-plan-id-1',
|
|
80
|
-
quantity: 5
|
|
81
|
-
}]
|
|
82
|
-
});
|
|
83
|
-
expect(rebillyInstruments.state.options.items[0].quantity).toEqual(5);
|
|
84
|
-
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
85
|
-
});
|
|
86
|
-
});
|
package/dist/i18n/en.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"en": {
|
|
3
|
-
"summary": {
|
|
4
|
-
"subTotal": "Sub Total",
|
|
5
|
-
"discounts": "Discounts",
|
|
6
|
-
"taxes": "Taxes",
|
|
7
|
-
"shipping": "Shipping",
|
|
8
|
-
"total": "Total"
|
|
9
|
-
},
|
|
10
|
-
"form": {
|
|
11
|
-
"expressCheckout": "Express checkout",
|
|
12
|
-
"or": "Or",
|
|
13
|
-
"popupOverlayText": "Click here to show popup window",
|
|
14
|
-
"error": {
|
|
15
|
-
"noPaymentMethods": "No payment methods available for this transaction, please contact support."
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"paymentMethods": {
|
|
19
|
-
"payment-card": "Payment card"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
package/dist/i18n/es.json
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"es": {
|
|
3
|
-
"summary": {
|
|
4
|
-
"subTotal": "Sub Total",
|
|
5
|
-
"discounts": "Descuentos",
|
|
6
|
-
"taxes": "Impuestos",
|
|
7
|
-
"shipping": "Envío",
|
|
8
|
-
"total": "Total"
|
|
9
|
-
},
|
|
10
|
-
"form": {
|
|
11
|
-
"expressCheckout": "Chequeo rápido",
|
|
12
|
-
"or": "O pague con",
|
|
13
|
-
"popupOverlayText": "Haga clic aquí para mostrar la ventana emergente",
|
|
14
|
-
"error": {
|
|
15
|
-
"noPaymentMethods": "No hay métodos de pago disponibles para esta transacción, por favor, póngase en contacto con el servicio de asistencia."
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"paymentMethods": {
|
|
19
|
-
"payment-card": "Tarjeta de crédito"
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
package/dist/i18n/i18n.spec.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = require("./index");
|
|
4
|
-
|
|
5
|
-
describe('i18n Class', () => {
|
|
6
|
-
const canTranslate = document.createElement('div');
|
|
7
|
-
canTranslate.innerHTML = 'Discounts';
|
|
8
|
-
canTranslate.setAttribute('data-rebilly-i18n', 'summary.discounts');
|
|
9
|
-
const canNotTranslate = document.createElement('div');
|
|
10
|
-
canNotTranslate.innerHTML = 'Untouched';
|
|
11
|
-
canNotTranslate.setAttribute('data-rebilly-i18n', 'does.not.exist');
|
|
12
|
-
document.body.append(canTranslate);
|
|
13
|
-
document.body.append(canNotTranslate);
|
|
14
|
-
it('can translate element with proper data attribute and skip wrong translation path or languages', () => {
|
|
15
|
-
const translate = new _index.Translate();
|
|
16
|
-
translate.init('es-US');
|
|
17
|
-
translate.translateItems();
|
|
18
|
-
const [translated, untouched] = document.querySelectorAll('[data-rebilly-i18n]');
|
|
19
|
-
expect(translated.innerHTML).toEqual('Descuentos');
|
|
20
|
-
expect(untouched.innerHTML).toEqual('Untouched');
|
|
21
|
-
});
|
|
22
|
-
});
|
package/dist/i18n/index.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Translate = void 0;
|
|
7
|
-
|
|
8
|
-
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
9
|
-
|
|
10
|
-
var _en = _interopRequireDefault(require("./en.json"));
|
|
11
|
-
|
|
12
|
-
var _es = _interopRequireDefault(require("./es.json"));
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
class Translate {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.locale = '';
|
|
19
|
-
this.items = [];
|
|
20
|
-
this.languages = {};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
init(locale, messages) {
|
|
24
|
-
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
25
|
-
this.locale = this.getLocale(locale);
|
|
26
|
-
this.languages = (0, _lodash.default)({}, { ..._en.default,
|
|
27
|
-
..._es.default
|
|
28
|
-
}, messages);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
translateItems() {
|
|
32
|
-
this.items = document.querySelectorAll('[data-rebilly-i18n]');
|
|
33
|
-
|
|
34
|
-
if (this.locale in this.languages) {
|
|
35
|
-
return this.items.forEach(item => {
|
|
36
|
-
const translate = this.getTranslation(this.languages[this.locale], item.dataset.rebillyI18n);
|
|
37
|
-
|
|
38
|
-
if (translate) {
|
|
39
|
-
item.innerHTML = translate;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
updateTranslationsToNewLocale(newLocale) {
|
|
48
|
-
this.locale = newLocale;
|
|
49
|
-
this.translateItems();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getLocale(locale = this.locale) {
|
|
53
|
-
if (!locale.includes('-') || locale in this.languages) {
|
|
54
|
-
return locale;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
locale = locale.replace(/[-._]\w+$/gi, '');
|
|
58
|
-
return this.getLocale(locale);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
translateItem(item) {
|
|
62
|
-
const locale = this.getLocale();
|
|
63
|
-
return this.getTranslation(this.languages[locale], item.dataset.rebillyI18n);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
getTranslation(lan = this.locale, prop) {
|
|
67
|
-
return prop.split('.').reduce((acc, val) => acc === null || acc === void 0 ? void 0 : acc[val], lan);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
exports.Translate = Translate;
|
package/dist/index.spec.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _index = _interopRequireWildcard(require("./index"));
|
|
4
|
-
|
|
5
|
-
var _asyncUtilities = require("../tests/async-utilities");
|
|
6
|
-
|
|
7
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
8
|
-
|
|
9
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
|
-
|
|
11
|
-
describe('RebillyInstruments instance', () => {
|
|
12
|
-
let rebillyInstruments;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
rebillyInstruments = _index.default;
|
|
15
|
-
});
|
|
16
|
-
it('should have default export as instance of class', () => {
|
|
17
|
-
expect(_index.default).toBeInstanceOf(_index.RebillyInstrumentsInstance);
|
|
18
|
-
});
|
|
19
|
-
it('should be mountable', async () => {
|
|
20
|
-
jest.spyOn(rebillyInstruments, 'mount');
|
|
21
|
-
document.body.innerHTML = `
|
|
22
|
-
<div class="form-selector"></div>
|
|
23
|
-
<div class="summary-selector"></div>
|
|
24
|
-
`;
|
|
25
|
-
const options = {
|
|
26
|
-
form: '.form-selector',
|
|
27
|
-
summary: '.summary-selector',
|
|
28
|
-
items: []
|
|
29
|
-
};
|
|
30
|
-
await rebillyInstruments.mount(options);
|
|
31
|
-
expect(rebillyInstruments.mount).toHaveBeenCalledTimes(1);
|
|
32
|
-
expect(rebillyInstruments.mount).toHaveBeenCalledWith(options);
|
|
33
|
-
await (0, _asyncUtilities.avoidUnhandledPromises)();
|
|
34
|
-
});
|
|
35
|
-
});
|
package/dist/loader/index.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Loader = void 0;
|
|
7
|
-
|
|
8
|
-
var _isDomElement = _interopRequireDefault(require("../utils/is-dom-element"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
class Loader {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.summary = [];
|
|
15
|
-
this.form = [];
|
|
16
|
-
this.modal = [];
|
|
17
|
-
this.DOM = {
|
|
18
|
-
loading: `
|
|
19
|
-
<div class="rebilly-instruments-loader is-active">
|
|
20
|
-
<div class="rebilly-instruments-loader-spinner"></div>
|
|
21
|
-
</div>
|
|
22
|
-
`
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
addDOMElement({
|
|
27
|
-
section = 'form',
|
|
28
|
-
el = null
|
|
29
|
-
} = {}) {
|
|
30
|
-
if ((0, _isDomElement.default)(el)) {
|
|
31
|
-
el.style.position = 'relative';
|
|
32
|
-
this.DOM[section] = el;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
startLoading({
|
|
37
|
-
section = 'form',
|
|
38
|
-
id = ''
|
|
39
|
-
} = {}) {
|
|
40
|
-
var _this$DOM;
|
|
41
|
-
|
|
42
|
-
const minHeight = '200px';
|
|
43
|
-
this[section].push(id);
|
|
44
|
-
|
|
45
|
-
if ((_this$DOM = this.DOM) !== null && _this$DOM !== void 0 && _this$DOM[section]) {
|
|
46
|
-
if (!this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
47
|
-
this.DOM[section].innerHTML = this.DOM.loading;
|
|
48
|
-
} else {
|
|
49
|
-
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.add('is-active');
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.DOM[section].style.minHeight = minHeight;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
stopLoading({
|
|
57
|
-
section = 'form',
|
|
58
|
-
id = ''
|
|
59
|
-
} = {}) {
|
|
60
|
-
const idIndex = this[section].indexOf(id);
|
|
61
|
-
|
|
62
|
-
if (idIndex !== -1) {
|
|
63
|
-
this[section].splice(idIndex, 1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!this[section].length && this.DOM[section].querySelector('.rebilly-instruments-loader')) {
|
|
67
|
-
this.DOM[section].querySelector('.rebilly-instruments-loader').classList.remove('is-active');
|
|
68
|
-
this.DOM[section].style.minHeight = '';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clearAll() {
|
|
73
|
-
this.form.forEach(id => {
|
|
74
|
-
this.stopLoading({
|
|
75
|
-
id
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
this.summary.forEach(id => {
|
|
79
|
-
this.stopLoading({
|
|
80
|
-
section: 'summary',
|
|
81
|
-
id
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
this.modal.forEach(id => {
|
|
85
|
-
this.stopLoading({
|
|
86
|
-
section: 'modal',
|
|
87
|
-
id
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
exports.Loader = Loader;
|