Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Malebestia committed Sep 4, 2023
1 parent 599ba82 commit 1617734
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 0 deletions.
60 changes: 60 additions & 0 deletions Actions/NetfunSendAction.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,46 @@
<?php

<<<<<<< HEAD
declare(strict_types=1);

=======
>>>>>>> 48d3f55 (up)
namespace Modules\Notify\Actions;

use Exception;
use GuzzleHttp\Client;
<<<<<<< HEAD
use GuzzleHttp\Exception\ClientException;
use Illuminate\Support\Str;
use Modules\Notify\Datas\SmsData;
use Spatie\QueueableAction\QueueableAction;

class NetfunSendAction
{
=======
use Illuminate\Support\Str;
use Modules\Notify\Data\SmsData;
use GuzzleHttp\Exception\ClientException;
use Spatie\QueueableAction\QueueableAction;

class NetfunSendAction {
>>>>>>> 48d3f55 (up)
use QueueableAction;

public string $token;

<<<<<<< HEAD
public array $vars = [];

=======
public array $vars=[];
>>>>>>> 48d3f55 (up)
/**
* Create a new action instance.
*
* @return void
*/
<<<<<<< HEAD
public function __construct()
{
// Prepare the action for execution, leveraging constructor injection.
Expand All @@ -39,11 +56,27 @@ public function __construct()
*/
public function execute(SmsData $sms): array
{
=======
public function __construct() {
// Prepare the action for execution, leveraging constructor injection.
$token=config('services.netfun.token');
if($token==null){
throw new Exception('put [NETFUN_TOKEN] variable to your .env and config [services.netfun.token] ');
}
$this->token=$token;
}

/**
* Execute the action.
*/
public function execute(SmsData $sms): array {
>>>>>>> 48d3f55 (up)
$endpoint = 'https://v2.smsviainternet.it/api/rest/v1/sms-batch.json';
$headers = [
'Cache-Control' => 'no-cache',
'Content-Type' => 'application/json',
];
<<<<<<< HEAD

// dddx([ord($this->body[0]), $this->body]);

Expand All @@ -54,13 +87,30 @@ public function execute(SmsData $sms): array

if (! Str::startsWith($sms->to, '+')) {
$sms->to = '+39' . $sms->to;
=======


// dddx([ord($this->body[0]), $this->body]);

$sms->to = $sms->to.'';
if (Str::startsWith($sms->to, '00')) {
$sms->to = '+39'.substr($sms->to, 2);
}

if (! Str::startsWith($sms->to, '+')) {
$sms->to = '+39'.$sms->to;
>>>>>>> 48d3f55 (up)
}

$body = [
'api_token' => $this->token,
// "gateway"=> 99,
'sender' => $sms->from,
<<<<<<< HEAD
'text_template' => $sms->body, // .' '.rand(1, 100),
=======
'text_template' => $sms->body,//.' '.rand(1, 100),
>>>>>>> 48d3f55 (up)
/*
'delivery_callback' => 'https://www.google.com?code={{code}}',
'default_placeholders' => [
Expand Down Expand Up @@ -90,7 +140,11 @@ public function execute(SmsData $sms): array
try {
$response = $client->post($endpoint, ['json' => $body]);
} catch (ClientException $e) {
<<<<<<< HEAD
throw new Exception($e->getMessage() . '[' . __LINE__ . '][' . __FILE__ . ']');
=======
throw new Exception($e->getMessage().'['.__LINE__.']['.__FILE__.']');
>>>>>>> 48d3f55 (up)
}
/*
echo '<hr/>';
Expand All @@ -102,7 +156,13 @@ public function execute(SmsData $sms): array

$this->vars['status_code'] = $response->getStatusCode();
$this->vars['status_txt'] = $response->getBody()->getContents();
<<<<<<< HEAD

return $this->vars;
}
}
=======
return $this->vars;
}
}
>>>>>>> 48d3f55 (up)
13 changes: 13 additions & 0 deletions Data/SmsData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Modules\Notify\Data;

use Spatie\LaravelData\Data;

class SmsData extends Data {

public string $from;
public string $to;
public string $body;

}
36 changes: 36 additions & 0 deletions Notifications/Channels/NetfunChannel.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

<<<<<<< HEAD
declare(strict_types=1);

namespace Modules\Notify\Notifications\Channels;
Expand All @@ -12,11 +13,26 @@ class NetfunChannel
{
public function __construct()
{
=======

namespace Modules\Notify\Notifications\Channels;

use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notification;
use Modules\Notify\Actions\NetfunSendAction;

class NetfunChannel {

public function __construct(){

>>>>>>> 48d3f55 (up)
}

/**
* Send the given notification.
*
<<<<<<< HEAD
* @param \Modules\Notify\Contracts\CanThemeNotificationContract $notifiable
* @return void
*/
Expand All @@ -36,3 +52,23 @@ public function send($notifiable, ThemeNotification $notification)
}
}
}
=======
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification) {

$message = $notification->toSms($notifiable);
// Send notification to the $notifiable instance...
$data=app(NetfunSendAction::class)->execute($message);

if($notifiable instanceof Model){
$data['sms_sent_at']=now();
$data['sms_count']=$notifiable->sms_count +1;
$notifiable->update($data);
}

}
}
>>>>>>> 48d3f55 (up)
84 changes: 84 additions & 0 deletions Notifications/RowAttributeNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

declare(strict_types=1);

namespace Modules\Notify\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;
use Modules\Notify\Data\SmsData;

class RowAttributeNotification extends Notification {
use Queueable;
public Model $model;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Model $row) {
$this->row=$row;
}

/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable) {
/*
dddx(['via'=>$this->row->getNotifyVia(),'notifiable'=>$notifiable,'row'=>$this->row]);
return ['mail'];
*/
return $this->row->getNotifyVia();
}

/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable) {
dddx($notifiable);
/*
return (new MailMessage())
->subject($this->subject)
->line('---')
->view('notify::notifications.html', ['html' => $this->html]);
*/
}

/**
* Undocumented function
*
* @param mixed $notifiable
* @return SmsData
*/
public function toSms($notifiable) {
return SmsData::from([
'from' => $this->row->sms_from,
'to'=> $this->row->mobile_phone,
'body'=>$this->row->sms_body,
]);
}

/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
*
* @return array
*/
public function toArray($notifiable) {
dddx($notifiable);

return [
];
}
}

0 comments on commit 1617734

Please sign in to comment.