PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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 / CancelBookingCommandHandler.php
ameliabooking / src / Application / Commands / Booking / Appointment Last commit date
AddAppointmentCommand.php 1 year ago AddAppointmentCommandHandler.php 3 weeks ago AddBookingCommand.php 1 year ago AddBookingCommandHandler.php 1 week ago ApproveBookingRemotelyCommand.php 1 year ago ApproveBookingRemotelyCommandHandler.php 4 months ago CancelBookingCommand.php 1 year ago CancelBookingCommandHandler.php 3 weeks ago CancelBookingRemotelyCommand.php 1 year ago CancelBookingRemotelyCommandHandler.php 2 months ago DeleteAppointmentCommand.php 1 year ago DeleteAppointmentCommandHandler.php 1 year ago DeleteBookingCommand.php 1 year ago DeleteBookingCommandHandler.php 11 months ago DeleteBookingRemotelyCommand.php 11 months ago DeleteBookingRemotelyCommandHandler.php 1 week ago GetAppointmentBookingsCommand.php 8 months ago GetAppointmentBookingsCommandHandler.php 3 weeks ago GetAppointmentCommand.php 7 years ago GetAppointmentCommandHandler.php 3 weeks ago GetAppointmentsCommand.php 1 year ago GetAppointmentsCommandHandler.php 3 weeks ago GetIcsCommand.php 8 months ago GetIcsCommandHandler.php 4 years ago GetTimeSlotsCommand.php 1 year ago GetTimeSlotsCommandHandler.php 1 week ago ReassignBookingCommand.php 1 year ago ReassignBookingCommandHandler.php 3 weeks ago RejectBookingRemotelyCommand.php 1 year ago RejectBookingRemotelyCommandHandler.php 6 months ago SuccessfulBookingCommand.php 1 year ago SuccessfulBookingCommandHandler.php 2 weeks ago UpdateAppointmentCommand.php 1 year ago UpdateAppointmentCommandHandler.php 1 week ago UpdateAppointmentNoteCommand.php 4 months ago UpdateAppointmentNoteCommandHandler.php 3 weeks ago UpdateAppointmentStatusCommand.php 1 year ago UpdateAppointmentStatusCommandHandler.php 3 weeks ago UpdateAppointmentTimeCommand.php 1 year ago UpdateAppointmentTimeCommandHandler.php 3 weeks ago UpdateBookingStatusCommand.php 1 year ago UpdateBookingStatusCommandHandler.php 7 months ago
CancelBookingCommandHandler.php
102 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\Domain\Common\Exceptions\BookingCancellationException;
9 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
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\ValueObjects\String\BookingStatus;
15 use AmeliaBooking\Domain\ValueObjects\String\Token;
16 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
18 use AmeliaBooking\Infrastructure\Repository\Booking\Appointment\CustomerBookingRepository;
19 use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings;
20
21 /**
22 * Class CancelBookingCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Booking\Appointment
25 */
26 class CancelBookingCommandHandler extends CommandHandler
27 {
28 /**
29 * @param CancelBookingCommand $command
30 *
31 * @return CommandResult
32 *
33 * @throws AccessDeniedException
34 * @throws InvalidArgumentException
35 * @throws NotFoundException
36 * @throws QueryExecutionException
37 */
38 public function handle(CancelBookingCommand $command)
39 {
40 /** @var AbstractUser $user */
41 $user = $command->authorize();
42
43 $result = new CommandResult();
44
45 /** @var CustomerBookingRepository $bookingRepository */
46 $bookingRepository = $this->container->get('domain.booking.customerBooking.repository');
47
48 /** @var CustomerBooking $booking */
49 $booking = $bookingRepository->getById((int)$command->getArg('id'));
50
51 $type = $booking->getAppointmentId() ? Entities::APPOINTMENT : Entities::EVENT;
52
53 /** @var ReservationServiceInterface $reservationService */
54 $reservationService = $this->container->get('application.reservation.service')->get($type);
55
56 $token = $bookingRepository->getToken((int)$command->getArg('id'));
57
58 if (!empty($token['token'])) {
59 $booking->setToken(new Token($token['token']));
60 }
61
62 if (!$command->getUserApplicationService()->isCustomerBooking($booking, $user, null)) {
63 throw new AccessDeniedException('You are not allowed to update booking status');
64 }
65
66 do_action('amelia_before_booking_canceled', $booking->toArray());
67
68 try {
69 $bookingData = $reservationService->updateStatus($booking, BookingStatus::CANCELED);
70 } catch (BookingCancellationException $e) {
71 $result->setResult(CommandResult::RESULT_ERROR);
72 $result->setMessage('You are not allowed to update booking status');
73 $result->setData(
74 [
75 'cancelBookingUnavailable' => true,
76 ]
77 );
78
79 return $result;
80 }
81
82 $result->setResult(CommandResult::RESULT_SUCCESS);
83 $result->setMessage('Successfully updated booking status');
84 $result->setData(
85 array_merge(
86 $bookingData,
87 [
88 'type' => $type,
89 'status' => BookingStatus::CANCELED,
90 'message' =>
91 BackendStrings::get('booking_status_changed') .
92 strtolower(BackendStrings::get(BookingStatus::CANCELED))
93 ],
94 )
95 );
96
97 do_action('amelia_after_booking_canceled', $bookingData);
98
99 return $result;
100 }
101 }
102