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