%PDF- %GIF98; %PNG;
Server : ApacheSystem : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64 User : addictionfreeind ( 1003) PHP Version : 7.2.34 Disable Function : exec,passthru,shell_exec,system Directory : /home/addictionfreeind/www/admin1/vendor/vonage/client-core/src/SMS/ |
Upload File : |
<?php
/**
* Vonage Client Library for PHP
*
* @copyright Copyright (c) 2016-2022 Vonage, Inc. (http://vonage.com)
* @license https://github.com/Vonage/vonage-php-sdk-core/blob/master/LICENSE.txt Apache License 2.0
*/
declare(strict_types=1);
namespace Vonage\SMS;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Log\LogLevel;
use Vonage\Client\APIClient;
use Vonage\Client\APIResource;
use Vonage\Client\Exception\Exception as ClientException;
use Vonage\Client\Exception\ThrottleException;
use Vonage\Logger\LoggerTrait;
use Vonage\SMS\Message\Message;
use function sleep;
class Client implements APIClient
{
use LoggerTrait;
public function __construct(protected APIResource $api)
{
}
public function getAPIResource(): APIResource
{
return $this->api;
}
/**
* @throws ClientExceptionInterface
* @throws ClientException
*/
public function send(Message $message): Collection
{
if ($warningMessage = $message->getWarningMessage()) {
$this->log(LogLevel::WARNING, $warningMessage);
}
try {
$response = $this->api->create($message->toArray(), '/sms/json');
return new Collection($response);
} catch (ThrottleException $e) {
sleep($e->getTimeout());
return $this->send($message);
}
}
/**
* @throws ClientExceptionInterface
* @throws ClientException
*/
public function sendTwoFactor(string $number, int $pin): SentSMS
{
$response = $this->api->create(
['to' => $number, 'pin' => $pin],
'/sc/us/2fa/json'
);
return new SentSMS($response['messages'][0]);
}
/**
* @throws ClientExceptionInterface
* @throws ClientException
*/
public function sendAlert(string $number, array $templateReplacements): Collection
{
$response = $this->api->create(
['to' => $number] + $templateReplacements,
'/sc/us/alert/json'
);
return new Collection($response);
}
}