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
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
[![Latest Version on Packagist](https://img.shields.io/packagist/v/robust-tools/resala.svg?style=flat-square)](https://packagist.org/packages/robust-tools/resala)
[![Total Downloads](https://img.shields.io/packagist/dt/robust-tools/resala.svg?style=flat-square)](https://packagist.org/packages/robust-tools/resala)

**Resala** is a PHP & Laravel Package, (Designed to add support to your laravel or just native php app for sending SMS using local operators in the MENA region Like `Vodafone`, `Infopib`, `Conneckio`, `VectoryLink`).
**Resala** is a PHP & Laravel Package, (Designed to add support to your laravel or just native php app for sending SMS using local operators in the MENA region Like `Vodafone`, `Infobip`, `Connekio`, `VectoryLink`, `Gateway SA`, `BrandEncode`).
**Resala** not just tied to use inside Laravel you can hook it up in any php code

## Supported Providers
- Vodafone SMS Gateway
- Connekio SMS Gateway
- InfoPib SMS Gateway
- Infobip SMS Gateway
- Vectory Link SMS Gateway
- Gateway SA SMS Gateway
- BrandEncode SMS Gateway

## Installation

Expand Down Expand Up @@ -82,6 +84,24 @@ return [
'sender_name' => env('VECTORY_LINK_SENDER_NAME', 'Vectory Link'),
'lang' => env('VECTORY_LINK_LANG', 'E')
],

'gateway_sa' => [
'end_point' => env('GATEWAYSA_END_POINT', 'http://REST.GATEWAY.SA/api/SendSMS'),
'api_id' => env('GATEWAYSA_API_ID'),
'api_password' => env('GATEWAYSA_API_PASSWORD'),
'sms_type' => env('GATEWAYSA_SMS_TYPE', 'T'),
'encoding' => env('GATEWAYSA_ENCODING', 'T'),
'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 @@ -96,7 +116,9 @@ return [
'vodafone' => VodafoneDriver::class,
'connekio' => ConnekioDriver::class,
'infobip' => InfobipDriver::class,
'vectory_link' => VectoryLink::class
'vectory_link' => VectoryLinkDriver::class,
'gateway_sa' => GatewaySA::class,
'brandencode' => BrandEncodeDriver::class
],
];
```
Expand All @@ -122,6 +144,16 @@ This adds `vectory_link` environment variables to your .env file.
php artisan resala:make vectory_link
```

This adds `brandencode` environment variables to your .env file.
```bash
php artisan resala:make brandencode
```

This adds `gateway_sa` environment variables to your .env file.
```bash
php artisan resala:make gateway_sa
```

## Usage

``` php
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
}
],
"require": {
"php": "^8.1|8.2",
"php": "^8.1|^8.2|^8.3",
"ext-dom": "*",
"ext-json": "*",
"ext-simplexml": "*",
"guzzlehttp/guzzle": "^7.5",
"illuminate/support": "^9.0|^10|^11.0"
"illuminate/support": "^9.0|^10.0|^11.0|^12.0"
},
"require-dev": {
"orchestra/testbench": "^8.0.8",
"phpunit/phpunit": "^10.0"
"orchestra/testbench": "^8.0|^9.0|^10.0",
"phpunit/phpunit": "^10.0|^11.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 0 additions & 1 deletion src/Abstracts/Driver.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Abstracts;

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

namespace RobustTools\Resala\Console;

use Illuminate\Console\Command;
Expand Down Expand Up @@ -86,5 +85,9 @@ private function getStubContent(): string
if ($this->argument('driver') == "brandencode") {
return File::get(__DIR__ . "/../../stubs/brandencode.env.stub");
}

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

namespace RobustTools\Resala\Contracts;

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

namespace RobustTools\Resala\Contracts;

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

namespace RobustTools\Resala\Drivers;

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

Expand Down
20 changes: 9 additions & 11 deletions src/Drivers/ConnekioDriver.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

namespace RobustTools\Resala\Drivers;

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

Expand Down Expand Up @@ -67,7 +65,7 @@ protected function payload(): string
];

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

Expand All @@ -86,13 +84,6 @@ protected function headers(): array
];
}

private function endpoint(): string
{
return $this->toMultiple($this->recipients)
? $this->batchSmsEndPoint
: $this->singleSmsEndPoint;
}

protected function formatPhoneNumber($phoneNumber): string
{
if (substr($phoneNumber, 0, 1) == '0') {
Expand All @@ -101,4 +92,11 @@ protected function formatPhoneNumber($phoneNumber): string

return $phoneNumber;
}

private function endpoint(): string
{
return $this->toMultiple($this->recipients)
? $this->batchSmsEndPoint
: $this->singleSmsEndPoint;
}
}
4 changes: 1 addition & 3 deletions src/Drivers/GatewaySA.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

namespace RobustTools\Resala\Drivers;

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

Expand Down
4 changes: 1 addition & 3 deletions src/Drivers/InfobipDriver.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

namespace RobustTools\Resala\Drivers;

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

Expand Down
15 changes: 7 additions & 8 deletions src/Drivers/VectoryLinkDriver.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Drivers;

use RobustTools\Resala\Abstracts\Driver;
Expand Down Expand Up @@ -72,6 +71,13 @@ protected function payload(): array
];
}

protected function headers(): array
{
return [
'Content-Type' => 'application/json',
];
}

private function generateGuid(): string
{
$data = random_bytes(16);
Expand All @@ -80,11 +86,4 @@ private function generateGuid(): string

return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}

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

namespace RobustTools\Resala\Drivers;

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

use RobustTools\Resala\Support\{HTTP, VodafonePayloadBuilder};
final class VodafoneDriver extends Driver implements SMSDriverInterface
{
/** @var string|array */
Expand Down
1 change: 0 additions & 1 deletion src/Facades/SMS.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Facades;

use Illuminate\Support\Facades\Facade;
Expand Down
1 change: 0 additions & 1 deletion src/Factories/SMSDriverFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Factories;

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

namespace RobustTools\Resala\Response;

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

namespace RobustTools\Resala\Response;

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

namespace RobustTools\Resala\Response;

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

namespace RobustTools\Resala\Response;

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

namespace RobustTools\Resala\Response;

use Psr\Http\Message\ResponseInterface;
Expand Down Expand Up @@ -36,14 +35,6 @@ public function __construct(ResponseInterface $response)
$this->status = $this->parseStatus($contents);
}

private function parseStatus(string $contents): int
{
if ($contents === '' || !is_numeric($contents)) {
return self::STATUS_OTHER_ERROR;
}
return (int) $contents;
}

public function success(): bool
{
return $this->status === self::STATUS_SUCCESS;
Expand Down Expand Up @@ -76,4 +67,13 @@ public function body(): string

return $messages[$this->status] ?? 'Something wrong happened';
}

private function parseStatus(string $contents): int
{
if ($contents === '' || !is_numeric($contents)) {
return self::STATUS_OTHER_ERROR;
}

return (int) $contents;
}
}
1 change: 0 additions & 1 deletion src/Response/VodafoneResponse.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Response;

use Psr\Http\Message\ResponseInterface;
Expand Down
4 changes: 1 addition & 3 deletions src/SMS.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?php

namespace RobustTools\Resala;

use RobustTools\Resala\Contracts\SMSDriverInterface;
use RobustTools\Resala\Contracts\SMSDriverResponseInterface;
use RobustTools\Resala\Contracts\{SMSDriverInterface, SMSDriverResponseInterface};
use RobustTools\Resala\Factories\SMSDriverFactory;

final class SMS
Expand Down
1 change: 0 additions & 1 deletion src/SMSServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala;

use Illuminate\Support\ServiceProvider;
Expand Down
1 change: 0 additions & 1 deletion src/Support/Config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Support;

use InvalidArgumentException;
Expand Down
1 change: 0 additions & 1 deletion src/Support/ConfigRepository.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Support;

use ArrayAccess;
Expand Down
1 change: 0 additions & 1 deletion src/Support/HTTP.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Support;

use GuzzleHttp\Client;
Expand Down
1 change: 0 additions & 1 deletion src/Support/VodafonePayloadBuilder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace RobustTools\Resala\Support;

use DOMAttr;
Expand Down
7 changes: 7 additions & 0 deletions stubs/gateway_sa.env.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
GATEWAYSA_END_POINT=http://REST.GATEWAY.SA/api/SendSMS
GATEWAYSA_API_ID=
GATEWAYSA_API_PASSWORD=
GATEWAYSA_SMS_TYPE=T
GATEWAYSA_ENCODING=T
GATEWAYSA_SENDER_ID=
GATEWAYSA_TEMPLATE_ID=
Loading
Loading