1. Go to this page and download the library: Download mizbanha/laravel-sms 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/ */
use Mizbanha\Sms\Models\SmsGateway;
SmsGateway::create([
'key' => 'kavenegar-main',
'label' => 'Kavenegar',
'driver' => 'kavenegar', // a key of config('laravel-sms.drivers')
'sender' => '30001234',
'priority' => 10, // lower goes first
])->forceFill([
'credentials' => ['api_key' => '...'], // encrypted at rest
'is_enabled' => true, // gateways are created disabled
])->save();
use Mizbanha\Sms\Enums\CountryPolicy;
// Everywhere. The default; a gateway that ignores this behaves as it always did.
$gateway->country_policy = CountryPolicy::All;
// Only these countries.
$gateway->country_policy = CountryPolicy::Allow;
$gateway->countries = ['IR'];
// Everywhere except these. Twilio, for instance, documents that it does not
// deliver to Iran, Syria or Cuba.
$gateway->country_policy = CountryPolicy::Deny;
$gateway->countries = ['IR', 'SY', 'CU'];
use Mizbanha\Sms\Enums\DeliveryMode;
use Mizbanha\Sms\Models\SmsTemplate;
use Mizbanha\Sms\Models\SmsTemplateGateway;
$template = SmsTemplate::create([
'key' => 'order-created',
'name' => 'Order created',
'body' => 'Hi {customer_name}, order {order_number} for {total} is placed.',
]);
SmsTemplateGateway::create([
'sms_template_id' => $template->id,
'sms_gateway_id' => $kavenegar->id,
'mode' => DeliveryMode::Pattern,
'pattern_code' => 'order-created', // what THIS provider calls it
// The parameters IN ORDER. Kavenegar numbers rather than names them, so the
// position of an entry is what decides which token a value becomes.
'parameter_map' => [
['provider' => 'token', 'variable' => 'customer_name'],
['provider' => 'token2', 'variable' => 'order_number'],
['provider' => 'token3', 'variable' => 'total'],
],
]);
SmsTemplateGateway::create([
'sms_template_id' => $template->id,
'sms_gateway_id' => $smsir->id,
'mode' => DeliveryMode::Pattern,
'pattern_code' => '100200',
// The same message at a provider that names its parameters instead.
'parameter_map' => [
['provider' => 'CUSTOMER', 'variable' => 'customer_name'],
['provider' => 'ORDER_NO', 'variable' => 'order_number'],
['provider' => 'AMOUNT', 'variable' => 'total'],
],
]);
use Mizbanha\Sms\Facades\Otp;
use Mizbanha\Sms\Otp\OtpStatus;
$result = Otp::send($phone, 'login-otp');
match ($result->status) {
OtpStatus::Sent => 'ask for the code',
OtpStatus::Cooldown => "wait {$result->retryAfter}s",
OtpStatus::Unknown => 'it may have arrived; ask for the code',
OtpStatus::Failed => 'try again',
OtpStatus::Suppressed => 'sending is off in this environment',
};
// The third argument is the PURPOSE, which defaults to the template key on send.
if (Otp::verify($phone, $typed, 'login-otp')) {
// your application decides what that means
}
use Mizbanha\Sms\Facades\Sms;
Sms::to('09121234567')
->template('order-created')
->with([
'customer_name' => 'Amid',
'order_number' => 'CF-1204',
'total' => '1,850,000',
])
->about($order) // optional context, recorded and never interpreted
->queue(); // or ->send() to deliver during this request
Sms::to('09121234567')
->template('connectivity-check')
->with(['customer_name' => 'Amid'])
->viaGateway('kavenegar-main') // a gateway key, or an SmsGateway
->send();
use Mizbanha\Sms\Enums\RoutingStrategy;
use Mizbanha\Sms\Models\SmsTemplate;
// A login code should start at the most reliable line, every single time.
SmsTemplate::where('key', 'login-otp')->first()
->update(['routing_strategy' => RoutingStrategy::Priority]);
// Order notifications are ordinary traffic worth spreading over the accounts
// you are paying for either way.
SmsTemplate::where('key', 'order-created')->first()
->update(['routing_strategy' => RoutingStrategy::WeightedRoundRobin]);
$breaker = app(Mizbanha\Sms\Health\CircuitBreaker::class);
$breaker->status($gateway); // state (closed|open|half_open), failures, openUntil
$breaker->reset($gateway); // clears the observation - and nothing else
Sms::refreshDelivery($message); // or an SmsAttempt, when you know which handover
$message->delivery_status; // null | pending | sent | delivered | failed | unknown
$message->delivery_confirmed_at; // when WE learned it arrived - not the handset's clock
$gateway->forceFill([
'credentials' => ['api_key' => '...'], // sent as a bare Authorization header
'options' => ['url' => 'https://api.another-host.example/v1'],
])->save();
SmsGateway::create([
'key' => 'iranpayamak',
'label' => 'IranPayamak',
'driver' => 'iranpayamak',
'sender' => '2191307530', // -> line_number, digits only
'priority' => 90,
])->forceFill([
'credentials' => ['api_key' => '...'], // sent as the Api-Key header
'is_enabled' => true,
])->save();