AbstractNotificationService.php
1 year ago
AbstractWhatsAppNotificationService.php
2 years ago
ApplicationNotificationService.php
1 year ago
AppointmentNotificationService.php
1 year ago
BasicWhatsAppNotificationService.php
2 years ago
EmailNotificationService.php
1 year ago
NotificationHelperService.php
4 years ago
SMSAPIService.php
2 years ago
SMSNotificationService.php
1 year ago
ApplicationNotificationService.php
275 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Application\Services\Notification; |
| 8 | |
| 9 | use AmeliaBooking\Domain\Collection\Collection; |
| 10 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 11 | use AmeliaBooking\Domain\Entity\Booking\Appointment\Appointment; |
| 12 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 13 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 14 | use AmeliaBooking\Infrastructure\Common\Container; |
| 15 | use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException; |
| 16 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 17 | use Interop\Container\Exception\ContainerException; |
| 18 | use Slim\Exception\ContainerValueNotFoundException; |
| 19 | |
| 20 | /** |
| 21 | * Class ApplicationNotificationService |
| 22 | * |
| 23 | * @package AmeliaBooking\Application\Services\Notification |
| 24 | */ |
| 25 | class ApplicationNotificationService |
| 26 | { |
| 27 | protected $container; |
| 28 | |
| 29 | /** |
| 30 | * ApplicationNotificationService constructor. |
| 31 | * |
| 32 | * @param Container $container |
| 33 | */ |
| 34 | public function __construct(Container $container) |
| 35 | { |
| 36 | $this->container = $container; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param Appointment $appointment |
| 41 | * @param bool $logNotification |
| 42 | * |
| 43 | * @throws InvalidArgumentException |
| 44 | * @throws QueryExecutionException |
| 45 | * @throws ContainerException |
| 46 | */ |
| 47 | public function sendAppointmentProviderStatusNotifications( |
| 48 | $appointment, |
| 49 | $logNotification = true |
| 50 | ) { |
| 51 | /** @var SettingsService $settingsService */ |
| 52 | $settingsService = $this->container->get('domain.settings.service'); |
| 53 | |
| 54 | /** @var AppointmentNotificationService $appointmentNotificationService */ |
| 55 | $appointmentNotificationService = $this->container->get('application.notification.appointment.service'); |
| 56 | |
| 57 | /** @var EmailNotificationService $emailNotificationService */ |
| 58 | $emailNotificationService = $this->container->get('application.emailNotification.service'); |
| 59 | |
| 60 | /** @var SMSNotificationService $smsNotificationService */ |
| 61 | $smsNotificationService = $this->container->get('application.smsNotification.service'); |
| 62 | |
| 63 | /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */ |
| 64 | $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service'); |
| 65 | |
| 66 | $appointmentNotificationService->sendProviderStatusNotifications( |
| 67 | $emailNotificationService, |
| 68 | $appointment, |
| 69 | $logNotification |
| 70 | ); |
| 71 | |
| 72 | if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) { |
| 73 | $appointmentNotificationService->sendProviderStatusNotifications( |
| 74 | $smsNotificationService, |
| 75 | $appointment, |
| 76 | $logNotification |
| 77 | ); |
| 78 | } |
| 79 | |
| 80 | if ($whatsAppNotificationService->checkRequiredFields()) { |
| 81 | $appointmentNotificationService->sendProviderStatusNotifications( |
| 82 | $whatsAppNotificationService, |
| 83 | $appointment, |
| 84 | $logNotification |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @param Appointment $appointment |
| 91 | * @param Collection $bookings |
| 92 | * @param bool $logNotification |
| 93 | * @param bool $isBackend |
| 94 | * @param bool $sendInvoice |
| 95 | * |
| 96 | * @throws InvalidArgumentException |
| 97 | * @throws QueryExecutionException |
| 98 | * @throws NotFoundException |
| 99 | * @throws ContainerException |
| 100 | */ |
| 101 | public function sendAppointmentCustomersStatusNotifications( |
| 102 | $appointment, |
| 103 | $bookings, |
| 104 | $logNotification = true, |
| 105 | $isBackend = true, |
| 106 | $sendInvoice = false |
| 107 | ) { |
| 108 | /** @var SettingsService $settingsService */ |
| 109 | $settingsService = $this->container->get('domain.settings.service'); |
| 110 | |
| 111 | /** @var AppointmentNotificationService $appointmentNotificationService */ |
| 112 | $appointmentNotificationService = $this->container->get('application.notification.appointment.service'); |
| 113 | |
| 114 | /** @var EmailNotificationService $emailNotificationService */ |
| 115 | $emailNotificationService = $this->container->get('application.emailNotification.service'); |
| 116 | |
| 117 | /** @var SMSNotificationService $smsNotificationService */ |
| 118 | $smsNotificationService = $this->container->get('application.smsNotification.service'); |
| 119 | |
| 120 | /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */ |
| 121 | $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service'); |
| 122 | |
| 123 | $appointmentNotificationService->sendCustomersStatusNotifications( |
| 124 | $emailNotificationService, |
| 125 | $appointment, |
| 126 | $bookings, |
| 127 | $logNotification, |
| 128 | $isBackend, |
| 129 | $sendInvoice |
| 130 | ); |
| 131 | |
| 132 | if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) { |
| 133 | $appointmentNotificationService->sendCustomersStatusNotifications( |
| 134 | $smsNotificationService, |
| 135 | $appointment, |
| 136 | $bookings, |
| 137 | $logNotification, |
| 138 | $isBackend, |
| 139 | $sendInvoice |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | if ($whatsAppNotificationService->checkRequiredFields()) { |
| 144 | $appointmentNotificationService->sendCustomersStatusNotifications( |
| 145 | $whatsAppNotificationService, |
| 146 | $appointment, |
| 147 | $bookings, |
| 148 | $logNotification, |
| 149 | $isBackend, |
| 150 | $sendInvoice |
| 151 | ); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /** |
| 156 | * @param Appointment $appointment |
| 157 | * @param bool $notifyProvider |
| 158 | * @param bool $notifyCustomers |
| 159 | * |
| 160 | * @throws QueryExecutionException |
| 161 | * @throws InvalidArgumentException |
| 162 | */ |
| 163 | public function sendAppointmentRescheduleNotifications( |
| 164 | $appointment, |
| 165 | $notifyProvider = true, |
| 166 | $notifyCustomers = true |
| 167 | ) { |
| 168 | /** @var SettingsService $settingsService */ |
| 169 | $settingsService = $this->container->get('domain.settings.service'); |
| 170 | |
| 171 | /** @var AppointmentNotificationService $appointmentNotificationService */ |
| 172 | $appointmentNotificationService = $this->container->get('application.notification.appointment.service'); |
| 173 | |
| 174 | /** @var EmailNotificationService $emailNotificationService */ |
| 175 | $emailNotificationService = $this->container->get('application.emailNotification.service'); |
| 176 | |
| 177 | /** @var SMSNotificationService $smsNotificationService */ |
| 178 | $smsNotificationService = $this->container->get('application.smsNotification.service'); |
| 179 | |
| 180 | /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */ |
| 181 | $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service'); |
| 182 | |
| 183 | $appointmentNotificationService->sendRescheduledNotifications( |
| 184 | $emailNotificationService, |
| 185 | $appointment, |
| 186 | $notifyProvider, |
| 187 | $notifyCustomers |
| 188 | ); |
| 189 | |
| 190 | if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) { |
| 191 | $appointmentNotificationService->sendRescheduledNotifications( |
| 192 | $smsNotificationService, |
| 193 | $appointment, |
| 194 | $notifyProvider, |
| 195 | $notifyCustomers |
| 196 | ); |
| 197 | } |
| 198 | |
| 199 | if ($whatsAppNotificationService->checkRequiredFields()) { |
| 200 | $appointmentNotificationService->sendRescheduledNotifications( |
| 201 | $whatsAppNotificationService, |
| 202 | $appointment, |
| 203 | $notifyProvider, |
| 204 | $notifyCustomers |
| 205 | ); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | /** |
| 210 | * @param Appointment $appointment |
| 211 | * @param int|null $changedProviderId |
| 212 | * @param bool $notifyProvider |
| 213 | * @param bool $notifyCustomers |
| 214 | * |
| 215 | * @throws QueryExecutionException |
| 216 | * @throws InvalidArgumentException |
| 217 | */ |
| 218 | public function sendAppointmentUpdatedNotifications( |
| 219 | $appointment, |
| 220 | $changedProviderId, |
| 221 | $notifyProvider = true, |
| 222 | $notifyCustomers = true |
| 223 | ) { |
| 224 | /** @var SettingsService $settingsService */ |
| 225 | $settingsService = $this->container->get('domain.settings.service'); |
| 226 | |
| 227 | /** @var AppointmentNotificationService $appointmentNotificationService */ |
| 228 | $appointmentNotificationService = $this->container->get('application.notification.appointment.service'); |
| 229 | |
| 230 | /** @var EmailNotificationService $emailNotificationService */ |
| 231 | $emailNotificationService = $this->container->get('application.emailNotification.service'); |
| 232 | |
| 233 | /** @var SMSNotificationService $smsNotificationService */ |
| 234 | $smsNotificationService = $this->container->get('application.smsNotification.service'); |
| 235 | |
| 236 | /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */ |
| 237 | $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service'); |
| 238 | |
| 239 | if ($changedProviderId) { |
| 240 | $newProviderId = $appointment->getProviderId()->getValue(); |
| 241 | |
| 242 | $appointment->setProviderId(new Id($changedProviderId)); |
| 243 | } |
| 244 | |
| 245 | $appointmentNotificationService->sendUpdatedNotifications( |
| 246 | $emailNotificationService, |
| 247 | $appointment, |
| 248 | $notifyProvider, |
| 249 | $notifyCustomers |
| 250 | ); |
| 251 | |
| 252 | if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) { |
| 253 | $appointmentNotificationService->sendUpdatedNotifications( |
| 254 | $smsNotificationService, |
| 255 | $appointment, |
| 256 | $notifyProvider, |
| 257 | $notifyCustomers |
| 258 | ); |
| 259 | } |
| 260 | |
| 261 | if ($whatsAppNotificationService->checkRequiredFields()) { |
| 262 | $appointmentNotificationService->sendUpdatedNotifications( |
| 263 | $whatsAppNotificationService, |
| 264 | $appointment, |
| 265 | $notifyProvider, |
| 266 | $notifyCustomers |
| 267 | ); |
| 268 | } |
| 269 | |
| 270 | if ($changedProviderId) { |
| 271 | $appointment->setProviderId(new Id($newProviderId)); |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 |