idpay-b2b-sdk 0.0.23 → 0.0.25
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 +117 -0
- package/index.js +13 -2
- package/index.umd.js +13 -2
- package/package.json +1 -1
package/index.cjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
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.IDPaySDK = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-undef */
|
|
8
|
+
|
|
9
|
+
let _type;
|
|
10
|
+
let _initialized = false;
|
|
11
|
+
let _openWhileInitializing = false;
|
|
12
|
+
let _collectionId;
|
|
13
|
+
const TYPE__IFRAME = 'IFRAME';
|
|
14
|
+
const TYPE_SILENT = 'SILENT';
|
|
15
|
+
const ENV_DEV = 'dev';
|
|
16
|
+
const ENV_UAT = 'uat';
|
|
17
|
+
const ENV_PROD = 'prod';
|
|
18
|
+
const _HOSTS = {
|
|
19
|
+
[ENV_DEV]: 'https://idpay-dev.unico.io',
|
|
20
|
+
[ENV_UAT]: 'https://idpay-uat.unico.io',
|
|
21
|
+
[ENV_PROD]: 'https://idpay.unico.io'
|
|
22
|
+
};
|
|
23
|
+
const _createScript = ({
|
|
24
|
+
host
|
|
25
|
+
}) => {
|
|
26
|
+
const script = document.createElement('script');
|
|
27
|
+
script.src = `${host}/sdk-assets/index.js`;
|
|
28
|
+
const prmScript = new Promise(resolve => {
|
|
29
|
+
script.onload = resolve;
|
|
30
|
+
});
|
|
31
|
+
document.body.appendChild(script);
|
|
32
|
+
return Promise.all([prmScript]);
|
|
33
|
+
};
|
|
34
|
+
const _createStyles = ({
|
|
35
|
+
host
|
|
36
|
+
}) => {
|
|
37
|
+
const style = document.createElement('link');
|
|
38
|
+
style.setAttribute('href', `${host}/sdk-assets/assets/styles.css`);
|
|
39
|
+
style.setAttribute('rel', 'stylesheet');
|
|
40
|
+
const prmStyle = new Promise(resolve => {
|
|
41
|
+
style.onload = resolve;
|
|
42
|
+
});
|
|
43
|
+
document.head.appendChild(style);
|
|
44
|
+
return Promise.all([prmStyle]);
|
|
45
|
+
};
|
|
46
|
+
const _getEnvHost = (env = ENV_PROD) => _HOSTS[env];
|
|
47
|
+
const init = async options => {
|
|
48
|
+
const token = options?.token;
|
|
49
|
+
const host = options?.useCurrentOrigin ? window.location.origin : _getEnvHost(options?.env);
|
|
50
|
+
await _createScript({
|
|
51
|
+
host
|
|
52
|
+
});
|
|
53
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
54
|
+
_type = options?.type;
|
|
55
|
+
if (_type === TYPE_SILENT) {
|
|
56
|
+
_collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
|
|
57
|
+
} else if (_type === TYPE__IFRAME) {
|
|
58
|
+
await _createStyles({
|
|
59
|
+
host
|
|
60
|
+
});
|
|
61
|
+
IDPaySDKAssets.clientBoxControl.create({
|
|
62
|
+
host,
|
|
63
|
+
token
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
_initialized = true;
|
|
67
|
+
if (_openWhileInitializing) {
|
|
68
|
+
startPayFlow(_openWhileInitializing);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const startPayFlow = ({
|
|
72
|
+
transactionId,
|
|
73
|
+
token,
|
|
74
|
+
onFinish
|
|
75
|
+
}) => {
|
|
76
|
+
console.log('startPayFlow', {
|
|
77
|
+
transactionId,
|
|
78
|
+
token,
|
|
79
|
+
onFinish
|
|
80
|
+
});
|
|
81
|
+
if (!_initialized) {
|
|
82
|
+
_openWhileInitializing = {
|
|
83
|
+
transactionId,
|
|
84
|
+
token,
|
|
85
|
+
onFinish
|
|
86
|
+
};
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.START_FLOW, {
|
|
90
|
+
transactionId,
|
|
91
|
+
token
|
|
92
|
+
});
|
|
93
|
+
if (_type === TYPE_SILENT) {
|
|
94
|
+
IDPaySDKAssets.clientBoxControl.verify({
|
|
95
|
+
transactionId,
|
|
96
|
+
token,
|
|
97
|
+
collectionId: _collectionId,
|
|
98
|
+
onFinish
|
|
99
|
+
});
|
|
100
|
+
} else if (_type === TYPE__IFRAME) {
|
|
101
|
+
IDPaySDKAssets.clientBoxControl.open({
|
|
102
|
+
transactionId,
|
|
103
|
+
token,
|
|
104
|
+
onFinish
|
|
105
|
+
});
|
|
106
|
+
} else {
|
|
107
|
+
IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const IDPaySDK = {
|
|
111
|
+
init,
|
|
112
|
+
open: startPayFlow
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
exports.IDPaySDK = IDPaySDK;
|
|
116
|
+
|
|
117
|
+
}));
|
package/index.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
let _type;
|
|
4
4
|
let _initialized = false;
|
|
5
5
|
let _openWhileInitializing = false;
|
|
6
|
+
let _collectionId;
|
|
6
7
|
const TYPE__IFRAME = 'IFRAME';
|
|
8
|
+
const TYPE_SILENT = 'SILENT';
|
|
7
9
|
const ENV_DEV = 'dev';
|
|
8
10
|
const ENV_UAT = 'uat';
|
|
9
11
|
const ENV_PROD = 'prod';
|
|
@@ -44,7 +46,9 @@ const init = async options => {
|
|
|
44
46
|
});
|
|
45
47
|
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
46
48
|
_type = options?.type;
|
|
47
|
-
if (_type ===
|
|
49
|
+
if (_type === TYPE_SILENT) {
|
|
50
|
+
_collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
|
|
51
|
+
} else if (_type === TYPE__IFRAME) {
|
|
48
52
|
await _createStyles({
|
|
49
53
|
host
|
|
50
54
|
});
|
|
@@ -80,7 +84,14 @@ const startPayFlow = ({
|
|
|
80
84
|
transactionId,
|
|
81
85
|
token
|
|
82
86
|
});
|
|
83
|
-
if (_type ===
|
|
87
|
+
if (_type === TYPE_SILENT) {
|
|
88
|
+
IDPaySDKAssets.clientBoxControl.verify({
|
|
89
|
+
transactionId,
|
|
90
|
+
token,
|
|
91
|
+
collectionId: _collectionId,
|
|
92
|
+
onFinish
|
|
93
|
+
});
|
|
94
|
+
} else if (_type === TYPE__IFRAME) {
|
|
84
95
|
IDPaySDKAssets.clientBoxControl.open({
|
|
85
96
|
transactionId,
|
|
86
97
|
token,
|
package/index.umd.js
CHANGED
|
@@ -9,7 +9,9 @@
|
|
|
9
9
|
let _type;
|
|
10
10
|
let _initialized = false;
|
|
11
11
|
let _openWhileInitializing = false;
|
|
12
|
+
let _collectionId;
|
|
12
13
|
const TYPE__IFRAME = 'IFRAME';
|
|
14
|
+
const TYPE_SILENT = 'SILENT';
|
|
13
15
|
const ENV_DEV = 'dev';
|
|
14
16
|
const ENV_UAT = 'uat';
|
|
15
17
|
const ENV_PROD = 'prod';
|
|
@@ -50,7 +52,9 @@
|
|
|
50
52
|
});
|
|
51
53
|
IDPaySDKAssets.trackEvent(IDPaySDKAssets.EVENT_TYPES.INITIALIZE);
|
|
52
54
|
_type = options?.type;
|
|
53
|
-
if (_type ===
|
|
55
|
+
if (_type === TYPE_SILENT) {
|
|
56
|
+
_collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
|
|
57
|
+
} else if (_type === TYPE__IFRAME) {
|
|
54
58
|
await _createStyles({
|
|
55
59
|
host
|
|
56
60
|
});
|
|
@@ -86,7 +90,14 @@
|
|
|
86
90
|
transactionId,
|
|
87
91
|
token
|
|
88
92
|
});
|
|
89
|
-
if (_type ===
|
|
93
|
+
if (_type === TYPE_SILENT) {
|
|
94
|
+
IDPaySDKAssets.clientBoxControl.verify({
|
|
95
|
+
transactionId,
|
|
96
|
+
token,
|
|
97
|
+
collectionId: _collectionId,
|
|
98
|
+
onFinish
|
|
99
|
+
});
|
|
100
|
+
} else if (_type === TYPE__IFRAME) {
|
|
90
101
|
IDPaySDKAssets.clientBoxControl.open({
|
|
91
102
|
transactionId,
|
|
92
103
|
token,
|