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 / SuccessfulBookingCommandHandler.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
SuccessfulBookingCommandHandler.php
107 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\Services\Reservation\AbstractReservationService;
8 use AmeliaBooking\Domain\Entity\Entities;
9 use AmeliaBooking\Domain\Entity\Payment\Payment;
10 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
11 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
12 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
13 use Slim\Exception\ContainerValueNotFoundException;
14 use Exception;
15
16 /**
17 * Class SuccessfulBookingCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Booking\Appointment
20 */
21 class SuccessfulBookingCommandHandler extends CommandHandler
22 {
23 /**
24 * @var array
25 */
26 public $mandatoryFields = [
27 'appointmentStatusChanged',
28 ];
29
30 /**
31 * @param SuccessfulBookingCommand $command
32 *
33 * @return CommandResult
34 * @throws InvalidArgumentException
35 * @throws ContainerValueNotFoundException
36 * @throws Exception
37 */
38 public function handle(SuccessfulBookingCommand $command)
39 {
40 $this->checkMandatoryFields($command);
41
42 $type = $command->getField('type') === Entities::CART ?
43 Entities::APPOINTMENT : $command->getField('type');
44
45 /** @var AbstractReservationService $reservationService */
46 $reservationService = $this->container->get('application.reservation.service')->get($type);
47
48 /** @var PaymentRepository $paymentRepository */
49 $paymentRepository = $this->container->get('domain.payment.repository');
50
51 $paymentId = $command->getField('paymentId');
52
53 if ($paymentId) {
54 /** @var Payment $payment */
55 $payment = $paymentRepository->getById($paymentId);
56
57 if (
58 ($payment && $payment->getActionsCompleted() && $payment->getActionsCompleted()->getValue()) ||
59 ($payment && $payment->getTriggeredActions() && $payment->getTriggeredActions()->getValue())
60 ) {
61 $result = new CommandResult();
62
63 $result->setResult(CommandResult::RESULT_SUCCESS);
64 $result->setMessage('Successfully get booking');
65 $result->setDataInResponse(false);
66
67 return $result;
68 } elseif ($payment && !$payment->getTriggeredActions()) {
69 $paymentRepository->updateFieldById($paymentId, 1, 'triggeredActions');
70 }
71 }
72
73 $resultData = [
74 'bookingId' => (int)$command->getArg('id'),
75 'type' => $command->getField('type') ?: Entities::APPOINTMENT,
76 'recurring' => !empty($command->getFields()['recurring']) ? $command->getFields()['recurring'] : [],
77 'isCart' => $command->getField('type') === Entities::CART,
78 'appointmentStatusChanged' => $command->getFields()['appointmentStatusChanged'],
79 'packageId' => $command->getField('packageId'),
80 'customer' => $command->getField('customer'),
81 'paymentId' => $command->getField('paymentId'),
82 'packageCustomerId' => $command->getField('packageCustomerId'),
83 'isPackageAppointment' => !empty($command->getFields()['isPackageAppointment']),
84 'packageBookingFromBackend' => !empty($command->getFields()['packageBookingFromBackend'])
85 ];
86
87 $resultData = apply_filters('amelia_before_post_booking_actions_filter', $resultData);
88
89 do_action('amelia_before_post_booking_actions', $resultData);
90
91
92 return $reservationService->getSuccessBookingResponse(
93 $resultData['bookingId'],
94 $resultData['type'],
95 $resultData['recurring'],
96 $resultData['isCart'],
97 $resultData['appointmentStatusChanged'],
98 $resultData['packageId'],
99 $resultData['customer'],
100 $resultData['paymentId'],
101 $resultData['packageCustomerId'],
102 $resultData['isPackageAppointment'],
103 $resultData['packageBookingFromBackend']
104 );
105 }
106 }
107