PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
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 / GetPaymentsCommandHandler.php
ameliabooking / src / Application / Commands / Payment Last commit date
AddPaymentCommand.php 7 months ago AddPaymentCommandHandler.php 7 months ago CalculatePaymentAmountCommand.php 7 months ago CalculatePaymentAmountCommandHandler.php 7 months ago DeletePaymentCommand.php 7 months ago DeletePaymentCommandHandler.php 7 months ago GetPaymentCommand.php 7 months ago GetPaymentCommandHandler.php 4 months ago GetPaymentsCommand.php 7 months ago GetPaymentsCommandHandler.php 3 weeks ago UpdatePaymentCommand.php 7 months ago UpdatePaymentCommandHandler.php 7 months ago
GetPaymentsCommandHandler.php
121 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\Commands\SortParamsTrait;
13 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
14 use AmeliaBooking\Application\Services\Payment\PaymentApplicationService;
15 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
16 use AmeliaBooking\Domain\Entity\Entities;
17 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Licence\Licence;
20 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
21
22 /**
23 * Class GetPaymentsCommandHandler
24 *
25 * @package AmeliaBooking\Application\Commands\Payment
26 */
27 class GetPaymentsCommandHandler extends CommandHandler
28 {
29 use SortParamsTrait;
30
31 /**
32 * @param GetPaymentsCommand $command
33 *
34 * @return CommandResult
35 * @throws \Slim\Exception\ContainerValueNotFoundException
36 * @throws QueryExecutionException
37 * @throws InvalidArgumentException
38 * @throws AccessDeniedException
39 */
40 public function handle(GetPaymentsCommand $command)
41 {
42 if (!$command->getPermissionService()->currentUserCanRead(Entities::FINANCE)) {
43 throw new AccessDeniedException('You are not allowed to read payments.');
44 }
45
46 $result = new CommandResult();
47
48 $this->checkMandatoryFields($command);
49
50 /** @var PaymentRepository $paymentRepository */
51 $paymentRepository = $this->container->get('domain.payment.repository');
52
53 /** @var PaymentApplicationService $paymentAS */
54 $paymentAS = $this->container->get('application.payment.service');
55
56 $params = $command->getField('params');
57
58 if (!empty($params['dates'])) {
59 $params['dates'][0] .= ' 00:00:00';
60 $params['dates'][1] .= ' 23:59:59';
61 }
62
63 $params = $this->parseSortParams($params, ['id', 'created', 'status', 'amount', 'invoiceNumber']);
64
65 $paymentsData = $paymentAS->getPaymentsData(
66 $params,
67 $params['limit'] ?? 10
68 );
69
70 $isInvoicePage = !empty($params['invoices']) && filter_var($params['invoices'], FILTER_VALIDATE_BOOLEAN);
71
72 $payments = [];
73
74 foreach ($paymentsData as $paymentId => $payment) {
75 if ($payment['type'] === Entities::PACKAGE && !Licence::hasFeatureAccess('packages')) {
76 $paymentsData[$paymentId]['summary'] = [
77 'bookable' => 0,
78 'subtotal' => 0,
79 'discount' => 0,
80 'wcDiscount' => 0,
81 'tax' => 0,
82 'wcTax' => 0,
83 ];
84 } else {
85 /** @var ReservationServiceInterface $reservationService */
86 $reservationService = $this->container->get('application.reservation.service')->get(
87 $payment['type']
88 );
89
90 $paymentsData[$paymentId]['summary'] = $reservationService->getPaymentSummary(
91 $payment,
92 $isInvoicePage
93 );
94 }
95
96 $payments[] = $paymentsData[$paymentId];
97 }
98
99 $payments = apply_filters('amelia_get_payments_filter', $payments);
100
101 do_action('amelia_get_payments', $payments);
102
103 $result->setResult(CommandResult::RESULT_SUCCESS);
104 $result->setMessage('Successfully retrieved payments.');
105 $result->setData(
106 [
107 Entities::PAYMENTS => $payments,
108 'filteredCount' => (int)$paymentRepository->getFilteredIdsCount($params, $isInvoicePage),
109 'totalCount' => (int)$paymentRepository->getFilteredIdsCount(
110 [
111 'separateRows' => !empty($params['separateRows']),
112 ],
113 $isInvoicePage
114 ),
115 ]
116 );
117
118 return $result;
119 }
120 }
121