sunra/turbosms-soapgate-client-php
PHP client library to connect to TurboSMS.ua via its SOAP gateway. Create a Turbosms\Soap\Client with login, password, and sender ID to send SMS through the TurboSMS SOAP API.
Installation Add the package via Composer:
composer require sunra/turbosms-soapgate-client-php
Basic Initialization Import the client and initialize with your TurboSMS credentials:
use Sunra\PhpSimple\SoapClient;
$client = new SoapClient('https://soap.turbosms.ua/soapgate.asmx?WSDL', [
'trace' => 1,
'exceptions' => true,
'login' => 'YOUR_TURBOSMS_LOGIN',
'password' => 'YOUR_TURBOSMS_PASSWORD',
]);
First Use Case: Sending an SMS
Call the SendSMS method with required parameters:
$response = $client->SendSMS([
'Phone' => '380661234567',
'Message' => 'Hello from Laravel!',
'Sender' => 'YourBrand',
]);
Sending Bulk SMS Loop through recipients and batch requests (avoid rate limits):
$recipients = ['380661234567', '380661234568'];
foreach ($recipients as $phone) {
$client->SendSMS(['Phone' => $phone, 'Message' => 'Bulk message']);
}
Handling Responses Parse SOAP responses (e.g., check for errors):
try {
$response = $client->SendSMS([...]);
if ($response->SendSMSResult === 'OK') {
Log::info('SMS sent successfully');
}
} catch (\SoapFault $fault) {
Log::error('SOAP Error: ' . $fault->getMessage());
}
Integration with Laravel Queues Dispatch a job for async SMS sending:
// In a job class
public function handle() {
$client = new SoapClient(...);
$client->SendSMS([...]);
}
Retrieving Balance Check remaining credits:
$balance = $client->GetBalance();
.env:
TURBOSMS_LOGIN=your_login
TURBOSMS_PASSWORD=your_password
// app/Providers/TurboSmsServiceProvider.php
public function register() {
$this->app->singleton('turbosms', function () {
return new SoapClient('https://soap.turbosms.ua/soapgate.asmx?WSDL', [
'login' => env('TURBOSMS_LOGIN'),
'password' => env('TURBOSMS_PASSWORD'),
]);
});
}
SOAP Fault Handling
\SoapFault on errors. Always wrap calls in try-catch.SOAP-ERROR: Encoding: Could not serialize parameters.Character Limits
$message = str_split('Your long message...', 70);
foreach ($message as $part) {
$client->SendSMS(['Phone' => $phone, 'Message' => $part]);
}
Rate Limits
sleep(1); // 1-second delay between requests
Deprecated Methods
$client = new SoapClient(..., ['trace' => 1]);
$lastRequest = $client->__getLastRequest();
$lastResponse = $client->__getLastResponse();
Sender format must match ^[A-Za-z0-9]{1,11}$).Custom Response Parsing Override the client to normalize responses:
$response = $client->SendSMS([...]);
$result = $response->SendSMSResult === 'OK' ? true : false;
Retry Logic Implement exponential backoff for failed requests:
$attempts = 0;
while ($attempts < 3) {
try {
$client->SendSMS([...]);
break;
} catch (\SoapFault $e) {
$attempts++;
sleep(2 ** $attempts);
}
}
Mocking for Tests
Use PHP’s SoapClient mocking or a wrapper:
// In tests
$mock = $this->getMockBuilder('SoapClient')
->disableOriginalConstructor()
->onlyMethods(['SendSMS'])
->getMock();
$mock->method('SendSMS')->willReturn(new stdClass());
How can I help you explore Laravel packages today?