26
26
*/
27
27
final class LightSmsTransport extends AbstractTransport
28
28
{
29
- protected const HOST = 'lightsms.com ' ;
29
+ protected const HOST = 'www. lightsms.com ' ;
30
30
31
31
private $ login ;
32
32
private $ password ;
@@ -72,6 +72,7 @@ final class LightSmsTransport extends AbstractTransport
72
72
37 => 'Base Id is not set ' ,
73
73
38 => 'Phone number already exists in this database ' ,
74
74
39 => 'Phone number does not exist in this database ' ,
75
+ 999 => 'Unknown Error ' ,
75
76
];
76
77
77
78
public function __construct (string $ login , string $ password , string $ from , HttpClientInterface $ client = null , EventDispatcherInterface $ dispatcher = null )
@@ -119,25 +120,27 @@ protected function doSend(MessageInterface $message): SentMessage
119
120
$ content = $ response ->toArray (false );
120
121
121
122
// it happens if the host without www
122
- if (isset ($ content ['' ]) && isset ( $ content [ '' ] ['error ' ])) {
123
- throw new TransportException ('Unable to send the SMS: ' .self :: ERROR_CODES [ $ content ['' ]['error ' ]] , $ response );
123
+ if (isset ($ content ['' ]['error ' ])) {
124
+ throw new TransportException ('Unable to send the SMS: ' .$ this -> getErrorMsg ( $ content ['' ]['error ' ]) , $ response );
124
125
}
125
126
126
127
if (isset ($ content ['error ' ])) {
127
- throw new TransportException ('Unable to send the SMS: ' .self :: ERROR_CODES [ $ content ['error ' ]] , $ response );
128
+ throw new TransportException ('Unable to send the SMS: ' .$ this -> getErrorMsg ( $ content ['error ' ]) , $ response );
128
129
}
129
130
130
131
$ phone = $ this ->escapePhoneNumber ($ message ->getPhone ());
131
132
if (32 === $ content [$ phone ]['error ' ]) {
132
- throw new TransportException ('Unable to send the SMS: ' .self :: ERROR_CODES [ $ content ['error ' ]] , $ response );
133
+ throw new TransportException ('Unable to send the SMS: ' .$ this -> getErrorMsg ( $ content [$ phone ][ 'error ' ]) , $ response );
133
134
}
134
135
135
136
if (0 == $ content [$ phone ]['error ' ]) {
136
137
$ sentMessage = new SentMessage ($ message , (string ) $ this );
137
138
$ sentMessage ->setMessageId ($ content [$ phone ]['id_sms ' ]);
139
+
140
+ return $ sentMessage ;
138
141
}
139
142
140
- return $ sentMessage ;
143
+ throw new TransportException ( ' Unable to send the SMS: ' , $ response ) ;
141
144
}
142
145
143
146
private function generateSignature (array $ data , int $ timestamp ): string
@@ -160,4 +163,9 @@ private function escapePhoneNumber(string $phoneNumber): string
160
163
{
161
164
return str_replace ('+ ' , '00 ' , $ phoneNumber );
162
165
}
166
+
167
+ private function getErrorMsg (string $ errorCode ): string
168
+ {
169
+ return isset (self ::ERROR_CODES [$ errorCode ]) ? self ::ERROR_CODES [$ errorCode ] : self ::ERROR_CODES [999 ];
170
+ }
163
171
}
0 commit comments