PHP code example of varaai / varasms

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

    

varaai / varasms example snippets


use VaraSMS\Laravel\Facades\VaraSMS;

// Basic usage
$response = VaraSMS::sendSMS('255738234345', 'Hello World!');

// With custom sender ID and reference
$response = VaraSMS::sendSMS(
    '255738234345',
    'Hello World!',
    'MYSENDER',
    'ref123'
);

use VaraSMS\Laravel\Facades\VaraSMS;

$messages = [
    [
        'to' => '255738234345',
        'message' => 'Hello User 1!',
        'reference' => 'ref1'
    ],
    [
        'to' => '255738234346',
        'message' => 'Hello User 2!',
        'reference' => 'ref2'
    ]
];

$response = VaraSMS::sendBulkSMS($messages);

use VaraSMS\Laravel\Facades\VaraSMS;

$balance = VaraSMS::getBalance();

use VaraSMS\Laravel\Facades\VaraSMS;

$response = VaraSMS::rechargeCustomer('[email protected]', 5000);

use VaraSMS\Laravel\Facades\VaraSMS;

$response = VaraSMS::deductCustomer('[email protected]', 2000);

[
    'success' => true,
    'message' => 'Message sent successfully',
    'reference' => 'ref123'
]

[
    'sms_balance' => 5000
]

[
    'success' => true,
    'status' => 200,
    'message' => 'Transaction completed successfully',
    'result' => [
        'Customer' => '[email protected]',
        'Sms transferred' => 5000,
        'Your sms balance' => 450000
    ]
]

try {
    $response = VaraSMS::sendSMS('255738234345', 'Hello World!');
} catch (\Exception $e) {
    // Handle the error
    Log::error('SMS sending failed: ' . $e->getMessage());
}

use VaraSMS\Laravel\Facades\VaraSMS;

class YourTest extends TestCase
{
    public function test_sends_sms()
    {
        VaraSMS::shouldReceive('sendSMS')
            ->once()
            ->with('255738234345', 'Test message')
            ->andReturn([
                'success' => true,
                'message' => 'Message sent successfully'
            ]);

        // Your test code here
    }
}
bash
php artisan vendor:publish --provider="VaraSMS\Laravel\VaraSMSServiceProvider"