idpay-b2b-sdk 0.0.14 → 0.0.16
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 +100 -0
- package/index.js +67 -1
- package/package.json +4 -3
- package/README.md +0 -11
package/index.cjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.IdpayB2bSdk = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _call(body, then, direct) {
|
|
8
|
+
if (direct) {
|
|
9
|
+
return then ? then(body()) : body();
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
var result = Promise.resolve(body());
|
|
13
|
+
return then ? result.then(then) : result;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return Promise.reject(e);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/* eslint-disable no-undef */
|
|
19
|
+
|
|
20
|
+
let _type;
|
|
21
|
+
function _invoke(body, then) {
|
|
22
|
+
var result = body();
|
|
23
|
+
if (result && result.then) {
|
|
24
|
+
return result.then(then);
|
|
25
|
+
}
|
|
26
|
+
return then(result);
|
|
27
|
+
}
|
|
28
|
+
let _initialized = false;
|
|
29
|
+
let _openWhileInitializing = false;
|
|
30
|
+
const TYPE__IFRAME = 'IFRAME';
|
|
31
|
+
const _createScript = () => {
|
|
32
|
+
const script = document.createElement('script');
|
|
33
|
+
script.src = 'https://idpay.unico.io/sdk-assets/index.js';
|
|
34
|
+
const prmScript = new Promise(resolve => {
|
|
35
|
+
script.onload = resolve;
|
|
36
|
+
});
|
|
37
|
+
document.body.appendChild(script);
|
|
38
|
+
return Promise.all([prmScript]);
|
|
39
|
+
};
|
|
40
|
+
const _createStyles = () => {
|
|
41
|
+
const style = document.createElement('link');
|
|
42
|
+
style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
|
|
43
|
+
style.setAttribute('rel', 'stylesheet');
|
|
44
|
+
const prmStyle = new Promise(resolve => {
|
|
45
|
+
style.onload = resolve;
|
|
46
|
+
});
|
|
47
|
+
document.head.appendChild(style);
|
|
48
|
+
return Promise.all([prmStyle]);
|
|
49
|
+
};
|
|
50
|
+
const init = function (options) {
|
|
51
|
+
return _call(_createScript, function () {
|
|
52
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
53
|
+
_type = options?.type;
|
|
54
|
+
return _invoke(function () {
|
|
55
|
+
if (_type === TYPE__IFRAME) {
|
|
56
|
+
return _call(_createStyles, function () {
|
|
57
|
+
IDPaySDKAssets.clientBoxControl.create();
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}, function () {
|
|
61
|
+
_initialized = true;
|
|
62
|
+
if (_openWhileInitializing) {
|
|
63
|
+
startPayFlow(_openWhileInitializing);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
const startPayFlow = ({
|
|
69
|
+
transactionId,
|
|
70
|
+
onFinish
|
|
71
|
+
}) => {
|
|
72
|
+
if (!_initialized) {
|
|
73
|
+
_openWhileInitializing = {
|
|
74
|
+
transactionId,
|
|
75
|
+
onFinish
|
|
76
|
+
};
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
|
|
80
|
+
transactionId
|
|
81
|
+
});
|
|
82
|
+
if (_type === TYPE__IFRAME) {
|
|
83
|
+
IDPaySDKAssets.clientBoxControl.open({
|
|
84
|
+
transactionId,
|
|
85
|
+
onFinish
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
IDPaySDKAssets.clientBoxControl.redirect(transactionId);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const IDPaySDK = {
|
|
92
|
+
init,
|
|
93
|
+
open: startPayFlow
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
exports.IDPaySDK = IDPaySDK;
|
|
97
|
+
|
|
98
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
99
|
+
|
|
100
|
+
}));
|
package/index.js
CHANGED
|
@@ -1 +1,67 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
|
|
3
|
+
let _type;
|
|
4
|
+
let _initialized = false;
|
|
5
|
+
let _openWhileInitializing = false;
|
|
6
|
+
const TYPE__IFRAME = 'IFRAME';
|
|
7
|
+
const _createScript = () => {
|
|
8
|
+
const script = document.createElement('script');
|
|
9
|
+
script.src = 'https://idpay.unico.io/sdk-assets/index.js';
|
|
10
|
+
const prmScript = new Promise(resolve => {
|
|
11
|
+
script.onload = resolve;
|
|
12
|
+
});
|
|
13
|
+
document.body.appendChild(script);
|
|
14
|
+
return Promise.all([prmScript]);
|
|
15
|
+
};
|
|
16
|
+
const _createStyles = () => {
|
|
17
|
+
const style = document.createElement('link');
|
|
18
|
+
style.setAttribute('href', 'https://idpay.unico.io/sdk-assets/assets/styles.css');
|
|
19
|
+
style.setAttribute('rel', 'stylesheet');
|
|
20
|
+
const prmStyle = new Promise(resolve => {
|
|
21
|
+
style.onload = resolve;
|
|
22
|
+
});
|
|
23
|
+
document.head.appendChild(style);
|
|
24
|
+
return Promise.all([prmStyle]);
|
|
25
|
+
};
|
|
26
|
+
const init = async options => {
|
|
27
|
+
await _createScript();
|
|
28
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
29
|
+
_type = options?.type;
|
|
30
|
+
if (_type === TYPE__IFRAME) {
|
|
31
|
+
await _createStyles();
|
|
32
|
+
IDPaySDKAssets.clientBoxControl.create();
|
|
33
|
+
}
|
|
34
|
+
_initialized = true;
|
|
35
|
+
if (_openWhileInitializing) {
|
|
36
|
+
startPayFlow(_openWhileInitializing);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const startPayFlow = ({
|
|
40
|
+
transactionId,
|
|
41
|
+
onFinish
|
|
42
|
+
}) => {
|
|
43
|
+
if (!_initialized) {
|
|
44
|
+
_openWhileInitializing = {
|
|
45
|
+
transactionId,
|
|
46
|
+
onFinish
|
|
47
|
+
};
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
|
|
51
|
+
transactionId
|
|
52
|
+
});
|
|
53
|
+
if (_type === TYPE__IFRAME) {
|
|
54
|
+
IDPaySDKAssets.clientBoxControl.open({
|
|
55
|
+
transactionId,
|
|
56
|
+
onFinish
|
|
57
|
+
});
|
|
58
|
+
} else {
|
|
59
|
+
IDPaySDKAssets.clientBoxControl.redirect(transactionId);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const IDPaySDK = {
|
|
63
|
+
init,
|
|
64
|
+
open: startPayFlow
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { IDPaySDK };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "idpay-b2b-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"publishConfig": {
|
|
11
11
|
"registry": "https://registry.npmjs.org"
|
|
12
12
|
},
|
|
13
|
-
"module": "index.js",
|
|
14
|
-
"main": "index.js"
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"main": "./index.js",
|
|
15
|
+
"types": "./src/index.d.ts"
|
|
15
16
|
}
|
package/README.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# idpay-b2b-sdk
|
|
2
|
-
|
|
3
|
-
This library was generated with [Nx](https://nx.dev).
|
|
4
|
-
|
|
5
|
-
## Building
|
|
6
|
-
|
|
7
|
-
Run `nx build idpay-b2b-sdk` to build the library.
|
|
8
|
-
|
|
9
|
-
## Running unit tests
|
|
10
|
-
|
|
11
|
-
Run `nx test idpay-b2b-sdk` to execute the unit tests via [Jest](https://jestjs.io).
|