Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .php_cs.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
->exclude("vendor")
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->name('*.php')
->notName('*.blade.php')
Expand Down
12 changes: 11 additions & 1 deletion config/resala.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use RobustTools\Resala\Drivers\InfobipDriver;
use RobustTools\Resala\Drivers\VodafoneDriver;
use RobustTools\Resala\Drivers\VectoryLinkDriver;
use RobustTools\Resala\Drivers\BrandEncodeDriver;

return [

Expand Down Expand Up @@ -66,6 +67,14 @@
'sender_id' => env('GATEWAYSA_SENDER_ID'),
'templateid' => env('GATEWAYSA_TEMPLATE_ID'),
],

'brandencode' => [
'end_point' => env('BRANDENCODE_END_POINT'),
'username' => env('BRANDENCODE_USERNAME'),
'password' => env('BRANDENCODE_PASSWORD'),
'sender_name' => env('BRANDENCODE_SENDER_NAME', 'Brandencode'),
'lang' => env('BRANDENCODE_LANG', 'E')
],
],

/*
Expand All @@ -81,6 +90,7 @@
'connekio' => ConnekioDriver::class,
'infobip' => InfobipDriver::class,
'vectory_link' => VectoryLinkDriver::class,
'gateway_sa' => GatewaySA::class
'gateway_sa' => GatewaySA::class,
'brandencode' => BrandEncodeDriver::class
],
];
1 change: 1 addition & 0 deletions src/Abstracts/Driver.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Abstracts;

use RobustTools\Resala\Contracts\SMSDriverInterface;
Expand Down
10 changes: 9 additions & 1 deletion src/Console/PublishProviderEnvVariablesCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Console;

use Illuminate\Console\Command;
Expand Down Expand Up @@ -35,7 +36,10 @@ public function handle()
$driver = $this->argument('driver');

if (! array_key_exists($driver, config('resala.map'))) {
$this->error("provided driver does not exists, you may check available drivers: " . implode(", ", array_keys(config('resala.map'))));
$this->error(
"provided driver does not exists, you may check available drivers: " .
implode(", ", array_keys(config('resala.map')))
);

return;
}
Expand Down Expand Up @@ -78,5 +82,9 @@ private function getStubContent(): string
if ($this->argument('driver') == "vectory_link") {
return File::get(__DIR__ . "/../../stubs/vectory_link.env.stub");
}

if ($this->argument('driver') == "brandencode") {
return File::get(__DIR__ . "/../../stubs/brandencode.env.stub");
}
}
}
1 change: 1 addition & 0 deletions src/Contracts/SMSDriverInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Contracts;

interface SMSDriverInterface
Expand Down
1 change: 1 addition & 0 deletions src/Contracts/SMSDriverResponseInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Contracts;

use Psr\Http\Message\ResponseInterface;
Expand Down
102 changes: 102 additions & 0 deletions src/Drivers/BrandEncodeDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\BrandEncodeResponse;
use RobustTools\Resala\Support\HTTP;

final class BrandEncodeDriver extends Driver implements SMSDriverInterface
{
/**
* @var string|array
*/
private $recipients;

/**
* @var string
*/
private string $message;

/**
* @var string
*/
private string $username;

/**
* @var string
*/
private string $password;

/**
* @var string
*/
private string $senderName;

/**
* @var string
*/
private string $endPoint;

/**
* @var string
*/
private string $lang;

/**
* @param array $config
*/
public function __construct(array $config)
{
$this->username = $config["username"];
$this->password = $config["password"];
$this->senderName = $config["sender_name"];
$this->endPoint = $config["end_point"];
$this->lang = $config["lang"];
}

/**
* @param string|array $recipients
* @return string|array
*/
public function to($recipients)
{
return $this->recipients = $this->toMultiple($recipients)
? implode(', ', $recipients)
: $recipients;
}

public function message(string $message): string
{
return $this->message = $message;
}

public function send(): SMSDriverResponseInterface
{
$response = HTTP::get($this->endPoint, $this->headers(), $this->payload());

return new BrandEncodeResponse($response);
}

protected function payload(): array
{
return
[
"message" => $this->message,
"receiver" => $this->recipients,
"sender" => $this->senderName,
'language' => $this->lang,
'username' => $this->username,
'password' => $this->password
];
}

protected function headers(): array
{
return [
'Content-Type' => 'application/json'
];
}
}
18 changes: 12 additions & 6 deletions src/Drivers/ConnekioDriver.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\ConnekioResponse;
use RobustTools\Resala\Support\HTTP;

Expand Down Expand Up @@ -64,9 +66,10 @@ protected function payload(): string
"sender" => $this->senderName
];

$this->toMultiple($this->recipients)
? $payload['mobile_list'] = array_map(fn ($recipient) => ['msisdn' => $this->formatPhoneNumber($recipient)], $this->recipients)
: $payload["msisdn"] = $this->formatPhoneNumber($this->recipients);
$this->toMultiple($this->recipients) ? $payload['mobile_list'] = array_map(
fn($recipient) => ['msisdn' => $this->formatPhoneNumber($recipient)],
$this->recipients
) : $payload["msisdn"] = $this->formatPhoneNumber($this->recipients);

return json_encode($payload);
}
Expand All @@ -76,7 +79,10 @@ protected function headers(): array
return [
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => sprintf("Basic %s", base64_encode($this->username . ':' . $this->password . ':' . $this->accountId))
'Authorization' => sprintf(
"Basic %s",
base64_encode($this->username . ':' . $this->password . ':' . $this->accountId)
)
];
}

Expand All @@ -92,7 +98,7 @@ protected function formatPhoneNumber($phoneNumber): string
if (substr($phoneNumber, 0, 1) == '0') {
$phoneNumber = '2' . $phoneNumber;
}

return $phoneNumber;
}
}
6 changes: 4 additions & 2 deletions src/Drivers/GatewaySA.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\GatewaySAResponse;
use RobustTools\Resala\Support\HTTP;

Expand Down Expand Up @@ -68,4 +70,4 @@ protected function headers(): array
{
return ['Accept' => 'application/json'];
}
}
}
4 changes: 3 additions & 1 deletion src/Drivers/InfobipDriver.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\InfobipResponse;
use RobustTools\Resala\Support\HTTP;

Expand Down
3 changes: 2 additions & 1 deletion src/Drivers/VectoryLinkDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\VectoryLinkResponse;
use RobustTools\Resala\Support\HTTP;

Expand Down
24 changes: 20 additions & 4 deletions src/Drivers/VodafoneDriver.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Response\VodafoneResponse;
use RobustTools\Resala\Support\{HTTP, VodafonePayloadBuilder};
use RobustTools\Resala\Support\HTTP;
use RobustTools\Resala\Support\VodafonePayloadBuilder;

final class VodafoneDriver extends Driver implements SMSDriverInterface
{
/** @var string|array */
Expand Down Expand Up @@ -80,12 +84,24 @@ private function hashableKey(): string

if ($this->toMultiple($this->recipients)) {
foreach ($this->recipients as $recipient) {
$hashableKey .= sprintf("&SenderName=%s&ReceiverMSISDN=%s&SMSText=%s", $this->senderName, $recipient, $this->message);
$hashableKey .= sprintf(
"&SenderName=%s&ReceiverMSISDN=%s&SMSText=%s",
$this->senderName,
$recipient,
$this->message
);
}

return $hashableKey;
} else {
return sprintf("AccountId=%s&Password=%s&SenderName=%s&ReceiverMSISDN=%s&SMSText=%s", $this->accountId, $this->password, $this->senderName, $this->recipients, $this->message);
return sprintf(
"AccountId=%s&Password=%s&SenderName=%s&ReceiverMSISDN=%s&SMSText=%s",
$this->accountId,
$this->password,
$this->senderName,
$this->recipients,
$this->message
);
}
}
}
1 change: 1 addition & 0 deletions src/Facades/SMS.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Facades;

use Illuminate\Support\Facades\Facade;
Expand Down
2 changes: 1 addition & 1 deletion src/Factories/SMSDriverFactory.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace RobustTools\Resala\Factories;

use RobustTools\Resala\Contracts\SMSDriverInterface;

use RobustTools\Resala\Support\Config;

final class SMSDriverFactory
Expand Down
46 changes: 46 additions & 0 deletions src/Response/BrandEncodeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace RobustTools\Resala\Response;

use Psr\Http\Message\ResponseInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;

final class BrandEncodeResponse implements SMSDriverResponseInterface
{
private const OK = 0;

/**
* @var array
*/
private $response;

/**
* @var string
*/
private string $statusCode;

/**
* @param ResponseInterface $response
*/
public function __construct(ResponseInterface $response)
{
$this->response = json_decode($response->getBody()->getContents(), true);
$this->statusCode = $response->getStatusCode();
}

/**
* @inheritDoc
*/
public function success(): bool
{
return $this->statusCode >= 200 && $this->statusCode < 300 && $this->response['code'] == self::OK;
}

/**
* @inheritDoc
*/
public function body(): string
{
return $this->response['message'];
}
}
1 change: 1 addition & 0 deletions src/Response/ConnekioResponse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Response;

use Psr\Http\Message\ResponseInterface;
Expand Down
1 change: 1 addition & 0 deletions src/Response/GatewaySAResponse.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace RobustTools\Resala\Response;

use Psr\Http\Message\ResponseInterface;
Expand Down
Loading
Loading