@medipass/checkout-sdk 2.1.0 → 3.0.0-alpha.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/lib/index.js DELETED
@@ -1,280 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports["default"] = void 0;
5
-
6
- var _get2 = _interopRequireDefault(require("lodash/get"));
7
-
8
- var _overlay = _interopRequireDefault(require("./overlay"));
9
-
10
- var _constants = require("./constants");
11
-
12
- require("./style.css");
13
-
14
- var _initialiseWindow = _interopRequireDefault(require("./initialiseWindow"));
15
-
16
- var _requestUpdatePaymentDetails = _interopRequireDefault(require("./requestUpdatePaymentDetails"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
-
20
- ////////////////////////////////////////////////////////////
21
- var _windowReferenceObject = null; ////////////////////////////////////////////////////////////
22
-
23
- var checkoutSDK = {
24
- ENVS: _constants.ENVS,
25
- isCheckoutInitiated: false,
26
- isCheckoutComplete: null,
27
- env: null,
28
- onSuccess: null,
29
- onFailure: null,
30
- onCancel: null,
31
- onCose: null,
32
- init: function init(_ref) {
33
- var _this = this;
34
-
35
- var env = _ref.env,
36
- onSuccess = _ref.onSuccess,
37
- onFailure = _ref.onFailure,
38
- onCancel = _ref.onCancel,
39
- onClose = _ref.onClose;
40
- if (!env) return;
41
- this.env = env;
42
- this.onSuccess = onSuccess;
43
- this.onFailure = onFailure;
44
- this.onCancel = onCancel;
45
- this.onClose = onClose; // Open a blank window
46
-
47
- _windowReferenceObject = (0, _initialiseWindow["default"])({
48
- url: ''
49
- });
50
-
51
- var handleClose = function handleClose() {
52
- _overlay["default"].removeOverlay();
53
-
54
- onClose && onClose();
55
- if (!_windowReferenceObject) return;
56
-
57
- _windowReferenceObject.close();
58
- };
59
-
60
- var onClickRelaunch = function onClickRelaunch() {
61
- if (!_windowReferenceObject) {
62
- _windowReferenceObject = (0, _initialiseWindow["default"])({
63
- url: ''
64
- });
65
- return;
66
- }
67
-
68
- _windowReferenceObject.focus();
69
- };
70
-
71
- var checkWindowClosed = function checkWindowClosed() {
72
- if (_this.isCheckoutInitiated) {
73
- clearInterval(timer);
74
- return;
75
- }
76
-
77
- if ((0, _get2["default"])(_windowReferenceObject, 'closed')) {
78
- clearInterval(timer);
79
- handleClose();
80
- }
81
- };
82
-
83
- var onClickCancel = function onClickCancel() {
84
- _overlay["default"].removeOverlay();
85
-
86
- if (_windowReferenceObject) {
87
- _windowReferenceObject.close();
88
- }
89
-
90
- clearInterval(timer);
91
- onClose && onClose();
92
- }; // This creates the gray overlay covering the client's screen while payment is in progress.
93
-
94
-
95
- _overlay["default"].createOverlay({
96
- window: window,
97
- onClickRelaunch: onClickRelaunch,
98
- onClickCancel: onClickCancel
99
- }); // Check the window every 0.5 seconds to see if it has been closed.
100
-
101
-
102
- var timer = setInterval(checkWindowClosed, 500);
103
- },
104
- createCheckout: function createCheckout(_ref2) {
105
- var _this2 = this;
106
-
107
- var paymentRequestUrl = _ref2.paymentRequestUrl;
108
- if (!paymentRequestUrl || !window) return;
109
- var env = this.env;
110
- var onSuccess = this.onSuccess;
111
- var onFailure = this.onFailure;
112
- var onCancel = this.onCancel;
113
- var onClose = this.onClose; ////////////////////////////////////////////////////////////
114
-
115
- var checkWindowClosed = function checkWindowClosed() {
116
- if ((0, _get2["default"])(_windowReferenceObject, 'closed')) {
117
- clearInterval(timer);
118
- handleClose();
119
- }
120
- }; // Check the window every 0.5 seconds to see if it has been closed.
121
-
122
-
123
- var timer = setInterval(checkWindowClosed, 500);
124
- this.isCheckoutInitiated = true; ////////////////////////////////////////////////////////////
125
-
126
- var openWindow = function openWindow() {
127
- // windowReferenceObject may not be defined if browser blocks the pop-up.
128
- if (!_windowReferenceObject) {
129
- _windowReferenceObject = (0, _initialiseWindow["default"])({
130
- url: paymentRequestUrl
131
- });
132
- } else {
133
- _windowReferenceObject.location.replace(paymentRequestUrl);
134
- }
135
-
136
- if (!_windowReferenceObject) {
137
- return;
138
- } // Start listening for incoming messages
139
-
140
-
141
- window.addEventListener('message', function (e) {
142
- return onReceiveMessage(e);
143
- });
144
-
145
- var onReceiveMessage = function onReceiveMessage(e) {
146
- if (!e) return;
147
- var transactionId = getMessage(e);
148
-
149
- if (transactionId) {
150
- _this2.isCheckoutComplete = true;
151
- }
152
- };
153
-
154
- var getMessage = function getMessage(e) {
155
- var origin = _constants.ORIGINS[env];
156
- if (!e || !origin) return; // Ensure the message is coming from the correct origin.
157
-
158
- if ((0, _get2["default"])(e, 'origin') !== origin) return;
159
- var event = (0, _get2["default"])(e, 'data.event');
160
- var transactionId = (0, _get2["default"])(e, 'data.transactionId');
161
- var receiptAutoSent = (0, _get2["default"])(e, 'data.receiptAutoSent');
162
- if (!event || !transactionId) return;
163
-
164
- if (event === _constants.EVENTS.SUCCESS) {
165
- if (receiptAutoSent) {
166
- // Give 1.5 seconds for the user to see the success page before auto-closing the pop-up.
167
- setTimeout(function () {
168
- onSuccess && onSuccess({
169
- transactionId: transactionId
170
- });
171
-
172
- _windowReferenceObject.close();
173
- }, 1500);
174
- } else {
175
- onSuccess && onSuccess({
176
- transactionId: transactionId
177
- });
178
- }
179
-
180
- return transactionId;
181
- }
182
-
183
- if (event === _constants.EVENTS.fAILURE) {
184
- onFailure && onFailure({
185
- transactionId: transactionId
186
- });
187
- return transactionId;
188
- }
189
-
190
- if (event === _constants.EVENTS.CANCEL) {
191
- // Give 1.5 seconds for the user to see the reject page before auto-closing the pop-up.
192
- setTimeout(function () {
193
- onCancel && onCancel({
194
- transactionId: transactionId
195
- });
196
-
197
- _windowReferenceObject.close();
198
- }, 1500);
199
- return transactionId;
200
- }
201
- };
202
-
203
- return _windowReferenceObject;
204
- }; ////////////////////////////////////////////////////////////
205
- // open the pop-up
206
-
207
-
208
- openWindow(); ////////////////////////////////////////////////////////////
209
-
210
- var handleClose = function handleClose() {
211
- // We need to remove the gray overlay covering the client's screen.
212
- _overlay["default"].removeOverlay(); // If the pop-up has been closed before a payment action has been taken out, then we
213
- // need to invoke the onClose callback.
214
-
215
-
216
- if (!_this2.isCheckoutComplete) {
217
- onClose && onClose();
218
- }
219
-
220
- if (!_windowReferenceObject) return;
221
-
222
- _windowReferenceObject.close();
223
- }; ////////////////////////////////////////////////////////////
224
-
225
-
226
- var onClickRelaunch = function onClickRelaunch() {
227
- if (!_windowReferenceObject) {
228
- _windowReferenceObject = openWindow();
229
- return;
230
- }
231
-
232
- _windowReferenceObject.focus();
233
- };
234
-
235
- var onClickCancel = function onClickCancel() {
236
- if (_windowReferenceObject) {
237
- _windowReferenceObject.close();
238
- } else {
239
- clearInterval(timer);
240
- }
241
-
242
- _overlay["default"].removeOverlay();
243
-
244
- onClose && onClose();
245
- }; // Reset the relaunch and cancel functions on the subheading
246
-
247
-
248
- _overlay["default"].updateSubheading({
249
- window: window,
250
- onClickRelaunch: onClickRelaunch,
251
- onClickCancel: onClickCancel
252
- }); ////////////////////////////////////////////////////////////
253
-
254
- },
255
- requestUpdatePaymentDetails: function requestUpdatePaymentDetails(_ref3) {
256
- var apiKey = _ref3.apiKey,
257
- token = _ref3.token,
258
- patientRefId = _ref3.patientRefId,
259
- env = _ref3.env,
260
- onSuccess = _ref3.onSuccess,
261
- onFailure = _ref3.onFailure,
262
- onCancel = _ref3.onCancel,
263
- onClose = _ref3.onClose,
264
- callbackOrigin = _ref3.callbackOrigin;
265
- (0, _requestUpdatePaymentDetails["default"])({
266
- apiKey: apiKey,
267
- token: token,
268
- patientRefId: patientRefId,
269
- env: env,
270
- onSuccess: onSuccess,
271
- onFailure: onFailure,
272
- onCancel: onCancel,
273
- onClose: onClose,
274
- callbackOrigin: callbackOrigin
275
- });
276
- }
277
- };
278
- var _default = checkoutSDK;
279
- exports["default"] = _default;
280
- module.exports = exports.default;
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports["default"] = void 0;
5
-
6
- var _get2 = _interopRequireDefault(require("lodash/get"));
7
-
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
9
-
10
- var POPUP_WIDTH = 450;
11
-
12
- var getWindowFeatures = function getWindowFeatures(_ref) {
13
- var height = _ref.height,
14
- width = _ref.width,
15
- left = _ref.left,
16
- top = _ref.top;
17
- return "menubar=no, location=no, resizable=no, scrollbars=yes, status=no, height=" + height + ", width=" + width + ", left=" + left + ", top=" + top;
18
- };
19
-
20
- function initialiseWindow(_ref2) {
21
- var url = _ref2.url;
22
- if (!window) return; // The target window could either be in an iframe, or just a normal standalone window.
23
- // We need to grab the correct window height and width for calculating dimensions.
24
-
25
- var windowHeight = (0, _get2["default"])(window, 'outerHeight') || (0, _get2["default"])(window, 'innerHeight');
26
- var windowWidth = (0, _get2["default"])(window, 'outerWidth') || (0, _get2["default"])(window, 'innerWidth');
27
- var popupHeight = windowHeight * 0.80;
28
- var popupWidth = windowWidth > POPUP_WIDTH ? POPUP_WIDTH : windowWidth * 0.25;
29
- var xPosition = windowWidth / 2 - popupWidth / 2;
30
- var yPosition = windowHeight / 2 - popupHeight / 2;
31
- var windowRef = window.open(url, 'Medipass Checkout', getWindowFeatures({
32
- height: popupHeight,
33
- width: popupWidth,
34
- left: xPosition,
35
- top: yPosition
36
- }));
37
- return windowRef;
38
- }
39
-
40
- var _default = initialiseWindow;
41
- exports["default"] = _default;
42
- module.exports = exports.default;
package/lib/overlay.js DELETED
@@ -1,196 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports["default"] = void 0;
5
-
6
- var _constants = require("./constants");
7
-
8
- var _objectToCss = _interopRequireDefault(require("./utils/object-to-css"));
9
-
10
- var _get2 = _interopRequireDefault(require("lodash/get"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- var SUBHEADING_ELEMENT_ID = 'medipass-checkout-sdk-subheading';
15
-
16
- function createElement(_ref) {
17
- var window = _ref.window,
18
- element = _ref.element,
19
- text = _ref.text,
20
- id = _ref.id,
21
- styles = _ref.styles,
22
- onClick = _ref.onClick;
23
- if (!window) return;
24
- var newElement = window.document.createElement(element);
25
-
26
- if (text) {
27
- newElement.innerHTML = text;
28
- }
29
-
30
- if (id) {
31
- newElement.id = id;
32
- }
33
-
34
- if (styles) {
35
- newElement.style.cssText = (0, _objectToCss["default"])(styles);
36
- }
37
-
38
- if ((0, _get2["default"])(newElement, 'addEventListener') && onClick) {
39
- newElement.addEventListener('click', function () {
40
- onClick();
41
- });
42
- }
43
-
44
- return newElement;
45
- }
46
-
47
- var overlay = {
48
- contentElement: null,
49
- removeOverlay: function removeOverlay() {
50
- var containerDiv = document.getElementById(_constants.ROOT_ELEMENT_ID);
51
- if (!containerDiv) return;
52
- containerDiv.remove();
53
- },
54
- createOverlay: function createOverlay(_ref2) {
55
- var window = _ref2.window,
56
- onClickRelaunch = _ref2.onClickRelaunch,
57
- onClickCancel = _ref2.onClickCancel;
58
- if (!window) return;
59
- var containerDiv = createElement({
60
- window: window,
61
- element: 'div',
62
- id: _constants.ROOT_ELEMENT_ID,
63
- styles: {
64
- 'z-index': '2147483100',
65
- position: 'fixed',
66
- top: '0',
67
- left: '0',
68
- width: '100%',
69
- height: '100%',
70
- 'background-color': 'rgba(0, 0, 0, 0.8)',
71
- 'font-family': 'Lato',
72
- color: 'white',
73
- display: 'flex'
74
- }
75
- });
76
- var content = createElement({
77
- window: window,
78
- element: 'div',
79
- styles: {
80
- 'max-width': '360px',
81
- 'margin-left': 'auto',
82
- 'margin-right': 'auto',
83
- 'margin-top': 'auto',
84
- 'margin-bottom': 'auto',
85
- 'text-align': 'center'
86
- }
87
- });
88
- this.contentElement = content; ////////////////////////////////////////////////////////////
89
-
90
- var heading = createElement({
91
- window: window,
92
- element: 'div',
93
- text: 'Secure Medipass payment in progress',
94
- styles: {
95
- color: 'white',
96
- 'font-size': '35px',
97
- 'font-weight': '600',
98
- 'margin-bottom': '30px'
99
- }
100
- }); ////////////////////////////////////////////////////////////
101
-
102
- var subHeading = this.createSubHeading({
103
- window: window,
104
- onClickRelaunch: onClickRelaunch,
105
- onClickCancel: onClickCancel
106
- }); ////////////////////////////////////////////////////////////
107
-
108
- content.appendChild(heading);
109
- content.appendChild(subHeading);
110
- containerDiv.appendChild(content); ////////////////////////////////////////////////////////////
111
-
112
- window.document.body.appendChild(containerDiv);
113
- },
114
- createSubHeading: function createSubHeading(_ref3) {
115
- var window = _ref3.window,
116
- onClickRelaunch = _ref3.onClickRelaunch,
117
- onClickCancel = _ref3.onClickCancel;
118
- if (!window) return;
119
- var subHeadingContainer = createElement({
120
- window: window,
121
- id: SUBHEADING_ELEMENT_ID,
122
- element: 'div'
123
- });
124
- var subHeading1 = createElement({
125
- window: window,
126
- element: 'div',
127
- text: 'Don\'t see the payment window?'
128
- });
129
- var link1 = createElement({
130
- window: window,
131
- element: 'a',
132
- text: 'Click here',
133
- onClick: onClickRelaunch,
134
- styles: {
135
- 'text-decoration': 'underline',
136
- cursor: 'pointer',
137
- 'font-weight': '600'
138
- }
139
- });
140
- var subHeading2 = createElement({
141
- window: window,
142
- element: 'span',
143
- text: ' to relaunch and complete your payment.'
144
- });
145
- var subHeading3 = createElement({
146
- window: window,
147
- element: 'div',
148
- text: 'OR',
149
- styles: {
150
- 'margin-top': '20px',
151
- 'margin-bottom': '20px'
152
- }
153
- });
154
- var link2 = createElement({
155
- window: window,
156
- element: 'a',
157
- text: 'Click here to cancel the payment.',
158
- onClick: onClickCancel,
159
- styles: {
160
- 'text-decoration': 'underline',
161
- cursor: 'pointer',
162
- 'font-weight': '600'
163
- }
164
- });
165
- subHeadingContainer.appendChild(subHeading1);
166
- subHeadingContainer.appendChild(link1);
167
- subHeadingContainer.appendChild(subHeading2);
168
- subHeadingContainer.appendChild(subHeading3);
169
- subHeadingContainer.appendChild(link2);
170
- return subHeadingContainer;
171
- },
172
- updateSubheading: function updateSubheading(_ref4) {
173
- var window = _ref4.window,
174
- onClickRelaunch = _ref4.onClickRelaunch,
175
- onClickCancel = _ref4.onClickCancel;
176
- if (!window) return;
177
- var subheaderElement = document.getElementById(SUBHEADING_ELEMENT_ID);
178
-
179
- if (subheaderElement) {
180
- subheaderElement.remove();
181
- }
182
-
183
- var newSubheading = this.createSubHeading({
184
- window: window,
185
- onClickRelaunch: onClickRelaunch,
186
- onClickCancel: onClickCancel
187
- });
188
-
189
- if (this.contentElement && (0, _get2["default"])(this.contentElement, 'appendChild')) {
190
- this.contentElement.appendChild(newSubheading);
191
- }
192
- }
193
- };
194
- var _default = overlay;
195
- exports["default"] = _default;
196
- module.exports = exports.default;