Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
hooman-mirghasemi committed Sep 1, 2023
2 parents 3e0098d + 1b08043 commit 1ba4af2
Show file tree
Hide file tree
Showing 30 changed files with 143 additions and 130 deletions.
12 changes: 6 additions & 6 deletions config/sms.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| You can switch to a different driver at runtime.
|
*/
'driver' => env('SMS_DRIVER', 'fake'),
'driver' => env('SMS_DRIVER', 'fake'),
'driver_voice_call' => 'fake',

/*
Expand All @@ -30,26 +30,26 @@
'from' => '1111111111',
],
'kavenegar' => [
'from' => '',
'from' => '',
'apiKey' => env('KAVENEGAR_API_KEY'),
],
'magfa' => [
'username' => env('SMS_MAGFA_USERNAME'),
'password' => env('SMS_MAGFA_PASSWORD'),
'domain' => env('SMS_MAGFA_DOMAIN'),
'from' => env('SMS_MAGFA_SENDER_NUMBER'),
'domain' => env('SMS_MAGFA_DOMAIN'),
'from' => env('SMS_MAGFA_SENDER_NUMBER'),
'wsdl_url' => 'https://sms.magfa.com/api/soap/sms/v2/server?wsdl',
],
'smsonline' => [
'username' => env('SMS_ONLINE_USERNAME'),
'password' => env('SMS_ONLINE_PASSWORD'),
'from' => env('SMS_ONLINE_SENDER_NUMBER'),
'from' => env('SMS_ONLINE_SENDER_NUMBER'),
'wsdl_url' => 'http://www.linepayamak.ir/Post/Send.asmx?wsdl',
],
'avanak' => [
'username' => env('VOICE_AVANAK_USERNAME'),
'password' => env('VOICE_AVANAK_PASSWORD'),
'from' => env('VOICE_AVANAK_SENDER_NUMBER'),
'from' => env('VOICE_AVANAK_SENDER_NUMBER'),
'wsdl_url' => 'http://portal.avanak.ir/webservice3.asmx?WSDL',
],
],
Expand Down
12 changes: 6 additions & 6 deletions database/factories/SmsReportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace HoomanMirghasemi\Sms\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use HoomanMirghasemi\Sms\Models\SmsReport;
use Illuminate\Database\Eloquent\Factories\Factory;

class SmsReportFactory extends Factory
{
Expand All @@ -24,12 +24,12 @@ public function definition()
$drivers = ['kavehnegar', 'fakesmssender'];

return [
'mobile' => '+98'.substr($this->faker->mobileNumber(), 1),
'message' => $this->faker->paragraph(),
'from' => $drivers[array_rand($drivers)],
'number' => $this->faker->phoneNumber,
'mobile' => '+98'.substr($this->faker->mobileNumber(), 1),
'message' => $this->faker->paragraph(),
'from' => $drivers[array_rand($drivers)],
'number' => $this->faker->phoneNumber,
'web_service_response' => $this->faker->paragraph(),
'success' => $this->faker->boolean,
'success' => $this->faker->boolean,
];
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php

use HoomanMirghasemi\Sms\Models\SmsReport;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use HoomanMirghasemi\Sms\Models\SmsReport;

// migrated up don't touch
return new class extends Migration
{
return new class() extends Migration {
/**
* Run the migrations.
*
Expand Down
2 changes: 1 addition & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
|
*/

use Illuminate\Support\Facades\Route;
use HoomanMirghasemi\Sms\Http\Controllers\Web\SmsController;
use Illuminate\Support\Facades\Route;

Route::get('sms/get-sms-list', [SmsController::class, 'index'])
->name('sms.index');
21 changes: 12 additions & 9 deletions src/Abstracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace HoomanMirghasemi\Sms\Abstracts;

use Illuminate\Support\Facades\Event;
use HoomanMirghasemi\Sms\Contracts\Driver as DriverContract;
use HoomanMirghasemi\Sms\Contracts\Message;
use HoomanMirghasemi\Sms\Events\ProviderConnectionFailedEvent;
use HoomanMirghasemi\Sms\Events\SmsSentEvent;
use Illuminate\Support\Facades\Event;

abstract class Driver implements DriverContract
{
Expand All @@ -18,21 +18,21 @@ abstract class Driver implements DriverContract
protected bool $serviceActive = true;

/**
* Recipient (mobile number in E164 format)
* Recipient (mobile number in E164 format).
*
* @param string
*/
protected string $recipient;

/**
* Sender number
* Sender number.
*
* @param string
*/
protected string $from;

/**
* Message
* Message.
*
* @var Message|string
*/
Expand All @@ -55,9 +55,10 @@ abstract class Driver implements DriverContract
public $callBackAfterSend;

/**
* Add recipient (phone or mobile numbers)
* Add recipient (phone or mobile numbers).
*
* @param string $recipient
*
* @param string $recipient
* @return self
*/
public function to(string $recipient): self
Expand All @@ -78,7 +79,7 @@ public function getRecipient(): string
}

/**
* Get sender number (from attribute)
* Get sender number (from attribute).
*
* @return string
*/
Expand All @@ -90,7 +91,8 @@ public function getSenderNumber(): string
/**
* Set related message.
*
* @param Message $message
* @param Message $message
*
* @return self
*/
public function message(Message|string $message): self
Expand Down Expand Up @@ -139,6 +141,7 @@ public function getWebServiceResponce(): string
* note: It do not only work correctly when use Notification Queueable.
*
* @param $function
*
* @return $this
*/
public function setCallBack(callable $function): self
Expand All @@ -150,7 +153,7 @@ public function setCallBack(callable $function): self

/**
* Each driver should call this parent method at end of own send.
* This fire SmsSentEvent
* This fire SmsSentEvent.
*
* @see SmsSentEvent
*
Expand Down
17 changes: 9 additions & 8 deletions src/Channels/SmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
namespace HoomanMirghasemi\Sms\Channels;

use Exception;
use Illuminate\Notifications\Notification;
use HoomanMirghasemi\Sms\Abstracts\Driver;
use HoomanMirghasemi\Sms\SmsManager;
use Illuminate\Notifications\Notification;

class SmsChannel
{
/**
* Send notification.
*
* @param $notifiable
* @param Notification $notification
* @return void
* @param $notifiable
* @param Notification $notification
*
* @throws Exception
*
* @return void
*/
public function send($notifiable, Notification $notification): void
{
$manager = $notification->toSms($notifiable);
if (! is_null($manager)) {
if (!is_null($manager)) {
$this->validate($manager);
$manager->send();
}
Expand All @@ -30,13 +31,13 @@ public function send($notifiable, Notification $notification): void
/**
* Validate sms.
*
* @return void
*
* @throws Exception
*
* @return void
*/
protected function validate($manager): void
{
if (! $manager instanceof SmsManager && ! $manager instanceof Driver) {
if (!$manager instanceof SmsManager && !$manager instanceof Driver) {
throw new Exception('Invalid data for sms notification.');
}
}
Expand Down
17 changes: 9 additions & 8 deletions src/Channels/VoiceCallChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
namespace HoomanMirghasemi\Sms\Channels;

use Exception;
use Illuminate\Notifications\Notification;
use HoomanMirghasemi\Sms\Abstracts\Driver;
use HoomanMirghasemi\Sms\VoiceCallManager;
use Illuminate\Notifications\Notification;

class VoiceCallChannel
{
/**
* Send notification.
*
* @param $notifiable
* @param Notification $notification
* @return void
* @param $notifiable
* @param Notification $notification
*
* @throws Exception
*
* @return void
*/
public function send($notifiable, Notification $notification): void
{
$manager = $notification->toVoiceCall($notifiable);
if (! is_null($manager)) {
if (!is_null($manager)) {
$this->validate($manager);
$manager->send();
}
Expand All @@ -30,13 +31,13 @@ public function send($notifiable, Notification $notification): void
/**
* Validate sms.
*
* @return void
*
* @throws Exception
*
* @return void
*/
protected function validate($manager): void
{
if (! $manager instanceof VoiceCallManager && ! $manager instanceof Driver) {
if (!$manager instanceof VoiceCallManager && !$manager instanceof Driver) {
throw new Exception('Invalid data for voice call notification.');
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Contracts/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
interface Driver
{
/**
* Add recipient (mobile numbers)
* Add recipient (mobile numbers).
*
* @param string $recipient
*
* @param string $recipient
* @return self
*/
public function to(string $recipient): self;

/**
* Set related message.
*
* @param Message $message
* @param Message $message
*
* @return self
*/
public function message(Message $message): self;
Expand Down
8 changes: 4 additions & 4 deletions src/Drivers/Avanak.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace HoomanMirghasemi\Sms\Drivers;

use Exception;
use HoomanMirghasemi\Sms\Abstracts\Driver;
use Illuminate\Support\Facades\Log;
use SoapClient;
use SoapFault;
use HoomanMirghasemi\Sms\Abstracts\Driver;

class Avanak extends Driver
{
Expand Down Expand Up @@ -35,14 +35,14 @@ public function __construct(protected array $settings)
*/
public function send(): bool
{
if (! $this->serviceActive) {
if (!$this->serviceActive) {
parent::failedConnectToProvider();

return false;
}
$this->params['text'] = $this->getMessage();
$this->params['number'] = $this->recipient;
if (! str_starts_with($this->params['number'], '+98')) {
if (!str_starts_with($this->params['number'], '+98')) {
return false;
}
// for sending to avanak change number format
Expand Down Expand Up @@ -72,7 +72,7 @@ public function send(): bool
*/
public function getBalance(): string
{
if (! $this->serviceActive) {
if (!$this->serviceActive) {
return 'وب سرویس آوانک با مشکل مواجه شده.';
}

Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/FakeSmsSender.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(protected array $settings)
*/
public function send(): bool
{
if (! self::$successSend) {
if (!self::$successSend) {
$this->webserviceResponse = 'An error happened !';
$this->success = false;
} else {
Expand All @@ -39,7 +39,7 @@ public function send(): bool
}

/**
* Return fake balance :D
* Return fake balance :D.
*
* @return string
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/Kavenegar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace HoomanMirghasemi\Sms\Drivers;

use Kavenegar\KavenegarApi;
use HoomanMirghasemi\Sms\Abstracts\Driver;
use Kavenegar\KavenegarApi;

class Kavenegar extends Driver
{
Expand Down Expand Up @@ -41,7 +41,6 @@ public function send(): bool
null,
$token10,
$token20

);
} else {
$result = $this->kavenegarApi->Send(null, $this->recipient, $this->message->toString());
Expand All @@ -65,6 +64,7 @@ private function replaceExtraSpace($string, $maxSpace)
if ($spaceCount > $maxSpace) {
$string = strrev(preg_replace('/ /', '-', strrev($string), $spaceCount - $maxSpace));
}

return $string;
}
}
Loading

0 comments on commit 1ba4af2

Please sign in to comment.