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