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
GetPaymentCommandHandler.php
70 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\Domain\Common\Exceptions\InvalidArgumentException; |
| 14 | use AmeliaBooking\Domain\Entity\Payment\Payment; |
| 15 | use AmeliaBooking\Domain\Entity\Entities; |
| 16 | use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException; |
| 17 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 18 | use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository; |
| 19 | use Interop\Container\Exception\ContainerException; |
| 20 | |
| 21 | /** |
| 22 | * Class GetPaymentCommandHandler |
| 23 | * |
| 24 | * @package AmeliaBooking\Application\Commands\Payment |
| 25 | */ |
| 26 | class GetPaymentCommandHandler extends CommandHandler |
| 27 | { |
| 28 | /** |
| 29 | * @param GetPaymentCommand $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(GetPaymentCommand $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 PaymentRepository $paymentRepository */ |
| 49 | $paymentRepository = $this->container->get('domain.payment.repository'); |
| 50 | |
| 51 | /** @var Payment $payment */ |
| 52 | $payment = $paymentRepository->getById($command->getArg('id')); |
| 53 | |
| 54 | $paymentArray = apply_filters('amelia_get_payment_filter', $payment->toArray()); |
| 55 | |
| 56 | do_action('amelia_get_payment', $paymentArray); |
| 57 | |
| 58 | |
| 59 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 60 | $result->setMessage('Successfully retrieved payment.'); |
| 61 | $result->setData( |
| 62 | [ |
| 63 | Entities::PAYMENT => $paymentArray, |
| 64 | ] |
| 65 | ); |
| 66 | |
| 67 | return $result; |
| 68 | } |
| 69 | } |
| 70 |