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 / CalculatePaymentAmountCommandHandler.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
CalculatePaymentAmountCommandHandler.php
107 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\Services\Booking\BookingApplicationService;
13 use AmeliaBooking\Application\Services\Payment\PaymentApplicationService;
14 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
15 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
16 use AmeliaBooking\Domain\Services\Settings\SettingsService;
17 use AmeliaBooking\Domain\ValueObjects\String\BookingType;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
19 use AmeliaBooking\Infrastructure\Services\Payment\SquareService;
20 use Exception;
21 use Interop\Container\Exception\ContainerException;
22 use Slim\Exception\ContainerValueNotFoundException;
23
24 /**
25 * Class CalculatePaymentAmountCommandHandler
26 *
27 * @package AmeliaBooking\Application\Commands\Payment
28 */
29 class CalculatePaymentAmountCommandHandler extends CommandHandler
30 {
31 /**
32 * @param CalculatePaymentAmountCommand $command
33 *
34 * @return CommandResult
35 * @throws ContainerValueNotFoundException
36 * @throws QueryExecutionException
37 * @throws InvalidArgumentException
38 * @throws ContainerException
39 * @throws Exception
40 */
41 public function handle(CalculatePaymentAmountCommand $command)
42 {
43 $result = new CommandResult();
44
45 $this->checkMandatoryFields($command);
46
47 /** @var SettingsService $settingsService */
48 $settingsService = $this->container->get('domain.settings.service');
49
50 /** @var ReservationServiceInterface $reservationService */
51 $reservationService = $this->container->get('application.reservation.service')->get($command->getField('type'));
52
53 /** @var PaymentApplicationService $paymentAS */
54 $paymentAS = $this->container->get('application.payment.service');
55
56 /** @var BookingApplicationService $bookingAS */
57 $bookingAS = $this->container->get('application.booking.booking.service');
58
59 $squareSettings = $settingsService->getCategorySettings('payments')['square'];
60
61 $reservation = $reservationService->getNew(true, true, true);
62
63 $reservationService->processBooking(
64 $result,
65 $bookingAS->getAppointmentData($command->getFields()),
66 $reservation,
67 false
68 );
69
70 if ($result->getResult() === CommandResult::RESULT_ERROR) {
71 return $result;
72 }
73
74 $transfers = [];
75
76 $paymentAS->setTransfers(
77 $bookingAS->getAppointmentData($command->getFields())['payment'],
78 $reservation,
79 new BookingType($command->getField('type')),
80 $transfers,
81 false
82 );
83
84 $paymentAmount = $reservationService->getReservationPaymentAmount($reservation);
85
86 $countryCode = null;
87 if ($squareSettings['enabled']) {
88 /** @var SquareService $squareService */
89 $squareService = $this->container->get('infrastructure.payment.square.service');
90
91 $countryCode = $squareService->getCountryCodeByLocationId($squareSettings['locationId']);
92 }
93
94 $result->setResult(CommandResult::RESULT_SUCCESS);
95 $result->setData(
96 [
97 'amount' => $paymentAmount,
98 'currency' => $settingsService->getCategorySettings('payments')['currency'],
99 'transfers' => $transfers,
100 'countryCode' => $countryCode,
101 ]
102 );
103
104 return $result;
105 }
106 }
107