idpay-b2b-sdk 0.0.23 → 0.0.24

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