-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathDefault.aspx.cs
executable file
·352 lines (298 loc) · 14 KB
/
Default.aspx.cs
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BlockScoreAPI;
using System.Collections.Generic;
using System.Globalization;
namespace TestBlockScore
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnverifyus_Click(object sender, EventArgs e)
{
VerifyUs();
}
protected void btnverifyinternational_Click(object sender, EventArgs e)
{
VerifyInternational();
}
public void VerifyInternational()
{
//Instantiate new BlockscoreAPI object
BlockscoreAPI blockscore = new BlockscoreAPI();
//Prepare a request for an International ID. For this example sample values are entered
BlockScoreVerifyInternationalRequest blockScoreInternationlRequest = GetBlockScoreInternationalRequest();
//Call Blockscore /verifications and return results
BlockScoreResponse verifyInternationalResult = VerifyInternational(blockscore, blockScoreInternationlRequest);
//Output the request and response values
lblverificationrequest.Text = GetblockscoreInternationalRequestoutput(blockScoreInternationlRequest);
lblverificationresponse.Text = GetblockscoreResponseoutput(verifyInternationalResult);
//Hide the Questions panel as there are no questions for international IDs
pnlquestions.Visible = false;
//Display the verifications panel
pnlverifications.Visible = true;
}
public void VerifyUs()
{
//Instantiate new BlockscoreAPI object
BlockscoreAPI blockscore = new BlockscoreAPI();
//Prepare a request for a Domestic ID. For this example sample values are entered
BlockScoreVerifyDomesticRequest blockScoreDomesticRequest = GetBlockScoreDomesticRequest();
//Call Blockscore /verifications and return results
BlockScoreResponse verifyUsResult = VerifyUs(blockscore, blockScoreDomesticRequest);
//Output the request and response values
lblverificationrequest.Text = GetblockscoreDomesticRequestoutput(blockScoreDomesticRequest);
lblverificationresponse.Text = GetblockscoreResponseoutput(verifyUsResult);
//Display the Questions panel as there are questions for US IDs
pnlquestions.Visible = true;
//Display the verifications panel
pnlverifications.Visible = true;
// Question Set Retrieval
HandleQuestionSet(verifyUsResult, blockscore);
}
/*
* Ouput Domestic ID Verification Request object to a string
*/
private string GetblockscoreDomesticRequestoutput(BlockScoreVerifyDomesticRequest blockscorerequest)
{
string strreturn = "";
strreturn += "LastFourDigitsOfSSN = " + blockscorerequest.LastFourDigitsOfSSN;
strreturn += "<br/>CountryCode = US";
strreturn += "<br/>CitizenshipType = " + blockscorerequest.CitizenshipType;
strreturn += "<br/>FirstName = " + blockscorerequest.FirstName;
strreturn += "<br/>MiddleName = " + blockscorerequest.MiddleName;
strreturn += "<br/>LastName = " + blockscorerequest.LastName;
strreturn += "<br/>DateOfBirth = " + blockscorerequest.DateOfBirth;
strreturn += "<br/>Street1 = " + blockscorerequest.Street1;
strreturn += "<br/>Street2 = " + blockscorerequest.Street2;
strreturn += "<br/>City = " + blockscorerequest.City;
strreturn += "<br/>State = " + blockscorerequest.State;
strreturn += "<br/>PostalCode = " + blockscorerequest.PostalCode;
return strreturn;
}
/*
* Ouput International Verification Request object to a string
*/
private string GetblockscoreInternationalRequestoutput(BlockScoreVerifyInternationalRequest blockscorerequest)
{
string strreturn = "";
strreturn += "Gender = " + blockscorerequest.Gender;
strreturn += "<br/>CountryCode = " + blockscorerequest.CountryCode;
strreturn += "<br/>PassportNumber = " + blockscorerequest.PassportNumber;
strreturn += "<br/>FirstName = " + blockscorerequest.FirstName;
strreturn += "<br/>MiddleName = " + blockscorerequest.MiddleName;
strreturn += "<br/>LastName = " + blockscorerequest.LastName;
strreturn += "<br/>DateOfBirth = " + blockscorerequest.DateOfBirth;
strreturn += "<br/>Street1 = " + blockscorerequest.Street1;
strreturn += "<br/>Street2 = " + blockscorerequest.Street2;
strreturn += "<br/>City = " + blockscorerequest.City;
strreturn += "<br/>State = " + blockscorerequest.State;
strreturn += "<br/>PostalCode = " + blockscorerequest.PostalCode;
return strreturn;
}
/*
* Ouput Blockscore Response object to a string
*/
private string GetblockscoreResponseoutput(BlockScoreResponse blockscoreresponse)
{
string strreturn = "";
strreturn += "<br/>id = " + blockscoreresponse.id;
strreturn += "<br/>verification_id = " + blockscoreresponse.verification_id;
strreturn += "<br/>question_set_id = " + blockscoreresponse.question_set_id;
if (blockscoreresponse.error != null)
{
strreturn += "<br/>error_code = " + blockscoreresponse.error.code;
strreturn += "<br/>error_message = " + blockscoreresponse.error.message;
strreturn += "<br/>error_type = " + blockscoreresponse.error.type;
}
return strreturn;
}
/*
* Ouput Blockscore Questions Response object to a string
*/
private string GetblockscoreQuestionsResponseoutput(BlockScoreQuestionsResponse blockscoreresponse)
{
string strreturn = "";
foreach (Question tempquestion in blockscoreresponse.questions)
{
strreturn += "<br/><br/>Question id: " + tempquestion.id.ToString();;
strreturn += "<br/>question: " + tempquestion.question.ToString();
strreturn += "<br/>Answers: ";
strreturn += "<div class='Tab1'>";
foreach (Answer tempanswer in tempquestion.answers)
{
strreturn += "<br/>id " + tempanswer.answer_id.ToString();
strreturn += "<br/>answer " + tempanswer.answer.ToString();
}
strreturn += "</div>";
}
return strreturn;
}
/*
* Ouput Blockscore Questions Request object to a string
*/
private string GetblockscoreQuestionsRequestoutput(BlockScoreResponse questionset, List<BlockScoreAnswer> answerlist)
{
string strreturn = "";
strreturn += "verification_id = " + questionset.verification_id;
strreturn += "<br/>question_set_id = " + questionset.question_set_id;
strreturn += "<br/>answers : ";
foreach (BlockScoreAnswer tempanswer in answerlist)
{
strreturn += "<div class='Tab1'>";
strreturn += "<br/> answer_id = " + tempanswer.answer_id;
strreturn += "<br/> question_id = " + tempanswer.question_id;
strreturn += "</div>";
}
return strreturn;
}
/*
* Ouput Blockscore Questions Score Response object to a string
*/
private string GetblockscoreQuestionsScoreResponseoutput(BlockScoreQuestionsScoreResponse blockscoreresponse)
{
string strreturn = "";
strreturn += "<br/>question_set_id = " + blockscoreresponse.question_set_id;
strreturn += "<br/>score = " + blockscoreresponse.score;
return strreturn;
}
/*
* Get the questions set from Blockscore
*/
private void HandleQuestionSet(BlockScoreResponse verifyUsResult, BlockscoreAPI blockscore)
{
if (!string.IsNullOrEmpty(verifyUsResult.id))
{
lblquestionrequest.Text = "verification_id = " + verifyUsResult.id.ToString();
BlockScoreQuestionsResponse questionSet = GetQuestionSet(blockscore);
lblquestionresponse.Text = GetblockscoreQuestionsResponseoutput(questionSet);
CheckAnswers(blockscore, questionSet);
}
}
/*
* Verify the Answers with Blockscore
*/
private void CheckAnswers(BlockscoreAPI blockscore, BlockScoreResponse questionSet)
{
if (!string.IsNullOrEmpty(questionSet.question_set_id))
{
try
{
var random = new Random();
List<BlockScoreAnswer> answerlist = new List<BlockScoreAnswer>
{
new BlockScoreAnswer{question_id = "1", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)},
new BlockScoreAnswer{ question_id= "2", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)},
new BlockScoreAnswer{ question_id= "3", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)},
new BlockScoreAnswer{ question_id= "4", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)},
new BlockScoreAnswer{question_id = "5", answer_id= random.Next(1, 5).ToString(CultureInfo.InvariantCulture)},
};
lblquestionscorerequest.Text = GetblockscoreQuestionsRequestoutput(questionSet, answerlist);
BlockScoreQuestionsScoreResponse blockscorequestionscoreresponse = blockscore.CheckQuestionAnswers(answerlist);
lblquestionscoreresponse.Text = GetblockscoreQuestionsScoreResponseoutput(blockscorequestionscoreresponse);
}
catch (Exception e)
{
throw new Exception("Caught exception: " + e.Message + "\n");
}
}
}
/*
* Get the questions set from Blockscore
*/
private static BlockScoreQuestionsResponse GetQuestionSet(BlockscoreAPI blockscore)
{
BlockScoreQuestionsResponse questionSet;
try
{
questionSet = blockscore.QuestionSet();
}
catch (Exception e)
{
throw new Exception("Caught exception: " + e.Message + "\n");
}
return questionSet;
}
/*
* Verify US ID
*/
private static BlockScoreResponse VerifyUs(BlockscoreAPI blockscore,
BlockScoreVerifyDomesticRequest blockScoreVerifyInternationlRequest)
{
BlockScoreResponse verifyUsResult = null;
try
{
verifyUsResult = blockscore.VerifyUs(blockScoreVerifyInternationlRequest);
}
catch (Exception e)
{
throw new Exception("Caught exception: " + e.Message + "\n");
}
return verifyUsResult;
}
/*
* Static values for a Domestic ID
*/
private static BlockScoreVerifyDomesticRequest GetBlockScoreDomesticRequest()
{
var blockScoreInternationlRequest = new BlockScoreVerifyDomesticRequest
{
FirstName = "John",
MiddleName = "W",
LastName = "Smith",
LastFourDigitsOfSSN = "0000",
DateOfBirth = "1980-10-10",
Street1 = "123 Broadway Ave",
Street2 = "",
City = "New York",
State = "NY",
PostalCode = "10011"
};
return blockScoreInternationlRequest;
}
/*
* Verify International ID
*/
private static BlockScoreResponse VerifyInternational(BlockscoreAPI blockscore, BlockScoreVerifyInternationalRequest blockScoreVerifyInternationlRequest)
{
BlockScoreResponse verifyIntlResult;
try
{
verifyIntlResult = blockscore.VerifyIntl(blockScoreVerifyInternationlRequest);
}
catch (Exception e)
{
throw new Exception("Caught exception:" + e.Message);
}
return verifyIntlResult;
}
/*
* Static values for an International ID
*/
private static BlockScoreVerifyInternationalRequest GetBlockScoreInternationalRequest()
{
var blockScoreInternationlRequest = new BlockScoreVerifyInternationalRequest
{
FirstName = "John",
MiddleName = "W",
LastName = "Smith",
Gender = "M",
DateOfBirth = "1980-10-10",
PassportNumber = "X110000",
Street1 = "Bahnhofstrasse 70",
Street2 = "",
City = "Zurich",
State = "ZH",
PostalCode = "8001",
CountryCode = "CH"
};
return blockScoreInternationlRequest;
}
}
}