HEX
Server: LiteSpeed
System: Linux s12873.lon1.stableserver.net 5.14.0-611.11.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Dec 3 09:47:37 EST 2025 x86_64
User: jairicem (1242)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/jairicem/4pfxclusive.ng/vendor/tecdiary/sms/src/Gateways/TwilioGateway.php
<?php

namespace Tecdiary\Sms\Gateways;

class TwilioGateway implements SmsGatewayInterface
{
    public $config;
    public $response = '';

    protected $url = '';
    protected $params = [];
    protected $request = '';
    protected $credentials = [];

    public function __construct($config)
    {
        $this->config = $config;
        $this->params['To'] = '';
        $this->params['Body'] = '';
        $this->params['From'] = $this->config[$this->config['gateway']]['from'];
        $this->credentials['sid'] = $this->config[$this->config['gateway']]['account_sid'];
        $this->credentials['token'] = $this->config[$this->config['gateway']]['auth_token'];
        $this->credentials['authorization'] = base64_encode($this->credentials['sid'].':'.$this->credentials['token']);
        $this->url = "https://api.twilio.com/2010-04-01/Accounts/".$this->credentials['sid']."/Messages.json";
    }

    public function getUrl()
    {
        return $this->url;
    }

    public function sendSms($mobile, $message)
    {
        $this->params['To'] = $mobile;
        $this->params['Body'] = $message;
        $client = new \GuzzleHttp\Client(['headers' => [
            'Accept' => 'application/json',
            'Authorization' => 'Basic ' . $this->credentials['authorization']
        ]]);
        try {
            $this->response = $client->request('POST', $this->getUrl(), $this->params)->getBody()->getContents();
        } catch (\Exception $e) {
            $this->response = ['error' => $e->getMessage()];
        }
        return $this;
    }

    public function response()
    {
        return $this->response;
    }
}