PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
2.4.5 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 1 year ago AddPaymentCommandHandler.php 1 year ago CalculatePaymentAmountCommand.php 1 year ago CalculatePaymentAmountCommandHandler.php 1 year ago DeletePaymentCommand.php 1 year ago DeletePaymentCommandHandler.php 1 year ago GetPaymentCommand.php 1 year ago GetPaymentCommandHandler.php 1 year ago GetPaymentsCommand.php 1 year ago GetPaymentsCommandHandler.php 1 year ago UpdatePaymentCommand.php 1 year ago UpdatePaymentCommandHandler.php 1 year ago
GetPaymentsCommandHandler.php
86 lines
1 <?php
2
3 /**
4 * @copyright © TMS-Plugins. 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\Settings\SettingsService;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
18 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
19
20 /**
21 * Class GetPaymentsCommandHandler
22 *
23 * @package AmeliaBooking\Application\Commands\Payment
24 */
25 class GetPaymentsCommandHandler extends CommandHandler
26 {
27 /**
28 * @param GetPaymentsCommand $command
29 *
30 * @return CommandResult
31 * @throws \Slim\Exception\ContainerValueNotFoundException
32 * @throws QueryExecutionException
33 * @throws InvalidArgumentException
34 * @throws AccessDeniedException
35 * @throws \Interop\Container\Exception\ContainerException
36 */
37 public function handle(GetPaymentsCommand $command)
38 {
39 if (!$command->getPermissionService()->currentUserCanRead(Entities::FINANCE)) {
40 throw new AccessDeniedException('You are not allowed to read payments.');
41 }
42
43 $result = new CommandResult();
44
45 $this->checkMandatoryFields($command);
46
47 /** @var PaymentRepository $paymentRepository */
48 $paymentRepository = $this->container->get('domain.payment.repository');
49
50 /** @var SettingsService $settingsService */
51 $settingsService = $this->container->get('domain.settings.service');
52
53 /** @var PaymentApplicationService $paymentAS */
54 $paymentAS = $this->container->get('application.payment.service');
55
56 $params = $command->getField('params');
57
58 if (!empty($params['dates'])) {
59 $params['dates'][0] .= ' 00:00:00';
60 $params['dates'][1] .= ' 23:59:59';
61 }
62
63 $paymentsData = $paymentAS->getPaymentsData($params, $settingsService->getSetting('general', 'itemsPerPageBackEnd'));
64
65 $payments = array_values($paymentsData);
66
67 $payments = apply_filters('amelia_get_payments_filter', $payments);
68
69 do_action('amelia_get_payments', $payments);
70
71 $isInvoicePage = !empty($params['invoices']) && filter_var($params['invoices'], FILTER_VALIDATE_BOOLEAN);
72
73 $result->setResult(CommandResult::RESULT_SUCCESS);
74 $result->setMessage('Successfully retrieved payments.');
75 $result->setData(
76 [
77 Entities::PAYMENTS => $payments,
78 'filteredCount' => (int)$paymentRepository->getFilteredIdsCount($params, $isInvoicePage),
79 'totalCount' => (int)$paymentRepository->getFilteredIdsCount([], $isInvoicePage),
80 ]
81 );
82
83 return $result;
84 }
85 }
86