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
DeletePaymentCommandHandler.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\Entity\Payment\Payment; |
| 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 DeletePaymentCommandHandler |
| 23 | * |
| 24 | * @package AmeliaBooking\Application\Commands\Payment |
| 25 | */ |
| 26 | class DeletePaymentCommandHandler extends CommandHandler |
| 27 | { |
| 28 | /** |
| 29 | * @param DeletePaymentCommand $command |
| 30 | * |
| 31 | * @return CommandResult |
| 32 | * @throws QueryExecutionException |
| 33 | * @throws InvalidArgumentException |
| 34 | * @throws NotFoundException |
| 35 | * @throws AccessDeniedException |
| 36 | * @throws ContainerException |
| 37 | */ |
| 38 | public function handle(DeletePaymentCommand $command) |
| 39 | { |
| 40 | if (!$command->getPermissionService()->currentUserCanDelete(Entities::FINANCE)) { |
| 41 | throw new AccessDeniedException('You are not allowed to delete payments.'); |
| 42 | } |
| 43 | |
| 44 | $result = new CommandResult(); |
| 45 | |
| 46 | $this->checkMandatoryFields($command); |
| 47 | |
| 48 | /** @var PaymentApplicationService $paymentAS */ |
| 49 | $paymentAS = $this->container->get('application.payment.service'); |
| 50 | |
| 51 | /** @var PaymentRepository $paymentRepository */ |
| 52 | $paymentRepository = $this->container->get('domain.payment.repository'); |
| 53 | |
| 54 | /** @var Payment $payment */ |
| 55 | $payment = $paymentRepository->getById($command->getArg('id')); |
| 56 | |
| 57 | $paymentRepository->beginTransaction(); |
| 58 | |
| 59 | do_action('amelia_before_payment_deleted', $payment ? $payment->toArray() : null); |
| 60 | |
| 61 | if (!$paymentAS->delete($payment)) { |
| 62 | $paymentRepository->rollback(); |
| 63 | |
| 64 | $result->setResult(CommandResult::RESULT_ERROR); |
| 65 | $result->setMessage('Unable to delete payment.'); |
| 66 | |
| 67 | return $result; |
| 68 | } |
| 69 | |
| 70 | $paymentRepository->commit(); |
| 71 | |
| 72 | do_action('amelia_after_payment_deleted', $payment ? $payment->toArray() : null); |
| 73 | |
| 74 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 75 | $result->setMessage('Payment successfully deleted.'); |
| 76 | $result->setData( |
| 77 | [ |
| 78 | Entities::PAYMENT => $payment->toArray() |
| 79 | ] |
| 80 | ); |
| 81 | |
| 82 | return $result; |
| 83 | } |
| 84 | } |
| 85 |