Skip to content

Commit

Permalink
Merge pull request #92 from arif98741/dev
Browse files Browse the repository at this point in the history
Adn Provider Single Sms Sending Issue Resolved
  • Loading branch information
arif98741 authored Jan 30, 2025
2 parents 1f05cfb + e633443 commit c1542cd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
'senderid' => env('SMS_ADN_SENDER_ID', ''),
'api_key' => env('SMS_ADN_API_KEY', ''),
'api_secret' => env('SMS_ADN_API_SECRET', ''),
'request_type' => env('SMS_ADN_API_REQUEST_TYPE', ''),
'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', ''),
'request_type' => env('SMS_ADN_API_REQUEST_TYPE', 'SINGLE_SMS'), //SINGLE_SMS, OTP, GENERAL_CAMPAIGN, MULTIBODY_CAMPAIGN
'message_type' => env('SMS_ADN_API_MESSAGE_TYPE', 'TEXT'),
],
AjuraTech::class => [
'apikey' => env('SMS_AjuraTechReveSms_API_KEY', ''),
Expand Down
33 changes: 21 additions & 12 deletions src/Provider/Adn.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

namespace Xenon\LaravelBDSms\Provider;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Xenon\LaravelBDSms\Handler\ParameterException;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

class Adn extends AbstractProvider
{
private string $apiEndpoint = 'https://portal.adnsms.com';
private string $apiEndpoint = 'https://portal.adnsms.com/api/v1/secure/send-sms';

/**
* Adn constructor.
* @param Sender $sender
Expand All @@ -39,20 +38,23 @@ public function sendRequest()
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();
$queueName = $this->senderObject->getQueueName();
$tries=$this->senderObject->getTries();
$backoff=$this->senderObject->getBackoff();
$tries = $this->senderObject->getTries();
$backoff = $this->senderObject->getBackoff();
$query = [];
$requestObject = new Request($this->apiEndpoint, $query, $queue, [
'Accept' => 'application/json'
], $queueName,$tries,$backoff);
], $queueName, $tries, $backoff);

$requestObject->setFormParams([
'api_key' => $config['api_key'],
'type' => $config['type'],
'senderid' => $config['senderid'],
'api_secret' => $config['api_secret'],
'request_type' => $config['request_type'],
'message_type' => $config['message_type'],
'senderid' => $config['senderid'] ?? null,
'mobile' => $number,
'message_body' => $text,
]);

$response = $requestObject->post();
if ($queue) {
return true;
Expand All @@ -70,18 +72,25 @@ public function sendRequest()
*/
public function errorException()
{
if (!array_key_exists('api_key', $this->senderObject->getConfig())) {
$configArray = $this->senderObject->getConfig();

if (!array_key_exists('api_key', $configArray)) {
throw new ParameterException('api_key is absent in configuration');
}
if (!array_key_exists('api_secret', $this->senderObject->getConfig())) {
if (!array_key_exists('api_secret', $configArray)) {
throw new ParameterException('api_secret key is absent in configuration');
}
if (!array_key_exists('request_type', $this->senderObject->getConfig())) {
if (!array_key_exists('request_type', $configArray)) {
throw new ParameterException('request_type key is absent in configuration');
}
if (!array_key_exists('message_type', $this->senderObject->getConfig())) {
if (!array_key_exists('message_type', $configArray)) {
throw new ParameterException('message_type key is absent in configuration');
}

$allowedRequestTypes = ['SINGLE_SMS', 'OTP', 'GENERAL_CAMPAIGN', 'MULTIBODY_CAMPAIGN'];

if (!in_array($configArray['request_type'], $allowedRequestTypes)) {
throw new ParameterException('request_type key is invalid. Allowed request_type values are ' . implode(', ', $allowedRequestTypes));
}
}
}

0 comments on commit c1542cd

Please sign in to comment.