PHP code example of sarkhanrasimoghlu / lsim

1. Go to this page and download the library: Download sarkhanrasimoghlu/lsim library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sarkhanrasimoghlu / lsim example snippets


use Sarkhanrasimoghlu\Lsim\Facades\SMS;

$response = SMS::send('994501234567', 'Hello World');

if ($response->isSuccessful()) {
    echo $response->getMessageId(); // transaction ID
}

$response = SMS::send('994501234567', 'Salam dunya', unicode: true);

$response = SMS::getBalance();

if ($response->isSuccessful()) {
    echo $response->getBalance(); // integer
}

$response = SMS::getReport($transactionId);

if ($response->isSuccessful()) {
    echo $response->getStatus()->name; // e.g. "Delivered"
    echo $response->isDelivered();     // true/false
}

use Sarkhanrasimoghlu\Lsim\Contracts\SmsServiceInterface;

class NotificationService
{
    public function __construct(
        private SmsServiceInterface $sms,
    ) {}

    public function notify(string $phone, string $text): bool
    {
        $response = $this->sms->send($phone, $text);
        return $response->isSuccessful();
    }
}

use Sarkhanrasimoghlu\Lsim\Facades\SMS;
use Sarkhanrasimoghlu\Lsim\Exceptions\SmsException;
use Sarkhanrasimoghlu\Lsim\Exceptions\InvalidMessageException;

try {
    $response = SMS::send($phone, $text);

    if ($response->hasError()) {
        $errorCode = $response->getErrorCode(); // ErrorCode enum or null
        $errorMessage = $response->getErrorMessage();
    }
} catch (InvalidMessageException $e) {
    // Invalid phone number or message text
} catch (SmsException $e) {
    // HTTP or other service error
}
bash
php artisan vendor:publish --tag=sms-config