PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / Payment / UpdatePaymentCommandHandler.php
ameliabooking / src / Application / Commands / Payment Last commit date
AddPaymentCommand.php 6 months ago AddPaymentCommandHandler.php 6 months ago CalculatePaymentAmountCommand.php 6 months ago CalculatePaymentAmountCommandHandler.php 6 months ago DeletePaymentCommand.php 6 months ago DeletePaymentCommandHandler.php 6 months ago GetPaymentCommand.php 6 months ago GetPaymentCommandHandler.php 3 months ago GetPaymentsCommand.php 6 months ago GetPaymentsCommandHandler.php 2 months ago UpdatePaymentCommand.php 6 months ago UpdatePaymentCommandHandler.php 6 months ago
UpdatePaymentCommandHandler.php
121 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Application\Commands\Payment;
9
10 use AmeliaBooking\Application\Commands\CommandHandler;
11 use AmeliaBooking\Application\Commands\CommandResult;
12 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
13 use AmeliaBooking\Application\Services\Notification\ApplicationNotificationService;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\Entity\Payment\Payment;
16 use AmeliaBooking\Domain\Entity\Entities;
17 use AmeliaBooking\Domain\Factory\Booking\Event\EventFactory;
18 use AmeliaBooking\Domain\Factory\Payment\PaymentFactory;
19 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
20 use AmeliaBooking\Domain\Services\Settings\SettingsService;
21 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
22 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
23 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
24
25 /**
26 * Class UpdatePaymentCommandHandler
27 *
28 * @package AmeliaBooking\Application\Commands\Payment
29 */
30 class UpdatePaymentCommandHandler extends CommandHandler
31 {
32 /**
33 * @param UpdatePaymentCommand $command
34 *
35 * @return CommandResult
36 * @throws \Slim\Exception\ContainerValueNotFoundException
37 * @throws QueryExecutionException
38 * @throws InvalidArgumentException
39 * @throws AccessDeniedException
40 */
41 public function handle(UpdatePaymentCommand $command)
42 {
43 if (!$command->getPermissionService()->currentUserCanWrite(Entities::FINANCE)) {
44 throw new AccessDeniedException('You are not allowed to update payment.');
45 }
46
47 $result = new CommandResult();
48
49 $this->checkMandatoryFields($command);
50
51 $paymentArray = $command->getFields();
52
53 $paymentArray = apply_filters('amelia_before_payment_updated_filter', $paymentArray);
54
55 do_action('amelia_before_payment_updated', $paymentArray);
56
57 $payment = PaymentFactory::create($paymentArray);
58
59 if (!$payment instanceof Payment) {
60 $result->setResult(CommandResult::RESULT_ERROR);
61 $result->setMessage('Unable to update payment.');
62
63 return $result;
64 }
65
66 /** @var PaymentRepository $paymentRepository */
67 $paymentRepository = $this->container->get('domain.payment.repository');
68
69 /** @var SettingsService $settingsDS */
70 $settingsDS = $this->container->get('domain.settings.service');
71
72 $paymentId = (int)$command->getArg('id');
73 if ($paymentRepository->update($paymentId, $payment)) {
74 $payment->setId(new Id($paymentId));
75 do_action('amelia_after_payment_updated', $payment->toArray());
76
77 $paymentEntity = $payment->getEntity() ? $payment->getEntity()->getValue() : null;
78 $paymentStatus = $payment->getStatus() ? $payment->getStatus()->getValue() : null;
79
80 if (
81 $settingsDS->isFeatureEnabled('eTickets') &&
82 $paymentEntity === Entities::EVENT &&
83 $paymentStatus === 'paid'
84 ) {
85 /** @var ReservationServiceInterface $reservationService */
86 $reservationService = $this->container->get('application.reservation.service')->get(
87 $paymentEntity
88 );
89 /** @var ApplicationNotificationService $applicationNotificationService */
90 $applicationNotificationService = $this->container->get('application.notification.service');
91
92 $customerBookingId = $payment->getCustomerBookingId() ? $payment->getCustomerBookingId()->getValue() : null;
93 $reservationEvent = $reservationService->getReservationByBookingId($customerBookingId);
94
95 $bookingKey = null;
96
97 foreach ($reservationEvent->getBookings()->toArray() as $index => $reservationBooking) {
98 if ($reservationBooking['id'] === $customerBookingId) {
99 $bookingKey = $index;
100 }
101 }
102
103 $applicationNotificationService->sendEventQrNotification(
104 EventFactory::create($reservationEvent->toArray()),
105 $bookingKey
106 );
107 }
108
109 $result->setResult(CommandResult::RESULT_SUCCESS);
110 $result->setMessage('Payment successfully updated.');
111 $result->setData(
112 [
113 Entities::PAYMENT => $payment->toArray(),
114 ]
115 );
116 }
117
118 return $result;
119 }
120 }
121