@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/README.md
CHANGED
|
@@ -7,8 +7,12 @@ The Medipass Checkout SDK is a client-side JavaScript library which allows you t
|
|
|
7
7
|
- [Medipass Checkout SDK](#medipass-checkout-sdk)
|
|
8
8
|
- [Table of Contents](#table-of-contents)
|
|
9
9
|
- [Install](#install)
|
|
10
|
-
- [
|
|
10
|
+
- [Create Checkout](#create-checkout)
|
|
11
|
+
- [Basic Usage](#basic-usage)
|
|
11
12
|
- [With a `<script>` tag](#with-a-script-tag)
|
|
13
|
+
- [Request To Update Patient Card Details](#request-to-update-patient-card-details)
|
|
14
|
+
- [Example](#example)
|
|
15
|
+
- [Using `<script>` tag](#using-script-tag)
|
|
12
16
|
- [API](#api)
|
|
13
17
|
- [sdk.init(config)](#sdkinitconfig)
|
|
14
18
|
- [config](#config)
|
|
@@ -27,7 +31,11 @@ or NPM:
|
|
|
27
31
|
npm install @medipass/checkout-sdk
|
|
28
32
|
```
|
|
29
33
|
|
|
30
|
-
##
|
|
34
|
+
## Create Checkout
|
|
35
|
+
|
|
36
|
+
A payment request URL is passed to the createCheckout function, which opens a secure pop-up window to Medipass to take the payment.
|
|
37
|
+
|
|
38
|
+
### Basic Usage
|
|
31
39
|
|
|
32
40
|
```jsx
|
|
33
41
|
import medipassCheckoutSDK from '@medipass/checkout-sdk';
|
|
@@ -51,7 +59,7 @@ medipassCheckoutSDK.init({
|
|
|
51
59
|
|
|
52
60
|
const paymentRequestUrl = getPaymentRequestUrl();
|
|
53
61
|
|
|
54
|
-
medipassCheckoutSDK.createCheckout({
|
|
62
|
+
await medipassCheckoutSDK.createCheckout({
|
|
55
63
|
paymentRequestUrl // the paymentRequestUrl returned after creating a Medipass invoice
|
|
56
64
|
});
|
|
57
65
|
|
|
@@ -92,6 +100,59 @@ medipassCheckoutSDK.createCheckout({
|
|
|
92
100
|
</html>
|
|
93
101
|
```
|
|
94
102
|
|
|
103
|
+
## Request To Update Patient Card Details
|
|
104
|
+
You can update a patient's payment details using the requestUpdatePaymentDetails function.
|
|
105
|
+
|
|
106
|
+
### Example
|
|
107
|
+
```jsx
|
|
108
|
+
import medipassCheckoutSDK from '@medipass/checkout-sdk';
|
|
109
|
+
// or: const medipassCheckoutSDK = require('@medipass/checkout-sdk');
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
await medipassCheckoutSDK.requestUpdatePaymentDetails({
|
|
113
|
+
apiKey, // apiKey | undefined
|
|
114
|
+
token, // token | undefined
|
|
115
|
+
patientRefId, // patientRefId
|
|
116
|
+
env, // 'stg' | 'prod'
|
|
117
|
+
onSuccess, // Invoked when the payment method update has been successful
|
|
118
|
+
onFailure, // Invoked when the payment method update has failed
|
|
119
|
+
onCancel, // Invoked when the payment method update has been rejected
|
|
120
|
+
onClose, // Invoked when the pop-up window has been closed by the user
|
|
121
|
+
callbackOrigin // The origin of the window invoking the checkout SDK
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Using `<script>` tag
|
|
127
|
+
|
|
128
|
+
```html
|
|
129
|
+
<html>
|
|
130
|
+
<head>
|
|
131
|
+
<script src="https://unpkg.com/@medipass/checkout-sdk/umd/@medipass/checkout-sdk.min.js"></script>
|
|
132
|
+
</head>
|
|
133
|
+
<body>
|
|
134
|
+
<script>
|
|
135
|
+
|
|
136
|
+
medipassCheckoutSDK.requestUpdatePaymentDetails({
|
|
137
|
+
apiKey, // apiKey | undefined
|
|
138
|
+
token, // token | undefined
|
|
139
|
+
patientRefId, // patientRefId
|
|
140
|
+
env, // 'stg' | 'prod'
|
|
141
|
+
onSuccess, // Invoked when the payment method update has been successful
|
|
142
|
+
onFailure, // Invoked when the payment method update has failed
|
|
143
|
+
onCancel, // Invoked when the payment method update has been rejected
|
|
144
|
+
onClose, // Invoked when the pop-up window has been closed by the user
|
|
145
|
+
callbackOrigin // The origin of the window invoking the checkout SDK
|
|
146
|
+
});
|
|
147
|
+
</script>
|
|
148
|
+
</body>
|
|
149
|
+
</html>
|
|
150
|
+
```
|
|
151
|
+
Take note of the following:
|
|
152
|
+
1. medipassCheckoutSDK.int() should not be called when using requestUpdatePaymentDetails
|
|
153
|
+
2. it is required that you pass either an apiKey or a token
|
|
154
|
+
|
|
155
|
+
|
|
95
156
|
## API
|
|
96
157
|
|
|
97
158
|
### sdk.init(config)
|
package/es/constants.js
CHANGED
|
@@ -13,4 +13,11 @@ export var EVENTS = {
|
|
|
13
13
|
fAILURE: 'failure',
|
|
14
14
|
CANCEL: 'cancel'
|
|
15
15
|
};
|
|
16
|
+
export var ERROR_MESSAGES = {
|
|
17
|
+
NO_API_KEY_OR_NO_TOKEN: 'apiKey or token is not provided',
|
|
18
|
+
NO_PATIENT_REF_ID: 'patientRefId is not provided',
|
|
19
|
+
NO_ENVIROMENT_SET: 'environment must be set',
|
|
20
|
+
NO_CALLBACK_ORIGIN: 'callbackOrigin must be set',
|
|
21
|
+
GENERAL_ERROR: 'Please ensure that all required values are passed'
|
|
22
|
+
};
|
|
16
23
|
export var ROOT_ELEMENT_ID = 'medipass-checkout-sdk-root';
|
package/es/index.js
CHANGED
|
@@ -2,38 +2,8 @@ import _get from 'lodash/get';
|
|
|
2
2
|
import overlay from './overlay';
|
|
3
3
|
import { ORIGINS, ENVS, EVENTS } from './constants';
|
|
4
4
|
import './style.css';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var getWindowFeatures = function getWindowFeatures(_ref) {
|
|
8
|
-
var height = _ref.height,
|
|
9
|
-
width = _ref.width,
|
|
10
|
-
left = _ref.left,
|
|
11
|
-
top = _ref.top;
|
|
12
|
-
return "menubar=no, location=no, resizable=no, scrollbars=yes, status=no, height=" + height + ", width=" + width + ", left=" + left + ", top=" + top;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
function initialiseWindow(_ref2) {
|
|
16
|
-
var url = _ref2.url;
|
|
17
|
-
if (!window) return; // The target window could either be in an iframe, or just a normal standalone window.
|
|
18
|
-
// We need to grab the correct window height and width for calculating dimensions.
|
|
19
|
-
|
|
20
|
-
var windowHeight = _get(window, 'outerHeight') || _get(window, 'innerHeight');
|
|
21
|
-
|
|
22
|
-
var windowWidth = _get(window, 'outerWidth') || _get(window, 'innerWidth');
|
|
23
|
-
|
|
24
|
-
var popupHeight = windowHeight * 0.80;
|
|
25
|
-
var popupWidth = windowWidth > POPUP_WIDTH ? POPUP_WIDTH : windowWidth * 0.25;
|
|
26
|
-
var xPosition = windowWidth / 2 - popupWidth / 2;
|
|
27
|
-
var yPosition = windowHeight / 2 - popupHeight / 2;
|
|
28
|
-
var windowRef = window.open(url, 'Medipass Checkout', getWindowFeatures({
|
|
29
|
-
height: popupHeight,
|
|
30
|
-
width: popupWidth,
|
|
31
|
-
left: xPosition,
|
|
32
|
-
top: yPosition
|
|
33
|
-
}));
|
|
34
|
-
return windowRef;
|
|
35
|
-
} ////////////////////////////////////////////////////////////
|
|
36
|
-
|
|
5
|
+
import initialiseWindow from './initialiseWindow';
|
|
6
|
+
import updatePaymentDetails from './requestUpdatePaymentDetails'; ////////////////////////////////////////////////////////////
|
|
37
7
|
|
|
38
8
|
var _windowReferenceObject = null; ////////////////////////////////////////////////////////////
|
|
39
9
|
|
|
@@ -46,14 +16,14 @@ var checkoutSDK = {
|
|
|
46
16
|
onFailure: null,
|
|
47
17
|
onCancel: null,
|
|
48
18
|
onCose: null,
|
|
49
|
-
init: function init(
|
|
19
|
+
init: function init(_ref) {
|
|
50
20
|
var _this = this;
|
|
51
21
|
|
|
52
|
-
var env =
|
|
53
|
-
onSuccess =
|
|
54
|
-
onFailure =
|
|
55
|
-
onCancel =
|
|
56
|
-
onClose =
|
|
22
|
+
var env = _ref.env,
|
|
23
|
+
onSuccess = _ref.onSuccess,
|
|
24
|
+
onFailure = _ref.onFailure,
|
|
25
|
+
onCancel = _ref.onCancel,
|
|
26
|
+
onClose = _ref.onClose;
|
|
57
27
|
if (!env) return;
|
|
58
28
|
this.env = env;
|
|
59
29
|
this.onSuccess = onSuccess;
|
|
@@ -116,10 +86,10 @@ var checkoutSDK = {
|
|
|
116
86
|
|
|
117
87
|
var timer = setInterval(checkWindowClosed, 500);
|
|
118
88
|
},
|
|
119
|
-
createCheckout: function createCheckout(
|
|
89
|
+
createCheckout: function createCheckout(_ref2) {
|
|
120
90
|
var _this2 = this;
|
|
121
91
|
|
|
122
|
-
var paymentRequestUrl =
|
|
92
|
+
var paymentRequestUrl = _ref2.paymentRequestUrl;
|
|
123
93
|
if (!paymentRequestUrl || !window) return;
|
|
124
94
|
var env = this.env;
|
|
125
95
|
var onSuccess = this.onSuccess;
|
|
@@ -267,6 +237,28 @@ var checkoutSDK = {
|
|
|
267
237
|
onClickRelaunch: onClickRelaunch,
|
|
268
238
|
onClickCancel: onClickCancel
|
|
269
239
|
}); ////////////////////////////////////////////////////////////
|
|
240
|
+
},
|
|
241
|
+
requestUpdatePaymentDetails: function requestUpdatePaymentDetails(_ref3) {
|
|
242
|
+
var apiKey = _ref3.apiKey,
|
|
243
|
+
token = _ref3.token,
|
|
244
|
+
patientRefId = _ref3.patientRefId,
|
|
245
|
+
env = _ref3.env,
|
|
246
|
+
onSuccess = _ref3.onSuccess,
|
|
247
|
+
onFailure = _ref3.onFailure,
|
|
248
|
+
onCancel = _ref3.onCancel,
|
|
249
|
+
onClose = _ref3.onClose,
|
|
250
|
+
callbackOrigin = _ref3.callbackOrigin;
|
|
251
|
+
updatePaymentDetails({
|
|
252
|
+
apiKey: apiKey,
|
|
253
|
+
token: token,
|
|
254
|
+
patientRefId: patientRefId,
|
|
255
|
+
env: env,
|
|
256
|
+
onSuccess: onSuccess,
|
|
257
|
+
onFailure: onFailure,
|
|
258
|
+
onCancel: onCancel,
|
|
259
|
+
onClose: onClose,
|
|
260
|
+
callbackOrigin: callbackOrigin
|
|
261
|
+
});
|
|
270
262
|
}
|
|
271
263
|
};
|
|
272
264
|
export default checkoutSDK;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _get from 'lodash/get';
|
|
2
|
+
var POPUP_WIDTH = 450;
|
|
3
|
+
|
|
4
|
+
var getWindowFeatures = function getWindowFeatures(_ref) {
|
|
5
|
+
var height = _ref.height,
|
|
6
|
+
width = _ref.width,
|
|
7
|
+
left = _ref.left,
|
|
8
|
+
top = _ref.top;
|
|
9
|
+
return "menubar=no, location=no, resizable=no, scrollbars=yes, status=no, height=" + height + ", width=" + width + ", left=" + left + ", top=" + top;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function initialiseWindow(_ref2) {
|
|
13
|
+
var url = _ref2.url;
|
|
14
|
+
if (!window) return; // The target window could either be in an iframe, or just a normal standalone window.
|
|
15
|
+
// We need to grab the correct window height and width for calculating dimensions.
|
|
16
|
+
|
|
17
|
+
var windowHeight = _get(window, 'outerHeight') || _get(window, 'innerHeight');
|
|
18
|
+
|
|
19
|
+
var windowWidth = _get(window, 'outerWidth') || _get(window, 'innerWidth');
|
|
20
|
+
|
|
21
|
+
var popupHeight = windowHeight * 0.80;
|
|
22
|
+
var popupWidth = windowWidth > POPUP_WIDTH ? POPUP_WIDTH : windowWidth * 0.25;
|
|
23
|
+
var xPosition = windowWidth / 2 - popupWidth / 2;
|
|
24
|
+
var yPosition = windowHeight / 2 - popupHeight / 2;
|
|
25
|
+
var windowRef = window.open(url, 'Medipass Checkout', getWindowFeatures({
|
|
26
|
+
height: popupHeight,
|
|
27
|
+
width: popupWidth,
|
|
28
|
+
left: xPosition,
|
|
29
|
+
top: yPosition
|
|
30
|
+
}));
|
|
31
|
+
return windowRef;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export default initialiseWindow;
|
package/es/overlay.js
CHANGED
|
@@ -130,12 +130,21 @@ var overlay = {
|
|
|
130
130
|
var subHeading2 = createElement({
|
|
131
131
|
window: window,
|
|
132
132
|
element: 'span',
|
|
133
|
-
text: ' to relaunch and complete your
|
|
133
|
+
text: ' to relaunch and complete your payment.'
|
|
134
|
+
});
|
|
135
|
+
var subHeading3 = createElement({
|
|
136
|
+
window: window,
|
|
137
|
+
element: 'div',
|
|
138
|
+
text: 'OR',
|
|
139
|
+
styles: {
|
|
140
|
+
'margin-top': '20px',
|
|
141
|
+
'margin-bottom': '20px'
|
|
142
|
+
}
|
|
134
143
|
});
|
|
135
144
|
var link2 = createElement({
|
|
136
145
|
window: window,
|
|
137
146
|
element: 'a',
|
|
138
|
-
text: '
|
|
147
|
+
text: 'Click here to cancel the payment.',
|
|
139
148
|
onClick: onClickCancel,
|
|
140
149
|
styles: {
|
|
141
150
|
'text-decoration': 'underline',
|
|
@@ -146,6 +155,7 @@ var overlay = {
|
|
|
146
155
|
subHeadingContainer.appendChild(subHeading1);
|
|
147
156
|
subHeadingContainer.appendChild(link1);
|
|
148
157
|
subHeadingContainer.appendChild(subHeading2);
|
|
158
|
+
subHeadingContainer.appendChild(subHeading3);
|
|
149
159
|
subHeadingContainer.appendChild(link2);
|
|
150
160
|
return subHeadingContainer;
|
|
151
161
|
},
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
|
+
|
|
3
|
+
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); } }
|
|
4
|
+
|
|
5
|
+
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); }); }; }
|
|
6
|
+
|
|
7
|
+
import _get from 'lodash/get';
|
|
8
|
+
import updatePaymentOverlay from './updatePaymentOverlay';
|
|
9
|
+
import { ENVS, EVENTS, ERROR_MESSAGES, ORIGINS } from './constants';
|
|
10
|
+
import coreSDK from '@medipass/web-sdk';
|
|
11
|
+
import initialiseWindow from './initialiseWindow';
|
|
12
|
+
|
|
13
|
+
if (!coreSDK.hasInit) {
|
|
14
|
+
coreSDK.setup();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var updatePaymentDetails = /*#__PURE__*/function () {
|
|
18
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
|
|
19
|
+
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;
|
|
20
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) {
|
|
22
|
+
switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
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;
|
|
25
|
+
|
|
26
|
+
if (!(!apiKey && !token)) {
|
|
27
|
+
_context.next = 3;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw new Error(ERROR_MESSAGES.NO_API_KEY_OR_NO_TOKEN);
|
|
32
|
+
|
|
33
|
+
case 3:
|
|
34
|
+
if (patientRefId) {
|
|
35
|
+
_context.next = 5;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
throw new Error(ERROR_MESSAGES.NO_PATIENT_REF_ID);
|
|
40
|
+
|
|
41
|
+
case 5:
|
|
42
|
+
if (env) {
|
|
43
|
+
_context.next = 7;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
throw new Error(ERROR_MESSAGES.NO_ENVIROMENT_SET);
|
|
48
|
+
|
|
49
|
+
case 7:
|
|
50
|
+
if (callbackOrigin) {
|
|
51
|
+
_context.next = 9;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
throw new Error(ERROR_MESSAGES.NO_CALLBACK_ORIGIN);
|
|
56
|
+
|
|
57
|
+
case 9:
|
|
58
|
+
isSessionComplete = false;
|
|
59
|
+
sdkConfig = {
|
|
60
|
+
env: env
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (env === ENVS.LOCAL) {
|
|
64
|
+
sdkConfig.env = ENVS.DEV;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (env === ENVS.STG) {
|
|
68
|
+
sdkConfig.env = 'staging';
|
|
69
|
+
} // Set Medipass web-sdk config
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
coreSDK.setConfig(sdkConfig);
|
|
73
|
+
|
|
74
|
+
if (apiKey || token) {
|
|
75
|
+
coreSDK.setToken("Bearer " + (apiKey || token));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
windowReferenceObject = initialiseWindow({
|
|
79
|
+
url: ''
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
handleClose = function handleClose() {
|
|
83
|
+
updatePaymentOverlay.removeOverlay();
|
|
84
|
+
|
|
85
|
+
if (!isSessionComplete) {
|
|
86
|
+
onClose && onClose();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!windowReferenceObject) return;
|
|
90
|
+
windowReferenceObject.close();
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
onClickRelaunch = function onClickRelaunch() {
|
|
94
|
+
if (!windowReferenceObject) {
|
|
95
|
+
windowReferenceObject = initialiseWindow({
|
|
96
|
+
url: ''
|
|
97
|
+
});
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
windowReferenceObject.focus();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
checkWindowClosed = function checkWindowClosed() {
|
|
105
|
+
if (_get(windowReferenceObject, 'closed')) {
|
|
106
|
+
clearInterval(timer);
|
|
107
|
+
handleClose();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
onClickCancel = function onClickCancel() {
|
|
112
|
+
updatePaymentOverlay.removeOverlay();
|
|
113
|
+
|
|
114
|
+
if (windowReferenceObject) {
|
|
115
|
+
windowReferenceObject.close();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
clearInterval(timer);
|
|
119
|
+
onClose && onClose();
|
|
120
|
+
}; // This creates the gray overlay covering the client's screen while patient update their payment information.
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
updatePaymentOverlay.createOverlay({
|
|
124
|
+
window: window,
|
|
125
|
+
onClickRelaunch: onClickRelaunch,
|
|
126
|
+
onClickCancel: onClickCancel
|
|
127
|
+
}); // Check the window every 0.5 seconds to see if it has been closed.
|
|
128
|
+
|
|
129
|
+
timer = setInterval(checkWindowClosed, 500);
|
|
130
|
+
_context.next = 24;
|
|
131
|
+
return coreSDK.businesses.getMyBusinesses();
|
|
132
|
+
|
|
133
|
+
case 24:
|
|
134
|
+
myBusinesses = _context.sent;
|
|
135
|
+
myBusiness = myBusinesses.items[0];
|
|
136
|
+
myBusinessId = _get(myBusiness, '_id');
|
|
137
|
+
_context.next = 29;
|
|
138
|
+
return coreSDK.patients.getBusinessPatientByRefId(myBusinessId, patientRefId);
|
|
139
|
+
|
|
140
|
+
case 29:
|
|
141
|
+
patient = _context.sent;
|
|
142
|
+
patientId = _get(patient, '_id');
|
|
143
|
+
_context.next = 33;
|
|
144
|
+
return coreSDK.patients.requestUpdatePatientPaymentMethod(myBusinessId, patientId, {
|
|
145
|
+
sms: {
|
|
146
|
+
sendToPatientRecordMobile: false,
|
|
147
|
+
mobile: patient.mobile
|
|
148
|
+
},
|
|
149
|
+
callbackOrigin: callbackOrigin
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
case 33:
|
|
153
|
+
requestPaymentMethodResponse = _context.sent;
|
|
154
|
+
paymentMethodUpdateLink = _get(requestPaymentMethodResponse, 'paymentMethodUpdateLink');
|
|
155
|
+
|
|
156
|
+
openWindow = function openWindow() {
|
|
157
|
+
// windowReferenceObject may not be defined if browser blocks the pop-up.
|
|
158
|
+
if (!windowReferenceObject) {
|
|
159
|
+
windowReferenceObject = initialiseWindow({
|
|
160
|
+
url: paymentMethodUpdateLink
|
|
161
|
+
});
|
|
162
|
+
} else {
|
|
163
|
+
windowReferenceObject.location.replace(paymentMethodUpdateLink);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (!windowReferenceObject) {
|
|
167
|
+
return;
|
|
168
|
+
} // Start listening for incoming messages
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
window.addEventListener('message', function (e) {
|
|
172
|
+
return onReceiveMessage(e);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
var onReceiveMessage = function onReceiveMessage(e) {
|
|
176
|
+
if (!e) return;
|
|
177
|
+
getMessage(e);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
var getMessage = function getMessage(e) {
|
|
181
|
+
var origin = ORIGINS[env];
|
|
182
|
+
if (!e || !origin) return; // Ensure the message is coming from the correct origin.
|
|
183
|
+
|
|
184
|
+
if (_get(e, 'origin') !== origin) return;
|
|
185
|
+
|
|
186
|
+
var event = _get(e, 'data.event');
|
|
187
|
+
|
|
188
|
+
if (!event) return;
|
|
189
|
+
|
|
190
|
+
if (event === EVENTS.SUCCESS) {
|
|
191
|
+
isSessionComplete = true; // Give 1.5 seconds for the user to see the success page before auto-closing the pop-up.
|
|
192
|
+
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
onSuccess && onSuccess();
|
|
195
|
+
windowReferenceObject.close();
|
|
196
|
+
}, 1500);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (event === EVENTS.fAILURE) {
|
|
200
|
+
isSessionComplete = true;
|
|
201
|
+
onFailure && onFailure();
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (event === EVENTS.CANCEL) {
|
|
205
|
+
isSessionComplete = true; // Give 1.5 seconds for the user to see the reject page before auto-closing the pop-up.
|
|
206
|
+
|
|
207
|
+
setTimeout(function () {
|
|
208
|
+
onCancel && onCancel();
|
|
209
|
+
windowReferenceObject.close();
|
|
210
|
+
}, 1500);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
return windowReferenceObject;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
openWindow();
|
|
218
|
+
|
|
219
|
+
case 37:
|
|
220
|
+
case "end":
|
|
221
|
+
return _context.stop();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, _callee);
|
|
225
|
+
}));
|
|
226
|
+
|
|
227
|
+
return function updatePaymentDetails(_x) {
|
|
228
|
+
return _ref2.apply(this, arguments);
|
|
229
|
+
};
|
|
230
|
+
}();
|
|
231
|
+
|
|
232
|
+
export default updatePaymentDetails;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { ROOT_ELEMENT_ID } from './constants';
|
|
2
|
+
import toCss from './utils/object-to-css';
|
|
3
|
+
import _get from 'lodash/get';
|
|
4
|
+
var SUBHEADING_ELEMENT_ID = 'medipass-checkout-sdk-subheading';
|
|
5
|
+
|
|
6
|
+
function createElement(_ref) {
|
|
7
|
+
var window = _ref.window,
|
|
8
|
+
element = _ref.element,
|
|
9
|
+
text = _ref.text,
|
|
10
|
+
id = _ref.id,
|
|
11
|
+
styles = _ref.styles,
|
|
12
|
+
onClick = _ref.onClick;
|
|
13
|
+
if (!window) return;
|
|
14
|
+
var newElement = window.document.createElement(element);
|
|
15
|
+
|
|
16
|
+
if (text) {
|
|
17
|
+
newElement.innerHTML = text;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (id) {
|
|
21
|
+
newElement.id = id;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (styles) {
|
|
25
|
+
newElement.style.cssText = toCss(styles);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (_get(newElement, 'addEventListener') && onClick) {
|
|
29
|
+
newElement.addEventListener('click', function () {
|
|
30
|
+
onClick();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return newElement;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var overlay = {
|
|
38
|
+
contentElement: null,
|
|
39
|
+
removeOverlay: function removeOverlay() {
|
|
40
|
+
var containerDiv = document.getElementById(ROOT_ELEMENT_ID);
|
|
41
|
+
if (!containerDiv) return;
|
|
42
|
+
containerDiv.remove();
|
|
43
|
+
},
|
|
44
|
+
createOverlay: function createOverlay(_ref2) {
|
|
45
|
+
var window = _ref2.window,
|
|
46
|
+
onClickRelaunch = _ref2.onClickRelaunch,
|
|
47
|
+
onClickCancel = _ref2.onClickCancel;
|
|
48
|
+
if (!window) return;
|
|
49
|
+
var containerDiv = createElement({
|
|
50
|
+
window: window,
|
|
51
|
+
element: 'div',
|
|
52
|
+
id: ROOT_ELEMENT_ID,
|
|
53
|
+
styles: {
|
|
54
|
+
'z-index': '2147483100',
|
|
55
|
+
position: 'fixed',
|
|
56
|
+
top: '0',
|
|
57
|
+
left: '0',
|
|
58
|
+
width: '100%',
|
|
59
|
+
height: '100%',
|
|
60
|
+
'background-color': 'rgba(0, 0, 0, 0.8)',
|
|
61
|
+
'font-family': 'Lato',
|
|
62
|
+
color: 'white',
|
|
63
|
+
display: 'flex'
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
var content = createElement({
|
|
67
|
+
window: window,
|
|
68
|
+
element: 'div',
|
|
69
|
+
styles: {
|
|
70
|
+
'max-width': '360px',
|
|
71
|
+
'margin-left': 'auto',
|
|
72
|
+
'margin-right': 'auto',
|
|
73
|
+
'margin-top': 'auto',
|
|
74
|
+
'margin-bottom': 'auto',
|
|
75
|
+
'text-align': 'center'
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
this.contentElement = content; ////////////////////////////////////////////////////////////
|
|
79
|
+
|
|
80
|
+
var heading = createElement({
|
|
81
|
+
window: window,
|
|
82
|
+
element: 'div',
|
|
83
|
+
text: 'Updates to patient payment information are in progress',
|
|
84
|
+
styles: {
|
|
85
|
+
color: 'white',
|
|
86
|
+
'font-size': '35px',
|
|
87
|
+
'font-weight': '600',
|
|
88
|
+
'margin-bottom': '30px'
|
|
89
|
+
}
|
|
90
|
+
}); ////////////////////////////////////////////////////////////
|
|
91
|
+
|
|
92
|
+
var subHeading = this.createSubHeading({
|
|
93
|
+
window: window,
|
|
94
|
+
onClickRelaunch: onClickRelaunch,
|
|
95
|
+
onClickCancel: onClickCancel
|
|
96
|
+
}); ////////////////////////////////////////////////////////////
|
|
97
|
+
|
|
98
|
+
content.appendChild(heading);
|
|
99
|
+
content.appendChild(subHeading);
|
|
100
|
+
containerDiv.appendChild(content); ////////////////////////////////////////////////////////////
|
|
101
|
+
|
|
102
|
+
window.document.body.appendChild(containerDiv);
|
|
103
|
+
},
|
|
104
|
+
createSubHeading: function createSubHeading(_ref3) {
|
|
105
|
+
var window = _ref3.window,
|
|
106
|
+
onClickRelaunch = _ref3.onClickRelaunch,
|
|
107
|
+
onClickCancel = _ref3.onClickCancel;
|
|
108
|
+
if (!window) return;
|
|
109
|
+
var subHeadingContainer = createElement({
|
|
110
|
+
window: window,
|
|
111
|
+
id: SUBHEADING_ELEMENT_ID,
|
|
112
|
+
element: 'div'
|
|
113
|
+
});
|
|
114
|
+
var subHeading1 = createElement({
|
|
115
|
+
window: window,
|
|
116
|
+
element: 'div',
|
|
117
|
+
text: 'Don\'t see the window?'
|
|
118
|
+
});
|
|
119
|
+
var link1 = createElement({
|
|
120
|
+
window: window,
|
|
121
|
+
element: 'a',
|
|
122
|
+
text: 'Click here',
|
|
123
|
+
onClick: onClickRelaunch,
|
|
124
|
+
styles: {
|
|
125
|
+
'text-decoration': 'underline',
|
|
126
|
+
cursor: 'pointer',
|
|
127
|
+
'font-weight': '600'
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
var subHeading2 = createElement({
|
|
131
|
+
window: window,
|
|
132
|
+
element: 'span',
|
|
133
|
+
text: ' to relaunch and complete updating patient payment details.'
|
|
134
|
+
});
|
|
135
|
+
var subHeading3 = createElement({
|
|
136
|
+
window: window,
|
|
137
|
+
element: 'div',
|
|
138
|
+
text: 'OR',
|
|
139
|
+
styles: {
|
|
140
|
+
'margin-top': '20px',
|
|
141
|
+
'margin-bottom': '20px'
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
var link2 = createElement({
|
|
145
|
+
window: window,
|
|
146
|
+
element: 'a',
|
|
147
|
+
text: 'Click here to cancel this request.',
|
|
148
|
+
onClick: onClickCancel,
|
|
149
|
+
styles: {
|
|
150
|
+
'text-decoration': 'underline',
|
|
151
|
+
cursor: 'pointer',
|
|
152
|
+
'font-weight': '600'
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
subHeadingContainer.appendChild(subHeading1);
|
|
156
|
+
subHeadingContainer.appendChild(link1);
|
|
157
|
+
subHeadingContainer.appendChild(subHeading2);
|
|
158
|
+
subHeadingContainer.appendChild(subHeading3);
|
|
159
|
+
subHeadingContainer.appendChild(link2);
|
|
160
|
+
return subHeadingContainer;
|
|
161
|
+
},
|
|
162
|
+
updateSubheading: function updateSubheading(_ref4) {
|
|
163
|
+
var window = _ref4.window,
|
|
164
|
+
onClickRelaunch = _ref4.onClickRelaunch,
|
|
165
|
+
onClickCancel = _ref4.onClickCancel;
|
|
166
|
+
if (!window) return;
|
|
167
|
+
var subheaderElement = document.getElementById(SUBHEADING_ELEMENT_ID);
|
|
168
|
+
|
|
169
|
+
if (subheaderElement) {
|
|
170
|
+
subheaderElement.remove();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var newSubheading = this.createSubHeading({
|
|
174
|
+
window: window,
|
|
175
|
+
onClickRelaunch: onClickRelaunch,
|
|
176
|
+
onClickCancel: onClickCancel
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (this.contentElement && _get(this.contentElement, 'appendChild')) {
|
|
180
|
+
this.contentElement.appendChild(newSubheading);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
export default overlay;
|