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
GetPaymentCommandHandler.php
92 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\Payment\Payment; |
| 16 | use AmeliaBooking\Domain\Entity\Entities; |
| 17 | use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface; |
| 18 | use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException; |
| 19 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 20 | use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository; |
| 21 | |
| 22 | /** |
| 23 | * Class GetPaymentCommandHandler |
| 24 | * |
| 25 | * @package AmeliaBooking\Application\Commands\Payment |
| 26 | */ |
| 27 | class GetPaymentCommandHandler extends CommandHandler |
| 28 | { |
| 29 | /** |
| 30 | * @param GetPaymentCommand $command |
| 31 | * |
| 32 | * @return CommandResult |
| 33 | * @throws QueryExecutionException |
| 34 | * @throws NotFoundException |
| 35 | * @throws InvalidArgumentException |
| 36 | * @throws AccessDeniedException |
| 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 PaymentApplicationService $paymentAS */ |
| 52 | $paymentAS = $this->container->get('application.payment.service'); |
| 53 | |
| 54 | /** @var Payment $payment */ |
| 55 | $payment = $paymentRepository->getById($command->getArg('id')); |
| 56 | |
| 57 | $paymentArray = $payment->toArray(); |
| 58 | |
| 59 | /** @var ReservationServiceInterface $reservationService */ |
| 60 | $reservationService = $this->container->get('application.reservation.service')->get( |
| 61 | $payment->getEntity()->getValue() |
| 62 | ); |
| 63 | |
| 64 | $paymentsData = $paymentAS->getPaymentsData( |
| 65 | [ |
| 66 | 'ids' => [$payment->getId()->getValue()], |
| 67 | 'invoices' => false, |
| 68 | ] |
| 69 | ); |
| 70 | |
| 71 | $paymentArray['summary'] = $reservationService->getPaymentSummary( |
| 72 | $paymentsData[$payment->getId()->getValue()], |
| 73 | false |
| 74 | ); |
| 75 | |
| 76 | $paymentArray = apply_filters('amelia_get_payment_filter', $paymentArray); |
| 77 | |
| 78 | do_action('amelia_get_payment', $paymentArray); |
| 79 | |
| 80 | |
| 81 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 82 | $result->setMessage('Successfully retrieved payment.'); |
| 83 | $result->setData( |
| 84 | [ |
| 85 | Entities::PAYMENT => $paymentArray, |
| 86 | ] |
| 87 | ); |
| 88 | |
| 89 | return $result; |
| 90 | } |
| 91 | } |
| 92 |