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 / Booking / Appointment / ApproveBookingRemotelyCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Appointment Last commit date
AddAppointmentCommand.php 7 years ago AddAppointmentCommandHandler.php 1 year ago AddBookingCommand.php 7 years ago AddBookingCommandHandler.php 1 year ago ApproveBookingRemotelyCommand.php 2 years ago ApproveBookingRemotelyCommandHandler.php 1 year ago CancelBookingCommand.php 7 years ago CancelBookingCommandHandler.php 2 years ago CancelBookingRemotelyCommand.php 7 years ago CancelBookingRemotelyCommandHandler.php 2 years ago DeleteAppointmentCommand.php 7 years ago DeleteAppointmentCommandHandler.php 2 years ago DeleteBookingCommand.php 4 years ago DeleteBookingCommandHandler.php 2 years ago GetAppointmentCommand.php 7 years ago GetAppointmentCommandHandler.php 1 year ago GetAppointmentsCommand.php 7 years ago GetAppointmentsCommandHandler.php 1 year ago GetIcsCommand.php 5 years ago GetIcsCommandHandler.php 4 years ago GetPackageAppointmentsCommand.php 1 year ago GetPackageAppointmentsCommandHandler.php 1 year ago GetTimeSlotsCommand.php 7 years ago GetTimeSlotsCommandHandler.php 1 year ago ReassignBookingCommand.php 5 years ago ReassignBookingCommandHandler.php 1 year ago RejectBookingRemotelyCommand.php 2 years ago RejectBookingRemotelyCommandHandler.php 1 year ago SuccessfulBookingCommand.php 7 years ago SuccessfulBookingCommandHandler.php 1 year ago UpdateAppointmentCommand.php 7 years ago UpdateAppointmentCommandHandler.php 1 year ago UpdateAppointmentStatusCommand.php 7 years ago UpdateAppointmentStatusCommandHandler.php 1 year ago UpdateAppointmentTimeCommand.php 7 years ago UpdateAppointmentTimeCommandHandler.php 1 year ago UpdateBookingStatusCommand.php 1 year ago UpdateBookingStatusCommandHandler.php 1 year ago
ApproveBookingRemotelyCommandHandler.php
130 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Booking\Appointment;
4
5 use AmeliaBooking\Application\Commands\CommandHandler;
6 use AmeliaBooking\Application\Commands\CommandResult;
7 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
8 use AmeliaBooking\Application\Services\User\CustomerApplicationService;
9 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
10 use AmeliaBooking\Domain\Entity\Entities;
11 use AmeliaBooking\Domain\Entity\User\AbstractUser;
12 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
13 use AmeliaBooking\Domain\Services\Settings\SettingsService;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
16 use AmeliaBooking\Domain\ValueObjects\String\Token;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
20 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
21 use Slim\Exception\ContainerException;
22 use Slim\Exception\ContainerValueNotFoundException;
23 use UnexpectedValueException;
24
25 /**
26 * Class ApproveBookingRemotelyCommandHandler
27 *
28 * @package AmeliaBooking\Application\Commands\Booking\Appointment
29 */
30 class ApproveBookingRemotelyCommandHandler extends CommandHandler
31 {
32 /**
33 * @var array
34 */
35 public $mandatoryFields = [
36 'token',
37 ];
38
39 /**
40 * @param ApproveBookingRemotelyCommand $command
41 *
42 * @return CommandResult
43 * @throws UnexpectedValueException
44 * @throws ContainerException
45 * @throws \InvalidArgumentException
46 * @throws ContainerValueNotFoundException
47 * @throws QueryExecutionException
48 * @throws InvalidArgumentException
49 * @throws AccessDeniedException
50 * @throws \Interop\Container\Exception\ContainerException
51 * @throws NotFoundException
52 */
53 public function handle(ApproveBookingRemotelyCommand $command)
54 {
55 $this->checkMandatoryFields($command);
56
57 $result = new CommandResult();
58
59 $type = Entities::APPOINTMENT;
60
61 /** @var CustomerApplicationService $customerAS */
62 $customerAS = $this->container->get('application.user.customer.service');
63 /** @var CustomerBookingRepository $bookingRepository */
64 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
65
66 /** @var AbstractUser $user */
67 $user = $this->container->get('logged.in.user');
68
69 /** @var CustomerBooking $booking */
70 $booking = $bookingRepository->getById((int)$command->getArg('id'));
71
72 /** @var SettingsService $settingsService */
73 $settingsService = $this->container->get('domain.settings.service');
74
75 $notificationSettings = $settingsService->getCategorySettings('notifications');
76
77 if ($booking === null) {
78 $result->setUrl($notificationSettings['approveErrorUrl']);
79 $result->setMessage('This booking does not exist!');
80 return $result;
81 }
82
83 $token = $bookingRepository->getToken((int)$command->getArg('id'));
84
85 if (empty($token['token'])) {
86 throw new AccessDeniedException('You are not allowed to update booking status');
87 }
88
89 $booking->setToken(new Token($token['token']));
90
91 if (!$customerAS->isCustomerBooking($booking, $user, $command->getField('token'))) {
92 throw new AccessDeniedException('You are not allowed to update booking status');
93 }
94
95 /** @var ReservationServiceInterface $reservationService */
96 $reservationService = $this->container->get('application.reservation.service')->get($type);
97
98 $status = BookingStatus::APPROVED;
99
100 do_action('amelia_before_booking_approved_link', $booking ? $booking->toArray() : null);
101
102 $bookingData = $reservationService->updateStatus($booking, $status);
103
104 $result->setResult(CommandResult::RESULT_SUCCESS);
105 $result->setMessage('Successfully updated booking status');
106 $result->setData(
107 array_merge(
108 $bookingData,
109 [
110 'type' => $type,
111 'status' => $status,
112 'message' => BackendStrings::getAppointmentStrings()['appointment_status_changed'] . strtolower(BackendStrings::getCommonStrings()[$status])
113 ]
114 )
115 );
116
117 if ($notificationSettings['approveSuccessUrl'] && $result->getResult() === CommandResult::RESULT_SUCCESS) {
118 $result->setUrl($notificationSettings['approveSuccessUrl']);
119
120 do_action('amelia_after_booking_approved_link', $booking ? $booking->toArray() : null);
121 } elseif ($notificationSettings['approveErrorUrl'] && $result->getResult() === CommandResult::RESULT_ERROR) {
122 $result->setUrl($notificationSettings['approveErrorUrl']);
123 } else {
124 $result->setUrl('/');
125 }
126
127 return $result;
128 }
129 }
130