PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Notification / SendUndeliveredNotificationsCommandHandler.php
ameliabooking / src / Application / Commands / Notification Last commit date
GetNotificationsCommand.php 7 years ago GetNotificationsCommandHandler.php 2 years ago GetSMSNotificationsHistoryCommand.php 7 years ago GetSMSNotificationsHistoryCommandHandler.php 2 years ago SendAmeliaSmsApiRequestCommand.php 7 years ago SendAmeliaSmsApiRequestCommandHandler.php 2 years ago SendTestEmailCommand.php 7 years ago SendTestEmailCommandHandler.php 2 years ago SendUndeliveredNotificationsCommand.php 4 years ago SendUndeliveredNotificationsCommandHandler.php 2 years ago UpdateNotificationCommand.php 7 years ago UpdateNotificationCommandHandler.php 2 years ago UpdateNotificationStatusCommand.php 7 years ago UpdateNotificationStatusCommandHandler.php 2 years ago UpdateSMSNotificationHistoryCommand.php 7 years ago UpdateSMSNotificationHistoryCommandHandler.php 1 year ago
SendUndeliveredNotificationsCommandHandler.php
112 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Notification;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Services\Notification\EmailNotificationService;
8 use AmeliaBooking\Application\Services\Notification\SMSNotificationService;
9 use AmeliaBooking\Application\Services\Notification\AbstractWhatsAppNotificationService;
10 use AmeliaBooking\Domain\Collection\Collection;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
13 use AmeliaBooking\Domain\Entity\Entities;
14 use AmeliaBooking\Domain\Entity\Payment\Payment;
15 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
16 use AmeliaBooking\Domain\Services\Settings\SettingsService;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
18 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
19 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
20 use AmeliaBooking\Infrastructure\WP\EventListeners\Booking\Appointment\BookingAddedEventHandler;
21 use Exception;
22 use Interop\Container\Exception\ContainerException;
23
24 /**
25 * Class SendUndeliveredNotificationsCommandHandler
26 *
27 * @package AmeliaBooking\Application\Commands\Notification
28 */
29 class SendUndeliveredNotificationsCommandHandler extends CommandHandler
30 {
31 /**
32 * @return CommandResult
33 * @throws InvalidArgumentException
34 * @throws QueryExecutionException
35 * @throws ContainerException
36 * @throws Exception
37 */
38 public function handle()
39 {
40 $result = new CommandResult();
41
42 /** @var EmailNotificationService $emailNotificationService */
43 $emailNotificationService = $this->getContainer()->get('application.emailNotification.service');
44
45 /** @var SMSNotificationService $smsNotificationService */
46 $smsNotificationService = $this->getContainer()->get('application.smsNotification.service');
47
48 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
49 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
50
51 /** @var PaymentRepository $paymentRepository */
52 $paymentRepository = $this->container->get('domain.payment.repository');
53
54 /** @var CustomerBookingRepository $bookingRepository */
55 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
56
57 /** @var SettingsService $settingsService */
58 $settingsService = $this->container->get('domain.settings.service');
59
60 $emailNotificationService->sendUndeliveredNotifications();
61
62 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
63 $smsNotificationService->sendUndeliveredNotifications();
64 }
65
66 if ($whatsAppNotificationService->checkRequiredFields()) {
67 $whatsAppNotificationService->sendUndeliveredNotifications();
68 }
69
70 /** @var Collection $payments */
71 $payments = $paymentRepository->getUncompletedActionsForPayments();
72
73 /** @var Collection $bookings */
74 $bookings = $bookingRepository->getUncompletedActionsForBookings();
75
76 do_action('amelia_before_run_uncompleted_actions', $payments->toArray(), $bookings->toArray());
77
78 /** @var Payment $payment */
79 foreach ($payments->getItems() as $payment) {
80 /** @var ReservationServiceInterface $reservationService */
81 $reservationService = $this->container->get('application.reservation.service')->get(
82 $payment->getEntity()->getValue()
83 );
84
85 BookingAddedEventHandler::handle(
86 $reservationService->getReservationByPayment($payment),
87 $this->container
88 );
89 }
90
91 /** @var CustomerBooking $booking */
92 foreach ($bookings->getItems() as $booking) {
93 /** @var ReservationServiceInterface $reservationService */
94 $reservationService = $this->container->get('application.reservation.service')->get(
95 $booking->getAppointmentId() ? Entities::APPOINTMENT : Entities::EVENT
96 );
97
98 BookingAddedEventHandler::handle(
99 $reservationService->getBookingResultByBookingId($booking->getId()->getValue()),
100 $this->container
101 );
102 }
103
104 do_action('amelia_after_run_uncompleted_actions', $payments->toArray(), $bookings->toArray());
105
106 $result->setResult(CommandResult::RESULT_SUCCESS);
107 $result->setMessage('Email notifications successfully sent');
108
109 return $result;
110 }
111 }
112