@rebilly/instruments 1.0.2-beta.8 → 2.1.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +13 -4
- package/.eslintrc.js +3 -0
- package/.prettierrc.js +11 -0
- package/README.md +15 -314
- package/dist/events/base-event.js +6 -9
- package/dist/events/events.spec.js +4 -4
- package/dist/events/index.js +2 -1
- package/dist/functions/destroy.js +12 -14
- package/dist/functions/destroy.spec.js +3 -3
- package/dist/functions/mount/fetch-data.js +183 -0
- package/dist/functions/mount/fetch-data.spec.js +189 -0
- package/dist/functions/mount/index.js +158 -251
- package/dist/functions/mount/mount.spec.js +24 -121
- package/dist/functions/mount/setup-element.js +40 -0
- package/dist/functions/mount/setup-framepay.js +46 -0
- package/dist/functions/mount/setup-i18n.js +33 -0
- package/dist/functions/mount/setup-options.js +96 -0
- package/dist/functions/mount/setup-options.spec.js +66 -0
- package/dist/functions/mount/setup-storefront.js +34 -0
- package/dist/functions/mount/setup-styles.js +43 -0
- package/dist/functions/on.js +13 -4
- package/dist/functions/on.spec.js +19 -5
- package/dist/functions/purchase.js +139 -22
- package/dist/functions/purchase.spec.js +23 -19
- package/dist/functions/setup.js +85 -0
- package/dist/functions/setup.spec.js +87 -0
- package/dist/functions/show.js +31 -14
- package/dist/functions/show.spec.js +47 -18
- package/dist/functions/update.js +53 -27
- package/dist/functions/update.spec.js +40 -21
- package/dist/i18n/en.json +4 -1
- package/dist/i18n/es.json +4 -1
- package/dist/index.js +67 -56
- package/dist/index.spec.js +7 -27
- package/dist/loader/index.js +4 -3
- package/dist/storefront/index.js +33 -0
- package/dist/storefront/invoices.js +27 -0
- package/dist/storefront/models/base-model.js +18 -0
- package/dist/storefront/models/invoice-model.js +14 -0
- package/dist/storefront/models/plan-model.js +4 -35
- package/dist/storefront/models/product-model.js +4 -23
- package/dist/storefront/models/summary-model.js +12 -25
- package/dist/storefront/models/transaction-model.js +31 -0
- package/dist/storefront/payment-instruments.js +47 -0
- package/dist/storefront/payment-instruments.spec.js +55 -0
- package/dist/storefront/plans.js +15 -24
- package/dist/storefront/plans.spec.js +17 -44
- package/dist/storefront/products.js +16 -20
- package/dist/storefront/products.spec.js +25 -49
- package/dist/storefront/purchase.js +28 -16
- package/dist/storefront/purchase.spec.js +4 -22
- package/dist/storefront/ready-to-pay.js +26 -22
- package/dist/storefront/ready-to-pay.spec.js +25 -54
- package/dist/storefront/storefront.spec.js +1 -1
- package/dist/storefront/summary.js +27 -24
- package/dist/storefront/summary.spec.js +44 -86
- package/dist/storefront/transactions.js +27 -0
- package/dist/style/base/theme.js +3 -3
- package/dist/style/components/methods.js +43 -42
- package/dist/style/utils/color-values.js +1 -3
- package/dist/style/views/confirmation.js +0 -4
- package/dist/style/views/method-selector.js +1 -1
- package/dist/style/views/modal.js +3 -1
- package/dist/style/views/summary.js +5 -1
- package/dist/utils/format-currency.js +4 -2
- package/dist/utils/has-valid-css-selector.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +0 -2
- package/dist/views/__snapshots__/summary.spec.js.snap +103 -113
- package/dist/views/common/iframe/base-iframe.js +10 -2
- package/dist/views/common/iframe/modal-iframe.js +44 -3
- package/dist/views/confirmation.js +44 -20
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +31 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +68 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/dist/views/method-selector/get-payment-methods.js +28 -8
- package/dist/views/method-selector/get-payment-methods.spec.js +25 -26
- package/dist/views/method-selector/index.js +55 -86
- package/dist/views/method-selector/method-selector.spec.js +80 -69
- package/dist/views/method-selector/mount-express-methods.js +38 -62
- package/dist/views/method-selector/mount-methods.js +18 -18
- package/dist/views/modal.js +21 -15
- package/dist/views/result.js +13 -16
- package/dist/views/summary.js +170 -114
- package/dist/views/summary.spec.js +72 -76
- package/package.json +5 -4
- package/src/events/base-event.js +15 -17
- package/src/events/events.spec.js +6 -4
- package/src/events/index.js +6 -3
- package/src/functions/destroy.js +12 -13
- package/src/functions/destroy.spec.js +30 -31
- package/src/functions/mount/fetch-data.js +148 -0
- package/src/functions/mount/fetch-data.spec.js +238 -0
- package/src/functions/mount/index.js +129 -244
- package/src/functions/mount/mount.spec.js +35 -139
- package/src/functions/mount/setup-element.js +26 -0
- package/src/functions/mount/setup-framepay.js +41 -0
- package/src/functions/mount/setup-i18n.js +19 -0
- package/src/functions/mount/setup-options.js +100 -0
- package/src/functions/mount/setup-options.spec.js +60 -0
- package/src/functions/mount/setup-storefront.js +24 -0
- package/src/functions/mount/setup-styles.js +30 -0
- package/src/functions/on.js +13 -8
- package/src/functions/on.spec.js +30 -17
- package/src/functions/purchase.js +101 -19
- package/src/functions/purchase.spec.js +18 -18
- package/src/functions/setup.js +48 -0
- package/src/functions/setup.spec.js +98 -0
- package/src/functions/show.js +20 -10
- package/src/functions/show.spec.js +43 -22
- package/src/functions/update.js +50 -27
- package/src/functions/update.spec.js +57 -22
- package/src/i18n/en.json +4 -1
- package/src/i18n/es.json +4 -1
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +14 -11
- package/src/index.js +41 -52
- package/src/index.spec.js +8 -37
- package/src/loader/index.js +51 -47
- package/src/loader/loader.spec.js +26 -19
- package/src/storefront/index.js +37 -7
- package/src/storefront/invoices.js +11 -0
- package/src/storefront/models/base-model.js +10 -0
- package/src/storefront/models/invoice-model.js +3 -0
- package/src/storefront/models/plan-model.js +3 -35
- package/src/storefront/models/product-model.js +3 -23
- package/src/storefront/models/ready-to-pay-model.js +3 -3
- package/src/storefront/models/summary-model.js +15 -29
- package/src/storefront/models/transaction-model.js +19 -0
- package/src/storefront/payment-instruments.js +30 -0
- package/src/storefront/payment-instruments.spec.js +69 -0
- package/src/storefront/plans.js +16 -23
- package/src/storefront/plans.spec.js +25 -54
- package/src/storefront/products.js +18 -22
- package/src/storefront/products.spec.js +23 -54
- package/src/storefront/purchase.js +14 -14
- package/src/storefront/purchase.spec.js +17 -29
- package/src/storefront/ready-to-pay.js +26 -23
- package/src/storefront/ready-to-pay.spec.js +41 -71
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +26 -22
- package/src/storefront/summary.spec.js +60 -109
- package/src/storefront/transactions.js +11 -0
- package/src/style/base/theme.js +10 -8
- package/src/style/base/theme.spec.js +4 -2
- package/src/style/browserslist.js +1 -3
- package/src/style/components/button.js +3 -1
- package/src/style/components/forms/checkbox.js +3 -1
- package/src/style/components/index.js +1 -1
- package/src/style/components/loader.js +3 -1
- package/src/style/components/methods.js +43 -42
- package/src/style/helpers/index.js +1 -1
- package/src/style/index.js +2 -1
- package/src/style/utils/color-values.js +4 -4
- package/src/style/vendor/framepay.js +1 -1
- package/src/style/vendor/postmate.js +1 -1
- package/src/style/views/confirmation.js +0 -4
- package/src/style/views/index.js +1 -1
- package/src/style/views/method-selector.js +1 -1
- package/src/style/views/modal.js +4 -2
- package/src/style/views/summary.js +5 -1
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +6 -2
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/is-dom-element.js +1 -1
- package/src/utils/process-property-as-dom-element.js +27 -24
- package/src/utils/sleep.js +1 -1
- package/src/views/__snapshots__/summary.spec.js.snap +103 -113
- package/src/views/common/iframe/base-iframe.js +12 -4
- package/src/views/common/iframe/event-listeners.js +6 -6
- package/src/views/common/iframe/index.js +1 -1
- package/src/views/common/iframe/method-iframe.js +3 -6
- package/src/views/common/iframe/modal-iframe.js +42 -6
- package/src/views/common/iframe/view-iframe.js +3 -5
- package/src/views/common/render-utilities.js +3 -3
- package/src/views/confirmation.js +34 -25
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +24 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +51 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +135 -0
- package/src/views/method-selector/get-method-data.js +7 -4
- package/src/views/method-selector/get-payment-methods.js +38 -29
- package/src/views/method-selector/get-payment-methods.spec.js +26 -33
- package/src/views/method-selector/index.js +70 -99
- package/src/views/method-selector/method-selector.spec.js +88 -78
- package/src/views/method-selector/mount-express-methods.js +36 -60
- package/src/views/method-selector/mount-methods.js +32 -21
- package/src/views/modal.js +37 -23
- package/src/views/result.js +12 -15
- package/src/views/summary.js +169 -101
- package/src/views/summary.spec.js +99 -74
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +89 -77
- package/tests/mocks/storefront-api-mock.js +8 -0
- package/tests/mocks/storefront-mock.js +17 -0
- package/dist/events/purchase-completed.js +0 -24
- package/dist/functions/initialize.js +0 -82
- package/dist/functions/initialize.spec.js +0 -34
- package/dist/functions/mount/fetch-summary-data.js +0 -31
- package/dist/functions/mount/fetch-summary-data.spec.js +0 -45
- package/dist/views/method-selector/process-digital-wallet-options.js +0 -35
- package/dist/views/method-selector/process-digital-wallet-options.spec.js +0 -80
- package/src/events/purchase-completed.js +0 -11
- package/src/functions/initialize.js +0 -74
- package/src/functions/initialize.spec.js +0 -38
- package/src/functions/mount/fetch-summary-data.js +0 -26
- package/src/functions/mount/fetch-summary-data.spec.js +0 -46
- package/src/views/method-selector/process-digital-wallet-options.js +0 -16
- package/src/views/method-selector/process-digital-wallet-options.spec.js +0 -94
|
@@ -1,126 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
|
|
3
|
+
var _rebillyInstrumentsMock = require("../../../tests/mocks/rebilly-instruments-mock");
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _instruments = require("@rebilly/instruments");
|
|
6
6
|
|
|
7
7
|
var _mswWhenThen = require("msw-when-then");
|
|
8
8
|
|
|
9
|
-
var _server = require("tests/msw/server");
|
|
9
|
+
var _server = require("../../../tests/msw/server");
|
|
10
10
|
|
|
11
|
-
var _storefrontApiMock = require("tests/mocks/storefront-api-mock");
|
|
11
|
+
var _storefrontApiMock = require("../../../tests/mocks/storefront-api-mock");
|
|
12
12
|
|
|
13
|
-
var _planModel = _interopRequireDefault(require("
|
|
13
|
+
var _planModel = _interopRequireDefault(require("../../storefront/models/plan-model"));
|
|
14
14
|
|
|
15
|
-
var _productModel = _interopRequireDefault(require("
|
|
15
|
+
var _productModel = _interopRequireDefault(require("../../storefront/models/product-model"));
|
|
16
16
|
|
|
17
|
-
var _summaryModel = _interopRequireDefault(require("
|
|
17
|
+
var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
|
|
18
18
|
|
|
19
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
20
|
|
|
21
21
|
describe('RebillyInstruments instance', () => {
|
|
22
|
-
it(
|
|
23
|
-
document.body.innerHTML = `
|
|
24
|
-
<div class="form-selector"></div>
|
|
25
|
-
<div class="summary-selector"></div>
|
|
26
|
-
`;
|
|
27
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
28
|
-
expect(async () => {
|
|
29
|
-
await rebillyInstruments.mount({});
|
|
30
|
-
}).rejects.toEqual(new Error('Could not find DOM element with CSS class or id ".rebilly-instruments" to mount form'));
|
|
31
|
-
});
|
|
32
|
-
it('should throw error when providing the wrong type for the form property', () => {
|
|
33
|
-
document.body.innerHTML = `
|
|
34
|
-
<div class="form-selector"></div>
|
|
35
|
-
<div class="summary-selector"></div>
|
|
36
|
-
`;
|
|
37
|
-
const options = {
|
|
38
|
-
form: []
|
|
39
|
-
};
|
|
40
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
41
|
-
expect(async () => {
|
|
42
|
-
await rebillyInstruments.mount(options);
|
|
43
|
-
}).rejects.toEqual(new Error('Please provide a valid CSS class, id or DOM element for "form" property'));
|
|
44
|
-
});
|
|
45
|
-
it('should inject HTML to the merchant\'s website', async () => {
|
|
46
|
-
const testPlan = new _planModel.default({
|
|
47
|
-
name: 'Test Plan',
|
|
48
|
-
id: 'test-plan-id-1'
|
|
49
|
-
});
|
|
50
|
-
const testProduct = new _productModel.default({
|
|
51
|
-
description: 'My Awesome Product',
|
|
52
|
-
id: 'test-product-1'
|
|
53
|
-
});
|
|
54
|
-
const testSummary = new _summaryModel.default({
|
|
55
|
-
currency: 'USD',
|
|
56
|
-
lineItems: [{
|
|
57
|
-
description: 'test-plan-id-1',
|
|
58
|
-
planId: 'test-plan-id-1',
|
|
59
|
-
productId: 'test-product-1',
|
|
60
|
-
quantity: 1
|
|
61
|
-
}]
|
|
62
|
-
});
|
|
22
|
+
it("should inject HTML to the merchant's website", async () => {
|
|
63
23
|
const framePayScriptUrl = 'https://framepay.rebilly.com/rebilly.js';
|
|
64
24
|
const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
|
|
65
|
-
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((() => {
|
|
66
|
-
return (0, _mswWhenThen.ok)([{
|
|
67
|
-
method: 'payment-card',
|
|
68
|
-
feature: {
|
|
69
|
-
name: 'Google Pay',
|
|
70
|
-
merchantName: 'google-pay-merchant-name',
|
|
71
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
72
|
-
},
|
|
73
|
-
brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
|
|
74
|
-
filters: []
|
|
75
|
-
}]);
|
|
76
|
-
})());
|
|
77
|
-
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((() => {
|
|
78
|
-
return (0, _mswWhenThen.ok)(testSummary);
|
|
79
|
-
})());
|
|
80
|
-
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((() => {
|
|
81
|
-
return (0, _mswWhenThen.ok)([testPlan]);
|
|
82
|
-
})());
|
|
83
|
-
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((() => {
|
|
84
|
-
return (0, _mswWhenThen.ok)([testProduct]);
|
|
85
|
-
})());
|
|
86
|
-
document.body.innerHTML = `
|
|
87
|
-
<div class="form-selector"></div>
|
|
88
|
-
<div class="summary-selector"></div>
|
|
89
|
-
`;
|
|
90
25
|
const options = {
|
|
91
26
|
form: '.form-selector',
|
|
92
27
|
summary: '.summary-selector',
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
intent: {
|
|
99
|
-
items: [{
|
|
100
|
-
planId: 'test-plan-id-1',
|
|
101
|
-
quantity: 1
|
|
102
|
-
}]
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const framepayMock = (0, _framepayMock.createFramepayMock)();
|
|
107
|
-
global.Rebilly = framepayMock;
|
|
108
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)({
|
|
28
|
+
locale: 'auto',
|
|
29
|
+
items: [{
|
|
30
|
+
planId: 'test-plan-id-1',
|
|
31
|
+
quantity: 1
|
|
32
|
+
}],
|
|
109
33
|
theme: {
|
|
110
34
|
color: {
|
|
111
35
|
background: '#000'
|
|
112
36
|
}
|
|
113
37
|
},
|
|
114
38
|
css: `
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
39
|
+
.rebilly-instruments-summary-line-item-synopsis-title {
|
|
40
|
+
color: rgb(0, 68, 212);
|
|
41
|
+
}
|
|
42
|
+
`,
|
|
43
|
+
_dev: {
|
|
44
|
+
framePayStyleLink: framePayStyleUrl
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options); // Mounts form and summary
|
|
121
48
|
|
|
122
49
|
const summarySelector = document.querySelector('.summary-selector');
|
|
123
|
-
expect(summarySelector.innerHTML).toMatch(
|
|
50
|
+
expect(summarySelector.innerHTML).toMatch('My Product'); // Theme config overrides initial styles
|
|
124
51
|
|
|
125
52
|
const SUMMARY_CONTAINER = summarySelector.querySelector('.rebilly-instruments-content');
|
|
126
53
|
expect(getComputedStyle(SUMMARY_CONTAINER).background).toEqual('rgb(0, 0, 0)'); // CSS config property overrides initial styles
|
|
@@ -134,30 +61,6 @@ describe('RebillyInstruments instance', () => {
|
|
|
134
61
|
|
|
135
62
|
const STYLE_LINKS = [...document.querySelectorAll('head link')];
|
|
136
63
|
const FRAMEPAY_STYLE = STYLE_LINKS.find(script => script.href === framePayStyleUrl);
|
|
137
|
-
expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
|
|
138
|
-
|
|
139
|
-
expect(framepayMock.initialize).toHaveBeenCalledWith(expect.objectContaining({
|
|
140
|
-
digitalWallet: {
|
|
141
|
-
googlePayDisplayOptions: {
|
|
142
|
-
buttonColor: 'black',
|
|
143
|
-
buttonHeight: '44px',
|
|
144
|
-
buttonType: 'short'
|
|
145
|
-
},
|
|
146
|
-
merchantConfig: {
|
|
147
|
-
merchantName: 'google-pay-merchant-name',
|
|
148
|
-
merchantOrigin: 'google-pay-merchant-origin'
|
|
149
|
-
},
|
|
150
|
-
transactionData: {
|
|
151
|
-
amount: 0,
|
|
152
|
-
countryCode: 'US',
|
|
153
|
-
currency: 'USD',
|
|
154
|
-
label: 'test-website-id'
|
|
155
|
-
}
|
|
156
|
-
},
|
|
157
|
-
organizationId: 'test-organization-id',
|
|
158
|
-
publishableKey: 'test-api-key'
|
|
159
|
-
})); //Simulate that framepay is ready
|
|
160
|
-
|
|
161
|
-
framepayMock.simulateEvent('ready');
|
|
64
|
+
expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
|
|
162
65
|
});
|
|
163
66
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
|
|
10
|
+
var _default = ({
|
|
11
|
+
element = '',
|
|
12
|
+
options = {}
|
|
13
|
+
}) => {
|
|
14
|
+
if (element !== 'form' && element !== 'summary') {
|
|
15
|
+
throw new Error('element must be "form" or "summary"');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const getProp = () => {
|
|
19
|
+
if (options[element]) {
|
|
20
|
+
return options[element];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
switch (element) {
|
|
24
|
+
case 'summary':
|
|
25
|
+
return '.rebilly-instruments-summary';
|
|
26
|
+
|
|
27
|
+
case 'form':
|
|
28
|
+
default:
|
|
29
|
+
return '.rebilly-instruments';
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (0, _utils.processPropertyAsDOMElement)({
|
|
34
|
+
prop: getProp(),
|
|
35
|
+
propName: element,
|
|
36
|
+
isRequired: ['form'].includes(element)
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.default = _default;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("../../utils");
|
|
9
|
+
|
|
10
|
+
var _default = ({
|
|
11
|
+
state: {
|
|
12
|
+
options: {
|
|
13
|
+
_dev
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
} = {}) => {
|
|
17
|
+
const framePayUrls = {
|
|
18
|
+
script: _dev ? _dev.framePayScriptLink || 'https://framepay.rebilly.com/rebilly.js' : 'https://framepay.rebilly.com/rebilly.js',
|
|
19
|
+
style: _dev ? _dev.framePayStyleLink || 'https://framepay.rebilly.com/rebilly.css' : 'https://framepay.rebilly.com/rebilly.css'
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
if (!document.querySelectorAll('[framepay*="script"]').length) {
|
|
23
|
+
(0, _utils.addDOMElement)({
|
|
24
|
+
element: 'script',
|
|
25
|
+
attributes: {
|
|
26
|
+
framepay: 'script',
|
|
27
|
+
src: framePayUrls.script
|
|
28
|
+
},
|
|
29
|
+
target: 'head'
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!document.querySelectorAll('[framepay*="stylesheet"]').length) {
|
|
34
|
+
(0, _utils.addDOMElement)({
|
|
35
|
+
element: 'link',
|
|
36
|
+
attributes: {
|
|
37
|
+
framepay: 'stylesheet',
|
|
38
|
+
href: framePayUrls.style,
|
|
39
|
+
rel: 'stylesheet'
|
|
40
|
+
},
|
|
41
|
+
target: 'head'
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.default = _default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
const triggerTranslations = ({
|
|
9
|
+
state
|
|
10
|
+
}) => {
|
|
11
|
+
state.translate.init(state.options.locale, state.options.i18n);
|
|
12
|
+
state.translate.translateItems();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
var _default = ({
|
|
16
|
+
state = {}
|
|
17
|
+
}) => {
|
|
18
|
+
var _state$data$riskMetad, _state$data$riskMetad2;
|
|
19
|
+
|
|
20
|
+
if (state.options.locale === 'auto' && (_state$data$riskMetad = state.data.riskMetadata) !== null && _state$data$riskMetad !== void 0 && (_state$data$riskMetad2 = _state$data$riskMetad.browserData) !== null && _state$data$riskMetad2 !== void 0 && _state$data$riskMetad2.language) {
|
|
21
|
+
const {
|
|
22
|
+
browserData: {
|
|
23
|
+
language
|
|
24
|
+
}
|
|
25
|
+
} = state.data.riskMetadata;
|
|
26
|
+
state.options.locale = language;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
state.translate.init(state.options.locale, state.options.i18n);
|
|
30
|
+
return triggerTranslations;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
exports.default = _default;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateOptions = validateOptions;
|
|
7
|
+
exports.default = exports.defaults = void 0;
|
|
8
|
+
|
|
9
|
+
var _lodash = _interopRequireDefault(require("lodash.merge"));
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const defaults = {
|
|
14
|
+
countryCode: 'US',
|
|
15
|
+
locale: 'auto',
|
|
16
|
+
paymentInstruments: {
|
|
17
|
+
address: {
|
|
18
|
+
name: 'default',
|
|
19
|
+
region: 'default',
|
|
20
|
+
hide: [],
|
|
21
|
+
show: [],
|
|
22
|
+
require: []
|
|
23
|
+
},
|
|
24
|
+
compactExpressInstruments: true,
|
|
25
|
+
googlePay: {
|
|
26
|
+
displayOptions: {
|
|
27
|
+
buttonColor: 'black',
|
|
28
|
+
buttonType: 'short',
|
|
29
|
+
buttonHeight: '44px'
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
applePay: {
|
|
33
|
+
displayOptions: {
|
|
34
|
+
buttonColor: 'black',
|
|
35
|
+
buttonType: 'plain',
|
|
36
|
+
buttonHeight: '44px'
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
paymentCard: {
|
|
40
|
+
popup: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
transactionType: 'purchase',
|
|
44
|
+
features: {
|
|
45
|
+
autoConfirmation: true,
|
|
46
|
+
autoResult: true
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
exports.defaults = defaults;
|
|
50
|
+
|
|
51
|
+
function validateOptions(options) {
|
|
52
|
+
// TODO: validate more options
|
|
53
|
+
const purchaseData = [options.items, options.invoiceId, options.money, options.transactionId].filter(v => v);
|
|
54
|
+
|
|
55
|
+
if (purchaseData.length === 0) {
|
|
56
|
+
throw new Error('Must provide purchase data');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (purchaseData.length > 1) {
|
|
60
|
+
throw new Error('Must provide only one purchase data type');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var _default = ({
|
|
65
|
+
options = {}
|
|
66
|
+
} = {}) => {
|
|
67
|
+
validateOptions(options);
|
|
68
|
+
const _computed = {
|
|
69
|
+
paymentMethodsUrl: options._dev ? options._dev.paymentMethodsUrl || 'https://forms.local.rebilly.dev:3000' : 'https://forms.secure-payments.app'
|
|
70
|
+
};
|
|
71
|
+
const combinedOptions = (0, _lodash.default)({ ...defaults
|
|
72
|
+
}, {
|
|
73
|
+
organizationId: options.organizationId,
|
|
74
|
+
publishableKey: options.publishableKey,
|
|
75
|
+
websiteId: options.websiteId,
|
|
76
|
+
apiMode: options.apiMode,
|
|
77
|
+
i18n: options.i18n,
|
|
78
|
+
theme: options.theme,
|
|
79
|
+
css: options.css,
|
|
80
|
+
locale: options.locale,
|
|
81
|
+
countryCode: options.countryCode,
|
|
82
|
+
features: options.features,
|
|
83
|
+
paymentInstruments: options.paymentInstruments,
|
|
84
|
+
transactionType: options.transactionType,
|
|
85
|
+
_computed
|
|
86
|
+
}); // Add optional key's
|
|
87
|
+
|
|
88
|
+
['items', 'money', 'invoiceId', 'transactionId', 'customerJwt', '_dev'].forEach(key => {
|
|
89
|
+
if (options[key]) {
|
|
90
|
+
combinedOptions[key] = options[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return combinedOptions;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.default = _default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _rebillyInstrumentsMock = require("../../../tests/mocks/rebilly-instruments-mock");
|
|
4
|
+
|
|
5
|
+
var _setupOptions = _interopRequireWildcard(require("./setup-options"));
|
|
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('Setup mount options', () => {
|
|
12
|
+
it("should fill with default options", () => {
|
|
13
|
+
const options = (0, _setupOptions.default)({
|
|
14
|
+
options: {
|
|
15
|
+
items: [{
|
|
16
|
+
planId: "test-plan-id",
|
|
17
|
+
quantity: 1
|
|
18
|
+
}]
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
expect(options).toMatchObject(_setupOptions.defaults);
|
|
22
|
+
});
|
|
23
|
+
it("should setup options from mount", async () => {
|
|
24
|
+
const options = {
|
|
25
|
+
publishableKey: 'test-publishable-key',
|
|
26
|
+
organizationId: 'test-organization-id',
|
|
27
|
+
websiteId: 'test-website-id',
|
|
28
|
+
invoiceId: 'test-invoice-id',
|
|
29
|
+
customerJwt: 'test-customer-jwt'
|
|
30
|
+
};
|
|
31
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)(options);
|
|
32
|
+
expect(rebillyInstruments.state.options).toMatchObject(options);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
describe('Validate mount options', () => {
|
|
36
|
+
it("should throw an error with no purchase data", async () => {
|
|
37
|
+
let error = null;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const options = {};
|
|
41
|
+
(0, _setupOptions.validateOptions)(options);
|
|
42
|
+
} catch (e) {
|
|
43
|
+
error = e;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
expect(error.message).toBe('Must provide purchase data');
|
|
47
|
+
});
|
|
48
|
+
it("should throw error if there are more than one purchase property", () => {
|
|
49
|
+
let error = null;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const options = {
|
|
53
|
+
invoiceId: "test-invoice-id",
|
|
54
|
+
items: [{
|
|
55
|
+
planId: "test-plan-id",
|
|
56
|
+
quantity: 1
|
|
57
|
+
}]
|
|
58
|
+
};
|
|
59
|
+
(0, _setupOptions.validateOptions)(options);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
error = e;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
expect(error.message).toBe('Must provide only one purchase data type');
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _storefront = _interopRequireDefault(require("../../storefront"));
|
|
9
|
+
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
|
|
12
|
+
var _default = ({
|
|
13
|
+
options: {
|
|
14
|
+
publishableKey,
|
|
15
|
+
orgnizationId,
|
|
16
|
+
apiMode,
|
|
17
|
+
_dev
|
|
18
|
+
}
|
|
19
|
+
}) => {
|
|
20
|
+
const storefront = {
|
|
21
|
+
publishableKey,
|
|
22
|
+
orgnizationId,
|
|
23
|
+
mode: apiMode || 'live'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (_dev) {
|
|
27
|
+
storefront.liveUrl = _dev.liveUrl || 'https://api.rebilly.com';
|
|
28
|
+
storefront.sandboxUrl = _dev.sandboxUrl || 'https://api-sandbox.rebilly.com';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (0, _storefront.default)(storefront);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.default = _default;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _style = require("../../style");
|
|
9
|
+
|
|
10
|
+
var _utils = require("../../utils");
|
|
11
|
+
|
|
12
|
+
var _default = async ({
|
|
13
|
+
options: {
|
|
14
|
+
theme = {},
|
|
15
|
+
css
|
|
16
|
+
}
|
|
17
|
+
} = {}) => {
|
|
18
|
+
// Adds base stylesheet
|
|
19
|
+
const style = await (0, _style.mainStyle)(theme || {});
|
|
20
|
+
(0, _utils.addDOMElement)({
|
|
21
|
+
element: 'style',
|
|
22
|
+
attributes: {
|
|
23
|
+
type: 'text/css'
|
|
24
|
+
},
|
|
25
|
+
content: style,
|
|
26
|
+
target: 'head'
|
|
27
|
+
}); // Adds options CSS to override any styles
|
|
28
|
+
|
|
29
|
+
if (css) {
|
|
30
|
+
(0, _utils.addDOMElement)({
|
|
31
|
+
element: 'style',
|
|
32
|
+
attributes: {
|
|
33
|
+
type: 'text/css'
|
|
34
|
+
},
|
|
35
|
+
content: css,
|
|
36
|
+
target: 'head'
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return style;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
exports.default = _default;
|
package/dist/functions/on.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.on = on;
|
|
7
7
|
|
|
8
8
|
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
9
9
|
|
|
@@ -15,12 +15,21 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
@typedef OnParams
|
|
20
|
+
@type {Object}
|
|
21
|
+
@property {string} eventName - The name of the event
|
|
22
|
+
@property {function} callback - The function that is triggered by the event.
|
|
23
|
+
*/
|
|
24
|
+
|
|
18
25
|
/**
|
|
19
26
|
* Register events that will be triggered
|
|
20
|
-
* @param {
|
|
21
|
-
* @param {function} callback - The function that is triggered by the event.
|
|
27
|
+
* @param {OnParams} params
|
|
22
28
|
*/
|
|
23
|
-
function
|
|
29
|
+
function on({
|
|
30
|
+
eventName,
|
|
31
|
+
callback
|
|
32
|
+
}) {
|
|
24
33
|
if (!_events.publicEventNames.includes(eventName)) {
|
|
25
34
|
throw new Error(`${eventName} is not a supported event`);
|
|
26
35
|
}
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _events = _interopRequireDefault(require("../events"));
|
|
8
8
|
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
10
|
|
|
11
11
|
describe('RebillyInstruments on', () => {
|
|
12
12
|
it('should register event listeners', async () => {
|
|
13
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.
|
|
13
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
14
14
|
const publicEventNames = ['instrument-ready', 'purchase-completed'];
|
|
15
15
|
await Promise.all(publicEventNames.map(async eventName => {
|
|
16
16
|
const callback = jest.fn();
|
|
@@ -25,9 +25,23 @@ describe('RebillyInstruments on', () => {
|
|
|
25
25
|
expect(callback).toBeCalledWith(details);
|
|
26
26
|
}));
|
|
27
27
|
});
|
|
28
|
+
it('should throw error for internal namespaced events', async () => {
|
|
29
|
+
const callback = jest.fn();
|
|
30
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
31
|
+
let error;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
// rebilly-instruments-purchase-completed will be used internally but not available externally
|
|
35
|
+
await rebillyInstruments.on('rebilly-instruments-purchase-completed', callback);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
error = e;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
expect(error).toEqual(new Error('rebilly-instruments-purchase-completed is not a supported event'));
|
|
41
|
+
});
|
|
28
42
|
it('should throw error for a non defined event', async () => {
|
|
29
43
|
const callback = jest.fn();
|
|
30
|
-
const rebillyInstruments = (0, _rebillyInstrumentsMock.
|
|
44
|
+
const rebillyInstruments = await (0, _rebillyInstrumentsMock.RenderMockRebillyInstruments)();
|
|
31
45
|
let error;
|
|
32
46
|
|
|
33
47
|
try {
|
|
@@ -36,6 +50,6 @@ describe('RebillyInstruments on', () => {
|
|
|
36
50
|
error = e;
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
expect(error).toEqual(new Error(
|
|
53
|
+
expect(error).toEqual(new Error('not-an-event is not a supported event'));
|
|
40
54
|
});
|
|
41
55
|
});
|