idpay-b2b-sdk 0.0.25 → 0.0.27

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 CHANGED
@@ -10,7 +10,10 @@
10
10
  let _initialized = false;
11
11
  let _openWhileInitializing = false;
12
12
  let _collectionId;
13
- const TYPE__IFRAME = 'IFRAME';
13
+ let _script;
14
+
15
+ // const TYPE__IFRAME = 'IFRAME';
16
+ const TYPE__REDIRECT = 'REDIRECT';
14
17
  const TYPE_SILENT = 'SILENT';
15
18
  const ENV_DEV = 'dev';
16
19
  const ENV_UAT = 'uat';
@@ -23,12 +26,15 @@
23
26
  const _createScript = ({
24
27
  host
25
28
  }) => {
26
- const script = document.createElement('script');
27
- script.src = `${host}/sdk-assets/index.js`;
29
+ if (_script) {
30
+ return Promise.resolve();
31
+ }
32
+ _script = document.createElement('script');
33
+ _script.src = `${host}/sdk-assets/index.js`;
28
34
  const prmScript = new Promise(resolve => {
29
- script.onload = resolve;
35
+ _script.onload = resolve;
30
36
  });
31
- document.body.appendChild(script);
37
+ document.body.appendChild(_script);
32
38
  return Promise.all([prmScript]);
33
39
  };
34
40
  const _createStyles = ({
@@ -54,7 +60,8 @@
54
60
  _type = options?.type;
55
61
  if (_type === TYPE_SILENT) {
56
62
  _collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
57
- } else if (_type === TYPE__IFRAME) {
63
+ } else if (_type !== TYPE__REDIRECT) {
64
+ // iframe
58
65
  await _createStyles({
59
66
  host
60
67
  });
@@ -67,6 +74,9 @@
67
74
  if (_openWhileInitializing) {
68
75
  startPayFlow(_openWhileInitializing);
69
76
  }
77
+ if (_collectionId) {
78
+ return _collectionId;
79
+ }
70
80
  };
71
81
  const startPayFlow = ({
72
82
  transactionId,
@@ -97,18 +107,23 @@
97
107
  collectionId: _collectionId,
98
108
  onFinish
99
109
  });
100
- } else if (_type === TYPE__IFRAME) {
110
+ } else if (_type === TYPE__REDIRECT) {
111
+ IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
112
+ } else {
113
+ // iframe
101
114
  IDPaySDKAssets.clientBoxControl.open({
102
115
  transactionId,
103
116
  token,
104
117
  onFinish
105
118
  });
106
- } else {
107
- IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
108
119
  }
109
120
  };
121
+ const close = () => {
122
+ IDPaySDKAssets.clientBoxControl.close();
123
+ };
110
124
  const IDPaySDK = {
111
125
  init,
126
+ close,
112
127
  open: startPayFlow
113
128
  };
114
129
 
package/index.js CHANGED
@@ -4,7 +4,10 @@ let _type;
4
4
  let _initialized = false;
5
5
  let _openWhileInitializing = false;
6
6
  let _collectionId;
7
- const TYPE__IFRAME = 'IFRAME';
7
+ let _script;
8
+
9
+ // const TYPE__IFRAME = 'IFRAME';
10
+ const TYPE__REDIRECT = 'REDIRECT';
8
11
  const TYPE_SILENT = 'SILENT';
9
12
  const ENV_DEV = 'dev';
10
13
  const ENV_UAT = 'uat';
@@ -17,12 +20,15 @@ const _HOSTS = {
17
20
  const _createScript = ({
18
21
  host
19
22
  }) => {
20
- const script = document.createElement('script');
21
- script.src = `${host}/sdk-assets/index.js`;
23
+ if (_script) {
24
+ return Promise.resolve();
25
+ }
26
+ _script = document.createElement('script');
27
+ _script.src = `${host}/sdk-assets/index.js`;
22
28
  const prmScript = new Promise(resolve => {
23
- script.onload = resolve;
29
+ _script.onload = resolve;
24
30
  });
25
- document.body.appendChild(script);
31
+ document.body.appendChild(_script);
26
32
  return Promise.all([prmScript]);
27
33
  };
28
34
  const _createStyles = ({
@@ -48,7 +54,8 @@ const init = async options => {
48
54
  _type = options?.type;
49
55
  if (_type === TYPE_SILENT) {
50
56
  _collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
51
- } else if (_type === TYPE__IFRAME) {
57
+ } else if (_type !== TYPE__REDIRECT) {
58
+ // iframe
52
59
  await _createStyles({
53
60
  host
54
61
  });
@@ -61,6 +68,9 @@ const init = async options => {
61
68
  if (_openWhileInitializing) {
62
69
  startPayFlow(_openWhileInitializing);
63
70
  }
71
+ if (_collectionId) {
72
+ return _collectionId;
73
+ }
64
74
  };
65
75
  const startPayFlow = ({
66
76
  transactionId,
@@ -91,18 +101,23 @@ const startPayFlow = ({
91
101
  collectionId: _collectionId,
92
102
  onFinish
93
103
  });
94
- } else if (_type === TYPE__IFRAME) {
104
+ } else if (_type === TYPE__REDIRECT) {
105
+ IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
106
+ } else {
107
+ // iframe
95
108
  IDPaySDKAssets.clientBoxControl.open({
96
109
  transactionId,
97
110
  token,
98
111
  onFinish
99
112
  });
100
- } else {
101
- IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
102
113
  }
103
114
  };
115
+ const close = () => {
116
+ IDPaySDKAssets.clientBoxControl.close();
117
+ };
104
118
  const IDPaySDK = {
105
119
  init,
120
+ close,
106
121
  open: startPayFlow
107
122
  };
108
123
 
package/index.umd.js CHANGED
@@ -10,7 +10,10 @@
10
10
  let _initialized = false;
11
11
  let _openWhileInitializing = false;
12
12
  let _collectionId;
13
- const TYPE__IFRAME = 'IFRAME';
13
+ let _script;
14
+
15
+ // const TYPE__IFRAME = 'IFRAME';
16
+ const TYPE__REDIRECT = 'REDIRECT';
14
17
  const TYPE_SILENT = 'SILENT';
15
18
  const ENV_DEV = 'dev';
16
19
  const ENV_UAT = 'uat';
@@ -23,12 +26,15 @@
23
26
  const _createScript = ({
24
27
  host
25
28
  }) => {
26
- const script = document.createElement('script');
27
- script.src = `${host}/sdk-assets/index.js`;
29
+ if (_script) {
30
+ return Promise.resolve();
31
+ }
32
+ _script = document.createElement('script');
33
+ _script.src = `${host}/sdk-assets/index.js`;
28
34
  const prmScript = new Promise(resolve => {
29
- script.onload = resolve;
35
+ _script.onload = resolve;
30
36
  });
31
- document.body.appendChild(script);
37
+ document.body.appendChild(_script);
32
38
  return Promise.all([prmScript]);
33
39
  };
34
40
  const _createStyles = ({
@@ -54,7 +60,8 @@
54
60
  _type = options?.type;
55
61
  if (_type === TYPE_SILENT) {
56
62
  _collectionId = await IDPaySDKAssets.clientBoxControl.initSilent();
57
- } else if (_type === TYPE__IFRAME) {
63
+ } else if (_type !== TYPE__REDIRECT) {
64
+ // iframe
58
65
  await _createStyles({
59
66
  host
60
67
  });
@@ -67,6 +74,9 @@
67
74
  if (_openWhileInitializing) {
68
75
  startPayFlow(_openWhileInitializing);
69
76
  }
77
+ if (_collectionId) {
78
+ return _collectionId;
79
+ }
70
80
  };
71
81
  const startPayFlow = ({
72
82
  transactionId,
@@ -97,18 +107,23 @@
97
107
  collectionId: _collectionId,
98
108
  onFinish
99
109
  });
100
- } else if (_type === TYPE__IFRAME) {
110
+ } else if (_type === TYPE__REDIRECT) {
111
+ IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
112
+ } else {
113
+ // iframe
101
114
  IDPaySDKAssets.clientBoxControl.open({
102
115
  transactionId,
103
116
  token,
104
117
  onFinish
105
118
  });
106
- } else {
107
- IDPaySDKAssets.clientBoxControl.redirect(transactionId, token);
108
119
  }
109
120
  };
121
+ const close = () => {
122
+ IDPaySDKAssets.clientBoxControl.close();
123
+ };
110
124
  const IDPaySDK = {
111
125
  init,
126
+ close,
112
127
  open: startPayFlow
113
128
  };
114
129
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idpay-b2b-sdk",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/acesso-io/frontend.git",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "publishConfig": {
10
10
  "registry": "https://registry.npmjs.org",
11
- "tag": "internal"
11
+ "tag": "beta"
12
12
  },
13
13
  "module": "./index.esm.js",
14
14
  "type": "module",