* 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:
Vasilij Dusko 2021-04-04 10:48:58 +03:00
parent 178d9c2a5a
commit 9a832ef595

View File

@ -26,7 +26,7 @@ use Symfony\Contracts\HttpClient\HttpClientInterface;
*/
final class LightSmsTransport extends AbstractTransport
{
protected const HOST = 'lightsms.com';
protected const HOST = 'www.lightsms.com';
private $login;
private $password;
@ -72,6 +72,7 @@ final class LightSmsTransport extends AbstractTransport
37 => 'Base Id is not set',
38 => 'Phone number already exists 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)
@ -119,27 +120,29 @@ final class LightSmsTransport extends AbstractTransport
$content = $response->toArray(false);
// it happens if the host without www
if (isset($content['']) && isset($content['']['error'])) {
throw new TransportException('Unable to send the SMS: '.self::ERROR_CODES[$content['']['error']], $response);
if (isset($content['']['error'])) {
throw new TransportException('Unable to send the SMS: '.$this->getErrorMsg($content['']['error']), $response);
}
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());
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']) {
$sentMessage = new SentMessage($message, (string) $this);
$sentMessage->setMessageId($content[$phone]['id_sms']);
}
return $sentMessage;
}
throw new TransportException('Unable to send the SMS: ', $response);
}
private function generateSignature(array $data, int $timestamp): string
{
$params = [
@ -160,4 +163,9 @@ final class LightSmsTransport extends AbstractTransport
{
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];
}
}