Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
320b6f9158 | |||
![]() |
2e8be09571 | ||
![]() |
542145bd3a | ||
![]() |
7f1e3a3b3c | ||
![]() |
44189876df | ||
![]() |
7cf887418f | ||
![]() |
3d14566889 |
@ -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));
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
||||||
|
2
LICENSE
2
LICENSE
@ -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
|
||||||
|
@ -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');
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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)
|
@ -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).
|
||||||
|
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user