Compare commits

...

7 Commits

Author SHA1 Message Date
320b6f9158 Adding 2fa API 2016-01-20 15:14:58 -07:00
javihgil
2e8be09571 Merge pull request #7 from xmontana/master
[FIX] update service name for commands
2015-02-06 08:55:38 +01:00
Xavier Montaña Carreras
542145bd3a [FIX] update service name for commands ISSUE:#2 2015-02-05 09:14:46 +01:00
Javier Hernández Gil
7f1e3a3b3c Update composer.json 2014-06-07 11:57:08 +02:00
Javier Hernández Gil
44189876df Update docblocks 2014-06-06 22:15:45 +02:00
Javi Hernández
7cf887418f Merge pull request #3 from rdubigny/master
improve doc
2014-04-29 20:57:27 +02:00
Raphaël Dubigny
3d14566889 improve doc 2014-04-14 16:36:54 +02:00
10 changed files with 85 additions and 13 deletions

View File

@ -26,7 +26,7 @@ class AccountBalanceCommand extends ContainerAwareCommand
* @see Command * @see Command
*/ */
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
$account = $this->getContainer()->get('jhg_nexmo.account'); $account = $this->getContainer()->get('jhg_nexmo_account');
$balance = $account->balance(); $balance = $account->balance();
$output->writeln(sprintf('Account balance: %f',$balance)); $output->writeln(sprintf('Account balance: %f',$balance));
} }

View File

@ -31,7 +31,7 @@ class SmsPricingCommand extends ContainerAwareCommand
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
$country = $input->getArgument('country'); $country = $input->getArgument('country');
$account = $this->getContainer()->get('jhg_nexmo.account'); $account = $this->getContainer()->get('jhg_nexmo_account');
$price = $account->smsPricing($country); $price = $account->smsPricing($country);
if($price===false) { if($price===false) {

View File

@ -1,6 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2013 javihernandezgil Copyright (c) 2013 Javi H. Gil
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View File

@ -45,6 +45,18 @@ class SmsManager
return SmsSendResponse::createFromResponse($response); return SmsSendResponse::createFromResponse($response);
} }
/**
* @param string $number
* @param string $pin
* @param int $client_ref
* @return SmsSendResponse
*/
public function send2fa($number,$pin,$client_ref=false) {
$number = PhoneNumber::prefixFilter($number);
$response = $this->nexmoClient->send2faMessage($number,$pin,$client_ref);
return SmsSendResponse::createFromResponse($response);
}
public function sendBinary() { public function sendBinary() {
throw new \Exception(__METHOD__.' not yet implemented'); throw new \Exception(__METHOD__.' not yet implemented');
} }

View File

@ -4,7 +4,7 @@ namespace Jhg\NexmoBundle\NexmoClient\Exceptions;
/** /**
* Class NexmoClientException * Class NexmoClientException
* @package Jhg\NexmoBundle\NexmoClient\Exceptions * @package Jhg\NexmoBundle\NexmoClient\Exceptions
* @author Javi Hernández <javibilboweb@gmail.com> * @author Javi H. Gil <javihgil@gmail.com>
*/ */
class NexmoClientException extends \Exception { class NexmoClientException extends \Exception {

View File

@ -4,7 +4,7 @@ namespace Jhg\NexmoBundle\NexmoClient\Exceptions;
/** /**
* Class QuotaExcededException * Class QuotaExcededException
* @package Jhg\NexmoBundle\NexmoClient\Exceptions * @package Jhg\NexmoBundle\NexmoClient\Exceptions
* @author Javi Hernández <javibilboweb@gmail.com> * @author Javi H. Gil <javihgil@gmail.com>
*/ */
class QuotaExcededException extends NexmoClientException { class QuotaExcededException extends NexmoClientException {

View File

@ -107,6 +107,66 @@ class NexmoClient {
return $this->jsonRequest('/account/get-pricing/outbound',array('country'=>$country)); return $this->jsonRequest('/account/get-pricing/outbound',array('country'=>$country));
} }
/**
* Sends a verifiation PIN using the Two-Factor Authentication API
*
* @param string $toNumber
* @param string $pin
* @param int $client_ref
* @return array
* @throws \Exception
*/
public function send2faMessage($toNumber,$pin,$client_ref=false) {
$this->logger->debug("Nexmo send2faMessage to $toNumber with PIN '$pin'");
// delivery phone for development
if($this->delivery_phone) {
$toNumber = $this->delivery_phone;
$this->logger->debug("Nexmo send2faMessage delivery to $toNumber");
}
$params = array(
'to'=>$toNumber,
'pin'=>$pin,
);
if($client_ref) {
$params['client_ref'] = $client_ref;
}
if($this->disable_delivery) {
$this->logger->debug("Nexmo send2faMessage delivery disabled by config");
return array(
"status" => "0",
"message-id" => "delivery-disabled",
"to" => $toNumber,
"client-ref" => 0,
"remaining-balance" => 0,
"message-price" => 0,
"network" => 0,
);
}
$response = $this->jsonRequest('sc/us/2fa/json',$params);
if(0 !== $code = (int)$response['messages'][0]['status']) {
$error = $response['messages'][0]['error-text'];
switch( $code) {
case 6:
throw new UnroutableSmsMessageException($error, $code);
case 9:
throw new QuotaExcededException($error, $code);
default:
throw new NexmoClientException($error, $code);
}
}
return $response['messages'][0];
}
/** /**
* @param string $fromName * @param string $fromName
* @param string $toNumber * @param string $toNumber

View File

@ -10,7 +10,7 @@ For documentation, see:
Resources/doc/ Resources/doc/
[Read the documentation](https://github.com/javihernandezgil/nexmo-bundle/blob/master/Resources/doc/index.md) [Read the documentation](https://github.com/javihgil/nexmo-bundle/blob/master/Resources/doc/index.md)
License License
@ -18,4 +18,4 @@ License
This bundle is under the MIT license: This bundle is under the MIT license:
[LICENSE](https://github.com/javihernandezgil/nexmo-bundle/blob/master/LICENSE) [LICENSE](https://github.com/javihgil/nexmo-bundle/blob/master/LICENSE)

View File

@ -13,12 +13,12 @@ Add this bundle to your `composer.json` file:
"repositories": [ "repositories": [
{ {
"type": "vcs", "type": "vcs",
"url": "https://github.com/javihernandezgil/nexmo-bundle.git" "url": "https://github.com/javihgil/nexmo-bundle.git"
} }
], ],
"require": { "require": {
"javihernandezgil/nexmo-bundle": "dev-master" "javihgil/nexmo-bundle": "dev-master"
} }
} }
@ -65,8 +65,8 @@ Usage
### Send SMS with service ### Send SMS with service
$sender = $this->getContainer()->get('jhg_nexmo.sms.sender'); $sender = $this->getContainer()->get('jhg_nexmo_sms');
$sender->send($number,$fromName,$message); $sender->sendText($number, $message, $fromName);
If no $fromName is provided 'jhg_nexmo.from_name' is used. This from name is limited to 11 characters (spaces and special chars are not allowed). If no $fromName is provided 'jhg_nexmo.from_name' is used. This from name is limited to 11 characters (spaces and special chars are not allowed).

View File

@ -1,5 +1,5 @@
{ {
"name": "javihernandezgil/nexmo-bundle", "name": "javihgil/nexmo-bundle",
"type": "symfony-bundle", "type": "symfony-bundle",
"description": "This bundle integrates Nexmo libs", "description": "This bundle integrates Nexmo libs",
"keywords": ["symfony", "bundle", "nexmo", "sms"], "keywords": ["symfony", "bundle", "nexmo", "sms"],
@ -8,7 +8,7 @@
"authors": [ "authors": [
{ {
"name": "Javi Hernández Gil", "name": "Javi Hernández Gil",
"homepage": "https://github.com/javihernandezgil/nexmo-bundle" "homepage": "https://github.com/javihgil/nexmo-bundle"
} }
], ],