PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.0.2
Booking for Appointments and Events Calendar – Amelia v2.0.2
2.4.4 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 / RejectBookingRemotelyCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Appointment Last commit date
AddAppointmentCommand.php 1 year ago AddAppointmentCommandHandler.php 6 months ago AddBookingCommand.php 1 year ago AddBookingCommandHandler.php 1 year ago ApproveBookingRemotelyCommand.php 1 year ago ApproveBookingRemotelyCommandHandler.php 6 months ago CancelBookingCommand.php 1 year ago CancelBookingCommandHandler.php 6 months ago CancelBookingRemotelyCommand.php 1 year ago CancelBookingRemotelyCommandHandler.php 6 months ago DeleteAppointmentCommand.php 1 year ago DeleteAppointmentCommandHandler.php 1 year ago DeleteBookingCommand.php 1 year ago DeleteBookingCommandHandler.php 10 months ago DeleteBookingRemotelyCommand.php 10 months ago DeleteBookingRemotelyCommandHandler.php 6 months ago GetAppointmentBookingsCommand.php 6 months ago GetAppointmentBookingsCommandHandler.php 6 months ago GetAppointmentCommand.php 7 years ago GetAppointmentCommandHandler.php 5 months ago GetAppointmentsCommand.php 1 year ago GetAppointmentsCommandHandler.php 6 months ago GetIcsCommand.php 6 months ago GetIcsCommandHandler.php 4 years ago GetPackageAppointmentsCommand.php 1 year ago GetPackageAppointmentsCommandHandler.php 6 months ago GetTimeSlotsCommand.php 1 year ago GetTimeSlotsCommandHandler.php 10 months ago ReassignBookingCommand.php 1 year ago ReassignBookingCommandHandler.php 10 months ago RejectBookingRemotelyCommand.php 1 year ago RejectBookingRemotelyCommandHandler.php 6 months ago SuccessfulBookingCommand.php 1 year ago SuccessfulBookingCommandHandler.php 1 year ago UpdateAppointmentCommand.php 1 year ago UpdateAppointmentCommandHandler.php 6 months ago UpdateAppointmentStatusCommand.php 1 year ago UpdateAppointmentStatusCommandHandler.php 5 months ago UpdateAppointmentTimeCommand.php 1 year ago UpdateAppointmentTimeCommandHandler.php 10 months ago UpdateBookingStatusCommand.php 1 year ago UpdateBookingStatusCommandHandler.php 5 months ago
RejectBookingRemotelyCommandHandler.php
136 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\Common\Exceptions\BookingCancellationException;
10 use AmeliaBooking\Domain\Entity\Booking\Appointment\CustomerBooking;
11 use AmeliaBooking\Domain\Entity\Entities;
12 use AmeliaBooking\Domain\Entity\User\AbstractUser;
13 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
14 use AmeliaBooking\Domain\Services\Settings\SettingsService;
15 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
16 use AmeliaBooking\Domain\ValueObjects\String\BookingStatus;
17 use AmeliaBooking\Domain\ValueObjects\String\Token;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
19 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
20 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
21 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
22 use Slim\Exception\ContainerException;
23 use Slim\Exception\ContainerValueNotFoundException;
24 use UnexpectedValueException;
25
26 /**
27 * Class RejectBookingRemotelyCommandHandler
28 *
29 * @package AmeliaBooking\Application\Commands\Booking\Appointment
30 */
31 class RejectBookingRemotelyCommandHandler extends CommandHandler
32 {
33 /**
34 * @var array
35 */
36 public $mandatoryFields = [
37 'token',
38 ];
39
40 /**
41 * @param RejectBookingRemotelyCommand $command
42 *
43 * @return CommandResult
44 * @throws UnexpectedValueException
45 * @throws ContainerException
46 * @throws \InvalidArgumentException
47 * @throws ContainerValueNotFoundException
48 * @throws QueryExecutionException
49 * @throws InvalidArgumentException
50 * @throws AccessDeniedException
51 * @throws NotFoundException
52 */
53 public function handle(RejectBookingRemotelyCommand $command)
54 {
55 $this->checkMandatoryFields($command);
56
57 $result = new CommandResult();
58
59 $type = $command->getField('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['rejectErrorUrl']);
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::REJECTED;
99
100 do_action('amelia_before_booking_rejected_link', $booking ? $booking->toArray() : null);
101
102 try {
103 $bookingData = $reservationService->updateStatus($booking, $status);
104
105 $result->setResult(CommandResult::RESULT_SUCCESS);
106 $result->setMessage('Successfully updated booking status');
107 $result->setData(
108 array_merge(
109 $bookingData,
110 [
111 'type' => $type,
112 'status' => $status,
113 'message' => BackendStrings::get('appointment_status_changed') . strtolower(BackendStrings::get($status))
114 ]
115 )
116 );
117 } catch (BookingCancellationException $e) {
118 $result->setResult(CommandResult::RESULT_ERROR);
119 }
120
121 $notificationSettings = $settingsService->getCategorySettings('notifications');
122
123 if ($notificationSettings['rejectSuccessUrl'] && $result->getResult() === CommandResult::RESULT_SUCCESS) {
124 $result->setUrl($notificationSettings['rejectSuccessUrl']);
125
126 do_action('amelia_after_booking_rejected_link', $booking ? $booking->toArray() : null);
127 } elseif ($notificationSettings['rejectErrorUrl'] && $result->getResult() === CommandResult::RESULT_ERROR) {
128 $result->setUrl($notificationSettings['rejectErrorUrl']);
129 } else {
130 $result->setUrl('/');
131 }
132
133 return $result;
134 }
135 }
136