PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.31
Booking for Appointments and Events Calendar – Amelia v1.2.31
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 / AddPaymentCommandHandler.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
AddPaymentCommandHandler.php
84 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\Domain\Factory\Payment\PaymentFactory;
17 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
20
21 /**
22 * Class AddPaymentCommandHandler
23 *
24 * @package AmeliaBooking\Application\Commands\Payment
25 */
26 class AddPaymentCommandHandler extends CommandHandler
27 {
28 /** @var array */
29 public $mandatoryFields = [];
30
31 /**
32 * @param AddPaymentCommand $command
33 *
34 * @return CommandResult
35 * @throws InvalidArgumentException
36 * @throws QueryExecutionException
37 * @throws AccessDeniedException
38 * @throws \Interop\Container\Exception\ContainerException
39 */
40 public function handle(AddPaymentCommand $command)
41 {
42 if (!$command->getPermissionService()->currentUserCanWrite(Entities::FINANCE)) {
43 throw new AccessDeniedException('You are not allowed to add new payment.');
44 }
45
46 $result = new CommandResult();
47
48 $this->checkMandatoryFields($command);
49
50 $paymentArray = $command->getFields();
51
52 $paymentArray = apply_filters('amelia_before_payment_added_filter', $paymentArray);
53
54 do_action('amelia_before_payment_added', $paymentArray);
55
56 $payment = PaymentFactory::create($paymentArray);
57 if (!$payment instanceof Payment) {
58 $result->setResult(CommandResult::RESULT_ERROR);
59 $result->setMessage('Unable to create payment.');
60
61 return $result;
62 }
63
64 /** @var PaymentRepository $paymentRepository */
65 $paymentRepository = $this->container->get('domain.payment.repository');
66
67 if ($paymentId = $paymentRepository->add($payment)) {
68 $payment->setId(new Id($paymentId));
69
70 do_action('amelia_after_payment_added', $payment->toArray());
71
72 $result->setResult(CommandResult::RESULT_SUCCESS);
73 $result->setMessage('New payment successfully created.');
74 $result->setData(
75 [
76 Entities::PAYMENT => $payment->toArray(),
77 ]
78 );
79 }
80
81 return $result;
82 }
83 }
84