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 / Payment / GetPaymentDetailsCommandHandler.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 6 months ago GetPaymentDetailsCommand.php 6 months ago GetPaymentDetailsCommandHandler.php 6 months ago GetPaymentsCommand.php 6 months ago GetPaymentsCommandHandler.php 6 months ago UpdatePaymentCommand.php 6 months ago UpdatePaymentCommandHandler.php 6 months ago
GetPaymentDetailsCommandHandler.php
83 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\Payment\PaymentApplicationService;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\Entity\Entities;
16 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use Interop\Container\Exception\ContainerException;
20
21 /**
22 * Class GetPaymentCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Payment
25 */
26 class GetPaymentDetailsCommandHandler extends CommandHandler
27 {
28 /**
29 * @param GetPaymentDetailsCommand $command
30 *
31 * @return CommandResult
32 * @throws QueryExecutionException
33 * @throws NotFoundException
34 * @throws InvalidArgumentException
35 * @throws AccessDeniedException
36 * @throws ContainerException
37 */
38 public function handle(GetPaymentDetailsCommand $command)
39 {
40 if (!$command->getPermissionService()->currentUserCanRead(Entities::FINANCE)) {
41 throw new AccessDeniedException('You are not allowed to read payment.');
42 }
43
44 $result = new CommandResult();
45
46 $this->checkMandatoryFields($command);
47
48 /** @var PaymentApplicationService $paymentAS */
49 $paymentAS = $this->container->get('application.payment.service');
50
51 $params = $command->getField('params');
52
53 $paymentId = $command->getArg('id');
54
55 $paymentsData = $paymentAS->getPaymentsData(
56 [
57 'ids' => [$paymentId],
58 'invoices' => !empty($params['invoices']),
59 ]
60 );
61
62 if (empty($paymentsData)) {
63 throw new NotFoundException('Payment not found.');
64 }
65
66 /** @var ReservationServiceInterface $reservationService */
67 $reservationService = $this->container->get('application.reservation.service')->get(
68 $paymentsData[$paymentId]['type']
69 );
70
71 $paymentsData[$paymentId]['summary'] = $reservationService->getPaymentSummary(
72 $paymentsData[$paymentId],
73 !empty($params['invoices'])
74 );
75
76 $result->setResult(CommandResult::RESULT_SUCCESS);
77 $result->setMessage('Successfully retrieved payment.');
78 $result->setData([Entities::PAYMENT => reset($paymentsData)]);
79
80 return $result;
81 }
82 }
83