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
UpdatePaymentCommandHandler.php
82 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\Domain\Common\Exceptions\InvalidArgumentException; |
| 13 | use AmeliaBooking\Domain\Entity\Payment\Payment; |
| 14 | use AmeliaBooking\Domain\Entity\Entities; |
| 15 | use AmeliaBooking\Domain\Factory\Payment\PaymentFactory; |
| 16 | use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id; |
| 17 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 18 | use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository; |
| 19 | |
| 20 | /** |
| 21 | * Class UpdatePaymentCommandHandler |
| 22 | * |
| 23 | * @package AmeliaBooking\Application\Commands\Payment |
| 24 | */ |
| 25 | class UpdatePaymentCommandHandler extends CommandHandler |
| 26 | { |
| 27 | /** |
| 28 | * @param UpdatePaymentCommand $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(UpdatePaymentCommand $command) |
| 38 | { |
| 39 | if (!$command->getPermissionService()->currentUserCanWrite(Entities::FINANCE)) { |
| 40 | throw new AccessDeniedException('You are not allowed to update payment.'); |
| 41 | } |
| 42 | |
| 43 | $result = new CommandResult(); |
| 44 | |
| 45 | $this->checkMandatoryFields($command); |
| 46 | |
| 47 | $paymentArray = $command->getFields(); |
| 48 | |
| 49 | $paymentArray = apply_filters('amelia_before_payment_updated_filter', $paymentArray); |
| 50 | |
| 51 | do_action('amelia_before_payment_updated', $paymentArray); |
| 52 | |
| 53 | $payment = PaymentFactory::create($paymentArray); |
| 54 | |
| 55 | if (!$payment instanceof Payment) { |
| 56 | $result->setResult(CommandResult::RESULT_ERROR); |
| 57 | $result->setMessage('Unable to update payment.'); |
| 58 | |
| 59 | return $result; |
| 60 | } |
| 61 | |
| 62 | /** @var PaymentRepository $paymentRepository */ |
| 63 | $paymentRepository = $this->container->get('domain.payment.repository'); |
| 64 | |
| 65 | $paymentId = (int)$command->getArg('id'); |
| 66 | if ($paymentRepository->update($paymentId, $payment)) { |
| 67 | $payment->setId(new Id($paymentId)); |
| 68 | do_action('amelia_after_payment_updated', $payment->toArray()); |
| 69 | |
| 70 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 71 | $result->setMessage('Payment successfully updated.'); |
| 72 | $result->setData( |
| 73 | [ |
| 74 | Entities::PAYMENT => $payment->toArray(), |
| 75 | ] |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | return $result; |
| 80 | } |
| 81 | } |
| 82 |