@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.
@@ -1,232 +0,0 @@
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;
package/es/style.css DELETED
@@ -1 +0,0 @@
1
- @import url("https://fonts.googleapis.com/css?family=Lato:400,700");
@@ -1,184 +0,0 @@
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;
@@ -1,3 +0,0 @@
1
- export default (function (style) {
2
- return JSON.stringify(style, null, '\t').replace(/"/g, '').replace(/,\n/g, ';').replace(/\}/g, '').replace(/\{/g, '');
3
- });
package/lib/constants.js DELETED
@@ -1,33 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.ROOT_ELEMENT_ID = exports.ERROR_MESSAGES = exports.EVENTS = exports.ORIGINS = exports.ENVS = void 0;
5
-
6
- var _ORIGINS;
7
-
8
- var ENVS = {
9
- LOCAL: 'local',
10
- DEV: 'dev',
11
- STG: 'stg',
12
- PROD_BLUE: 'prod-blue',
13
- PROD: 'prod'
14
- };
15
- exports.ENVS = ENVS;
16
- var ORIGINS = (_ORIGINS = {}, _ORIGINS[ENVS.LOCAL] = 'http://localhost:3001', _ORIGINS[ENVS.DEV] = 'https://dev-my.medipass.io', _ORIGINS[ENVS.STG] = 'https://stg-my.medipass.io', _ORIGINS[ENVS.PROD_BLUE] = 'https://my-blue.medipass.io', _ORIGINS[ENVS.PROD] = 'https://my.medipass.io', _ORIGINS);
17
- exports.ORIGINS = ORIGINS;
18
- var EVENTS = {
19
- SUCCESS: 'success',
20
- fAILURE: 'failure',
21
- CANCEL: 'cancel'
22
- };
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;
32
- var ROOT_ELEMENT_ID = 'medipass-checkout-sdk-root';
33
- exports.ROOT_ELEMENT_ID = ROOT_ELEMENT_ID;