PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.32
Booking for Appointments and Events Calendar – Amelia v1.2.32
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Application / Commands / Payment / DeletePaymentCommandHandler.php
ameliabooking / src / Application / Commands / Payment Last commit date
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
DeletePaymentCommandHandler.php
86 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\Application\Services\Payment\PaymentApplicationService;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\Entity\Entities;
16 use AmeliaBooking\Domain\Entity\Payment\Payment;
17 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
20 use Interop\Container\Exception\ContainerException;
21
22 /**
23 * Class DeletePaymentCommandHandler
24 *
25 * @package AmeliaBooking\Application\Commands\Payment
26 */
27 class DeletePaymentCommandHandler extends CommandHandler
28 {
29 /**
30 * @param DeletePaymentCommand $command
31 *
32 * @return CommandResult
33 * @throws QueryExecutionException
34 * @throws InvalidArgumentException
35 * @throws NotFoundException
36 * @throws AccessDeniedException
37 * @throws ContainerException
38 */
39 public function handle(DeletePaymentCommand $command)
40 {
41 if (!$command->getPermissionService()->currentUserCanDelete(Entities::FINANCE)) {
42 throw new AccessDeniedException('You are not allowed to delete payments.');
43 }
44
45 $result = new CommandResult();
46
47 $this->checkMandatoryFields($command);
48
49 /** @var PaymentApplicationService $paymentAS */
50 $paymentAS = $this->container->get('application.payment.service');
51
52 /** @var PaymentRepository $paymentRepository */
53 $paymentRepository = $this->container->get('domain.payment.repository');
54
55 /** @var Payment $payment */
56 $payment = $paymentRepository->getById($command->getArg('id'));
57
58 $paymentRepository->beginTransaction();
59
60 do_action('amelia_before_payment_deleted', $payment ? $payment->toArray() : null);
61
62 if (!$paymentAS->delete($payment)) {
63 $paymentRepository->rollback();
64
65 $result->setResult(CommandResult::RESULT_ERROR);
66 $result->setMessage('Unable to delete payment.');
67
68 return $result;
69 }
70
71 $paymentRepository->commit();
72
73 do_action('amelia_after_payment_deleted', $payment ? $payment->toArray() : null);
74
75 $result->setResult(CommandResult::RESULT_SUCCESS);
76 $result->setMessage('Payment successfully deleted.');
77 $result->setData(
78 [
79 Entities::PAYMENT => $payment->toArray()
80 ]
81 );
82
83 return $result;
84 }
85 }
86