Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Including parameter locale to set the phone verification message.
Browse files Browse the repository at this point in the history
Phone verification starts now supports an optional fourth parameter to
set the locale of the message (english by default). Also the
documentation was updated.
  • Loading branch information
serargz committed Oct 20, 2015
1 parent 35e00bd commit e3a8b2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -114,6 +114,13 @@ In order to start a phone verification, we ask the API to send a token to the us

$authy_api->phoneVerificationStart('111-111-1111', '1', 'sms');

Optionally you can specify the language that you prefer the phone verification message to be sent. Supported
languages include: English (`en`), Spanish (`es`), Portuguese (`pt`), German (`de`), French (`fr`) and
Italian (`it`). If not specified, English will be used.

$authy_api->phoneVerificationStart('111-111-1111', '1', 'sms', 'es');
// This will send a message in spanish

### Phone Verification Check

Once you get the verification from user, you can check if it's valid with:
Expand Down
21 changes: 11 additions & 10 deletions lib/Authy/AuthyApi.php
Expand Up @@ -178,13 +178,14 @@ public function userStatus($authy_id)
*
* @return AuthyResponse the server response
*/
public function phoneVerificationStart($phone_number, $country_code, $via='sms')
public function phoneVerificationStart($phone_number, $country_code, $via='sms', $locale='en')
{
$resp = $this->rest->post("phones/verification/start", array(
'query' => array(
"phone_number" => $phone_number,
"country_code" => $country_code,
"via" => $via
"via" => $via,
"locale" => $locale
)
));

Expand Down Expand Up @@ -236,26 +237,26 @@ public function phoneInfo($phone_number, $country_code)
private function __getUserAgent()
{
return sprintf(
'AuthyPHP/%s (%s-%s-%s; PHP %s)',
AuthyApi::VERSION,
php_uname('s'),
php_uname('r'),
php_uname('m'),
'AuthyPHP/%s (%s-%s-%s; PHP %s)',
AuthyApi::VERSION,
php_uname('s'),
php_uname('r'),
php_uname('m'),
phpversion()
);
}

private function __validateVerify($token, $authy_id)
private function __validateVerify($token, $authy_id)
{
$this->__validate_digit($token, "Invalid Token. Only digits accepted.");
$this->__validate_digit($authy_id, "Invalid Authy id. Only digits accepted.");
$length = strlen((string)$token);
if( $length < 6 or $length > 10 ) {
throw new AuthyFormatException("Invalid Token. Unexpected length.");
throw new AuthyFormatException("Invalid Token. Unexpected length.");
}
}

private function __validate_digit($var, $message)
private function __validate_digit($var, $message)
{
if( !is_int($var) && !is_numeric($var) ) {
throw new AuthyFormatException($message);
Expand Down

0 comments on commit e3a8b2f

Please sign in to comment.