AddPaymentCommand.php
7 years ago
AddPaymentCommandHandler.php
2 years ago
CalculatePaymentAmountCommand.php
3 years ago
CalculatePaymentAmountCommandHandler.php
3 years ago
DeletePaymentCommand.php
7 years ago
DeletePaymentCommandHandler.php
2 years ago
GetPaymentCommand.php
7 years ago
GetPaymentCommandHandler.php
1 year ago
GetPaymentsCommand.php
7 years ago
GetPaymentsCommandHandler.php
1 year ago
UpdatePaymentCommand.php
7 years ago
UpdatePaymentCommandHandler.php
2 years ago
CalculatePaymentAmountCommandHandler.php
74 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace AmeliaBooking\Application\Commands\Payment; |
| 8 | |
| 9 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 10 | use AmeliaBooking\Application\Commands\CommandResult; |
| 11 | use AmeliaBooking\Application\Services\Booking\BookingApplicationService; |
| 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 Exception; |
| 17 | use Interop\Container\Exception\ContainerException; |
| 18 | use Slim\Exception\ContainerValueNotFoundException; |
| 19 | |
| 20 | /** |
| 21 | * Class CalculatePaymentAmountCommandHandler |
| 22 | * |
| 23 | * @package AmeliaBooking\Application\Commands\Payment |
| 24 | */ |
| 25 | class CalculatePaymentAmountCommandHandler extends CommandHandler |
| 26 | { |
| 27 | /** |
| 28 | * @param CalculatePaymentAmountCommand $command |
| 29 | * |
| 30 | * @return CommandResult |
| 31 | * @throws ContainerValueNotFoundException |
| 32 | * @throws QueryExecutionException |
| 33 | * @throws InvalidArgumentException |
| 34 | * @throws ContainerException |
| 35 | * @throws Exception |
| 36 | */ |
| 37 | public function handle(CalculatePaymentAmountCommand $command) |
| 38 | { |
| 39 | $result = new CommandResult(); |
| 40 | |
| 41 | $this->checkMandatoryFields($command); |
| 42 | |
| 43 | /** @var SettingsService $settingsService */ |
| 44 | $settingsService = $this->container->get('domain.settings.service'); |
| 45 | |
| 46 | /** @var ReservationServiceInterface $reservationService */ |
| 47 | $reservationService = $this->container->get('application.reservation.service')->get($command->getField('type')); |
| 48 | |
| 49 | /** @var BookingApplicationService $bookingAS */ |
| 50 | $bookingAS = $this->container->get('application.booking.booking.service'); |
| 51 | |
| 52 | $reservation = $reservationService->getNew(true, true, true); |
| 53 | |
| 54 | $reservationService->processBooking( |
| 55 | $result, |
| 56 | $bookingAS->getAppointmentData($command->getFields()), |
| 57 | $reservation, |
| 58 | false |
| 59 | ); |
| 60 | |
| 61 | $paymentAmount = $reservationService->getReservationPaymentAmount($reservation); |
| 62 | |
| 63 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 64 | $result->setData( |
| 65 | [ |
| 66 | 'amount' => $paymentAmount, |
| 67 | 'currency' => $settingsService->getCategorySettings('payments')['currency'], |
| 68 | ] |
| 69 | ); |
| 70 | |
| 71 | return $result; |
| 72 | } |
| 73 | } |
| 74 |