aybimyazilim/dataport-sms-notification

DataPort SMS notification channel for Laravel

Installs: 29

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/aybimyazilim/dataport-sms-notification

v1.0.0 2025-09-11 06:19 UTC

This package is not auto-updated.

Last update: 2025-12-19 09:32:33 UTC


README

Bu paket, Laravel uygulamalarında DataPort SMS servisi üzerinden SMS gönderimi için notification channel sağlar.

✨ Özellikler

  • ✅ Kapsamlı hata yakalama ve handling
  • ✅ Detaylı SMS gönderim logları
  • ✅ Veritabanı tabanlı SMS takibi
  • ✅ İstatistik ve raporlama
  • ✅ Otomatik retry mekanizması
  • ✅ Rate limiting desteği
  • ✅ Telefon numarası validasyonu
  • ✅ Queue desteği
  • ✅ Artisan komutları
  • ✅ Comprehensive testing

🚀 Kurulum

Composer ile paketi yükleyin:

composer require AybimYazilim/dataport-sms-notification

Konfigürasyon dosyasını yayınlayın:

php artisan vendor:publish --tag=dataport-sms-config

Migration'ları Yayınlayın ve Çalıştırın

php artisan vendor:publish --tag=dataport-sms-migrations
php artisan migrate

⚙️ Konfigürasyon

.env dosyanıza DataPort SMS bilgilerinizi ekleyin:

DATAPORT_SMS_USERNAME=your_username
DATAPORT_SMS_PASSWORD=your_password
DATAPORT_SMS_SCOPE=your_scope
DATAPORT_SMS_ORIGINATOR="YOUR COMPANY"
DATAPORT_SMS_SHORT_NUMBER=5967
DATAPORT_SMS_TIMEOUT=120
DATAPORT_SMS_MAX_MESSAGE_LENGTH=1000

Kullanım

Basit Notification

<?php

namespace App\Notifications;

use AybimYazilim\DataPortSms\Notifications\DataPortSmsNotification;

class OrderConfirmation extends DataPortSmsNotification
{
    private $order;

    public function __construct($order)
    {
        $this->order = $order;
    }

    public function toDataPortSms($notifiable): array
    {
        return [
            'text' => "Siparişiniz #{$this->order->id} onaylandı!",
            'phone' => $notifiable->phone, // Opsiyonel
        ];
    }
}
<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class OrderConfirmation extends Notification implements ShouldQueue
{
    use Queueable;

    private $order;

    public function __construct($order)
    {
        $this->order = $order;
    }

    public function via($notifiable)
    {
        return ['dataport-sms'];
    }

    public function toDataPortSms($notifiable): array
    {
        return [
            'text' => "Siparişiniz #{$this->order->id} onaylandı! Toplam: {$this->order->total}",
            'phone' => $notifiable->phone, // Opsiyonel
        ];
    }
}

Notification Gönderme

// User model üzerinden
$user = User::find(1);
$user->notify(new OrderConfirmation($order));

// Notification facade ile
use Illuminate\Support\Facades\Notification;

Notification::send($users, new OrderConfirmation($order));

// Belirli bir telefon numarasına
Notification::route('dataport-sms', '905551234567')
    ->notify(new OrderConfirmation($order));

Model Konfigürasyonu

User modelinizde telefon numarası için routing tanımlayabilirsiniz:

class User extends Authenticatable
{
    // Telefon numarası için özel routing
    public function routeNotificationForDataPortSms()
    {
        return $this->phone_number;
    }
    
    // Veya telefon alanı için accessor
    public function getPhoneAttribute()
    {
        return $this->mobile ?? $this->telephone;
    }

    // SMS loglarına erişim
    public function smsLogs()
    {
        return $this->morphMany(SmsLog::class, 'notifiable');
    }
}

Message Builder Kullanımı

use AybimYazilim\DataPortSms\Messages\DataPortSmsMessage;

public function toDataPortSms($notifiable): array
{
    return (new DataPortSmsMessage('Mesaj içeriği'))
        ->to('905551234567')
        ->toArray();
}

Queue Kullanımı

Notification sınıfınız otomatik olarak queue edilir:

// Queue konfigürasyonu
public function __construct($order)
{
    $this->order = $order;
    $this->onQueue('sms'); // Özel queue
    $this->delay(now()->addMinutes(5)); // Gecikme
}

Test Etme

Artisan komutu ile SMS test edebilirsiniz:

php artisan dataport:test-sms 905551234567 "Test mesajı"

Unit Tests

use AybimYazilim\DataPortSms\Tests\TestCase;
use Illuminate\Support\Facades\Http;

class MyNotificationTest extends TestCase
{
    /** @test */
    public function it_sends_sms_notification()
    {
        Http::fake([
            'api.dataport.com.tr/*' => Http::response(['success' => true])
        ]);

        $user = new User(['phone' => '905551234567']);
        $user->notify(new MyNotification());

        Http::assertSent(function ($request) {
            return str_contains($request->url(), 'dataport.com.tr');
        });
    }
}

Hata Yakalama

use AybimYazilim\DataPortSms\Exceptions\DataPortSmsException;
use AybimYazilim\DataPortSms\Exceptions\InvalidPhoneNumberException;
use AybimYazilim\DataPortSms\Exceptions\QuotaExceededException;

try {
    $user->notify(new OrderConfirmation($order));
} catch (InvalidPhoneNumberException $e) {
    Log::error('Geçersiz telefon numarası: ' . $e->getMessage());
} catch (QuotaExceededException $e) {
    Log::error('SMS kotası dolmuş: ' . $e->getMessage());
} catch (DataPortSmsException $e) {
    Log::error('SMS gönderilemedi: ' . $e->getMessage());
}

🗃️ SMS Logları

SMS gönderim logları sms_logs tablosunda otomatik olarak kaydedilir:

use AybimYazilim\DataPortSms\Models\SmsLog;

// Başarılı SMS'ler
$successfulSms = SmsLog::successful()->get();

// Başarısız SMS'ler
$failedSms = SmsLog::failed()->get();

// Bekleyen SMS'ler
$pendingSms = SmsLog::pending()->get();

// Belirli bir kullanıcının SMS'leri
$userSms = SmsLog::where('notifiable_type', User::class)
    ->where('notifiable_id', $userId)
    ->get();

Konfigürasyon Seçenekleri

config/dataport-sms.php dosyasındaki seçenekler:

Seçenek Varsayılan Açıklama
username - DataPort kullanıcı adı
password - DataPort şifre
scope - DataPort scope
originator 'LARAVEL' SMS gönderen adı
short_number '5967' Kısa numara
timeout 120 İstek timeout süresi
log_requests true İstekleri logla
log_responses true Cevapları logla

Lisans

Bu paket MIT lisansı altında yayınlanmıştır.

Changelog

v2.0.0

  • ✅ Kapsamlı hata yakalama sistemi
  • ✅ Detaylı SMS loglama
  • ✅ İstatistik ve raporlama
  • ✅ Artisan komutları
  • ✅ Rate limiting
  • ✅ Retry mekanizması
  • ✅ Gelişmiş validasyon

v1.0.0

  • İlk sürüm
  • DataPort SMS entegrasyonu
  • Laravel notification channel desteği
  • Queue desteği
  • Test komutları