@rebilly/instruments 1.0.1-beta → 1.0.2-beta.10
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 +23 -5
- package/.eslintrc.js +27 -0
- package/.prettierrc.js +11 -0
- package/CONTRIBUTING.md +4 -0
- package/README.md +361 -2
- package/dist/events/base-event.js +51 -37
- package/dist/events/events.spec.js +18 -0
- package/dist/events/index.js +11 -8
- package/dist/functions/destroy.js +27 -5
- package/dist/functions/destroy.spec.js +69 -0
- package/dist/functions/initialize.js +60 -41
- package/dist/functions/initialize.spec.js +13 -13
- package/dist/functions/mount/fetch-summary-data.js +46 -0
- package/dist/functions/mount/fetch-summary-data.spec.js +44 -0
- package/dist/functions/mount/index.js +346 -0
- package/dist/functions/mount/mount.spec.js +135 -0
- package/dist/functions/on.js +26 -18
- package/dist/functions/on.spec.js +45 -63
- package/dist/functions/purchase.js +41 -154
- package/dist/functions/purchase.spec.js +60 -76
- package/dist/functions/show.js +39 -43
- package/dist/functions/show.spec.js +57 -0
- package/dist/functions/update.js +60 -5
- package/dist/functions/update.spec.js +100 -0
- package/dist/i18n/en.json +19 -0
- package/dist/i18n/es.json +19 -0
- package/dist/i18n/i18n.spec.js +6 -23
- package/dist/i18n/index.js +44 -67
- package/dist/index.js +70 -71
- package/dist/index.spec.js +24 -44
- package/dist/loader/index.js +63 -62
- package/dist/loader/loader.spec.js +14 -11
- package/dist/storefront/index.js +28 -39
- package/dist/storefront/models/plan-model.js +37 -54
- package/dist/storefront/models/product-model.js +25 -36
- package/dist/storefront/models/ready-to-pay-model.js +38 -42
- package/dist/storefront/models/summary-model.js +72 -99
- package/dist/storefront/plans.js +37 -84
- package/dist/storefront/plans.spec.js +61 -151
- package/dist/storefront/products.js +35 -83
- package/dist/storefront/products.spec.js +60 -150
- package/dist/storefront/purchase.js +27 -64
- package/dist/storefront/purchase.spec.js +51 -87
- package/dist/storefront/ready-to-pay.js +45 -107
- package/dist/storefront/ready-to-pay.spec.js +72 -147
- package/dist/storefront/storefront.spec.js +6 -6
- package/dist/storefront/summary.js +37 -84
- package/dist/storefront/summary.spec.js +135 -240
- package/dist/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/dist/style/base/index.js +72 -0
- package/dist/style/base/theme.js +73 -0
- package/dist/style/base/theme.spec.js +30 -0
- package/dist/style/browserslist.js +8 -0
- package/dist/style/components/address.js +64 -0
- package/dist/style/components/button.js +61 -0
- package/dist/style/components/divider.js +48 -0
- package/dist/style/components/forms/checkbox.js +83 -0
- package/dist/style/components/forms/field.js +53 -0
- package/dist/style/components/forms/form.js +28 -0
- package/dist/style/components/forms/input.js +45 -0
- package/dist/style/components/forms/label.js +43 -0
- package/dist/style/components/forms/select.js +63 -0
- package/dist/style/components/forms/validation.js +34 -0
- package/dist/style/components/icons.js +22 -0
- package/dist/style/components/index.js +57 -0
- package/dist/style/components/loader.js +48 -0
- package/dist/style/components/methods.js +104 -0
- package/dist/style/components/overlay.js +33 -0
- package/dist/style/helpers/index.js +59 -0
- package/dist/style/index.js +48 -0
- package/dist/style/payment-instruments/content.js +17 -0
- package/dist/style/payment-instruments/index.js +20 -0
- package/dist/style/payment-instruments/payment-card.js +35 -0
- package/dist/style/utils/color-values.js +22 -0
- package/dist/style/vendor/framepay.js +34 -0
- package/dist/style/vendor/postmate.js +17 -0
- package/dist/style/views/confirmation.js +85 -0
- package/dist/style/views/index.js +29 -0
- package/dist/style/views/method-selector.js +20 -0
- package/dist/style/views/modal.js +93 -0
- package/dist/style/views/result.js +61 -0
- package/dist/style/views/summary.js +123 -0
- package/dist/utils/add-dom-element.js +12 -34
- package/dist/utils/format-currency.js +4 -4
- package/dist/utils/has-valid-css-selector.js +2 -2
- package/dist/utils/index.js +15 -31
- package/dist/utils/is-dom-element.js +1 -1
- package/dist/utils/process-property-as-dom-element.js +12 -17
- package/dist/utils/sleep.js +10 -0
- package/{src/components → dist/views}/__snapshots__/summary.spec.js.snap +7 -3
- package/dist/views/common/iframe/base-iframe.js +57 -0
- package/dist/views/common/iframe/event-listeners.js +50 -0
- package/dist/views/common/iframe/index.js +19 -0
- package/dist/views/common/iframe/method-iframe.js +33 -0
- package/dist/views/common/iframe/modal-iframe.js +38 -0
- package/dist/views/common/iframe/view-iframe.js +31 -0
- package/dist/views/common/render-utilities.js +11 -0
- package/dist/views/confirmation.js +82 -0
- package/dist/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/dist/views/method-selector/express-methods/apple-pay.js +92 -0
- package/dist/views/method-selector/express-methods/google-pay.js +32 -0
- package/dist/views/method-selector/express-methods/paypal.js +19 -0
- package/dist/views/method-selector/generate-digital-wallet.js +59 -0
- package/dist/views/method-selector/generate-digital-wallet.spec.js +132 -0
- package/dist/views/method-selector/get-method-data.js +25 -0
- package/dist/views/method-selector/get-payment-methods.js +55 -0
- package/dist/views/method-selector/get-payment-methods.spec.js +44 -0
- package/dist/views/method-selector/index.js +133 -0
- package/dist/views/method-selector/method-selector.spec.js +139 -0
- package/dist/views/method-selector/mount-express-methods.js +69 -0
- package/dist/views/method-selector/mount-methods.js +78 -0
- package/dist/views/modal.js +83 -0
- package/dist/views/result.js +42 -0
- package/dist/views/summary.js +162 -0
- package/dist/views/summary.spec.js +148 -0
- package/package.json +12 -6
- package/src/events/base-event.js +35 -12
- package/src/events/events.spec.js +11 -0
- package/src/events/index.js +12 -6
- package/src/functions/destroy.js +22 -3
- package/src/functions/destroy.spec.js +63 -0
- package/src/functions/initialize.js +43 -20
- package/src/functions/initialize.spec.js +9 -7
- package/src/functions/mount/fetch-summary-data.js +29 -0
- package/src/functions/mount/fetch-summary-data.spec.js +41 -0
- package/src/functions/mount/index.js +312 -0
- package/src/functions/mount/mount.spec.js +171 -0
- package/src/functions/on.js +17 -14
- package/src/functions/on.spec.js +39 -29
- package/src/functions/purchase.js +24 -64
- package/src/functions/purchase.spec.js +19 -17
- package/src/functions/show.js +27 -7
- package/src/functions/show.spec.js +61 -0
- package/src/functions/update.js +50 -3
- package/src/functions/update.spec.js +107 -0
- package/src/i18n/i18n.spec.js +6 -4
- package/src/i18n/index.js +20 -12
- package/src/index.js +43 -49
- package/src/index.spec.js +11 -42
- package/src/loader/index.js +55 -39
- package/src/loader/loader.spec.js +30 -23
- package/src/storefront/index.js +9 -7
- package/src/storefront/models/plan-model.js +1 -1
- package/src/storefront/models/product-model.js +1 -1
- package/src/storefront/models/ready-to-pay-model.js +10 -4
- package/src/storefront/models/summary-model.js +8 -15
- package/src/storefront/plans.js +16 -12
- package/src/storefront/plans.spec.js +29 -37
- package/src/storefront/products.js +16 -12
- package/src/storefront/products.spec.js +28 -39
- package/src/storefront/purchase.js +8 -6
- package/src/storefront/purchase.spec.js +18 -17
- package/src/storefront/ready-to-pay.js +19 -13
- package/src/storefront/ready-to-pay.spec.js +41 -41
- package/src/storefront/storefront.spec.js +1 -1
- package/src/storefront/summary.js +14 -12
- package/src/storefront/summary.spec.js +37 -50
- package/src/style/base/__snapshots__/theme.spec.js.snap +52 -0
- package/src/style/base/index.js +63 -0
- package/src/style/base/theme.js +61 -0
- package/src/style/base/theme.spec.js +32 -0
- package/src/style/browserslist.js +1 -0
- package/src/style/components/address.js +55 -0
- package/src/style/components/button.js +54 -0
- package/src/style/components/divider.js +39 -0
- package/src/style/components/forms/checkbox.js +76 -0
- package/src/style/components/forms/field.js +44 -0
- package/src/style/components/forms/form.js +19 -0
- package/src/style/components/forms/input.js +36 -0
- package/src/style/components/forms/label.js +34 -0
- package/src/style/components/forms/select.js +54 -0
- package/src/style/components/forms/validation.js +25 -0
- package/src/style/components/icons.js +13 -0
- package/src/style/components/index.js +35 -0
- package/src/style/components/loader.js +41 -0
- package/src/style/components/methods.js +93 -0
- package/src/style/components/overlay.js +24 -0
- package/src/style/helpers/index.js +51 -0
- package/src/style/index.js +30 -0
- package/src/style/payment-instruments/content.js +8 -0
- package/src/style/payment-instruments/index.js +10 -0
- package/src/style/payment-instruments/payment-card.js +26 -0
- package/src/style/utils/color-values.js +9 -0
- package/src/style/vendor/framepay.js +25 -0
- package/src/style/vendor/postmate.js +8 -0
- package/src/style/views/confirmation.js +76 -0
- package/src/style/views/index.js +16 -0
- package/src/style/views/method-selector.js +11 -0
- package/src/style/views/modal.js +84 -0
- package/src/style/views/result.js +52 -0
- package/src/style/views/summary.js +114 -0
- package/src/utils/add-dom-element.js +12 -13
- package/src/utils/format-currency.js +4 -1
- package/src/utils/has-valid-css-selector.js +2 -2
- package/src/utils/index.js +2 -6
- 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 +3 -0
- package/src/views/__snapshots__/summary.spec.js.snap +292 -0
- package/src/views/common/iframe/base-iframe.js +46 -0
- package/src/views/common/iframe/event-listeners.js +27 -0
- package/src/views/common/iframe/index.js +7 -0
- package/src/views/common/iframe/method-iframe.js +21 -0
- package/src/views/common/iframe/modal-iframe.js +27 -0
- package/src/views/common/iframe/view-iframe.js +18 -0
- package/src/views/common/render-utilities.js +4 -0
- package/src/views/confirmation.js +57 -0
- package/src/views/method-selector/__snapshots__/method-selector.spec.js.snap +3 -0
- package/src/views/method-selector/express-methods/apple-pay.js +78 -0
- package/src/views/method-selector/express-methods/google-pay.js +25 -0
- package/src/views/method-selector/express-methods/paypal.js +7 -0
- package/src/views/method-selector/generate-digital-wallet.js +44 -0
- package/src/views/method-selector/generate-digital-wallet.spec.js +131 -0
- package/src/{components/form → views/method-selector}/get-method-data.js +9 -5
- package/src/views/method-selector/get-payment-methods.js +40 -0
- package/src/views/method-selector/get-payment-methods.spec.js +40 -0
- package/src/views/method-selector/index.js +110 -0
- package/src/views/method-selector/method-selector.spec.js +146 -0
- package/src/views/method-selector/mount-express-methods.js +53 -0
- package/src/views/method-selector/mount-methods.js +71 -0
- package/src/views/modal.js +84 -0
- package/src/views/result.js +30 -0
- package/src/{components → views}/summary.js +90 -21
- package/src/views/summary.spec.js +170 -0
- package/tests/async-utilities.js +22 -0
- package/tests/mocks/rebilly-instruments-mock.js +105 -7
- package/dist/components/confirmation.js +0 -103
- package/dist/components/form/form.js +0 -110
- package/dist/components/form/form.spec.js +0 -135
- package/dist/components/form/get-method-data.js +0 -21
- package/dist/components/form/get-payment-methods.js +0 -42
- package/dist/components/form/method-selector.js +0 -61
- package/dist/components/form/mount-express-payment-methods.js +0 -102
- package/dist/components/form/process-digital-wallet-options.js +0 -20
- package/dist/components/form/zoid-helpers.js +0 -130
- package/dist/components/result.js +0 -66
- package/dist/components/summary.js +0 -60
- package/dist/components/summary.spec.js +0 -144
- package/dist/events/instrument-ready.js +0 -51
- package/dist/events/purchase-complete.js +0 -51
- package/dist/functions/mount.js +0 -311
- package/dist/functions/mount.spec.js +0 -203
- package/dist/styles/base-styles.js +0 -12
- package/dist/styles/flat-theme-object.js +0 -42
- package/dist/styles/framepay.js +0 -15
- package/dist/styles/main.js +0 -25
- package/dist/styles/payment-card.js +0 -12
- package/dist/styles/shade-tint-values-helper.js +0 -28
- package/dist/styles/style-variables.js +0 -43
- package/dist/utils/camel-case.js +0 -12
- package/dist/utils/kebab-case.js +0 -10
- package/dist/utils/un-kebab-case.js +0 -10
- package/src/components/confirmation.js +0 -77
- package/src/components/form/__snapshots__/form.spec.js.snap +0 -43
- package/src/components/form/form.js +0 -88
- package/src/components/form/form.spec.js +0 -109
- package/src/components/form/get-payment-methods.js +0 -32
- package/src/components/form/method-selector.js +0 -47
- package/src/components/form/mount-express-payment-methods.js +0 -84
- package/src/components/form/process-digital-wallet-options.js +0 -11
- package/src/components/form/zoid-helpers.js +0 -114
- package/src/components/result.js +0 -50
- package/src/components/summary.spec.js +0 -106
- package/src/events/instrument-ready.js +0 -11
- package/src/events/purchase-complete.js +0 -11
- package/src/functions/mount.js +0 -204
- package/src/functions/mount.spec.js +0 -172
- package/src/styles/base-styles.js +0 -741
- package/src/styles/flat-theme-object.js +0 -12
- package/src/styles/framepay.js +0 -30
- package/src/styles/main.js +0 -17
- package/src/styles/payment-card.js +0 -18
- package/src/styles/shade-tint-values-helper.js +0 -13
- package/src/styles/style-variables.js +0 -34
- package/src/utils/camel-case.js +0 -3
- package/src/utils/kebab-case.js +0 -3
- package/src/utils/un-kebab-case.js +0 -3
|
@@ -0,0 +1,135 @@
|
|
|
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 _planModel = _interopRequireDefault(require("../../storefront/models/plan-model"));
|
|
12
|
+
|
|
13
|
+
var _productModel = _interopRequireDefault(require("../../storefront/models/product-model"));
|
|
14
|
+
|
|
15
|
+
var _summaryModel = _interopRequireDefault(require("../../storefront/models/summary-model"));
|
|
16
|
+
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
|
|
19
|
+
describe('RebillyInstruments instance', () => {
|
|
20
|
+
it('should throw error when there is no DOM element to mount the form', () => {
|
|
21
|
+
document.body.innerHTML = `
|
|
22
|
+
<div class="form-selector"></div>
|
|
23
|
+
<div class="summary-selector"></div>
|
|
24
|
+
`;
|
|
25
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
26
|
+
expect(async () => {
|
|
27
|
+
await rebillyInstruments.mount({});
|
|
28
|
+
}).rejects.toEqual(new Error('Could not find DOM element with CSS class or id ".rebilly-instruments" to mount form'));
|
|
29
|
+
});
|
|
30
|
+
it('should throw error when providing the wrong type for the form property', () => {
|
|
31
|
+
document.body.innerHTML = `
|
|
32
|
+
<div class="form-selector"></div>
|
|
33
|
+
<div class="summary-selector"></div>
|
|
34
|
+
`;
|
|
35
|
+
const options = {
|
|
36
|
+
form: []
|
|
37
|
+
};
|
|
38
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
39
|
+
expect(async () => {
|
|
40
|
+
await rebillyInstruments.mount(options);
|
|
41
|
+
}).rejects.toEqual(new Error('Please provide a valid CSS class, id or DOM element for "form" property'));
|
|
42
|
+
});
|
|
43
|
+
it.only("should inject HTML to the merchant's website", async () => {
|
|
44
|
+
const testPlan = new _planModel.default({
|
|
45
|
+
name: 'Test Plan',
|
|
46
|
+
id: 'test-plan-id-1'
|
|
47
|
+
});
|
|
48
|
+
const testProduct = new _productModel.default({
|
|
49
|
+
description: 'My Awesome Product',
|
|
50
|
+
id: 'test-product-1'
|
|
51
|
+
});
|
|
52
|
+
const testSummary = new _summaryModel.default({
|
|
53
|
+
currency: 'USD',
|
|
54
|
+
lineItems: [{
|
|
55
|
+
description: 'test-plan-id-1',
|
|
56
|
+
planId: 'test-plan-id-1',
|
|
57
|
+
productId: 'test-product-1',
|
|
58
|
+
quantity: 1
|
|
59
|
+
}]
|
|
60
|
+
});
|
|
61
|
+
const framePayScriptUrl = 'https://framepay.rebilly.com/rebilly.js';
|
|
62
|
+
const framePayStyleUrl = 'https://dev.framepay.rebilly.com/rebilly.css';
|
|
63
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/ready-to-pay`)).thenReturn((() => {
|
|
64
|
+
return (0, _mswWhenThen.ok)([{
|
|
65
|
+
method: 'payment-card',
|
|
66
|
+
feature: {
|
|
67
|
+
name: 'Google Pay',
|
|
68
|
+
merchantName: 'google-pay-merchant-name',
|
|
69
|
+
merchantOrigin: 'google-pay-merchant-origin'
|
|
70
|
+
},
|
|
71
|
+
brands: ['Visa', 'MasterCard', 'American Express', 'Discover'],
|
|
72
|
+
filters: []
|
|
73
|
+
}]);
|
|
74
|
+
})());
|
|
75
|
+
(0, _server.when)((0, _mswWhenThen.post)(`${_storefrontApiMock.storefrontURL}/preview-purchase`)).thenReturn((() => {
|
|
76
|
+
return (0, _mswWhenThen.ok)(testSummary);
|
|
77
|
+
})());
|
|
78
|
+
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/plans`)).thenReturn((() => {
|
|
79
|
+
return (0, _mswWhenThen.ok)([testPlan]);
|
|
80
|
+
})());
|
|
81
|
+
(0, _server.when)((0, _mswWhenThen.get)(`${_storefrontApiMock.storefrontURL}/products`)).thenReturn((() => {
|
|
82
|
+
return (0, _mswWhenThen.ok)([testProduct]);
|
|
83
|
+
})());
|
|
84
|
+
document.body.innerHTML = `
|
|
85
|
+
<div class="form-selector"></div>
|
|
86
|
+
<div class="summary-selector"></div>
|
|
87
|
+
`;
|
|
88
|
+
const options = {
|
|
89
|
+
form: '.form-selector',
|
|
90
|
+
summary: '.summary-selector',
|
|
91
|
+
_dev: {
|
|
92
|
+
framePayStyleLink: framePayStyleUrl
|
|
93
|
+
},
|
|
94
|
+
options: {
|
|
95
|
+
locale: 'auto',
|
|
96
|
+
intent: {
|
|
97
|
+
items: [{
|
|
98
|
+
planId: 'test-plan-id-1',
|
|
99
|
+
quantity: 1
|
|
100
|
+
}]
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)({
|
|
105
|
+
theme: {
|
|
106
|
+
color: {
|
|
107
|
+
background: '#000'
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
css: `
|
|
111
|
+
.rebilly-instruments-summary-line-item-synopsis-title {
|
|
112
|
+
color: rgb(0, 68, 212);
|
|
113
|
+
}
|
|
114
|
+
`
|
|
115
|
+
});
|
|
116
|
+
await rebillyInstruments.mount(options); // Mounts form and summary
|
|
117
|
+
|
|
118
|
+
const summarySelector = document.querySelector('.summary-selector');
|
|
119
|
+
expect(summarySelector.innerHTML).toMatch(testPlan.name); // Theme config overrides initial styles
|
|
120
|
+
|
|
121
|
+
const SUMMARY_CONTAINER = summarySelector.querySelector('.rebilly-instruments-content');
|
|
122
|
+
expect(getComputedStyle(SUMMARY_CONTAINER).background).toEqual('rgb(0, 0, 0)'); // CSS config property overrides initial styles
|
|
123
|
+
|
|
124
|
+
const LINE_ITEM_TITLE = document.querySelector('.rebilly-instruments-summary-line-item-synopsis-title');
|
|
125
|
+
expect(getComputedStyle(LINE_ITEM_TITLE).color).toEqual('rgb(0, 68, 212)'); // Mounts default FramePay script
|
|
126
|
+
|
|
127
|
+
const SCRIPTS = [...document.querySelectorAll('head script')];
|
|
128
|
+
const FRAMEPAY_SCRIPT = SCRIPTS.find(script => script.src === framePayScriptUrl);
|
|
129
|
+
expect(FRAMEPAY_SCRIPT.src).toEqual(framePayScriptUrl); // Mounts _dev FramePay style
|
|
130
|
+
|
|
131
|
+
const STYLE_LINKS = [...document.querySelectorAll('head link')];
|
|
132
|
+
const FRAMEPAY_STYLE = STYLE_LINKS.find(script => script.href === framePayStyleUrl);
|
|
133
|
+
expect(FRAMEPAY_STYLE.href).toEqual(framePayStyleUrl);
|
|
134
|
+
});
|
|
135
|
+
});
|
package/dist/functions/on.js
CHANGED
|
@@ -3,30 +3,38 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.on = on;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
var _events = _interopRequireWildcard(require("../events"));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
* Register events that will be triggered
|
|
14
|
-
* @param {string} eventName - The name of the event
|
|
15
|
-
* @param {function} callback - The function that is triggered by the event.
|
|
16
|
-
*/
|
|
17
|
-
function On(eventName, callback) {
|
|
18
|
-
switch (eventName) {
|
|
19
|
-
case 'instrument-ready':
|
|
20
|
-
_events["default"].instrumentReady.addEventListener(callback);
|
|
12
|
+
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); }
|
|
21
13
|
|
|
22
|
-
|
|
14
|
+
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; }
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
_events["default"].purchaseComplete.addEventListener(callback);
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
26
17
|
|
|
27
|
-
|
|
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
|
+
*/
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Register events that will be triggered
|
|
27
|
+
* @param {OnParams} params
|
|
28
|
+
*/
|
|
29
|
+
function on({
|
|
30
|
+
eventName,
|
|
31
|
+
callback
|
|
32
|
+
}) {
|
|
33
|
+
if (!_events.publicEventNames.includes(eventName)) {
|
|
34
|
+
throw new Error(`${eventName} is not a supported event`);
|
|
31
35
|
}
|
|
36
|
+
|
|
37
|
+
const internalEventName = (0, _lodash.default)(eventName);
|
|
38
|
+
|
|
39
|
+
_events.default[internalEventName].addEventListener(callback);
|
|
32
40
|
}
|
|
@@ -1,73 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
var _rebillyInstrumentsMock = require("tests/mocks/rebilly-instruments-mock");
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
3
|
+
var _lodash = _interopRequireDefault(require("lodash.camelcase"));
|
|
8
4
|
|
|
9
|
-
|
|
5
|
+
var _rebillyInstrumentsMock = require("../../tests/mocks/rebilly-instruments-mock");
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
describe('RebillyInstruments on', function () {
|
|
14
|
-
it('should be able to register event listeners', function () {
|
|
15
|
-
var events = [{
|
|
16
|
-
name: 'instrument-ready',
|
|
17
|
-
dispatch: _events["default"].instrumentReady.dispatch
|
|
18
|
-
}, {
|
|
19
|
-
name: 'purchase-complete',
|
|
20
|
-
dispatch: _events["default"].purchaseComplete.dispatch
|
|
21
|
-
}];
|
|
22
|
-
var rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
23
|
-
events.forEach( /*#__PURE__*/function () {
|
|
24
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(event) {
|
|
25
|
-
var callback, details;
|
|
26
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
27
|
-
while (1) {
|
|
28
|
-
switch (_context.prev = _context.next) {
|
|
29
|
-
case 0:
|
|
30
|
-
callback = jest.fn();
|
|
31
|
-
rebillyInstruments.on(event.name, callback);
|
|
32
|
-
details = {
|
|
33
|
-
test: 'data'
|
|
34
|
-
};
|
|
35
|
-
_context.next = 5;
|
|
36
|
-
return event.dispatch(details);
|
|
7
|
+
var _events = _interopRequireDefault(require("../events"));
|
|
37
8
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
|
|
11
|
+
describe('RebillyInstruments on', () => {
|
|
12
|
+
it('should register event listeners', async () => {
|
|
13
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
14
|
+
const publicEventNames = ['instrument-ready', 'purchase-completed'];
|
|
15
|
+
await Promise.all(publicEventNames.map(async eventName => {
|
|
16
|
+
const callback = jest.fn();
|
|
17
|
+
rebillyInstruments.on(eventName, callback);
|
|
18
|
+
const details = {
|
|
19
|
+
test: 'data'
|
|
20
|
+
};
|
|
41
21
|
|
|
42
|
-
|
|
43
|
-
case "end":
|
|
44
|
-
return _context.stop();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}, _callee);
|
|
48
|
-
}));
|
|
22
|
+
_events.default[(0, _lodash.default)(eventName)].dispatch(details);
|
|
49
23
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}());
|
|
24
|
+
expect(callback).toBeCalledTimes(1);
|
|
25
|
+
expect(callback).toBeCalledWith(details);
|
|
26
|
+
}));
|
|
54
27
|
});
|
|
55
|
-
it('should throw error for
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
28
|
+
it('should throw error for internal namespaced events', async () => {
|
|
29
|
+
const callback = jest.fn();
|
|
30
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
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
|
+
});
|
|
42
|
+
it('should throw error for a non defined event', async () => {
|
|
43
|
+
const callback = jest.fn();
|
|
44
|
+
const rebillyInstruments = (0, _rebillyInstrumentsMock.MockRebillyInstruments)();
|
|
45
|
+
let error;
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
await rebillyInstruments.on('not-an-event', callback);
|
|
49
|
+
} catch (e) {
|
|
50
|
+
error = e;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
expect(error).toEqual(new Error('not-an-event is not a supported event'));
|
|
72
54
|
});
|
|
73
55
|
});
|
|
@@ -3,164 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.purchase = purchase;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _purchase = require("../storefront/purchase");
|
|
9
9
|
|
|
10
10
|
var _events = _interopRequireDefault(require("../events"));
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
43
|
-
while (1) {
|
|
44
|
-
switch (_context.prev = _context.next) {
|
|
45
|
-
case 0:
|
|
46
|
-
_context.prev = 0;
|
|
47
|
-
|
|
48
|
-
_this.storefront.setSessionToken(purchase.token);
|
|
49
|
-
|
|
50
|
-
_context.next = 4;
|
|
51
|
-
return Promise.all([_this.storefront.transactions.get({
|
|
52
|
-
id: purchase.transaction.id
|
|
53
|
-
}), _this.storefront.invoices.get({
|
|
54
|
-
id: purchase.invoice.id
|
|
55
|
-
})]);
|
|
56
|
-
|
|
57
|
-
case 4:
|
|
58
|
-
_yield$Promise$all = _context.sent;
|
|
59
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
60
|
-
transaction = _yield$Promise$all2[0].fields;
|
|
61
|
-
invoice = _yield$Promise$all2[1].fields;
|
|
62
|
-
updatedPurchase = _objectSpread(_objectSpread({}, purchase), {}, {
|
|
63
|
-
transaction: transaction,
|
|
64
|
-
invoice: invoice
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
_events["default"].purchaseComplete.dispatch(updatedPurchase);
|
|
68
|
-
|
|
69
|
-
_context.next = 15;
|
|
70
|
-
break;
|
|
71
|
-
|
|
72
|
-
case 12:
|
|
73
|
-
_context.prev = 12;
|
|
74
|
-
_context.t0 = _context["catch"](0);
|
|
75
|
-
|
|
76
|
-
_events["default"].purchaseComplete.dispatch(_context.t0);
|
|
77
|
-
|
|
78
|
-
case 15:
|
|
79
|
-
case "end":
|
|
80
|
-
return _context.stop();
|
|
12
|
+
var _modal = require("../views/modal");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
async function purchase({
|
|
17
|
+
state,
|
|
18
|
+
payload: purchasePayload
|
|
19
|
+
}) {
|
|
20
|
+
try {
|
|
21
|
+
const {
|
|
22
|
+
fields: purchaseFields
|
|
23
|
+
} = await (0, _purchase.postPurchase)({
|
|
24
|
+
state,
|
|
25
|
+
data: purchasePayload
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (purchaseFields.transaction.approvalUrl) {
|
|
29
|
+
const {
|
|
30
|
+
paymentMethodsUrl
|
|
31
|
+
} = state.options._computed;
|
|
32
|
+
(0, _modal.mountModal)({
|
|
33
|
+
state,
|
|
34
|
+
name: 'rebilly-instruments-approval-url',
|
|
35
|
+
url: `${paymentMethodsUrl}/approval-url`,
|
|
36
|
+
model: {
|
|
37
|
+
purchase: purchaseFields
|
|
38
|
+
},
|
|
39
|
+
close: updatedPurchase => {
|
|
40
|
+
// TODO: Check if this is purchase...
|
|
41
|
+
_events.default.purchaseCompleted.dispatch(updatedPurchase);
|
|
81
42
|
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
focus = _ref2.focus;
|
|
92
|
-
var container = doc.createElement('div');
|
|
93
|
-
var text = doc.createElement('p');
|
|
94
|
-
text.innerText = 'Click here to show popup window';
|
|
95
|
-
container.id = uid;
|
|
96
|
-
container.append(text);
|
|
97
|
-
container.classList.add('rebilly-instruments-overlay');
|
|
98
|
-
container.addEventListener('click', focus);
|
|
99
|
-
return container;
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
_events.default.purchaseCompleted.dispatch(purchaseFields);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return purchaseFields;
|
|
49
|
+
} catch (error) {
|
|
50
|
+
// TODO: Display error to customer
|
|
51
|
+
return error;
|
|
100
52
|
}
|
|
101
|
-
|
|
102
|
-
;
|
|
103
|
-
var paymentMethodsUrl = this.options._computed.paymentMethodsUrl;
|
|
104
|
-
|
|
105
|
-
var zoidComponent = _zoid["default"].create({
|
|
106
|
-
tag: 'rebilly-instruments-approval-url',
|
|
107
|
-
url: "".concat(paymentMethodsUrl, "/approval-url"),
|
|
108
|
-
defaultContext: 'popup',
|
|
109
|
-
dimensions: {
|
|
110
|
-
width: '600px',
|
|
111
|
-
height: '600px'
|
|
112
|
-
},
|
|
113
|
-
containerTemplate: containerTemplate
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
zoidComponent({
|
|
117
|
-
RebillyInstruments: {
|
|
118
|
-
approvalUrl: purchase.transaction.approvalUrl
|
|
119
|
-
},
|
|
120
|
-
onClose: zoidComponentClose.call(this, purchase)
|
|
121
|
-
}).render();
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function Purchase(_x) {
|
|
125
|
-
return _Purchase.apply(this, arguments);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function _Purchase() {
|
|
129
|
-
_Purchase = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(purchasePayload) {
|
|
130
|
-
var _yield$this$_postPurc, purchase;
|
|
131
|
-
|
|
132
|
-
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
133
|
-
while (1) {
|
|
134
|
-
switch (_context2.prev = _context2.next) {
|
|
135
|
-
case 0:
|
|
136
|
-
_context2.prev = 0;
|
|
137
|
-
_context2.next = 3;
|
|
138
|
-
return this._postPurchase(purchasePayload);
|
|
139
|
-
|
|
140
|
-
case 3:
|
|
141
|
-
_yield$this$_postPurc = _context2.sent;
|
|
142
|
-
purchase = _yield$this$_postPurc.fields;
|
|
143
|
-
|
|
144
|
-
if (purchase.transaction.approvalUrl) {
|
|
145
|
-
openApprovalUrl.call(this, purchase);
|
|
146
|
-
} else {
|
|
147
|
-
_events["default"].purchaseComplete.dispatch(purchase);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
_context2.next = 11;
|
|
151
|
-
break;
|
|
152
|
-
|
|
153
|
-
case 8:
|
|
154
|
-
_context2.prev = 8;
|
|
155
|
-
_context2.t0 = _context2["catch"](0);
|
|
156
|
-
return _context2.abrupt("return", _context2.t0);
|
|
157
|
-
|
|
158
|
-
case 11:
|
|
159
|
-
case "end":
|
|
160
|
-
return _context2.stop();
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}, _callee2, this, [[0, 8]]);
|
|
164
|
-
}));
|
|
165
|
-
return _Purchase.apply(this, arguments);
|
|
166
53
|
}
|