76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Events\ExampleEvent;
|
|
use App\Events\CustomerAccountRequestEvent;
|
|
use App\Traits\Helper;
|
|
use GuzzleHttp\Client;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Support\Facades\Log;
|
|
use stdClass;
|
|
use Throwable;
|
|
|
|
class NotifyUser
|
|
{
|
|
use Helper;
|
|
|
|
/**
|
|
* Create the event listener.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the event.
|
|
*
|
|
* @param CustomerAccountRequestEvent $event
|
|
* @return void
|
|
*/
|
|
public function handle(CustomerAccountRequestEvent $event)
|
|
{
|
|
//
|
|
$request = $event->request;
|
|
$user = $request->user;
|
|
try {
|
|
$client = new Client([
|
|
'base_uri' => config('services.notification_service.base_uri'),
|
|
]);
|
|
$headers = [
|
|
'Authorization' => config('services.notification_service.key'),
|
|
];
|
|
|
|
$body = new stdClass();
|
|
$body->title = $event->mailTitle;
|
|
$body->message = $event->mailMessage;
|
|
$body->email = $user->email;
|
|
|
|
$client->request('POST', '/send-mail', ['json' => $body, 'headers' => $headers]);
|
|
|
|
if (isset($event->notification)) {
|
|
$body = new stdClass();
|
|
$body->user_code = $user->user_code;
|
|
$body->message = $event->notification;
|
|
$body->date = $request->created_at->format('Y-m-d H:i:s') ?? date('Y-m-d H:i:s');
|
|
|
|
$data = new stdClass();
|
|
$data->screen = "notificationview";
|
|
$data->data = new stdClass();
|
|
$data->data->type = 'customer_account_opening_request';
|
|
$data->data->request_id = $data->data->id = $request->id;
|
|
$body->data = $data;
|
|
|
|
$client->request('POST', '/onesignal/pushToUser', ['json' => $body, 'headers' => $headers]);
|
|
}
|
|
} catch (Throwable $t) {
|
|
Log::error('-------- User notification not sent-----------');
|
|
Log::error($t->getMessage() . '\n' . $t->getTraceAsString());
|
|
}
|
|
}
|
|
}
|