Skip to content

Commit

Permalink
Merge pull request #61 from arif98741/dev
Browse files Browse the repository at this point in the history
Merge Request for Custom Gateway Addition
  • Loading branch information
sim8568X authored Nov 2, 2023
2 parents f4d0de3 + c2329c6 commit a6779bc
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 59 deletions.
101 changes: 65 additions & 36 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,45 +163,74 @@ $sender->setConfig(
$status = $sender->send();
</pre>

# Sms Send Using Custom Gateway
`We have tried to added most of the gateways of Bangladesh in this package as much as possible. But still if you don't find your expected gateway in this list, then use Custom Gateway using following code snippet.`
<pre>
use Xenon\LaravelBDSms\Provider\CustomGateway;
use Xenon\LaravelBDSms\Sender;

# Currently Supported Sms Gateways
$sender = Sender::getInstance();
$sender->setProvider(CustomGateway::class);
$sender->setUrl('https://your_cusom_gateway_provider_url_here')
->setMethod('post')
->setHeaders([
'Content-Type: application/json',
'Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
], false);
$sender->setMobile(true);
$sender->setMessage(true);
$sender->setQueue(false);
//use required parameters based on your sms gateway
$sender->setConfig(
[
'MsgType' => 'TEXT',
'masking' => 'sample',
'userName' => 'test_user',
'message' => 'test message',
'receiver' => '017xxxxxxxxxx',
]
);
echo $status = $sender->send();
</pre>

# Currently Supported Sms Gateways

| Provider | Credentials Required <br> For Sending SMS | Support Multiple | Status | Comment | Contact |
|-----------------|-------------------------------------------------------------------|------------------|----------------|------------------------|---------|
| AjuraTech | apikey, secretkey , callerID | - | Done | - | - |
| Adn | api_key, type, senderid | - | Done | - | - |
| Alpha | api_key | Yes | Done | - | - |
| Banglalink | userID, passwd , sender | - | Done | - | - |
| BDBulkSMS | token | - | Done | - | - |
| BoomCast | masking , userName , password | - | Done | - | - |
| BulksmsBD | api_key,senderid | - | Done | - | - |
| DianaHost | api_key, type, senderid | - | Done | - | - |
| DianaSMS | ApiKey, ClientId, SenderId | - | Done | - | - |
| Esms | api_token, sender_id | - | Done | - | - |
| ElitBuzz | api_key, type, senderid | - | Done | not tested yet in live | - |
| Grameenphone | username, password, messagetype | - | Done | not tested yet in live | - |
| Infobip | user, password | - | Done | not tested yet in live | - |
| Lpeek | acode, apiKey, requestID, masking | - | Done | - | - |
| MDL | api_key, type, senderid | - | Done | not tested yet in live | - |
| Metronet | api_key, mask | | Done | - | - |
| MimSms | api_key, type, senderid | - | Done | - | - |
| Mobireach | Username,Password, From | - | Done | - | - |
| Muthofun | sender_id | Yes | Done | - | - |
| NovocomBD | ApiKey , ClientId , SenderId | - | Done | - | - |
| OnnoRokomSMS | userName, userPassword, type, maskName, campaignName | - | Done | not tested yet in live | - |
| QuickSms | api_key, senderid, type,scheduledDateTime | - | Done | not tested yet in live | - |
| RedmoITSms | api_token, sender_id | - | Support closed | - |
| SmartLabSMS | user, password, sender | - | Done | - | - |
| SmsinBD | api_token, senderid | - | Done | | - |
| SmsQ | sender_id, client_id, api_key | - | Done | | - |
| SMSNet24 | user_id, user_password, route_id(optional), sms_type_id(optional) | - | Done | - | |
| SmsNoc | sender_id, bearer_token | - | Done | - | |
| Sslsms | api_token, sid, csms_id | Yes | Done | - | - |
| Tense | user, password, campaign, masking | - | Done | - | - |
| TwentyFourSmsBD | apiKey, sender_id | - | Done | - | - |
| Trubosms | api_token, sender_id | - | Done | - | - |
| Viatech | api_key, mask | - | Done | - | - |
| Provider | Credentials Required <br> For Sending SMS | Support Multiple | Status | Comment | Contact |
|-----------------|-------------------------------------------------------------------|------------------|----------------|----------------------------------------------------------|---------|
| AjuraTech | apikey, secretkey , callerID | - | Done | - | - |
| Adn | api_key, type, senderid | - | Done | - | - |
| Alpha | api_key | Yes | Done | - | - |
| Banglalink | userID, passwd , sender | - | Done | - | - |
| BDBulkSMS | token | - | Done | - | - |
| BoomCast | masking , userName , password | - | Done | - | - |
| BulksmsBD | api_key,senderid | - | Done | - | - |
| CustomGateway | provide necessary token/api_key/others based on requirements | - | Done | Be careful using this and test based on several scenario | - |
| DianaHost | api_key, type, senderid | - | Done | - | - |
| DianaSMS | ApiKey, ClientId, SenderId | - | Done | - | - |
| Esms | api_token, sender_id | - | Done | - | - |
| ElitBuzz | api_key, type, senderid | - | Done | not tested yet in live | - |
| Grameenphone | username, password, messagetype | - | Done | not tested yet in live | - |
| Infobip | user, password | - | Done | not tested yet in live | - |
| Lpeek | acode, apiKey, requestID, masking | - | Done | - | - |
| MDL | api_key, type, senderid | - | Done | not tested yet in live | - |
| Metronet | api_key, mask | | Done | - | - |
| MimSms | api_key, type, senderid | - | Done | - | - |
| Mobireach | Username,Password, From | - | Done | - | - |
| Muthofun | sender_id | Yes | Done | - | - |
| NovocomBD | ApiKey , ClientId , SenderId | - | Done | - | - |
| OnnoRokomSMS | userName, userPassword, type, maskName, campaignName | - | Done | not tested yet in live | - |
| QuickSms | api_key, senderid, type,scheduledDateTime | - | Done | not tested yet in live | - |
| RedmoITSms | api_token, sender_id | - | Support closed | - |
| SmartLabSMS | user, password, sender | - | Done | - | - |
| SmsinBD | api_token, senderid | - | Done | | - |
| SmsQ | sender_id, client_id, api_key | - | Done | | - |
| SMSNet24 | user_id, user_password, route_id(optional), sms_type_id(optional) | - | Done | - | |
| SmsNoc | sender_id, bearer_token | - | Done | - | |
| Sslsms | api_token, sid, csms_id | Yes | Done | - | - |
| Tense | user, password, campaign, masking | - | Done | - | - |
| TwentyFourSmsBD | apiKey, sender_id | - | Done | - | - |
| Trubosms | api_token, sender_id | - | Done | - | - |
| Viatech | api_key, mask | - | Done | - | - |



Expand Down
4 changes: 4 additions & 0 deletions src/Config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Xenon\LaravelBDSms\Provider\BoomCast;
use Xenon\LaravelBDSms\Provider\Brilliant;
use Xenon\LaravelBDSms\Provider\BulkSmsBD;
use Xenon\LaravelBDSms\Provider\CustomGateway;
use Xenon\LaravelBDSms\Provider\DianaHost;
use Xenon\LaravelBDSms\Provider\DianaSms;
use Xenon\LaravelBDSms\Provider\DnsBd;
Expand Down Expand Up @@ -115,6 +116,9 @@
BulkSmsBD::class => [
'api_key' => env('SMS_BULK_SMS_BD_API_KEY', ''),
'senderid' => env('SMS_BULK_SMS_BD_SENDERID', ''),
],
CustomGateway::class => [

],
DianaHost::class => [
'senderid' => env('SMS_DIANA_HOST_SENDER_ID', ''),
Expand Down
71 changes: 71 additions & 0 deletions src/Provider/CustomGateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/*
* Last Modified: 02/02/23, 11:50 PM
* Copyright (c) 2023
* -created by Ariful Islam
* -All Rights Preserved By
* -If you have any query then knock me at
* arif98741@gmail.com
* See my profile @https://github.com/arif98741
*/

namespace Xenon\LaravelBDSms\Provider;

use GuzzleHttp\Exception\GuzzleException;
use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Request;
use Xenon\LaravelBDSms\Sender;

class CustomGateway extends AbstractProvider
{
/**
* Custom Gateway constructor.
* @param Sender $sender
*/
public function __construct(Sender $sender)
{
$this->senderObject = $sender;
}

/**
* Send Request To Api and Send Message
* @throws RenderException|GuzzleException
*/
public function sendRequest()
{
$mobile = $this->senderObject->getMobile();
$text = $this->senderObject->getMessage();
$config = $this->senderObject->getConfig();
$queue = $this->senderObject->getQueue();
$query = $config;

$requestObject = new Request($this->senderObject->url, $query, $queue);

if (isset($this->senderObject->headers)) {
$requestObject->setHeaders($this->senderObject->headers);
$this->senderObject->contentTypeJson && $requestObject->setContentTypeJson(true);
}

$response = $this->senderObject->method === 'post' ? $requestObject->post() : $requestObject->get();

if ($queue) {
return true;
}

$body = $response->getBody();
$smsResult = $body->getContents();
$data['number'] = $mobile;
$data['message'] = $text;
return $this->generateReport($smsResult, $data)->getContent();
}

/**
* @throws RenderException
*/
final public function errorException(): void
{
if (!isset($this->senderObject->url)) {
throw new RenderException("Url missing for custom gateway. Use setUrl() to set sms gateway endpoint ");
}
}
}
76 changes: 53 additions & 23 deletions src/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Xenon\LaravelBDSms\Handler\ParameterException;
use Xenon\LaravelBDSms\Handler\RenderException;
use Xenon\LaravelBDSms\Provider\AbstractProvider;
use Xenon\LaravelBDSms\Provider\CustomGateway;

class Sender
{
Expand All @@ -37,34 +38,24 @@ class Sender
* @var
*/
private $config;

/**
* @var string
*/
public string $url;
/**
* @var
*/
private $method;
public $method;

/**
* @var bool
*/
private bool $queue = false;

/**
* @return mixed
*/
public function getMethod()
{
return $this->method;
}

/**
* @param mixed $method
*/
public function setMethod($method): void
{
$this->method = $method;
}

/**
* @var null
* @var Sender|null
*/
private static $instance = null;

Expand All @@ -81,12 +72,27 @@ public function setMethod($method): void
public static function getInstance(): Sender
{
if (!isset(self::$instance)) {
self::$instance = new Sender;
self::$instance = new self;
}

return self::$instance;
}

/**
* @return mixed
*/
public function getMethod()
{
return $this->method;
}

/**
* @param mixed $method
*/
public function setMethod($method)
{
$this->method = $method;
return self::$instance;
}

/**
Expand Down Expand Up @@ -130,6 +136,17 @@ public function getQueue()

}

/**
* @param array $headers
* @return Sender
* @since v1.0.55.0-beta
*/
public function setHeaders(array $headers,bool $contentTypeJson = true): Sender
{
$this->headers = $headers;
$this->contentTypeJson = $contentTypeJson;
return self::getInstance();
}

/**
* Send Message Finally
Expand All @@ -144,14 +161,17 @@ public function send()
throw new ParameterException('config must be an array');
}

if (empty($this->getMobile())) {
throw new ParameterException('Mobile number should not be empty');
}
if(!$this->provider instanceof CustomGateway){ //empty check for all providers mobile and message
if (empty($this->getMobile())) {
throw new ParameterException('Mobile number should not be empty');
}

if (empty($this->getMessage())) {
throw new ParameterException('Message text should not be empty');
if (empty($this->getMessage())) {
throw new ParameterException('Message text should not be empty');
}
}


$this->provider->errorException();

$config = Config::get('sms');
Expand Down Expand Up @@ -205,6 +225,16 @@ public function setMessage($message = ''): Sender
return self::getInstance();
}

/**
* @param string $url
* @return $this
*/
public function setUrl(string $url)
{
$this->url = $url;
return self::getInstance();
}

/**
* @return mixed
* @since v1.0.0
Expand Down

0 comments on commit a6779bc

Please sign in to comment.