idpay-b2b-sdk 0.0.16 → 0.0.18
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/index.cjs +39 -15
- package/index.js +20 -6
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -4,16 +4,14 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IdpayB2bSdk = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
function
|
|
7
|
+
function _await(value, then, direct) {
|
|
8
8
|
if (direct) {
|
|
9
|
-
return then ? then(
|
|
9
|
+
return then ? then(value) : value;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return then ? result.then(then) : result;
|
|
14
|
-
} catch (e) {
|
|
15
|
-
return Promise.reject(e);
|
|
11
|
+
if (!value || !value.then) {
|
|
12
|
+
value = Promise.resolve(value);
|
|
16
13
|
}
|
|
14
|
+
return then ? value.then(then) : value;
|
|
17
15
|
}
|
|
18
16
|
/* eslint-disable no-undef */
|
|
19
17
|
|
|
@@ -26,20 +24,36 @@
|
|
|
26
24
|
return then(result);
|
|
27
25
|
}
|
|
28
26
|
let _initialized = false;
|
|
27
|
+
function _async(f) {
|
|
28
|
+
return function () {
|
|
29
|
+
for (var args = [], i = 0; i < arguments.length; i++) {
|
|
30
|
+
args[i] = arguments[i];
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
return Promise.resolve(f.apply(this, args));
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return Promise.reject(e);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
29
39
|
let _openWhileInitializing = false;
|
|
30
40
|
const TYPE__IFRAME = 'IFRAME';
|
|
31
|
-
const _createScript = (
|
|
41
|
+
const _createScript = ({
|
|
42
|
+
host
|
|
43
|
+
}) => {
|
|
32
44
|
const script = document.createElement('script');
|
|
33
|
-
script.src =
|
|
45
|
+
script.src = `${host}/sdk-assets/index.js`;
|
|
34
46
|
const prmScript = new Promise(resolve => {
|
|
35
47
|
script.onload = resolve;
|
|
36
48
|
});
|
|
37
49
|
document.body.appendChild(script);
|
|
38
50
|
return Promise.all([prmScript]);
|
|
39
51
|
};
|
|
40
|
-
const _createStyles = (
|
|
52
|
+
const _createStyles = ({
|
|
53
|
+
host
|
|
54
|
+
}) => {
|
|
41
55
|
const style = document.createElement('link');
|
|
42
|
-
style.setAttribute('href',
|
|
56
|
+
style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
|
|
43
57
|
style.setAttribute('rel', 'stylesheet');
|
|
44
58
|
const prmStyle = new Promise(resolve => {
|
|
45
59
|
style.onload = resolve;
|
|
@@ -47,13 +61,19 @@
|
|
|
47
61
|
document.head.appendChild(style);
|
|
48
62
|
return Promise.all([prmStyle]);
|
|
49
63
|
};
|
|
50
|
-
const init = function (options) {
|
|
51
|
-
|
|
64
|
+
const init = _async(function (options) {
|
|
65
|
+
console.log('init', options);
|
|
66
|
+
const host = options?.useCurrentOrigin ? window.location.origin : 'https://idpay.unico.io';
|
|
67
|
+
return _await(_createScript({
|
|
68
|
+
host
|
|
69
|
+
}), function () {
|
|
52
70
|
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
53
71
|
_type = options?.type;
|
|
54
72
|
return _invoke(function () {
|
|
55
73
|
if (_type === TYPE__IFRAME) {
|
|
56
|
-
return
|
|
74
|
+
return _await(_createStyles({
|
|
75
|
+
host
|
|
76
|
+
}), function () {
|
|
57
77
|
IDPaySDKAssets.clientBoxControl.create();
|
|
58
78
|
});
|
|
59
79
|
}
|
|
@@ -64,11 +84,15 @@
|
|
|
64
84
|
}
|
|
65
85
|
});
|
|
66
86
|
});
|
|
67
|
-
};
|
|
87
|
+
});
|
|
68
88
|
const startPayFlow = ({
|
|
69
89
|
transactionId,
|
|
70
90
|
onFinish
|
|
71
91
|
}) => {
|
|
92
|
+
console.log('startPayFlow', {
|
|
93
|
+
transactionId,
|
|
94
|
+
onFinish
|
|
95
|
+
});
|
|
72
96
|
if (!_initialized) {
|
|
73
97
|
_openWhileInitializing = {
|
|
74
98
|
transactionId,
|
package/index.js
CHANGED
|
@@ -4,18 +4,22 @@ let _type;
|
|
|
4
4
|
let _initialized = false;
|
|
5
5
|
let _openWhileInitializing = false;
|
|
6
6
|
const TYPE__IFRAME = 'IFRAME';
|
|
7
|
-
const _createScript = (
|
|
7
|
+
const _createScript = ({
|
|
8
|
+
host
|
|
9
|
+
}) => {
|
|
8
10
|
const script = document.createElement('script');
|
|
9
|
-
script.src =
|
|
11
|
+
script.src = `${host}/sdk-assets/index.js`;
|
|
10
12
|
const prmScript = new Promise(resolve => {
|
|
11
13
|
script.onload = resolve;
|
|
12
14
|
});
|
|
13
15
|
document.body.appendChild(script);
|
|
14
16
|
return Promise.all([prmScript]);
|
|
15
17
|
};
|
|
16
|
-
const _createStyles = (
|
|
18
|
+
const _createStyles = ({
|
|
19
|
+
host
|
|
20
|
+
}) => {
|
|
17
21
|
const style = document.createElement('link');
|
|
18
|
-
style.setAttribute('href',
|
|
22
|
+
style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
|
|
19
23
|
style.setAttribute('rel', 'stylesheet');
|
|
20
24
|
const prmStyle = new Promise(resolve => {
|
|
21
25
|
style.onload = resolve;
|
|
@@ -24,11 +28,17 @@ const _createStyles = () => {
|
|
|
24
28
|
return Promise.all([prmStyle]);
|
|
25
29
|
};
|
|
26
30
|
const init = async options => {
|
|
27
|
-
|
|
31
|
+
console.log('init', options);
|
|
32
|
+
const host = options?.useCurrentOrigin ? window.location.origin : 'https://idpay.unico.io';
|
|
33
|
+
await _createScript({
|
|
34
|
+
host
|
|
35
|
+
});
|
|
28
36
|
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
29
37
|
_type = options?.type;
|
|
30
38
|
if (_type === TYPE__IFRAME) {
|
|
31
|
-
await _createStyles(
|
|
39
|
+
await _createStyles({
|
|
40
|
+
host
|
|
41
|
+
});
|
|
32
42
|
IDPaySDKAssets.clientBoxControl.create();
|
|
33
43
|
}
|
|
34
44
|
_initialized = true;
|
|
@@ -40,6 +50,10 @@ const startPayFlow = ({
|
|
|
40
50
|
transactionId,
|
|
41
51
|
onFinish
|
|
42
52
|
}) => {
|
|
53
|
+
console.log('startPayFlow', {
|
|
54
|
+
transactionId,
|
|
55
|
+
onFinish
|
|
56
|
+
});
|
|
43
57
|
if (!_initialized) {
|
|
44
58
|
_openWhileInitializing = {
|
|
45
59
|
transactionId,
|