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 / GetPaymentsCommandHandler.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
GetPaymentsCommandHandler.php
109 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\Commands\SortParamsTrait;
13 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
14 use AmeliaBooking\Application\Services\Payment\PaymentApplicationService;
15 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
16 use AmeliaBooking\Domain\Entity\Entities;
17 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
20
21 /**
22 * Class GetPaymentsCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Payment
25 */
26 class GetPaymentsCommandHandler extends CommandHandler
27 {
28 use SortParamsTrait;
29
30 /**
31 * @param GetPaymentsCommand $command
32 *
33 * @return CommandResult
34 * @throws \Slim\Exception\ContainerValueNotFoundException
35 * @throws QueryExecutionException
36 * @throws InvalidArgumentException
37 * @throws AccessDeniedException
38 */
39 public function handle(GetPaymentsCommand $command)
40 {
41 if (!$command->getPermissionService()->currentUserCanRead(Entities::FINANCE)) {
42 throw new AccessDeniedException('You are not allowed to read payments.');
43 }
44
45 $result = new CommandResult();
46
47 $this->checkMandatoryFields($command);
48
49 /** @var PaymentRepository $paymentRepository */
50 $paymentRepository = $this->container->get('domain.payment.repository');
51
52 /** @var PaymentApplicationService $paymentAS */
53 $paymentAS = $this->container->get('application.payment.service');
54
55 $params = $command->getField('params');
56
57 if (!empty($params['dates'])) {
58 $params['dates'][0] .= ' 00:00:00';
59 $params['dates'][1] .= ' 23:59:59';
60 }
61
62 $params = $this->parseSortParams($params, ['id', 'created', 'status', 'amount', 'invoiceNumber']);
63
64 $paymentsData = $paymentAS->getPaymentsData(
65 $params,
66 $params['limit'] ?? 10
67 );
68
69 $isInvoicePage = !empty($params['invoices']) && filter_var($params['invoices'], FILTER_VALIDATE_BOOLEAN);
70
71 $payments = [];
72
73 foreach ($paymentsData as $paymentId => $payment) {
74 /** @var ReservationServiceInterface $reservationService */
75 $reservationService = $this->container->get('application.reservation.service')->get(
76 $payment['type']
77 );
78
79 $paymentsData[$paymentId]['summary'] = $reservationService->getPaymentSummary(
80 $payment,
81 $isInvoicePage
82 );
83
84 $payments[] = $paymentsData[$paymentId];
85 }
86
87 $payments = apply_filters('amelia_get_payments_filter', $payments);
88
89 do_action('amelia_get_payments', $payments);
90
91 $result->setResult(CommandResult::RESULT_SUCCESS);
92 $result->setMessage('Successfully retrieved payments.');
93 $result->setData(
94 [
95 Entities::PAYMENTS => $payments,
96 'filteredCount' => (int)$paymentRepository->getFilteredIdsCount($params, $isInvoicePage),
97 'totalCount' => (int)$paymentRepository->getFilteredIdsCount(
98 [
99 'separateRows' => !empty($params['separateRows']),
100 ],
101 $isInvoicePage
102 ),
103 ]
104 );
105
106 return $result;
107 }
108 }
109