diff --git a/README.md b/README.md index 586d697..c891121 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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') + ], ], /* @@ -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 ], ]; ``` @@ -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 diff --git a/composer.json b/composer.json index 66700b9..08e7214 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Abstracts/Driver.php b/src/Abstracts/Driver.php index 348fcc4..1873068 100644 --- a/src/Abstracts/Driver.php +++ b/src/Abstracts/Driver.php @@ -1,5 +1,4 @@ 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"); + } } } diff --git a/src/Contracts/SMSDriverInterface.php b/src/Contracts/SMSDriverInterface.php index 35913e4..05c0db7 100644 --- a/src/Contracts/SMSDriverInterface.php +++ b/src/Contracts/SMSDriverInterface.php @@ -1,5 +1,4 @@ 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); @@ -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') { @@ -101,4 +92,11 @@ protected function formatPhoneNumber($phoneNumber): string return $phoneNumber; } + + private function endpoint(): string + { + return $this->toMultiple($this->recipients) + ? $this->batchSmsEndPoint + : $this->singleSmsEndPoint; + } } diff --git a/src/Drivers/GatewaySA.php b/src/Drivers/GatewaySA.php index 7197aa2..5e363c4 100644 --- a/src/Drivers/GatewaySA.php +++ b/src/Drivers/GatewaySA.php @@ -1,10 +1,8 @@ 'application/json', + ]; + } + private function generateGuid(): string { $data = random_bytes(16); @@ -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', - ]; - } } diff --git a/src/Drivers/VodafoneDriver.php b/src/Drivers/VodafoneDriver.php index aa88e17..7c9e917 100644 --- a/src/Drivers/VodafoneDriver.php +++ b/src/Drivers/VodafoneDriver.php @@ -1,14 +1,10 @@ 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; @@ -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; + } } diff --git a/src/Response/VodafoneResponse.php b/src/Response/VodafoneResponse.php index e62c5f6..aa427d1 100644 --- a/src/Response/VodafoneResponse.php +++ b/src/Response/VodafoneResponse.php @@ -1,5 +1,4 @@ shouldReceive('create') ->once() - ->andReturn(\Mockery::mock(SMSDriverInterface::class));; + ->andReturn(\Mockery::mock(SMSDriverInterface::class)); + ; SMSDriverFactory::create(); } diff --git a/tests/SMSTest.php b/tests/SMSTest.php index 68ee801..db42ae9 100644 --- a/tests/SMSTest.php +++ b/tests/SMSTest.php @@ -1,4 +1,5 @@ sendSMS(); $this->assertInstanceOf(SMSDriverResponseInterface::class, $sms); - } private function createMockXMLResponse(): self