PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.9
Booking for Appointments and Events Calendar – Amelia v2.4.9
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 / CalculatePaymentAmountCommandHandler.php
ameliabooking / src / Application / Commands / Payment Last commit date
AddPaymentCommand.php 8 months ago AddPaymentCommandHandler.php 8 months ago CalculatePaymentAmountCommand.php 8 months ago CalculatePaymentAmountCommandHandler.php 5 days ago DeletePaymentCommand.php 8 months ago DeletePaymentCommandHandler.php 8 months ago GetPaymentCommand.php 8 months ago GetPaymentCommandHandler.php 4 months ago GetPaymentsCommand.php 8 months ago GetPaymentsCommandHandler.php 1 month ago UpdatePaymentCommand.php 8 months ago UpdatePaymentCommandHandler.php 8 months ago
CalculatePaymentAmountCommandHandler.php
85 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\Domain\Common\Exceptions\InvalidArgumentException;
13 use AmeliaBooking\Domain\Services\Reservation\ReservationServiceInterface;
14 use AmeliaBooking\Domain\Services\Settings\SettingsService;
15 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
16 use AmeliaBooking\Infrastructure\Services\Payment\SquareService;
17 use Exception;
18
19 /**
20 * Class CalculatePaymentAmountCommandHandler
21 *
22 * @package AmeliaBooking\Application\Commands\Payment
23 */
24 class CalculatePaymentAmountCommandHandler extends CommandHandler
25 {
26 /**
27 * @param CalculatePaymentAmountCommand $command
28 *
29 * @return CommandResult
30 * @throws QueryExecutionException
31 * @throws InvalidArgumentException
32 * @throws Exception
33 */
34 public function handle(CalculatePaymentAmountCommand $command)
35 {
36 $result = new CommandResult();
37
38 $this->checkMandatoryFields($command);
39
40 $requestData = $this->getAppointmentData($command->getFields());
41
42 /** @var SettingsService $settingsService */
43 $settingsService = $this->container->get('domain.settings.service');
44
45 /** @var ReservationServiceInterface $reservationService */
46 $reservationService = $this->container->get('application.reservation.service')->get($command->getField('type'));
47
48 $squareSettings = $settingsService->getCategorySettings('payments')['square'];
49
50 $reservation = $reservationService->getNew(true, true, true);
51
52 $reservationService->processBooking(
53 $result,
54 $requestData,
55 $reservation,
56 false
57 );
58
59 if ($result->getResult() === CommandResult::RESULT_ERROR) {
60 return $result;
61 }
62
63 $paymentAmount = $reservationService->getReservationPaymentAmount($reservation);
64
65 $countryCode = null;
66 if ($squareSettings['enabled']) {
67 /** @var SquareService $squareService */
68 $squareService = $this->container->get('infrastructure.payment.square.service');
69
70 $countryCode = $squareService->getCountryCodeByLocationId($squareSettings['locationId']);
71 }
72
73 $result->setResult(CommandResult::RESULT_SUCCESS);
74 $result->setData(
75 [
76 'amount' => $paymentAmount,
77 'currency' => $settingsService->getCategorySettings('payments')['currency'],
78 'countryCode' => $countryCode,
79 ]
80 );
81
82 return $result;
83 }
84 }
85