@medipass/checkout-sdk 2.0.0 → 2.1.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/README.md +64 -3
- package/es/constants.js +7 -0
- package/es/index.js +32 -40
- package/es/initialiseWindow.js +34 -0
- package/es/overlay.js +12 -2
- package/es/requestUpdatePaymentDetails.js +232 -0
- package/es/updatePaymentOverlay.js +184 -0
- package/lib/constants.js +9 -1
- package/lib/index.js +37 -41
- package/lib/initialiseWindow.js +42 -0
- package/lib/overlay.js +12 -2
- package/lib/requestUpdatePaymentDetails.js +244 -0
- package/lib/updatePaymentOverlay.js +196 -0
- package/package.json +5 -2
- package/umd/checkout-sdk.js +49346 -1115
- package/umd/checkout-sdk.min.js +30 -2
- package/umd/checkout-sdk.min.js.map +1 -1
- package/umd/main.3a4213e0.css +1 -1
- package/umd/main.3a4213e0.css.map +1 -1
package/lib/constants.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.ROOT_ELEMENT_ID = exports.EVENTS = exports.ORIGINS = exports.ENVS = void 0;
|
|
4
|
+
exports.ROOT_ELEMENT_ID = exports.ERROR_MESSAGES = exports.EVENTS = exports.ORIGINS = exports.ENVS = void 0;
|
|
5
5
|
|
|
6
6
|
var _ORIGINS;
|
|
7
7
|
|
|
@@ -21,5 +21,13 @@ var EVENTS = {
|
|
|
21
21
|
CANCEL: 'cancel'
|
|
22
22
|
};
|
|
23
23
|
exports.EVENTS = EVENTS;
|
|
24
|
+
var ERROR_MESSAGES = {
|
|
25
|
+
NO_API_KEY_OR_NO_TOKEN: 'apiKey or token is not provided',
|
|
26
|
+
NO_PATIENT_REF_ID: 'patientRefId is not provided',
|
|
27
|
+
NO_ENVIROMENT_SET: 'environment must be set',
|
|
28
|
+
NO_CALLBACK_ORIGIN: 'callbackOrigin must be set',
|
|
29
|
+
GENERAL_ERROR: 'Please ensure that all required values are passed'
|
|
30
|
+
};
|
|
31
|
+
exports.ERROR_MESSAGES = ERROR_MESSAGES;
|
|
24
32
|
var ROOT_ELEMENT_ID = 'medipass-checkout-sdk-root';
|
|
25
33
|
exports.ROOT_ELEMENT_ID = ROOT_ELEMENT_ID;
|
package/lib/index.js
CHANGED
|
@@ -11,39 +11,13 @@ var _constants = require("./constants");
|
|
|
11
11
|
|
|
12
12
|
require("./style.css");
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
var POPUP_WIDTH = 450;
|
|
17
|
-
|
|
18
|
-
var getWindowFeatures = function getWindowFeatures(_ref) {
|
|
19
|
-
var height = _ref.height,
|
|
20
|
-
width = _ref.width,
|
|
21
|
-
left = _ref.left,
|
|
22
|
-
top = _ref.top;
|
|
23
|
-
return "menubar=no, location=no, resizable=no, scrollbars=yes, status=no, height=" + height + ", width=" + width + ", left=" + left + ", top=" + top;
|
|
24
|
-
};
|
|
14
|
+
var _initialiseWindow = _interopRequireDefault(require("./initialiseWindow"));
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
var url = _ref2.url;
|
|
28
|
-
if (!window) return; // The target window could either be in an iframe, or just a normal standalone window.
|
|
29
|
-
// We need to grab the correct window height and width for calculating dimensions.
|
|
30
|
-
|
|
31
|
-
var windowHeight = (0, _get2["default"])(window, 'outerHeight') || (0, _get2["default"])(window, 'innerHeight');
|
|
32
|
-
var windowWidth = (0, _get2["default"])(window, 'outerWidth') || (0, _get2["default"])(window, 'innerWidth');
|
|
33
|
-
var popupHeight = windowHeight * 0.80;
|
|
34
|
-
var popupWidth = windowWidth > POPUP_WIDTH ? POPUP_WIDTH : windowWidth * 0.25;
|
|
35
|
-
var xPosition = windowWidth / 2 - popupWidth / 2;
|
|
36
|
-
var yPosition = windowHeight / 2 - popupHeight / 2;
|
|
37
|
-
var windowRef = window.open(url, 'Medipass Checkout', getWindowFeatures({
|
|
38
|
-
height: popupHeight,
|
|
39
|
-
width: popupWidth,
|
|
40
|
-
left: xPosition,
|
|
41
|
-
top: yPosition
|
|
42
|
-
}));
|
|
43
|
-
return windowRef;
|
|
44
|
-
} ////////////////////////////////////////////////////////////
|
|
16
|
+
var _requestUpdatePaymentDetails = _interopRequireDefault(require("./requestUpdatePaymentDetails"));
|
|
45
17
|
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
46
19
|
|
|
20
|
+
////////////////////////////////////////////////////////////
|
|
47
21
|
var _windowReferenceObject = null; ////////////////////////////////////////////////////////////
|
|
48
22
|
|
|
49
23
|
var checkoutSDK = {
|
|
@@ -55,14 +29,14 @@ var checkoutSDK = {
|
|
|
55
29
|
onFailure: null,
|
|
56
30
|
onCancel: null,
|
|
57
31
|
onCose: null,
|
|
58
|
-
init: function init(
|
|
32
|
+
init: function init(_ref) {
|
|
59
33
|
var _this = this;
|
|
60
34
|
|
|
61
|
-
var env =
|
|
62
|
-
onSuccess =
|
|
63
|
-
onFailure =
|
|
64
|
-
onCancel =
|
|
65
|
-
onClose =
|
|
35
|
+
var env = _ref.env,
|
|
36
|
+
onSuccess = _ref.onSuccess,
|
|
37
|
+
onFailure = _ref.onFailure,
|
|
38
|
+
onCancel = _ref.onCancel,
|
|
39
|
+
onClose = _ref.onClose;
|
|
66
40
|
if (!env) return;
|
|
67
41
|
this.env = env;
|
|
68
42
|
this.onSuccess = onSuccess;
|
|
@@ -70,7 +44,7 @@ var checkoutSDK = {
|
|
|
70
44
|
this.onCancel = onCancel;
|
|
71
45
|
this.onClose = onClose; // Open a blank window
|
|
72
46
|
|
|
73
|
-
_windowReferenceObject =
|
|
47
|
+
_windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
74
48
|
url: ''
|
|
75
49
|
});
|
|
76
50
|
|
|
@@ -85,7 +59,7 @@ var checkoutSDK = {
|
|
|
85
59
|
|
|
86
60
|
var onClickRelaunch = function onClickRelaunch() {
|
|
87
61
|
if (!_windowReferenceObject) {
|
|
88
|
-
_windowReferenceObject =
|
|
62
|
+
_windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
89
63
|
url: ''
|
|
90
64
|
});
|
|
91
65
|
return;
|
|
@@ -127,10 +101,10 @@ var checkoutSDK = {
|
|
|
127
101
|
|
|
128
102
|
var timer = setInterval(checkWindowClosed, 500);
|
|
129
103
|
},
|
|
130
|
-
createCheckout: function createCheckout(
|
|
104
|
+
createCheckout: function createCheckout(_ref2) {
|
|
131
105
|
var _this2 = this;
|
|
132
106
|
|
|
133
|
-
var paymentRequestUrl =
|
|
107
|
+
var paymentRequestUrl = _ref2.paymentRequestUrl;
|
|
134
108
|
if (!paymentRequestUrl || !window) return;
|
|
135
109
|
var env = this.env;
|
|
136
110
|
var onSuccess = this.onSuccess;
|
|
@@ -152,7 +126,7 @@ var checkoutSDK = {
|
|
|
152
126
|
var openWindow = function openWindow() {
|
|
153
127
|
// windowReferenceObject may not be defined if browser blocks the pop-up.
|
|
154
128
|
if (!_windowReferenceObject) {
|
|
155
|
-
_windowReferenceObject =
|
|
129
|
+
_windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
156
130
|
url: paymentRequestUrl
|
|
157
131
|
});
|
|
158
132
|
} else {
|
|
@@ -277,6 +251,28 @@ var checkoutSDK = {
|
|
|
277
251
|
onClickCancel: onClickCancel
|
|
278
252
|
}); ////////////////////////////////////////////////////////////
|
|
279
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
|
+
});
|
|
280
276
|
}
|
|
281
277
|
};
|
|
282
278
|
var _default = checkoutSDK;
|
|
@@ -0,0 +1,42 @@
|
|
|
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
CHANGED
|
@@ -140,12 +140,21 @@ var overlay = {
|
|
|
140
140
|
var subHeading2 = createElement({
|
|
141
141
|
window: window,
|
|
142
142
|
element: 'span',
|
|
143
|
-
text: ' to relaunch and complete your
|
|
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
|
+
}
|
|
144
153
|
});
|
|
145
154
|
var link2 = createElement({
|
|
146
155
|
window: window,
|
|
147
156
|
element: 'a',
|
|
148
|
-
text: '
|
|
157
|
+
text: 'Click here to cancel the payment.',
|
|
149
158
|
onClick: onClickCancel,
|
|
150
159
|
styles: {
|
|
151
160
|
'text-decoration': 'underline',
|
|
@@ -156,6 +165,7 @@ var overlay = {
|
|
|
156
165
|
subHeadingContainer.appendChild(subHeading1);
|
|
157
166
|
subHeadingContainer.appendChild(link1);
|
|
158
167
|
subHeadingContainer.appendChild(subHeading2);
|
|
168
|
+
subHeadingContainer.appendChild(subHeading3);
|
|
159
169
|
subHeadingContainer.appendChild(link2);
|
|
160
170
|
return subHeadingContainer;
|
|
161
171
|
},
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports["default"] = void 0;
|
|
5
|
+
|
|
6
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
7
|
+
|
|
8
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
9
|
+
|
|
10
|
+
var _updatePaymentOverlay = _interopRequireDefault(require("./updatePaymentOverlay"));
|
|
11
|
+
|
|
12
|
+
var _constants = require("./constants");
|
|
13
|
+
|
|
14
|
+
var _webSdk = _interopRequireDefault(require("@medipass/web-sdk"));
|
|
15
|
+
|
|
16
|
+
var _initialiseWindow = _interopRequireDefault(require("./initialiseWindow"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
19
|
+
|
|
20
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
21
|
+
|
|
22
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
23
|
+
|
|
24
|
+
if (!_webSdk["default"].hasInit) {
|
|
25
|
+
_webSdk["default"].setup();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var updatePaymentDetails = /*#__PURE__*/function () {
|
|
29
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(_ref) {
|
|
30
|
+
var apiKey, token, patientRefId, env, onSuccess, onFailure, onCancel, onClose, callbackOrigin, isSessionComplete, sdkConfig, windowReferenceObject, handleClose, onClickRelaunch, checkWindowClosed, onClickCancel, timer, myBusinesses, myBusiness, myBusinessId, patient, patientId, requestPaymentMethodResponse, paymentMethodUpdateLink, openWindow;
|
|
31
|
+
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
32
|
+
while (1) {
|
|
33
|
+
switch (_context.prev = _context.next) {
|
|
34
|
+
case 0:
|
|
35
|
+
apiKey = _ref.apiKey, token = _ref.token, patientRefId = _ref.patientRefId, env = _ref.env, onSuccess = _ref.onSuccess, onFailure = _ref.onFailure, onCancel = _ref.onCancel, onClose = _ref.onClose, callbackOrigin = _ref.callbackOrigin;
|
|
36
|
+
|
|
37
|
+
if (!(!apiKey && !token)) {
|
|
38
|
+
_context.next = 3;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
throw new Error(_constants.ERROR_MESSAGES.NO_API_KEY_OR_NO_TOKEN);
|
|
43
|
+
|
|
44
|
+
case 3:
|
|
45
|
+
if (patientRefId) {
|
|
46
|
+
_context.next = 5;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
throw new Error(_constants.ERROR_MESSAGES.NO_PATIENT_REF_ID);
|
|
51
|
+
|
|
52
|
+
case 5:
|
|
53
|
+
if (env) {
|
|
54
|
+
_context.next = 7;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
throw new Error(_constants.ERROR_MESSAGES.NO_ENVIROMENT_SET);
|
|
59
|
+
|
|
60
|
+
case 7:
|
|
61
|
+
if (callbackOrigin) {
|
|
62
|
+
_context.next = 9;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
throw new Error(_constants.ERROR_MESSAGES.NO_CALLBACK_ORIGIN);
|
|
67
|
+
|
|
68
|
+
case 9:
|
|
69
|
+
isSessionComplete = false;
|
|
70
|
+
sdkConfig = {
|
|
71
|
+
env: env
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
if (env === _constants.ENVS.LOCAL) {
|
|
75
|
+
sdkConfig.env = _constants.ENVS.DEV;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (env === _constants.ENVS.STG) {
|
|
79
|
+
sdkConfig.env = 'staging';
|
|
80
|
+
} // Set Medipass web-sdk config
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
_webSdk["default"].setConfig(sdkConfig);
|
|
84
|
+
|
|
85
|
+
if (apiKey || token) {
|
|
86
|
+
_webSdk["default"].setToken("Bearer " + (apiKey || token));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
90
|
+
url: ''
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
handleClose = function handleClose() {
|
|
94
|
+
_updatePaymentOverlay["default"].removeOverlay();
|
|
95
|
+
|
|
96
|
+
if (!isSessionComplete) {
|
|
97
|
+
onClose && onClose();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!windowReferenceObject) return;
|
|
101
|
+
windowReferenceObject.close();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
onClickRelaunch = function onClickRelaunch() {
|
|
105
|
+
if (!windowReferenceObject) {
|
|
106
|
+
windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
107
|
+
url: ''
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
windowReferenceObject.focus();
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
checkWindowClosed = function checkWindowClosed() {
|
|
116
|
+
if ((0, _get2["default"])(windowReferenceObject, 'closed')) {
|
|
117
|
+
clearInterval(timer);
|
|
118
|
+
handleClose();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
onClickCancel = function onClickCancel() {
|
|
123
|
+
_updatePaymentOverlay["default"].removeOverlay();
|
|
124
|
+
|
|
125
|
+
if (windowReferenceObject) {
|
|
126
|
+
windowReferenceObject.close();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
clearInterval(timer);
|
|
130
|
+
onClose && onClose();
|
|
131
|
+
}; // This creates the gray overlay covering the client's screen while patient update their payment information.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
_updatePaymentOverlay["default"].createOverlay({
|
|
135
|
+
window: window,
|
|
136
|
+
onClickRelaunch: onClickRelaunch,
|
|
137
|
+
onClickCancel: onClickCancel
|
|
138
|
+
}); // Check the window every 0.5 seconds to see if it has been closed.
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
timer = setInterval(checkWindowClosed, 500);
|
|
142
|
+
_context.next = 24;
|
|
143
|
+
return _webSdk["default"].businesses.getMyBusinesses();
|
|
144
|
+
|
|
145
|
+
case 24:
|
|
146
|
+
myBusinesses = _context.sent;
|
|
147
|
+
myBusiness = myBusinesses.items[0];
|
|
148
|
+
myBusinessId = (0, _get2["default"])(myBusiness, '_id');
|
|
149
|
+
_context.next = 29;
|
|
150
|
+
return _webSdk["default"].patients.getBusinessPatientByRefId(myBusinessId, patientRefId);
|
|
151
|
+
|
|
152
|
+
case 29:
|
|
153
|
+
patient = _context.sent;
|
|
154
|
+
patientId = (0, _get2["default"])(patient, '_id');
|
|
155
|
+
_context.next = 33;
|
|
156
|
+
return _webSdk["default"].patients.requestUpdatePatientPaymentMethod(myBusinessId, patientId, {
|
|
157
|
+
sms: {
|
|
158
|
+
sendToPatientRecordMobile: false,
|
|
159
|
+
mobile: patient.mobile
|
|
160
|
+
},
|
|
161
|
+
callbackOrigin: callbackOrigin
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
case 33:
|
|
165
|
+
requestPaymentMethodResponse = _context.sent;
|
|
166
|
+
paymentMethodUpdateLink = (0, _get2["default"])(requestPaymentMethodResponse, 'paymentMethodUpdateLink');
|
|
167
|
+
|
|
168
|
+
openWindow = function openWindow() {
|
|
169
|
+
// windowReferenceObject may not be defined if browser blocks the pop-up.
|
|
170
|
+
if (!windowReferenceObject) {
|
|
171
|
+
windowReferenceObject = (0, _initialiseWindow["default"])({
|
|
172
|
+
url: paymentMethodUpdateLink
|
|
173
|
+
});
|
|
174
|
+
} else {
|
|
175
|
+
windowReferenceObject.location.replace(paymentMethodUpdateLink);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!windowReferenceObject) {
|
|
179
|
+
return;
|
|
180
|
+
} // Start listening for incoming messages
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
window.addEventListener('message', function (e) {
|
|
184
|
+
return onReceiveMessage(e);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
var onReceiveMessage = function onReceiveMessage(e) {
|
|
188
|
+
if (!e) return;
|
|
189
|
+
getMessage(e);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
var getMessage = function getMessage(e) {
|
|
193
|
+
var origin = _constants.ORIGINS[env];
|
|
194
|
+
if (!e || !origin) return; // Ensure the message is coming from the correct origin.
|
|
195
|
+
|
|
196
|
+
if ((0, _get2["default"])(e, 'origin') !== origin) return;
|
|
197
|
+
var event = (0, _get2["default"])(e, 'data.event');
|
|
198
|
+
if (!event) return;
|
|
199
|
+
|
|
200
|
+
if (event === _constants.EVENTS.SUCCESS) {
|
|
201
|
+
isSessionComplete = true; // Give 1.5 seconds for the user to see the success page before auto-closing the pop-up.
|
|
202
|
+
|
|
203
|
+
setTimeout(function () {
|
|
204
|
+
onSuccess && onSuccess();
|
|
205
|
+
windowReferenceObject.close();
|
|
206
|
+
}, 1500);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (event === _constants.EVENTS.fAILURE) {
|
|
210
|
+
isSessionComplete = true;
|
|
211
|
+
onFailure && onFailure();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (event === _constants.EVENTS.CANCEL) {
|
|
215
|
+
isSessionComplete = true; // Give 1.5 seconds for the user to see the reject page before auto-closing the pop-up.
|
|
216
|
+
|
|
217
|
+
setTimeout(function () {
|
|
218
|
+
onCancel && onCancel();
|
|
219
|
+
windowReferenceObject.close();
|
|
220
|
+
}, 1500);
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
return windowReferenceObject;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
openWindow();
|
|
228
|
+
|
|
229
|
+
case 37:
|
|
230
|
+
case "end":
|
|
231
|
+
return _context.stop();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}, _callee);
|
|
235
|
+
}));
|
|
236
|
+
|
|
237
|
+
return function updatePaymentDetails(_x) {
|
|
238
|
+
return _ref2.apply(this, arguments);
|
|
239
|
+
};
|
|
240
|
+
}();
|
|
241
|
+
|
|
242
|
+
var _default = updatePaymentDetails;
|
|
243
|
+
exports["default"] = _default;
|
|
244
|
+
module.exports = exports.default;
|
|
@@ -0,0 +1,196 @@
|
|
|
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: 'Updates to patient payment information are 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 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 updating patient payment details.'
|
|
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 this request.',
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medipass/checkout-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Describe medipass-checkout-sdk here",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
"test:coverage": "nwb test --coverage",
|
|
20
20
|
"test:watch": "nwb test --server"
|
|
21
21
|
},
|
|
22
|
-
"dependencies": {
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@medipass/utils": "11.69.2",
|
|
24
|
+
"@medipass/web-sdk": "11.43.0"
|
|
25
|
+
},
|
|
23
26
|
"devDependencies": {
|
|
24
27
|
"eslint": "5.10.0",
|
|
25
28
|
"eslint-plugin-react": "7.11.1",
|