⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.1
Server IP:
185.238.29.86
Server:
Linux server2 6.8.12-6-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.12-6 (2024-12-19T19:05Z) x86_64
Server Software:
nginx/1.18.0
PHP Version:
8.1.31
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
var
/
www
/
work
/
modules
/
Sms
/
Listeners
/
View File Name :
SendSmsUpdateBookingListen.php
<?php namespace Modules\Sms\Listeners; use Illuminate\Support\Facades\Log; use Modules\Booking\Events\BookingCreatedEvent; use Modules\Booking\Events\BookingUpdatedEvent; use Modules\Sms\Core\Facade\Sms; use Propaganistas\LaravelPhone\PhoneNumber; class SendSmsUpdateBookingListen { /** * Create the event listener. * * @return void */ public $user; const CODE = [ 'id' => '[booking_id]', 'total' => '[price]', 'service_name' => '[service_name]', 'start_date' => '[start_date]', 'total_guests' => '[total_guests]', ]; public function __construct() { } /** * Handle the event. * * @param BookingCreatedEvent $event * @return void */ public function handle(BookingUpdatedEvent $event) { $booking = $event->booking; $vendor = $booking->vendor; $adminPhone = setting_item('admin_phone_has_booking'); $adminCountry = setting_item('admin_country_has_booking'); if (!empty($booking->phone) and !empty($booking->country) and !empty(setting_item('enable_sms_user_update_booking'))) { $message = $this->replaceMessage($booking, setting_item_with_lang('sms_message_user_update_booking', app()->getLocale())); try { $to = (string)PhoneNumber::make($booking->phone)->ofCountry($booking->country); Sms::to($to)->content($message)->send(); } catch (\Exception $e) { Log::error($e->getMessage()); } } if (!empty($vendor->phone) and !empty($vendor->country) and !empty(setting_item('enable_sms_vendor_update_booking'))) { $message = $this->replaceMessage($booking, setting_item_with_lang('sms_message_vendor_update_booking', app()->getLocale())); try { $to = (string)PhoneNumber::make($vendor->phone)->ofCountry($vendor->country); Sms::to($to)->content($message)->send(); } catch (\Exception $e) { Log::error($e->getMessage()); } } if (!empty($adminPhone) and !empty($adminCountry) and !empty(setting_item('enable_sms_admin_update_booking')) and !empty(setting_item('admin_phone_has_booking'))) { $message = $this->replaceMessage($booking, setting_item_with_lang('sms_message_admin_update_booking', app()->getLocale())); try { $to = (string)PhoneNumber::make($adminPhone)->ofCountry($adminCountry); Sms::to($to)->content($message)->send(); } catch (\Exception $e) { Log::error($e->getMessage()); } } } public function replaceMessage($booking, $content) { if (!empty($content)) { foreach (self::CODE as $item => $value) { if ($value == '[service_name]') { if (!empty($booking->service->title)) { $content = str_replace('[service_name]', $booking->service->title, $content); } } else { $content = str_replace($value, @$booking->$item, $content); } } } else { return $this->replaceMessage($booking, $this->defaultContent()); } return $content; } public function defaultContent() { return 'Service Name: [service_name] Price: [price] Date: [start_date] Total: [total_guests]'; } }