Skip to content

Commit 663cb8d

Browse files
committed
Merge pull request #7 from illiminable/master
Merge mobile support
2 parents 0a343e7 + 0b4e4b1 commit 663cb8d

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

src/TeleSign.Services.Verify/RawVerifyService.cs

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,33 @@ public string CallRaw(
120120
language);
121121
}
122122

123+
/// <summary>
124+
/// Initiates a PhoneId Push Mobile transaction returning the raw JSON response from
125+
/// the REST API.
126+
/// </summary>
127+
/// <param name="phoneNumber">The phone number to call.</param>
128+
/// <param name="verifyCode">
129+
/// The code to send to the user. When null a code will
130+
/// be generated for you.
131+
/// </param>
132+
/// <param name="language">
133+
/// The language that the message should be in. This parameter is ignored if
134+
/// you supplied a message template.
135+
/// </param>
136+
/// <returns>The raw JSON response from the REST API.</returns>
137+
public string PushRaw(
138+
string phoneNumber,
139+
string verifyCode = null)
140+
{
141+
phoneNumber = this.CleanupPhoneNumber(phoneNumber);
142+
143+
return this.InternalVerify(
144+
VerificationMethod.Push,
145+
phoneNumber,
146+
verifyCode,
147+
"TS2FA");
148+
}
149+
123150
/// <summary>
124151
/// Checks the status of a Verify transaction. When the code is
125152
/// supplied it verifies this code. The response also contains
@@ -242,10 +269,21 @@ private static Dictionary<string, string> ConstructVerifyArgs(
242269

243270
Dictionary<string, string> args = new Dictionary<string, string>();
244271
args.Add("phone_number", phoneNumber);
245-
args.Add("verify_code", verifyCode.ToString());
272+
273+
if (verificationMethod == VerificationMethod.Push)
274+
{
275+
if (!string.IsNullOrEmpty(verifyCode))
276+
{
277+
args.Add("notification_value", verifyCode.ToString());
278+
}
279+
}
280+
else
281+
{
282+
args.Add("verify_code", verifyCode.ToString());
283+
}
246284
args.Add("language", language);
247285

248-
if (verificationMethod == VerificationMethod.Sms)
286+
if (verificationMethod == VerificationMethod.Sms || verificationMethod == VerificationMethod.Push)
249287
{
250288
args.Add("template", messageTemplate);
251289
}

src/TeleSign.Services.Verify/VerifyService.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,44 @@ public VerifyResponse InitiateCall(
211211
}
212212
}
213213

214+
/// <summary>
215+
/// Initiates a TeleSign Verify transaction via a voice call.
216+
/// </summary>
217+
/// <param name="phoneNumber">The phone number to call.</param>
218+
/// <param name="verifyCode">
219+
/// The code to send to the user. When null a code will
220+
/// be generated for you.
221+
/// </param>
222+
/// <param name="language">
223+
/// The language that the message should be in. This parameter is ignored if
224+
/// you supplied a message template.
225+
/// TODO: Details about language string format.
226+
/// </param>
227+
/// <returns>
228+
/// A VerifyResponse object with the status and returned information
229+
/// for the transaction.
230+
/// </returns>
231+
public VerifyResponse InitiatePush(
232+
string phoneNumber,
233+
string verifyCode = null)
234+
{
235+
string rawResponse = this.PushRaw(
236+
phoneNumber,
237+
verifyCode);
238+
239+
try
240+
{
241+
return this.parser.ParseVerifyResponse(rawResponse);
242+
}
243+
catch (Exception x)
244+
{
245+
throw new ResponseParseException(
246+
"Error parsing Verify call response",
247+
rawResponse,
248+
x);
249+
}
250+
}
251+
214252
/// <summary>
215253
/// Validates the code provided by the user. After the code has been
216254
/// sent to the user, they enter the code to your website/application

src/TeleSign.Services/VerificationMethod.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,10 @@ public enum VerificationMethod
2828
/// Verify by sms.
2929
/// </summary>
3030
Sms,
31+
32+
/// <summary>
33+
/// Verify by mobile push.
34+
/// </summary>
35+
Push,
3136
}
3237
}

0 commit comments

Comments
 (0)