amorebietakoudala/smsservice-bundle
Install the Bundle
composer require amorebietakoudala/smsservice-bundle
Configure .env
Add these to your .env file (Laravel-compatible):
SMS_USERNAME=your_dinasms_username
SMS_PASSWORD=your_dinasms_password
SMS_ACCOUNT=your_account_id
SMS_TEST=false # Set to `true` for testing (no real sends)
SMS_PROVIDER=dinasms # Options: dinasms, acumbamail, smspubli
Verify Installation
/smsBundle/ to check remaining credits.First SMS Send (Symfony Route) Use the bundle’s built-in route (Symfony only):
/smsBundle/send?phone=3412345678&message=Hello
Laravel Workaround: Create a controller to call the service:
use Amorebietakoudala\SMSServiceBundle\Service\SMSService;
public function sendSMS(SMSService $smsService) {
$result = $smsService->send('3412345678', 'Hello');
return response()->json($result);
}
Symfony/Laravel (with Bridge):
// In a controller or command
public function __invoke(SMSService $smsService) {
$response = $smsService->send(
'34600123456', // Recipient phone (format: countrycode+number)
'Your OTP is 12345'
);
return $response->getStatusCode() === 200;
}
Laravel (Manual Binding):
Bind the Symfony service to Laravel’s container in AppServiceProvider:
$this->app->bind(\Amorebietakoudala\SMSServiceBundle\Service\SMSService::class,
function ($app) {
return new \Amorebietakoudala\SMSServiceBundle\Service\SMSService(
$app['config']['sms.username'],
$app['config']['sms.password'],
$app['config']['sms.provider']
);
}
);
Override default provider settings in config/packages/amorebietakoudala_sms.yaml (Symfony) or config/sms.php (Laravel):
# Symfony config
amorebietakoudala_sms:
providers:
dinasms:
username: '%env(SMS_USERNAME)%'
password: '%env(SMS_PASSWORD)%'
endpoint: 'https://api.dinasms.com/send'
Laravel Equivalent:
// config/sms.php
return [
'providers' => [
'dinasms' => [
'username' => env('SMS_USERNAME'),
'password' => env('SMS_PASSWORD'),
'endpoint' => 'https://api.dinasms.com/send',
],
],
];
SMS_TEST=true in .env to bypass real API calls.SMSService in PHPUnit:
$mock = Mockery::mock(SMSService::class);
$mock->shouldReceive('send')
->once()
->andReturn(new Response(200, [], '{"status":"success"}'));
$this->app->instance(SMSService::class, $mock);
The bundle doesn’t natively support bulk sends. Workaround:
foreach ($phones as $phone) {
$smsService->send($phone, $message);
sleep(1); // Rate limiting
}
Wrap API calls to handle failures:
try {
$response = $smsService->send($phone, $message);
if ($response->getStatusCode() !== 200) {
Log::error('SMS failed', ['error' => $response->getContent()]);
throw new \RuntimeException('SMS delivery failed');
}
} catch (\Exception $e) {
// Retry logic or fallback
}
Queue SMS Jobs Create a job to send SMS asynchronously:
php artisan make:job SendSmsJob
// app/Jobs/SendSmsJob.php
public function handle(SMSService $smsService) {
$smsService->send($this->phone, $this->message);
}
Dispatch in a controller:
SendSmsJob::dispatch('34600123456', 'Your message')->onQueue('sms');
Event-Driven SMS
Trigger SMS on Laravel events (e.g., OrderShipped):
// Listen to event
event(new OrderShipped($order));
// In event listener
SendSmsJob::dispatch($order->customerPhone, 'Order shipped!');
API Resource Wrapper Create a Laravel API resource to standardize SMS responses:
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class SmsResponse extends JsonResource {
public function toArray($request) {
return [
'status' => $this->status,
'message' => $this->message,
'provider' => $this->provider,
];
}
}
If using the Symfony Bridge:
config/bundles.php:
return [
// ...
Amorebietakoudala\SMSServiceBundle\SMSServiceBundle::class => ['all' => true],
];
SMSService in controllers:
use Amorebietakoudala\SMSServiceBundle\Service\SMSService;
public function __construct(private SMSService $smsService) {}
To switch providers dynamically:
// config/sms.php
'default_provider' => env('SMS_PROVIDER', 'dinasms'),
'providers' => [
'dinasms' => [...],
'acumbamail' => [...],
],
class SmsFactory {
public static function create(string $provider) {
return match ($provider) {
'dinasms' => new DinSmsService(...),
'acumbamail' => new AcumbaMailService(...),
default => throw new \InvalidArgumentException('Provider not supported'),
};
}
}
Symfony Dependency Hell
HttpClient, DependencyInjection).spatie/laravel-sms.Provider-Specific Quirks
34600123456 for Spain).YYYY-MM-DD HH:MM).No Native Queue Support
SendSmsJob (see Implementation Patterns).Testing Mode Limitations
SMS_TEST=true only prevents API calls but doesn’t mock responses.MockHttp:
$this->mock(Http::class, function ($mock) {
$mock->shouldReceive('post')
->once()
->andReturn(Http::response('{"status":"success"}', 200));
How can I help you explore Laravel packages today?