PHP code example of tookantech / chapaar

1. Go to this page and download the library: Download tookantech/chapaar 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/ */

    

tookantech / chapaar example snippets


return [
    'default' => env('CHAPAAR_DRIVER', 'kavenegar'),

    'drivers' => [
        'kavenegar' => [
            'url' => 'https://api.kavenegar.com/v1/',
            'api_key' => '',
            'line_number' => ''
        ],
        'smsir' => [
            'url' => 'https://api.sms.ir/v1/',
            'api_key' => '',
            'line_number' => '',
        ],
        'ghasedak' => [
            'url'         => 'https://api.ghasedak.me/v2/',
            'api_key'     => '',
            'line_number' => '',
        ],
    ],
];


use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;

$message = (new SmsMessage())->driver()
    ->setFrom('12345678')
    ->setTo('0912111111')
    ->setContent('Hello, this is a test message.');

$response = Chapaar::send($message);


use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;

#Kavenegar
$message =(new SmsMessage())
    ->driver()
    ->setTemplate("invoice-paid")
    ->setTo('09121111111')
    ->setTokens([
        '123', // token
        '456', // token2
        '789', // token3
        '111', // token10, with 4 space
        '222', // token20, with 8 space
    ]);
    
# SmsIr
$message =(new SmsMessage())
    ->driver()
    ->setTemplate('invoice-paid')
    ->setTo('09121111111')
    ->setTokens([
        'code' => '123' // 'variable_name' => 'value'
    ]);
    
# Ghasedak
$message =(new SmsMessage())
    ->driver()
    ->setTemplate("invoice-paid")
    ->setTo('09121111111')
    ->setTokens([
        'test1', // param1
        'test2'  // param2
    ]);

$response = Chapaar::verify($message);


use TookanTech\Chapaar\Facades\Chapaar;
use TookanTech\Chapaar\SmsMessage;
use TookanTech\Chapaar\Enums\Drivers;

$message = (new SmsMessage())
    ->driver(Drivers::SMSIR)
    ->setFrom('12345678')
    ->setTo('0912111111')
    ->setContent('Hello, this is a test message.');

$response = Chapaar::send($message);


$response = Chapaar::outbox(100);

use TookanTech\Chapaar\SmsChannel;
class InvoicePaid extends KavenegarBaseNotification
{
    public function via($notifiable): array
    {
        return [SmsChannel::class];
    }
    public function toSms($notifiable)
    {
        return (new SmsMessage)->driver()
        ->setTemplate('verify')
        ->setTokens([123],[456])
    }
}

class User extends Authenticatable
{
    use Notifiable;

    public function routeNotificationForSms($driver, $notification = null)
    {
        return $this->mobile;
    }

}
bash
php artisan vendor:publish --tag="chapaar-config"