-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
137 lines (134 loc) · 4.59 KB
/
index.html
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Web SDK test page</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
integrity="sha512-NhSC1YmyruXifcj/KFRWoC561YpHpc5Jtzgvbuzx5VozKpWvQ+4nXhPdFgmx8xqexRcpAglTj9sIBWINXa8x5w=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<h2>Test web SDK</h2>
<div class="flex" style="margin: 0 -30px">
<div class="row">
<p class="explain">
You need the
<a href="https://github.com/tru-ID/dev-server">node server</a> running
to be able to create a real PhoneCheck.
</p>
<div class="box">
<label for="input-phone-number">Mobile number</label>
<input type="text" id="input-phone-number" value="" />
</div>
<div class="box">
<label for="input-server-url">Server url</label>
<input
type="text"
id="input-server-url"
placeholder="https://xxxxxxx.ngrok.io"
value=""
/>
</div>
<div class="box">
<button type="button" id="btn-create-phonecheck">
Create PhoneCheck
</button>
</div>
</div>
<div class="row">
<p class="explain">
Useful to check the device coverage without the need to run the node
server and create a real PhoneCheck
</p>
<div class="box">
<label for="input-server-url">test check_url</label>
<input
type="text"
id="input-test-url"
value="https://eu.api.tru.id/phone_check/v0.1/checks/123-test-abc/redirect"
/>
</div>
<div class="box">
<button type="button" id="btn-test-check-url">
Test check_url only
</button>
</div>
</div>
</div>
<span id="spinner" class="spinner hidden"></span>
<pre class="box" id="output" />
<script src="/dist/tru-id-sdk.umd.js"></script>
<script>
const btnCreatePhoneCheck = document.getElementById(
'btn-create-phonecheck',
)
const btnTestCheckUrl = document.getElementById('btn-test-check-url')
const inputPhoneNumber = document.getElementById('input-phone-number')
const inputServerUrl = document.getElementById('input-server-url')
const inputTestUrl = document.getElementById('input-test-url')
const output = document.getElementById('output')
const spinner = document.getElementById('spinner')
output.innerHTML = ''
async function createPhoneCheck() {
spinner.classList.remove('hidden')
const phone_number = inputPhoneNumber.value
const serverUrl = inputServerUrl.value
let checkUrl
// CREATE PHONE CHECK
try {
const res = await fetch(`${serverUrl}/phone-check`, {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({
phone_number,
}),
})
const json = await res.json()
output.innerHTML += JSON.stringify(json, null, 2)
if (!res.ok) {
console.error('Error creating phone check')
return
}
checkurl = json.check_url
} catch (err) {
output.innerHTML = 'Error creating phone check'
console.error(err)
}
if (checkUrl) {
try {
await tru.ID.openCheckUrl(checkUrl)
output.innerHTML += 'URL opened\n '
output.innerHTML += JSON.stringify(result, null, 2)
} catch (err) {
console.error('error', err)
output.innerHTML += err.message + '\n'
}
}
spinner.classList.add('hidden')
}
async function checkUrlOnly() {
spinner.classList.remove('hidden')
const testUrl = inputTestUrl.value
try {
await tru.ID.openCheckUrl(testUrl)
output.innerHTML += 'URL opened\n '
output.innerHTML += JSON.stringify(result, null, 2)
} catch (err) {
output.innerHTML += err.message + '\n'
}
spinner.classList.add('hidden')
}
btnCreatePhoneCheck.addEventListener('click', createPhoneCheck)
btnTestCheckUrl.addEventListener('click', checkUrlOnly)
</script>
</body>
</html>