🚀 Hostinger Optimized
🖥️ Server: LiteSpeed
💻 System: Linux s20058.bom1.stableserver.net 5.14.0-611.55.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 19 15:19:29 EDT 2026 x86_64
👤 User: skhata (1324)
🐘 PHP: 8.4.20
🚫 Disabled: ✨ NONE

💻 Terminal

📁 /home/skhata/chandrasons.com/public
$

📄 SparrowSmsChannel.php

📁 Path: /home/skhata/new.chandrapharma.com/app/Modules/Notification/Channels/SparrowSmsChannel.php
📊 Size: 1.84 KB
🔒 Perm: 0644
📝 MIME: text/x-php
<?php

namespace App\Modules\Notification\Channels;

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

/**
 * SparrowSMS Channel — Nepal domestic SMS
 *
 * API: https://api.sparrowsms.com/v2/sms/
 * Env: SPARROW_SMS_TOKEN, SPARROW_SMS_FROM
 *
 * Usage:
 *   SparrowSmsChannel::send('+9779XXXXXXXX', 'Your message here');
 */
class SparrowSmsChannel
{
    private const API_URL = 'https://api.sparrowsms.com/v2/sms/';

    public function send(string $to, string $message): bool
    {
        $token = config('notification.sparrow.token');
        $from  = config('notification.sparrow.from', 'STPStore');

        if (! $token) {
            Log::warning('SparrowSMS: token not configured');
            return false;
        }

        // Normalise number — strip country code prefix if present, re-add +977
        $to = $this->normaliseNepalNumber($to);

        $response = Http::get(self::API_URL, [
            'token'   => $token,
            'from'    => $from,
            'to'      => $to,
            'text'    => $message,
        ]);

        if (! $response->successful() || ($response->json('response_code') ?? 200) >= 300) {
            Log::error('SparrowSMS send failed', [
                'to'       => $to,
                'response' => $response->body(),
            ]);
            return false;
        }

        Log::info('SparrowSMS sent', ['to' => $to]);
        return true;
    }

    private function normaliseNepalNumber(string $phone): string
    {
        // Strip non-digits
        $digits = preg_replace('/\D/', '', $phone);
        // Remove leading 977 country code if present
        if (str_starts_with($digits, '977') && strlen($digits) === 12) {
            $digits = substr($digits, 3);
        }
        // Return with country code for international format
        return '+977' . ltrim($digits, '0');
    }
}
← Back📥 Raw✏️ Edit🔒 Chmod
✨ File Manager Magic ✨