AddPaymentCommand.php
7 years ago
AddPaymentCommandHandler.php
2 years ago
CalculatePaymentAmountCommand.php
3 years ago
CalculatePaymentAmountCommandHandler.php
3 years ago
DeletePaymentCommand.php
7 years ago
DeletePaymentCommandHandler.php
2 years ago
GetPaymentCommand.php
7 years ago
GetPaymentCommandHandler.php
1 year ago
GetPaymentsCommand.php
7 years ago
GetPaymentsCommandHandler.php
1 year ago
UpdatePaymentCommand.php
7 years ago
UpdatePaymentCommandHandler.php
2 years ago
GetPaymentsCommandHandler.php
85 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Application\Commands\Payment; |
| 8 | |
| 9 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 10 | use AmeliaBooking\Application\Commands\CommandResult; |
| 11 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 12 | use AmeliaBooking\Application\Services\Payment\PaymentApplicationService; |
| 13 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 14 | use AmeliaBooking\Domain\Entity\Entities; |
| 15 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 16 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 17 | use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository; |
| 18 | |
| 19 | /** |
| 20 | * Class GetPaymentsCommandHandler |
| 21 | * |
| 22 | * @package AmeliaBooking\Application\Commands\Payment |
| 23 | */ |
| 24 | class GetPaymentsCommandHandler extends CommandHandler |
| 25 | { |
| 26 | /** |
| 27 | * @param GetPaymentsCommand $command |
| 28 | * |
| 29 | * @return CommandResult |
| 30 | * @throws \Slim\Exception\ContainerValueNotFoundException |
| 31 | * @throws QueryExecutionException |
| 32 | * @throws InvalidArgumentException |
| 33 | * @throws AccessDeniedException |
| 34 | * @throws \Interop\Container\Exception\ContainerException |
| 35 | */ |
| 36 | public function handle(GetPaymentsCommand $command) |
| 37 | { |
| 38 | if (!$command->getPermissionService()->currentUserCanRead(Entities::FINANCE)) { |
| 39 | throw new AccessDeniedException('You are not allowed to read payments.'); |
| 40 | } |
| 41 | |
| 42 | $result = new CommandResult(); |
| 43 | |
| 44 | $this->checkMandatoryFields($command); |
| 45 | |
| 46 | /** @var PaymentRepository $paymentRepository */ |
| 47 | $paymentRepository = $this->container->get('domain.payment.repository'); |
| 48 | |
| 49 | /** @var SettingsService $settingsService */ |
| 50 | $settingsService = $this->container->get('domain.settings.service'); |
| 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 | $paymentsData = $paymentAS->getPaymentsData($params, $settingsService->getSetting('general', 'itemsPerPageBackEnd')); |
| 63 | |
| 64 | $payments = array_values($paymentsData); |
| 65 | |
| 66 | $payments = apply_filters('amelia_get_payments_filter', $payments); |
| 67 | |
| 68 | do_action('amelia_get_payments', $payments); |
| 69 | |
| 70 | $isInvoicePage = !empty($params['invoices']) && filter_var($params['invoices'], FILTER_VALIDATE_BOOLEAN); |
| 71 | |
| 72 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 73 | $result->setMessage('Successfully retrieved payments.'); |
| 74 | $result->setData( |
| 75 | [ |
| 76 | Entities::PAYMENTS => $payments, |
| 77 | 'filteredCount' => (int)$paymentRepository->getFilteredIdsCount($params, $isInvoicePage), |
| 78 | 'totalCount' => (int)$paymentRepository->getFilteredIdsCount([], $isInvoicePage), |
| 79 | ] |
| 80 | ); |
| 81 | |
| 82 | return $result; |
| 83 | } |
| 84 | } |
| 85 |