@medipass/checkout-sdk 2.1.0 → 3.0.0-alpha.1

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.
Files changed (58) hide show
  1. package/.eslintrc +40 -0
  2. package/CONTRIBUTING.md +21 -0
  3. package/{lib/style.css → dist/cjs/assets/index-e17dd0fd.css} +1 -1
  4. package/dist/cjs/constants.d.ts +27 -0
  5. package/dist/cjs/index.d.ts +32 -0
  6. package/dist/cjs/index.js +9 -0
  7. package/dist/cjs/initialiseWindow.d.ts +4 -0
  8. package/dist/cjs/overlay.d.ts +21 -0
  9. package/dist/cjs/requestUpdatePaymentDetails.d.ts +21 -0
  10. package/dist/cjs/updatePaymentOverlay.d.ts +21 -0
  11. package/dist/cjs/utils/object-to-css.d.ts +2 -0
  12. package/dist/esm/assets/index-e17dd0fd.css +1 -0
  13. package/dist/esm/constants.d.ts +27 -0
  14. package/dist/esm/index.d.ts +32 -0
  15. package/dist/esm/index.js +9 -0
  16. package/dist/esm/initialiseWindow.d.ts +4 -0
  17. package/dist/esm/overlay.d.ts +21 -0
  18. package/dist/esm/requestUpdatePaymentDetails.d.ts +21 -0
  19. package/dist/esm/updatePaymentOverlay.d.ts +21 -0
  20. package/dist/esm/utils/object-to-css.d.ts +2 -0
  21. package/dist/umd/assets/index.min-e17dd0fd.css +1 -0
  22. package/dist/umd/constants.d.ts +27 -0
  23. package/dist/umd/index.d.ts +32 -0
  24. package/dist/umd/index.min.js +17 -0
  25. package/dist/umd/initialiseWindow.d.ts +4 -0
  26. package/dist/umd/overlay.d.ts +21 -0
  27. package/dist/umd/requestUpdatePaymentDetails.d.ts +21 -0
  28. package/dist/umd/updatePaymentOverlay.d.ts +21 -0
  29. package/dist/umd/utils/object-to-css.d.ts +2 -0
  30. package/package.json +33 -15
  31. package/rollup.config.mjs +35 -0
  32. package/src/constants.ts +31 -0
  33. package/src/index.ts +244 -0
  34. package/src/initialiseWindow.ts +46 -0
  35. package/src/overlay.ts +272 -0
  36. package/src/requestUpdatePaymentDetails.ts +190 -0
  37. package/{es → src}/style.css +1 -1
  38. package/src/updatePaymentOverlay.ts +247 -0
  39. package/{es/utils/object-to-css.js → src/utils/object-to-css.ts} +4 -2
  40. package/tsconfig.json +32 -0
  41. package/es/constants.js +0 -23
  42. package/es/index.js +0 -264
  43. package/es/initialiseWindow.js +0 -34
  44. package/es/overlay.js +0 -184
  45. package/es/requestUpdatePaymentDetails.js +0 -232
  46. package/es/updatePaymentOverlay.js +0 -184
  47. package/lib/constants.js +0 -33
  48. package/lib/index.js +0 -280
  49. package/lib/initialiseWindow.js +0 -42
  50. package/lib/overlay.js +0 -196
  51. package/lib/requestUpdatePaymentDetails.js +0 -244
  52. package/lib/updatePaymentOverlay.js +0 -196
  53. package/lib/utils/object-to-css.js +0 -11
  54. package/umd/checkout-sdk.js +0 -50414
  55. package/umd/checkout-sdk.min.js +0 -31
  56. package/umd/checkout-sdk.min.js.map +0 -1
  57. package/umd/main.3a4213e0.css +0 -2
  58. package/umd/main.3a4213e0.css.map +0 -1
@@ -1,3 +1,5 @@
1
- export default (function (style) {
1
+ const toCss = (style: Record<string, string>) => {
2
2
  return JSON.stringify(style, null, '\t').replace(/"/g, '').replace(/,\n/g, ';').replace(/\}/g, '').replace(/\{/g, '');
3
- });
3
+ };
4
+
5
+ export default toCss;
package/tsconfig.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "useDefineForClassFields": true,
5
+ "lib": ["ESNext", "DOM", "DOM.Iterable"],
6
+ "module": "ESNext",
7
+ "skipLibCheck": true,
8
+ "allowJs": true,
9
+ "esModuleInterop": true,
10
+ "baseUrl": "src",
11
+ "declaration": true,
12
+ "sourceMap": false,
13
+ "rootDir": "./src",
14
+
15
+ /* Bundler mode */
16
+ "moduleResolution": "Node",
17
+ "resolveJsonModule": true,
18
+ "isolatedModules": true,
19
+ "jsx": "react",
20
+ "outDir": "./dist",
21
+ "allowSyntheticDefaultImports": true,
22
+
23
+ /* Linting */
24
+ "strict": true,
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noFallthroughCasesInSwitch": true,
28
+
29
+ "typeRoots" : ["node_modules/@types", "types"],
30
+ },
31
+ "include": ["src", "types"]
32
+ }
package/es/constants.js DELETED
@@ -1,23 +0,0 @@
1
- var _ORIGINS;
2
-
3
- export var ENVS = {
4
- LOCAL: 'local',
5
- DEV: 'dev',
6
- STG: 'stg',
7
- PROD_BLUE: 'prod-blue',
8
- PROD: 'prod'
9
- };
10
- export 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);
11
- export var EVENTS = {
12
- SUCCESS: 'success',
13
- fAILURE: 'failure',
14
- CANCEL: 'cancel'
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
- };
23
- export var ROOT_ELEMENT_ID = 'medipass-checkout-sdk-root';
package/es/index.js DELETED
@@ -1,264 +0,0 @@
1
- import _get from 'lodash/get';
2
- import overlay from './overlay';
3
- import { ORIGINS, ENVS, EVENTS } from './constants';
4
- import './style.css';
5
- import initialiseWindow from './initialiseWindow';
6
- import updatePaymentDetails from './requestUpdatePaymentDetails'; ////////////////////////////////////////////////////////////
7
-
8
- var _windowReferenceObject = null; ////////////////////////////////////////////////////////////
9
-
10
- var checkoutSDK = {
11
- ENVS: ENVS,
12
- isCheckoutInitiated: false,
13
- isCheckoutComplete: null,
14
- env: null,
15
- onSuccess: null,
16
- onFailure: null,
17
- onCancel: null,
18
- onCose: null,
19
- init: function init(_ref) {
20
- var _this = this;
21
-
22
- var env = _ref.env,
23
- onSuccess = _ref.onSuccess,
24
- onFailure = _ref.onFailure,
25
- onCancel = _ref.onCancel,
26
- onClose = _ref.onClose;
27
- if (!env) return;
28
- this.env = env;
29
- this.onSuccess = onSuccess;
30
- this.onFailure = onFailure;
31
- this.onCancel = onCancel;
32
- this.onClose = onClose; // Open a blank window
33
-
34
- _windowReferenceObject = initialiseWindow({
35
- url: ''
36
- });
37
-
38
- var handleClose = function handleClose() {
39
- overlay.removeOverlay();
40
- onClose && onClose();
41
- if (!_windowReferenceObject) return;
42
-
43
- _windowReferenceObject.close();
44
- };
45
-
46
- var onClickRelaunch = function onClickRelaunch() {
47
- if (!_windowReferenceObject) {
48
- _windowReferenceObject = initialiseWindow({
49
- url: ''
50
- });
51
- return;
52
- }
53
-
54
- _windowReferenceObject.focus();
55
- };
56
-
57
- var checkWindowClosed = function checkWindowClosed() {
58
- if (_this.isCheckoutInitiated) {
59
- clearInterval(timer);
60
- return;
61
- }
62
-
63
- if (_get(_windowReferenceObject, 'closed')) {
64
- clearInterval(timer);
65
- handleClose();
66
- }
67
- };
68
-
69
- var onClickCancel = function onClickCancel() {
70
- overlay.removeOverlay();
71
-
72
- if (_windowReferenceObject) {
73
- _windowReferenceObject.close();
74
- }
75
-
76
- clearInterval(timer);
77
- onClose && onClose();
78
- }; // This creates the gray overlay covering the client's screen while payment is in progress.
79
-
80
-
81
- overlay.createOverlay({
82
- window: window,
83
- onClickRelaunch: onClickRelaunch,
84
- onClickCancel: onClickCancel
85
- }); // Check the window every 0.5 seconds to see if it has been closed.
86
-
87
- var timer = setInterval(checkWindowClosed, 500);
88
- },
89
- createCheckout: function createCheckout(_ref2) {
90
- var _this2 = this;
91
-
92
- var paymentRequestUrl = _ref2.paymentRequestUrl;
93
- if (!paymentRequestUrl || !window) return;
94
- var env = this.env;
95
- var onSuccess = this.onSuccess;
96
- var onFailure = this.onFailure;
97
- var onCancel = this.onCancel;
98
- var onClose = this.onClose; ////////////////////////////////////////////////////////////
99
-
100
- var checkWindowClosed = function checkWindowClosed() {
101
- if (_get(_windowReferenceObject, 'closed')) {
102
- clearInterval(timer);
103
- handleClose();
104
- }
105
- }; // Check the window every 0.5 seconds to see if it has been closed.
106
-
107
-
108
- var timer = setInterval(checkWindowClosed, 500);
109
- this.isCheckoutInitiated = true; ////////////////////////////////////////////////////////////
110
-
111
- var openWindow = function openWindow() {
112
- // windowReferenceObject may not be defined if browser blocks the pop-up.
113
- if (!_windowReferenceObject) {
114
- _windowReferenceObject = initialiseWindow({
115
- url: paymentRequestUrl
116
- });
117
- } else {
118
- _windowReferenceObject.location.replace(paymentRequestUrl);
119
- }
120
-
121
- if (!_windowReferenceObject) {
122
- return;
123
- } // Start listening for incoming messages
124
-
125
-
126
- window.addEventListener('message', function (e) {
127
- return onReceiveMessage(e);
128
- });
129
-
130
- var onReceiveMessage = function onReceiveMessage(e) {
131
- if (!e) return;
132
- var transactionId = getMessage(e);
133
-
134
- if (transactionId) {
135
- _this2.isCheckoutComplete = true;
136
- }
137
- };
138
-
139
- var getMessage = function getMessage(e) {
140
- var origin = ORIGINS[env];
141
- if (!e || !origin) return; // Ensure the message is coming from the correct origin.
142
-
143
- if (_get(e, 'origin') !== origin) return;
144
-
145
- var event = _get(e, 'data.event');
146
-
147
- var transactionId = _get(e, 'data.transactionId');
148
-
149
- var receiptAutoSent = _get(e, 'data.receiptAutoSent');
150
-
151
- if (!event || !transactionId) return;
152
-
153
- if (event === EVENTS.SUCCESS) {
154
- if (receiptAutoSent) {
155
- // Give 1.5 seconds for the user to see the success page before auto-closing the pop-up.
156
- setTimeout(function () {
157
- onSuccess && onSuccess({
158
- transactionId: transactionId
159
- });
160
-
161
- _windowReferenceObject.close();
162
- }, 1500);
163
- } else {
164
- onSuccess && onSuccess({
165
- transactionId: transactionId
166
- });
167
- }
168
-
169
- return transactionId;
170
- }
171
-
172
- if (event === EVENTS.fAILURE) {
173
- onFailure && onFailure({
174
- transactionId: transactionId
175
- });
176
- return transactionId;
177
- }
178
-
179
- if (event === EVENTS.CANCEL) {
180
- // Give 1.5 seconds for the user to see the reject page before auto-closing the pop-up.
181
- setTimeout(function () {
182
- onCancel && onCancel({
183
- transactionId: transactionId
184
- });
185
-
186
- _windowReferenceObject.close();
187
- }, 1500);
188
- return transactionId;
189
- }
190
- };
191
-
192
- return _windowReferenceObject;
193
- }; ////////////////////////////////////////////////////////////
194
- // open the pop-up
195
-
196
-
197
- openWindow(); ////////////////////////////////////////////////////////////
198
-
199
- var handleClose = function handleClose() {
200
- // We need to remove the gray overlay covering the client's screen.
201
- overlay.removeOverlay(); // If the pop-up has been closed before a payment action has been taken out, then we
202
- // need to invoke the onClose callback.
203
-
204
- if (!_this2.isCheckoutComplete) {
205
- onClose && onClose();
206
- }
207
-
208
- if (!_windowReferenceObject) return;
209
-
210
- _windowReferenceObject.close();
211
- }; ////////////////////////////////////////////////////////////
212
-
213
-
214
- var onClickRelaunch = function onClickRelaunch() {
215
- if (!_windowReferenceObject) {
216
- _windowReferenceObject = openWindow();
217
- return;
218
- }
219
-
220
- _windowReferenceObject.focus();
221
- };
222
-
223
- var onClickCancel = function onClickCancel() {
224
- if (_windowReferenceObject) {
225
- _windowReferenceObject.close();
226
- } else {
227
- clearInterval(timer);
228
- }
229
-
230
- overlay.removeOverlay();
231
- onClose && onClose();
232
- }; // Reset the relaunch and cancel functions on the subheading
233
-
234
-
235
- overlay.updateSubheading({
236
- window: window,
237
- onClickRelaunch: onClickRelaunch,
238
- onClickCancel: onClickCancel
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
- });
262
- }
263
- };
264
- export default checkoutSDK;
@@ -1,34 +0,0 @@
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 DELETED
@@ -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: 'Secure Medipass payment 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 payment 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 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
- }
143
- });
144
- var link2 = createElement({
145
- window: window,
146
- element: 'a',
147
- text: 'Click here to cancel the payment.',
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;