CalloutVerification Class
Provides Verification using Callout.
Note: Do not instantiate Verification, rather use the createCalloutVerification() method in SinchClient. See the example below.
Constructor
CalloutVerification
-
sinch
-
number
-
[custom]
Parameters:
-
sinch
SinchClientThe parent object
-
number
StringThe phone number to verify
-
[custom]
String optionalCustom string to pass to your backend through callback. Useful for identifying user session, or similar. Max size is 4 kbyte.
Example:
// Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createCalloutVerification('+46123456789'); // Verification to telephone +46123456789
// Initiate verification, using promises
verification.initiate().then(function() {
// Handle successful verification
}).fail(function(error) {
// Handle failed verification
});
Methods
initiate
-
success
-
fail
Initiate verification by callout to the phone number provided earlier. Returns promise which is resolved when verified or failed.
Parameters:
-
success
FunctionOptional success callback, method also returns a promise for chaining
-
fail
FunctionOptional fail callback, method also returns a promise for chaining
Returns:
promise Promise which resolves when verified, fail resolves with VerificationError
Example:
To be written..
initiate
-
success
-
fail
Initiate verification by callout to the phone number provided earlier. Returns promise which is resolved when verified or failed.
Parameters:
-
success
FunctionOptional success callback, method also returns a promise for chaining
-
fail
FunctionOptional fail callback, method also returns a promise for chaining
Returns:
promise Promise which resolves when verified, fail resolves with VerificationError
Example:
To be written..
verify
-
code
-
success
-
fail
Verify a code retrieved over a secondary channel. Pass in code, success and fail callbacks, or rely on promises.
Note: The code for a particular verification session can only attempt verification at most five times.
Parameters:
-
code
StringMandatory code to verify, this code should have been retrieved from the user (who got it through SMS)
-
success
FunctionOptional success callback, method also returns a promise for chaining
-
fail
FunctionOptional fail callback, method also returns a promise for chaining
Returns:
promise Promise which resolves when verified, fail resolves with VerificationError
Example:
//Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createSmsVerification(+46123456789); // Verification to telephone +46123456789
//Send a verification code
verification.initiate().then(function() {
//Ask user to enter secret CODE
}).fail(function(error) {
//Infom user of error sending SMS (more info in error.message)
});
//Verification of code
verification.verify(CODE).then(function() {
//Perform action on successful verification
}).fail(function(error) {
//Perform action on unsuccessful verification
});