react-native-bootpay-api 1.3.0 → 1.4.3

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.
@@ -0,0 +1,131 @@
1
+
2
+
3
+ import base64 from 'react-native-base64'
4
+ import DeviceInfo from 'react-native-device-info';
5
+
6
+ // import CryptoJS from 'crypto-js';
7
+ import CryptoAesCbc from 'react-native-crypto-aes-cbc';
8
+ import { NativeModules, Platform } from 'react-native'
9
+ var Aes = NativeModules.Aes
10
+
11
+
12
+ const userTrace = async (applicationId, userId, phone, email, gender, birth, area) => {
13
+ try {
14
+ const payload = {
15
+ "id": userId,
16
+ "ver": DeviceInfo.getVersion(),
17
+ "application_id": applicationId,
18
+ "phone": phone,
19
+ "email": email,
20
+ "gender": gender,
21
+ "birth": birth,
22
+ "area": area
23
+ };
24
+
25
+ var key = getRandomKey(32);
26
+ var iv = getRandomKey(16);
27
+
28
+ try {
29
+ const data = await Aes.encrypt(JSON.stringify(payload), stringToHex(key), stringToHex(iv)).then(cipher => cipher);
30
+
31
+ const response = await fetch(
32
+ 'https://analytics.bootpay.co.kr/login',
33
+ {
34
+ method: 'POST',
35
+ headers: {
36
+ Accept: 'application/json',
37
+ 'Content-Type': 'application/json'
38
+ },
39
+ body: JSON.stringify({
40
+ data: data,
41
+ session_key: await getSessionKey(key, iv)
42
+ })
43
+ }
44
+ );
45
+ const json = await response.json();
46
+ return json;
47
+ } catch (e) {
48
+ console.log(e);
49
+ }
50
+ } catch (error) {
51
+ console.error(error);
52
+ }
53
+ }
54
+
55
+ const pageTrace = async (applicationId, url, pageType, items) => {
56
+ try {
57
+ const payload = {
58
+ "application_id": applicationId,
59
+ "url": url,
60
+ "page_type": pageType,
61
+ "items": items,
62
+ "referer": ''
63
+ };
64
+
65
+ var key = getRandomKey(32);
66
+ var iv = getRandomKey(16);
67
+
68
+ try {
69
+ const data = await Aes.encrypt(JSON.stringify(payload), stringToHex(key), stringToHex(iv)).then(cipher => cipher);
70
+
71
+ const response = await fetch(
72
+ 'https://analytics.bootpay.co.kr/call',
73
+ {
74
+ method: 'POST',
75
+ headers: {
76
+ Accept: 'application/json',
77
+ 'Content-Type': 'application/json'
78
+ },
79
+ body: JSON.stringify({
80
+ data: data,
81
+ session_key: await getSessionKey(key, iv)
82
+ })
83
+ }
84
+ );
85
+ const json = await response.json();
86
+ return json;
87
+ } catch (e) {
88
+ console.log(e);
89
+ }
90
+ } catch (error) {
91
+ console.error(error);
92
+ }
93
+ }
94
+
95
+ const stringToHex = (str) => {
96
+ var hex = ''
97
+ for (var i = 0, l = str.length; i < l; i++) {
98
+ hex += str.charCodeAt(i).toString(16)
99
+ }
100
+ return hex
101
+ }
102
+
103
+ const getRandomKey = (length) => {
104
+ var text = '';
105
+ var keys = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
106
+
107
+ for (var i = 0; i < length; i++)
108
+ text += keys.charAt(Math.floor(Math.random() * keys.length));
109
+
110
+ return text;
111
+ }
112
+
113
+
114
+ const getSessionKey = async (key, iv) => {
115
+ const keyValue = base64.encode(key);
116
+ const ivValue = base64.encode(iv);
117
+
118
+ return `${keyValue}##${ivValue}`;
119
+ }
120
+
121
+ const strEncode = async (str, key, iv) => {
122
+ return await Aes.encrypt(str, key, iv).then(cipher => {
123
+ Aes.hmac256(cipher, key).then(hash => {
124
+ console.log('HMAC', hash)
125
+ return hash;
126
+ })
127
+ })
128
+
129
+ }
130
+
131
+ export { userTrace, pageTrace }
@@ -24,7 +24,7 @@ s
24
24
  )
25
25
  UserInfo.setBootpayLastTime(Date.now());
26
26
  }
27
-
27
+
28
28
  render() {
29
29
 
30
30
 
package/src/index.d.ts CHANGED
@@ -3,23 +3,41 @@ import { ViewProperties, EmitterSubscription } from 'react-native';
3
3
  import { EventEmitter } from 'events';
4
4
 
5
5
 
6
- interface BootpayWebViewProps {
7
- ios_application_id: string;
8
- android_application_id: string;
9
-
10
- onCancel: (data: string) => void;
11
- onError: (data: string) => void;
12
- onReady: (data: string) => void;
13
- onConfirm: (data: string) => void;
14
- onDone: (data: string) => void;
15
- onClose: () => void;
16
- }
17
-
18
- export class BootpayWebView extends Component<BootpayWebViewProps> {
19
- request: (payload: Object, items: Object, user: Object, extra: Object) => Promise<string>;
20
- dismiss: () => Promise<string>;
21
- transactionConfirm: (data: string) => Promise<string>;
22
- }
6
+ import { BootpayWebView } from './BootpayWebView'
7
+ import { userTrace, pageTrace } from './BootpayAnalytics'
23
8
 
9
+
10
+ export { BootpayWebView, userTrace, pageTrace }
11
+
12
+ // interface BootpayWebViewProps {
13
+ // ios_application_id: string;
14
+ // android_application_id: string;
15
+
16
+ // onCancel: (data: string) => void;
17
+ // onError: (data: string) => void;
18
+ // onReady: (data: string) => void;
19
+ // onConfirm: (data: string) => void;
20
+ // onDone: (data: string) => void;
21
+ // onClose: () => void;
22
+ // }
23
+
24
+ // export class BootpayWebView extends Component<BootpayWebViewProps> {
25
+ // request: (payload: Object, items: Object, user: Object, extra: Object) => Promise<string>;
26
+ // dismiss: () => Promise<string>;
27
+ // transactionConfirm: (data: string) => Promise<string>;
28
+ // }
29
+
30
+ // export class BootpayAnalytics {
31
+ // static userTrace: () => void;
32
+ // static pageTrace: () => void;
33
+ // }
34
+
35
+ // export const userTrace: () => void;
36
+ // export default function pageTrace(): void;
37
+ // export const userTrace: () => void;
38
+
39
+ // export default function PageTrace() : void;
40
+
41
+ // const Bootpay =
24
42
 
25
- export { BootpayWebView }
43
+ // export { BootpayWebView, userTrace, pageTrace }
package/src/index.js CHANGED
@@ -1,8 +1,10 @@
1
1
 
2
- import { useBootpay } from './useBootpay';
2
+ // import { useBootpay } from './useBootpay';
3
3
  import { BootpayWebView } from './BootpayWebView'
4
+ import { userTrace, pageTrace } from './BootpayAnalytics'
4
5
 
5
- export { useBootpay, BootpayWebView };
6
+ export { BootpayWebView, userTrace, pageTrace };
7
+ // export { useBootpay };
6
8
 
7
9
  // import React, { Component } from 'react';
8
10
  // import WebView from 'react-native-webview-bootpay';
package/src/useBootpay.js CHANGED
@@ -1,30 +1,51 @@
1
- import { useCallback } from 'react';
2
- import BootpayWebView from './BootpayWebView';
3
-
4
- export const useBootpay = () => {
5
- const bootpay = useRef(new BootpayWebView());
6
- const [bootpayEvents, setBootpayEvents] = useState([]);
7
-
8
- const request = useCallback((payload, items, user, extra) => {
9
- return bootpay.current.request(payload, items, user, extra);
10
- }, []);
11
-
12
- const dismiss = useCallback(() => {
13
- return bootpay.current.dismiss();
14
- }, []);
15
-
16
- const transactionConfirm = useCallback((data) => {
17
- return bootpay.current.transactionConfirm(data);
18
- }, []);
19
-
20
- return [
21
- {
22
- bootpayEvents,
23
- },
24
- {
25
- request,
26
- transactionConfirm,
27
- dismiss
28
- },
29
- ];
30
- }
1
+ // import { useCallback } from 'react';
2
+ // import BootpayAnalytics from './BootpayAnalytics';
3
+ // import BootpayWebView from './BootpayWebView';
4
+
5
+ // export const useBootpay = () => {
6
+ // const bootpay = useRef(new BootpayWebView());
7
+ // // const anlaytics = useRef(new BootpayAnalytics());
8
+
9
+ // const [bootpayEvents, setBootpayEvents] = useState([]);
10
+
11
+ // const request = useCallback((payload, items, user, extra) => {
12
+ // console.log('use call reqeust');
13
+ // return bootpay.current.request(payload, items, user, extra);
14
+ // }, []);
15
+
16
+ // const dismiss = useCallback(() => {
17
+ // console.log('use call dismiss');
18
+ // return bootpay.current.dismiss();
19
+ // }, []);
20
+
21
+ // const transactionConfirm = useCallback((data) => {
22
+ // console.log('use call transactionConfirm');
23
+ // return bootpay.current.transactionConfirm(data);
24
+ // }, []);
25
+
26
+ // const userTrace = useCallback(() => {
27
+
28
+ // console.log('user trace click');
29
+ // BootpayAnalytics.userTrace();
30
+ // // return anlaytics.current.userTrace();
31
+ // }, []);
32
+
33
+ // const pageTrace = useCallback(() => {
34
+ // BootpayAnalytics.pageTrace();
35
+ // // return anlaytics.current.pageTrace();
36
+ // }, []);
37
+
38
+ // return [
39
+ // {
40
+ // bootpayEvents,
41
+ // },
42
+ // {
43
+ // request,
44
+ // transactionConfirm,
45
+ // dismiss,
46
+ // text,
47
+ // userTrace,
48
+ // pageTrace
49
+ // },
50
+ // ];
51
+ // }