react-native-bootpay-api 13.13.4 → 13.13.42
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/lib/Bootpay.js +25 -7
- package/lib/BootpayTypes.js +1 -1
- package/lib/UserInfo.js +1 -1
- package/lib/bootpayAnalytics.js +1 -1
- package/package.json +3 -3
- package/src/Bootpay.tsx +324 -467
- package/src/BootpayTypes.ts +98 -114
- package/src/UserInfo.ts +69 -63
- package/src/bootpayAnalytics.ts +151 -47
- package/src/index.tsx +3 -8
- package/lib/Bootpay.d.ts +0 -45
- package/lib/Bootpay.d.ts.map +0 -1
- package/lib/BootpayTypes.d.ts +0 -106
- package/lib/BootpayTypes.d.ts.map +0 -1
- package/lib/Loader.d.ts +0 -1
- package/lib/Loader.d.ts.map +0 -1
- package/lib/Loader.js +0 -0
- package/lib/UserInfo.d.ts +0 -14
- package/lib/UserInfo.d.ts.map +0 -1
- package/lib/bootpayAnalytics.d.ts +0 -12
- package/lib/bootpayAnalytics.d.ts.map +0 -1
- package/lib/index.d.ts +0 -4
- package/lib/index.d.ts.map +0 -1
- package/src/Loader.tsx +0 -41
package/src/Bootpay.tsx
CHANGED
|
@@ -1,479 +1,336 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
1
|
import React, { Component } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import {
|
|
3
|
+
SafeAreaView,
|
|
4
|
+
Modal,
|
|
5
|
+
TouchableOpacity,
|
|
6
|
+
Image,
|
|
7
|
+
StyleSheet,
|
|
8
|
+
Platform,
|
|
9
|
+
} from 'react-native';
|
|
10
|
+
import WebView, { WebViewMessageEvent } from 'react-native-webview-bootpay';
|
|
11
|
+
import { BootpayTypesProps, Payload, Item, User, Extra } from './BootpayTypes';
|
|
12
|
+
import { debounce } from 'lodash';
|
|
13
|
+
import UserInfo from './UserInfo';
|
|
14
|
+
|
|
15
|
+
const SDK_VERSION = '13.13.4';
|
|
16
|
+
const DEBUG_MODE = false;
|
|
13
17
|
|
|
14
18
|
export class Bootpay extends Component<BootpayTypesProps> {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
webView: React.RefObject<WebView>;
|
|
18
|
-
|
|
19
|
-
constructor(props: BootpayTypesProps) {
|
|
20
|
-
super(props);
|
|
21
|
-
|
|
22
|
-
this.webView = React.createRef();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
payload?: Payload
|
|
26
|
-
|
|
27
|
-
state = {
|
|
28
|
-
visibility: false,
|
|
29
|
-
script: '',
|
|
30
|
-
firstLoad: false,
|
|
31
|
-
showCloseButton: false,
|
|
32
|
-
isShowProgress: false
|
|
33
|
-
}
|
|
34
|
-
// _payload = {}
|
|
35
|
-
_VERSION = "13.13.4"
|
|
36
|
-
_DEBUG = false;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
dismiss = () => {
|
|
40
|
-
this.setState(
|
|
41
|
-
{
|
|
42
|
-
visibility: false
|
|
43
|
-
}
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
showProgressBar = (isShow: boolean) => {
|
|
49
|
-
this.setState(
|
|
50
|
-
{
|
|
51
|
-
isShowProgress: isShow
|
|
52
|
-
}
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
closeDismiss = () => {
|
|
58
|
-
if(this.props.onClose != undefined) this.props.onClose();
|
|
59
|
-
this.dismiss();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
onMessage = async (event: WebViewMessageEvent) => {
|
|
65
|
-
|
|
66
|
-
if (event == undefined) return;
|
|
67
|
-
console.log(event.nativeEvent.data);
|
|
68
|
-
|
|
69
|
-
const res = JSON.parse(JSON.stringify(event.nativeEvent.data));
|
|
70
|
-
|
|
71
|
-
console.log(res);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if(res == 'close') {
|
|
75
|
-
this.showProgressBar(false);
|
|
76
|
-
this.closeDismiss();
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const data = JSON.parse(res);
|
|
82
|
-
// console.log(`redirect: ${JSON.stringify(data)}`);
|
|
83
|
-
|
|
84
|
-
var redirect = false
|
|
85
|
-
let show_success = false
|
|
86
|
-
let show_error = false
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if(this.payload?.extra != undefined) {
|
|
90
|
-
if(this.payload.extra?.open_type == 'redirect') {
|
|
91
|
-
redirect = true;
|
|
92
|
-
}
|
|
93
|
-
if(this.payload.extra?.display_error_result == true) {
|
|
94
|
-
show_error = true;
|
|
95
|
-
}
|
|
96
|
-
if(this.payload.extra?.display_success_result == true) {
|
|
97
|
-
show_success = true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if(redirect === true) {
|
|
103
|
-
switch (data.event) {
|
|
104
|
-
case 'cancel':
|
|
105
|
-
this.showProgressBar(false);
|
|
106
|
-
if(this.props.onCancel != undefined) this.props.onCancel(data);
|
|
107
|
-
this.closeDismiss();
|
|
108
|
-
break;
|
|
109
|
-
case 'error':
|
|
110
|
-
this.showProgressBar(false);
|
|
111
|
-
if(this.props.onError != undefined) this.props.onError(data);
|
|
112
|
-
if(show_error == false) {
|
|
113
|
-
this.closeDismiss();
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
case 'issued':
|
|
117
|
-
this.showProgressBar(false);
|
|
118
|
-
if(this.props.onIssued != undefined) this.props.onIssued(data);
|
|
119
|
-
if(show_success == false) {
|
|
120
|
-
this.closeDismiss();
|
|
121
|
-
}
|
|
122
|
-
break;
|
|
123
|
-
case 'confirm':
|
|
124
|
-
this.showProgressBar(true);
|
|
125
|
-
// if(this.props.onConfirm != undefined) this.props.onConfirm(data);
|
|
126
|
-
if(this.props.onConfirm != undefined) {
|
|
127
|
-
if(this.props.onConfirm(data)) {
|
|
128
|
-
this.transactionConfirm();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
case 'done':
|
|
133
|
-
this.showProgressBar(false);
|
|
134
|
-
if(this.props.onDone != undefined) this.props.onDone(data);
|
|
135
|
-
if(show_success == false) {
|
|
136
|
-
this.closeDismiss();
|
|
137
|
-
}
|
|
138
|
-
break;
|
|
139
|
-
case 'close':
|
|
140
|
-
this.showProgressBar(false);
|
|
141
|
-
this.closeDismiss();
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
} else {
|
|
145
|
-
switch (data.event) {
|
|
146
|
-
case 'cancel':
|
|
147
|
-
this.showProgressBar(false);
|
|
148
|
-
if(this.props.onCancel != undefined) this.props.onCancel(data);
|
|
149
|
-
break;
|
|
150
|
-
case 'error':
|
|
151
|
-
this.showProgressBar(false);
|
|
152
|
-
if(this.props.onError != undefined) this.props.onError(data);
|
|
153
|
-
break;
|
|
154
|
-
case 'issued':
|
|
155
|
-
this.showProgressBar(false);
|
|
156
|
-
if(this.props.onIssued != undefined) this.props.onIssued(data);
|
|
157
|
-
break;
|
|
158
|
-
case 'confirm':
|
|
159
|
-
this.showProgressBar(true);
|
|
160
|
-
if(this.props.onConfirm != undefined) {
|
|
161
|
-
if(this.props.onConfirm(data)) {
|
|
162
|
-
this.transactionConfirm();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
break;
|
|
166
|
-
case 'done':
|
|
167
|
-
this.showProgressBar(false);
|
|
168
|
-
if(this.props.onDone != undefined) this.props.onDone(data);
|
|
169
|
-
break;
|
|
170
|
-
case 'close':
|
|
171
|
-
this.showProgressBar(false);
|
|
172
|
-
this.closeDismiss();
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
onShouldStartLoadWithRequest = (_ : string) => {
|
|
179
|
-
return true;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
getSDKVersion = () => {
|
|
183
|
-
if(Platform.OS == 'ios') {
|
|
184
|
-
return "Bootpay.setVersion('" + this._VERSION + "', 'ios_react_native')"
|
|
185
|
-
// return "Bootpay.setDevice('IOS');";
|
|
186
|
-
} else if(Platform.OS == 'android'){
|
|
187
|
-
return "Bootpay.setVersion('" + this._VERSION + "', 'android_react_native')"
|
|
188
|
-
// return "Bootpay.setDevice('ANDROID');";
|
|
189
|
-
} else {
|
|
190
|
-
return ""
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
getEnvironmentMode = () => {
|
|
195
|
-
if(this._DEBUG) {
|
|
196
|
-
return "Bootpay.setEnvironmentMode('development');";
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
return "";
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
getBootpayPlatform = () => {
|
|
203
|
-
if(Platform.OS == 'ios') {
|
|
204
|
-
return "Bootpay.setDevice('IOS');";
|
|
205
|
-
} else if(Platform.OS == 'android'){
|
|
206
|
-
return "Bootpay.setDevice('ANDROID');";
|
|
207
|
-
} else {
|
|
208
|
-
return ""
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// setPayScript = () => {
|
|
213
|
-
// const fullScript = this.generateScript(this.state.script);
|
|
214
|
-
// this.injectJavaScript(fullScript);
|
|
215
|
-
// if(this.state.showCloseButton == true) {
|
|
216
|
-
// if(this.webView == null || this.webView == undefined) return;
|
|
217
|
-
// this.webView.showCloseButton( );
|
|
218
|
-
// }
|
|
219
|
-
// }
|
|
220
|
-
|
|
221
|
-
transactionConfirm = () => {
|
|
222
|
-
const script = "Bootpay.confirm()"
|
|
223
|
-
+
|
|
224
|
-
".then( function (res) {" +
|
|
225
|
-
this.confirm() +
|
|
226
|
-
this.issued() +
|
|
227
|
-
this.done() +
|
|
228
|
-
"}, function (res) {" +
|
|
229
|
-
this.error() +
|
|
230
|
-
this.cancel() +
|
|
231
|
-
"})";
|
|
232
|
-
|
|
233
|
-
this.callJavaScript(script);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
removePaymentWindow = () => {
|
|
237
|
-
this.dismiss();
|
|
238
|
-
// this.callJavaScript(`
|
|
239
|
-
// Bootpay.removePaymentWindow();
|
|
240
|
-
// `);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
callJavaScript = (script: string) => {
|
|
244
|
-
if(this.webView == null || this.webView == undefined) return
|
|
245
|
-
|
|
246
|
-
this.webView.current?.injectJavaScript(`
|
|
247
|
-
setTimeout(function() { ${script} }, 30);
|
|
248
|
-
`)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
getAnalyticsData = async () => {
|
|
252
|
-
const uuid = await UserInfo.getBootpayUUID();
|
|
253
|
-
// const bootpaySK = await UserInfo.getBootpaySK();
|
|
254
|
-
const bootLastTime = await UserInfo.getBootpayLastTime();
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const elaspedTime = Date.now() - bootLastTime;
|
|
258
|
-
return `window.Bootpay.$analytics.setAnalyticsData({uuid:'${uuid}', time:${elaspedTime}});`;
|
|
259
|
-
// this.callJavaScript(`window.BootPay.setAnalyticsData({uuid:'${uuid}',sk:'${bootpaySK}',sk_time:${bootLastTime},time:${elaspedTime}});`);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
confirm = () => {
|
|
263
|
-
return "if (res.event === 'confirm') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
done = () => {
|
|
267
|
-
return "else if (res.event === 'done') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
issued = () => {
|
|
271
|
-
return "else if (res.event === 'issued') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
error = () => {
|
|
275
|
-
return "if (res.event === 'error') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
cancel = () => {
|
|
279
|
-
return "else if (res.event === 'cancel') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
close = () => {
|
|
283
|
-
return "document.addEventListener('bootpayclose', function (e) { window.BootpayRNWebView.postMessage('close'); });";
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
async componentWillUnmount() {
|
|
289
|
-
this.setState(
|
|
290
|
-
{
|
|
291
|
-
visibility: false,
|
|
292
|
-
firstLoad: false,
|
|
293
|
-
showCloseButton: false
|
|
294
|
-
}
|
|
295
|
-
)
|
|
296
|
-
UserInfo.setBootpayLastTime(Date.now());
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
componentDidMount() {
|
|
301
|
-
this.closeDismiss = debounce(this.closeDismiss, 30);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
render() {
|
|
305
|
-
return (
|
|
306
|
-
<Modal
|
|
307
|
-
animationType={'slide'}
|
|
308
|
-
transparent={false}
|
|
309
|
-
onRequestClose={()=> {
|
|
310
|
-
this.closeDismiss();
|
|
311
|
-
// console.log(1234);
|
|
312
|
-
// this.dismiss();
|
|
313
|
-
}}
|
|
314
|
-
|
|
315
|
-
visible={this.state.visibility}>
|
|
316
|
-
<SafeAreaView style={{ flex: 1 }}>
|
|
317
|
-
{
|
|
318
|
-
this.state.showCloseButton &&
|
|
319
|
-
<TouchableOpacity
|
|
320
|
-
onPress={() => {
|
|
321
|
-
var cancelData = {
|
|
322
|
-
action: 'BootpayCancel',
|
|
323
|
-
message: '사용자에 의해 취소되었습니다'
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if(this.props.onCancel != undefined) this.props.onCancel(cancelData);
|
|
327
|
-
if(this.props.onClose != undefined) this.props.onClose();
|
|
328
|
-
|
|
329
|
-
this.setState({visibility: false})
|
|
330
|
-
|
|
331
|
-
// this.showProgressBar(true);
|
|
332
|
-
|
|
333
|
-
} }>
|
|
334
|
-
<Image
|
|
335
|
-
style={[styles.overlay]}
|
|
336
|
-
source={require('../images/close.png')} />
|
|
337
|
-
</TouchableOpacity>
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
<WebView
|
|
341
|
-
ref={this.webView}
|
|
342
|
-
originWhitelist={['*']}
|
|
343
|
-
source={{
|
|
344
|
-
uri: 'https://webview.bootpay.co.kr/5.1.0'
|
|
345
|
-
}}
|
|
346
|
-
injectedJavaScript={this.state.script}
|
|
347
|
-
javaScriptEnabled={true}
|
|
348
|
-
javaScriptCanOpenWindowsAutomatically={true}
|
|
349
|
-
// scalesPageToFit={true}
|
|
350
|
-
onMessage={this.onMessage}
|
|
351
|
-
onError={(syntheticEvent) => {
|
|
352
|
-
const { nativeEvent } = syntheticEvent;
|
|
353
|
-
if(nativeEvent.code == 3) {
|
|
354
|
-
this.showProgressBar(false);
|
|
355
|
-
if(this.props.onError != undefined) this.props.onError({
|
|
356
|
-
code: nativeEvent.code,
|
|
357
|
-
message: nativeEvent.description
|
|
358
|
-
});
|
|
359
|
-
this.closeDismiss();
|
|
360
|
-
}
|
|
361
|
-
}}
|
|
362
|
-
// onError={ error => {
|
|
363
|
-
// if(error.code == 3) {
|
|
364
|
-
// console.log()
|
|
365
|
-
// }
|
|
366
|
-
// }}
|
|
367
|
-
// onError={syntheticEvent => {
|
|
368
|
-
// const { nativeEvent } = syntheticEvent;
|
|
369
|
-
// console.warn('WebView error: ', nativeEvent);
|
|
370
|
-
// }}
|
|
371
|
-
// onError={}
|
|
372
|
-
/>
|
|
373
|
-
</SafeAreaView>
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
</Modal>
|
|
377
|
-
)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// onMessage = async (event: WebViewMessageEvent) => {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
requestPayment = async (payload: Payload, items: [Item], user: User, extra: Extra) => {
|
|
386
|
-
|
|
387
|
-
this.bootpayRequest(payload, items, user, extra, "requestPayment");
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
requestSubscription = async (payload: Payload, items: [Item], user: User, extra: Extra) => {
|
|
391
|
-
this.bootpayRequest(payload, items, user, extra, "requestSubscription");
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
requestAuthentication = async (payload: Payload, items: [Item], user: User, extra: Extra) => {
|
|
395
|
-
this.bootpayRequest(payload, items, user, extra, "requestAuthentication");
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
bootpayRequest = async (payload: Payload, items: [Item], user: User, extra: Extra, requestMethod: string) => {
|
|
399
|
-
|
|
400
|
-
payload.application_id = Platform.OS == 'ios' ? this.props.ios_application_id : this.props.android_application_id;
|
|
401
|
-
payload.items = items;
|
|
402
|
-
payload.user = user;
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
payload.user = Object.assign(new User(), user); //set default value from class optional parameter value
|
|
406
|
-
payload.extra = Object.assign(new Extra(), extra); //set default value from class optional parameter value
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
this.payload = payload
|
|
410
|
-
|
|
411
|
-
this.setState(
|
|
412
|
-
{
|
|
413
|
-
visibility: true,
|
|
414
|
-
script: `
|
|
415
|
-
${await this.getMountJavascript()}
|
|
416
|
-
${this.generateScript(payload, requestMethod)}
|
|
417
|
-
`,
|
|
418
|
-
firstLoad: false,
|
|
419
|
-
showCloseButton: extra.show_close_button || false,
|
|
420
|
-
spinner: false
|
|
421
|
-
}
|
|
422
|
-
)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
UserInfo.updateInfo();
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
getMountJavascript = async () => {
|
|
430
|
-
return `
|
|
19
|
+
getMountJavascript = async () => {
|
|
20
|
+
return `
|
|
431
21
|
${this.getSDKVersion()}
|
|
432
22
|
${this.getEnvironmentMode()}
|
|
433
23
|
${this.getBootpayPlatform()}
|
|
434
24
|
${this.close()}
|
|
435
25
|
${await this.getAnalyticsData()}
|
|
436
|
-
`;
|
|
26
|
+
`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
webView: React.RefObject<WebView>;
|
|
30
|
+
payload?: Payload;
|
|
31
|
+
|
|
32
|
+
constructor(props: BootpayTypesProps) {
|
|
33
|
+
super(props);
|
|
34
|
+
this.webView = React.createRef();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
state = {
|
|
38
|
+
visibility: false,
|
|
39
|
+
script: '',
|
|
40
|
+
firstLoad: false,
|
|
41
|
+
showCloseButton: false,
|
|
42
|
+
isShowProgress: false,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
dismiss = () => {
|
|
46
|
+
this.setState({ visibility: false });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
showProgressBar = (isShow: boolean) => {
|
|
50
|
+
this.setState({ isShowProgress: isShow });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
closeDismiss = () => {
|
|
54
|
+
if (this.props.onClose) this.props.onClose();
|
|
55
|
+
this.dismiss();
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
callJavaScript = (script: string) => {
|
|
59
|
+
this.webView.current?.injectJavaScript(
|
|
60
|
+
`setTimeout(function() { ${script} }, 30);`
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
transactionConfirm = () => {
|
|
65
|
+
const script = `
|
|
66
|
+
Bootpay.confirm()
|
|
67
|
+
.then(res => {
|
|
68
|
+
${this.confirm()}
|
|
69
|
+
${this.issued()}
|
|
70
|
+
${this.done()}
|
|
71
|
+
}, res => {
|
|
72
|
+
${this.error()}
|
|
73
|
+
${this.cancel()}
|
|
74
|
+
});
|
|
75
|
+
`;
|
|
76
|
+
this.callJavaScript(script);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
confirm = () => {
|
|
80
|
+
return "if (res.event === 'confirm') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
done = () => {
|
|
84
|
+
return "else if (res.event === 'done') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
issued = () => {
|
|
88
|
+
return "else if (res.event === 'issued') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
error = () => {
|
|
92
|
+
return "if (res.event === 'error') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
cancel = () => {
|
|
96
|
+
return "else if (res.event === 'cancel') { window.BootpayRNWebView.postMessage( JSON.stringify(res) ); }";
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
close = () => {
|
|
100
|
+
return "document.addEventListener('bootpayclose', function (e) { window.BootpayRNWebView.postMessage('close'); });";
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
onMessage = async (event: WebViewMessageEvent) => {
|
|
104
|
+
if (!event) return;
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
const res = JSON.parse(event.nativeEvent.data);
|
|
108
|
+
|
|
109
|
+
if (res === 'close') {
|
|
110
|
+
this.showProgressBar(false);
|
|
111
|
+
this.closeDismiss();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const data = typeof res === 'string' ? JSON.parse(res) : res;
|
|
116
|
+
|
|
117
|
+
let show_success = false;
|
|
118
|
+
let show_error = false;
|
|
119
|
+
|
|
120
|
+
if (this.payload?.extra) {
|
|
121
|
+
// redirect = this.payload.extra?.open_type === 'redirect';
|
|
122
|
+
show_error = !!this.payload.extra?.display_error_result;
|
|
123
|
+
show_success = !!this.payload.extra?.display_success_result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const handleEvent = (_eventName, callback, showResult) => {
|
|
127
|
+
this.showProgressBar(false);
|
|
128
|
+
if (callback) callback(data);
|
|
129
|
+
if (!showResult) this.closeDismiss();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
switch (data.event) {
|
|
133
|
+
case 'cancel':
|
|
134
|
+
handleEvent('cancel', this.props.onCancel, false);
|
|
135
|
+
break;
|
|
136
|
+
case 'error':
|
|
137
|
+
handleEvent('error', this.props.onError, show_error);
|
|
138
|
+
break;
|
|
139
|
+
case 'issued':
|
|
140
|
+
handleEvent('issued', this.props.onIssued, show_success);
|
|
141
|
+
break;
|
|
142
|
+
case 'confirm':
|
|
143
|
+
this.showProgressBar(true);
|
|
144
|
+
if (this.props.onConfirm && this.props.onConfirm(data)) {
|
|
145
|
+
this.transactionConfirm();
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
case 'done':
|
|
149
|
+
handleEvent('done', this.props.onDone, show_success);
|
|
150
|
+
break;
|
|
151
|
+
case 'close':
|
|
152
|
+
this.showProgressBar(false);
|
|
153
|
+
this.closeDismiss();
|
|
154
|
+
break;
|
|
155
|
+
default:
|
|
156
|
+
console.warn(`Unknown event type: ${data.event}`);
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('Error processing message:', error);
|
|
437
161
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
generateScript = (payload: Payload, requestMethod: string) => {
|
|
165
|
+
return `
|
|
166
|
+
Bootpay.${requestMethod}(${JSON.stringify(payload)})
|
|
167
|
+
.then(res => {
|
|
168
|
+
${this.confirm()}
|
|
169
|
+
${this.issued()}
|
|
170
|
+
${this.done()}
|
|
171
|
+
}, res => {
|
|
172
|
+
${this.error()}
|
|
173
|
+
${this.cancel()}
|
|
174
|
+
});
|
|
175
|
+
`;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
getSDKVersion = () => {
|
|
179
|
+
const os = Platform.OS;
|
|
180
|
+
return `Bootpay.setVersion('${SDK_VERSION}', '${os}_react_native')`;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
getEnvironmentMode = () => {
|
|
184
|
+
return DEBUG_MODE ? "Bootpay.setEnvironmentMode('development');" : '';
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
getBootpayPlatform = () => {
|
|
188
|
+
return Platform.OS === 'ios'
|
|
189
|
+
? "Bootpay.setDevice('IOS');"
|
|
190
|
+
: "Bootpay.setDevice('ANDROID');";
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
async componentWillUnmount() {
|
|
194
|
+
this.setState({
|
|
195
|
+
visibility: false,
|
|
196
|
+
firstLoad: false,
|
|
197
|
+
showCloseButton: false,
|
|
198
|
+
});
|
|
199
|
+
UserInfo.setBootpayLastTime(Date.now());
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
componentDidMount() {
|
|
203
|
+
this.closeDismiss = debounce(this.closeDismiss, 30);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
removePaymentWindow = () => {
|
|
207
|
+
this.dismiss();
|
|
208
|
+
// this.callJavaScript(`
|
|
209
|
+
// Bootpay.removePaymentWindow();
|
|
210
|
+
// `);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
getAnalyticsData = async () => {
|
|
214
|
+
const uuid = await UserInfo.getBootpayUUID();
|
|
215
|
+
const bootpaySK = await UserInfo.getBootpaySK();
|
|
216
|
+
const bootLastTime = await UserInfo.getBootpayLastTime();
|
|
217
|
+
|
|
218
|
+
const elaspedTime = Date.now() - bootLastTime;
|
|
219
|
+
|
|
220
|
+
console.log(uuid, bootpaySK, bootLastTime);
|
|
221
|
+
|
|
222
|
+
return `window.Bootpay.$analytics.setAnalyticsData({uuid:'${uuid}',sk:'${bootpaySK}',time:${elaspedTime}});`;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
requestPayment = async (
|
|
226
|
+
payload: Payload,
|
|
227
|
+
items: [Item],
|
|
228
|
+
user: User,
|
|
229
|
+
extra: Extra
|
|
230
|
+
) => {
|
|
231
|
+
this.bootpayRequest(payload, items, user, extra, 'requestPayment');
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
requestSubscription = async (
|
|
235
|
+
payload: Payload,
|
|
236
|
+
items: [Item],
|
|
237
|
+
user: User,
|
|
238
|
+
extra: Extra
|
|
239
|
+
) => {
|
|
240
|
+
this.bootpayRequest(payload, items, user, extra, 'requestSubscription');
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
requestAuthentication = async (
|
|
244
|
+
payload: Payload,
|
|
245
|
+
items: [Item],
|
|
246
|
+
user: User,
|
|
247
|
+
extra: Extra
|
|
248
|
+
) => {
|
|
249
|
+
this.bootpayRequest(payload, items, user, extra, 'requestAuthentication');
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
bootpayRequest = async (
|
|
253
|
+
payload: Payload,
|
|
254
|
+
items: [Item],
|
|
255
|
+
user: User,
|
|
256
|
+
extra: Extra,
|
|
257
|
+
requestMethod: string
|
|
258
|
+
) => {
|
|
259
|
+
payload.application_id =
|
|
260
|
+
Platform.OS === 'ios'
|
|
261
|
+
? this.props.ios_application_id
|
|
262
|
+
: this.props.android_application_id;
|
|
263
|
+
payload.items = items;
|
|
264
|
+
payload.user = user;
|
|
265
|
+
|
|
266
|
+
payload.user = Object.assign(new User(), user); //set default value from class optional parameter value
|
|
267
|
+
payload.extra = Object.assign(new Extra(), extra); //set default value from class optional parameter value
|
|
268
|
+
|
|
269
|
+
this.payload = payload;
|
|
270
|
+
|
|
271
|
+
this.setState({
|
|
272
|
+
visibility: true,
|
|
273
|
+
script: `
|
|
274
|
+
${await this.getMountJavascript()}
|
|
275
|
+
${this.generateScript(payload, requestMethod)}
|
|
276
|
+
`,
|
|
277
|
+
firstLoad: false,
|
|
278
|
+
showCloseButton: extra.show_close_button || false,
|
|
279
|
+
spinner: false,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
UserInfo.updateInfo();
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
render() {
|
|
286
|
+
return (
|
|
287
|
+
<Modal
|
|
288
|
+
animationType="slide"
|
|
289
|
+
transparent={false}
|
|
290
|
+
visible={this.state.visibility}
|
|
291
|
+
onRequestClose={this.closeDismiss}
|
|
292
|
+
>
|
|
293
|
+
<SafeAreaView style={{ flex: 1 }}>
|
|
294
|
+
{this.state.showCloseButton && (
|
|
295
|
+
<TouchableOpacity onPress={this.closeDismiss}>
|
|
296
|
+
<Image
|
|
297
|
+
style={styles.overlay}
|
|
298
|
+
source={require('../images/close.png')}
|
|
299
|
+
/>
|
|
300
|
+
</TouchableOpacity>
|
|
301
|
+
)}
|
|
302
|
+
<WebView
|
|
303
|
+
ref={this.webView}
|
|
304
|
+
originWhitelist={['*']}
|
|
305
|
+
source={{ uri: 'https://webview.bootpay.co.kr/5.1.0' }}
|
|
306
|
+
injectedJavaScript={this.state.script}
|
|
307
|
+
javaScriptEnabled
|
|
308
|
+
javaScriptCanOpenWindowsAutomatically
|
|
309
|
+
onMessage={this.onMessage}
|
|
310
|
+
onError={(syntheticEvent) => {
|
|
311
|
+
const { nativeEvent } = syntheticEvent;
|
|
312
|
+
if (nativeEvent.code === 3) {
|
|
313
|
+
this.showProgressBar(false);
|
|
314
|
+
if (this.props.onError)
|
|
315
|
+
this.props.onError({
|
|
316
|
+
code: nativeEvent.code,
|
|
317
|
+
message: nativeEvent.description,
|
|
318
|
+
});
|
|
319
|
+
this.closeDismiss();
|
|
320
|
+
}
|
|
321
|
+
}}
|
|
322
|
+
/>
|
|
323
|
+
</SafeAreaView>
|
|
324
|
+
</Modal>
|
|
325
|
+
);
|
|
326
|
+
}
|
|
455
327
|
}
|
|
456
328
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
},
|
|
465
|
-
welcome: {
|
|
466
|
-
fontSize: 20,
|
|
467
|
-
textAlign: 'center',
|
|
468
|
-
margin: 10,
|
|
469
|
-
},
|
|
470
|
-
// Flex to fill, position absolute,
|
|
471
|
-
// Fixed left/top, and the width set to the window width
|
|
472
|
-
overlay: {
|
|
473
|
-
width: 25,
|
|
474
|
-
height: 25,
|
|
475
|
-
right: 5,
|
|
476
|
-
alignSelf: 'flex-end'
|
|
477
|
-
}
|
|
329
|
+
const styles = StyleSheet.create({
|
|
330
|
+
overlay: {
|
|
331
|
+
width: 25,
|
|
332
|
+
height: 25,
|
|
333
|
+
right: 5,
|
|
334
|
+
alignSelf: 'flex-end',
|
|
335
|
+
},
|
|
478
336
|
});
|
|
479
|
-
|