* LightSmsTransport.php - via mistake removed www which return (Closing direction to the user). Removed additional isset which in reality not needed. Added new method which allow to return "unknown error" and throw exception if not successfully
This commit is contained in:
parent
178d9c2a5a
commit
9a832ef595
@ -26,7 +26,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|||||||
*/
|
*/
|
||||||
final class LightSmsTransport extends AbstractTransport
|
final class LightSmsTransport extends AbstractTransport
|
||||||
{
|
{
|
||||||
protected const HOST = 'lightsms.com';
|
protected const HOST = 'www.lightsms.com';
|
||||||
|
|
||||||
private $login;
|
private $login;
|
||||||
private $password;
|
private $password;
|
||||||
@ -72,6 +72,7 @@ final class LightSmsTransport extends AbstractTransport
|
|||||||
37 => 'Base Id is not set',
|
37 => 'Base Id is not set',
|
||||||
38 => 'Phone number already exists in this database',
|
38 => 'Phone number already exists in this database',
|
||||||
39 => 'Phone number does not exist in this database',
|
39 => 'Phone number does not exist in this database',
|
||||||
|
999 => 'Unknown Error',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
|
public function __construct(string $login, string $password, string $from, HttpClientInterface $client = null, EventDispatcherInterface $dispatcher = null)
|
||||||
@ -119,27 +120,29 @@ final class LightSmsTransport extends AbstractTransport
|
|||||||
$content = $response->toArray(false);
|
$content = $response->toArray(false);
|
||||||
|
|
||||||
// it happens if the host without www
|
// it happens if the host without www
|
||||||
if (isset($content['']) && isset($content['']['error'])) {
|
if (isset($content['']['error'])) {
|
||||||
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response);
|
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['']['error']), $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($content['error'])) {
|
if (isset($content['error'])) {
|
||||||
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response);
|
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['error']), $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
$phone = $this->escapePhoneNumber($message->getPhone());
|
$phone = $this->escapePhoneNumber($message->getPhone());
|
||||||
if (32 === $content[$phone]['error']) {
|
if (32 === $content[$phone]['error']) {
|
||||||
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['error']], $response);
|
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content[$phone]['error']), $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == $content[$phone]['error']) {
|
if (0 == $content[$phone]['error']) {
|
||||||
$sentMessage = new SentMessage($message, (string) $this);
|
$sentMessage = new SentMessage($message, (string) $this);
|
||||||
$sentMessage->setMessageId($content[$phone]['id_sms']);
|
$sentMessage->setMessageId($content[$phone]['id_sms']);
|
||||||
}
|
|
||||||
|
|
||||||
return $sentMessage;
|
return $sentMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new TransportException('Unable to send the SMS: ', $response);
|
||||||
|
}
|
||||||
|
|
||||||
private function generateSignature(array $data, int $timestamp): string
|
private function generateSignature(array $data, int $timestamp): string
|
||||||
{
|
{
|
||||||
$params = [
|
$params = [
|
||||||
@ -160,4 +163,9 @@ final class LightSmsTransport extends AbstractTransport
|
|||||||
{
|
{
|
||||||
return str_replace('+', '00', $phoneNumber);
|
return str_replace('+', '00', $phoneNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getErrorMsg(string $errorCode): string
|
||||||
|
{
|
||||||
|
return isset(self::ERROR_CODES[$errorCode]) ? self::ERROR_CODES[$errorCode] : self::ERROR_CODES[999];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user