This repository has been archived by the owner on Nov 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
App.js
112 lines (105 loc) · 2.8 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
NativeModules,
Button
} from 'react-native';
export default class App extends Component<{}> {
constructor(props) {
super(props)
this.state = {
title: "Welcome to Onfido SDK!",
subtitle: "To get started, press \"Launch\""
}
this.token = "YOUR_TOKEN"
}
setTextContent(titleContent, subtitleContent) {
this.setState({
title: titleContent,
subtitle: subtitleContent
})
}
launchSDK = () => {
this.createApplicant((applicantId) => {
NativeModules.OnfidoSDK.startSDK(
this.token,
applicantId,
() => { this.setTextContent("Verification complete", "To perform another verification, press \"Launch\"") },
(errorCause) => {
if (errorCause == "USER_LEFT_ACTIVITY") {
this.setTextContent("Flow cancelled", "To try again, press \"Launch\"")
} else {
this.setTextContent("Flow not finished", "To try again, press \"Launch\"")
}
}
);
})
}
// we recommend to create applicant in your backend server. The code below is demo a working integration of the Onfido Mobile SDK's
createApplicant = (callback) => {
let applicant = {
first_name: 'Jane',
last_name: 'Doe'
}
fetch('https://api.onfido.com/v2/applicants', {
method: 'POST',
headers: {
'Authorization': "Token token="+this.token,
'Content-Type': 'application/json'
},
body: JSON.stringify(applicant)
})
.then((response) => {
if (response.ok) {
response.json().then((responseJson) => {
let applicantId = responseJson.id
console.log(applicantId)
callback(applicantId)
})
} else {
this.setTextContent("Unable to create applicant", "Applicant Id is required to initiate SDK flow. Check your internet connection or token. To try again, press \"Launch\"")
}
})
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
{this.state.title}
</Text>
<Text style={styles.instructions}>
{this.state.subtitle}
</Text>
<Button onPress={this.launchSDK}
title="Launch"
color="#159375"/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 10,
},
});