ameliabooking
/
src
/
Application
/
Commands
/
Square
/
DisconnectFromSquareAccountDirectlyCommandHandler.php
DisconnectFromSquareAccountCommand.php
1 year ago
DisconnectFromSquareAccountCommandHandler.php
6 months ago
DisconnectFromSquareAccountDirectlyCommand.php
6 months ago
DisconnectFromSquareAccountDirectlyCommandHandler.php
6 months ago
FetchAccessTokenSquareCommand.php
1 year ago
FetchAccessTokenSquareCommandHandler.php
6 months ago
GetSquareAuthURLCommand.php
10 months ago
GetSquareAuthURLCommandHandler.php
10 months ago
SquareRefundWebhookCommand.php
1 year ago
SquareRefundWebhookCommandHandler.php
6 months ago
DisconnectFromSquareAccountDirectlyCommandHandler.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaBooking\Application\Commands\Square; |
| 4 | |
| 5 | use AmeliaBooking\Application\Commands\CommandHandler; |
| 6 | use AmeliaBooking\Application\Commands\CommandResult; |
| 7 | use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException; |
| 8 | use AmeliaBooking\Application\Services\Helper\HelperService; |
| 9 | use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException; |
| 10 | use AmeliaBooking\Domain\Entity\Entities; |
| 11 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 12 | use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException; |
| 13 | use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException; |
| 14 | use AmeliaBooking\Infrastructure\Services\Payment\SquareService; |
| 15 | use Slim\Exception\ContainerException; |
| 16 | |
| 17 | /** |
| 18 | * Class DisconnectFromSquareAccountDirectlyCommandHandler |
| 19 | * |
| 20 | * @package AmeliaBooking\Application\Commands\Square |
| 21 | */ |
| 22 | class DisconnectFromSquareAccountDirectlyCommandHandler extends CommandHandler |
| 23 | { |
| 24 | /** |
| 25 | * @param DisconnectFromSquareAccountDirectlyCommand $command |
| 26 | * |
| 27 | * @return CommandResult |
| 28 | * @throws AccessDeniedException |
| 29 | * @throws NotFoundException |
| 30 | * @throws QueryExecutionException |
| 31 | * @throws ContainerException |
| 32 | * @throws InvalidArgumentException |
| 33 | * @throws \Exception |
| 34 | */ |
| 35 | public function handle(DisconnectFromSquareAccountDirectlyCommand $command) |
| 36 | { |
| 37 | if (!$this->getContainer()->getPermissionsService()->currentUserCanWrite(Entities::SETTINGS)) { |
| 38 | throw new AccessDeniedException('You are not allowed to write settings.'); |
| 39 | } |
| 40 | |
| 41 | /** @var SquareService $squareService */ |
| 42 | $squareService = $this->container->get('infrastructure.payment.square.service'); |
| 43 | |
| 44 | /** @var SettingsService $settingsService */ |
| 45 | $settingsService = $this->container->get('domain.settings.service'); |
| 46 | |
| 47 | $result = new CommandResult(); |
| 48 | |
| 49 | if ( |
| 50 | !empty($settingsService->getCategorySettings('payments')['square']['accessToken']) && |
| 51 | !$squareService->disconnectAccount() |
| 52 | ) { |
| 53 | $result->setResult(CommandResult::RESULT_ERROR); |
| 54 | $result->setMessage('Unable to disconnect from Square account.'); |
| 55 | $result->setData(['success' => false]); |
| 56 | |
| 57 | return $result; |
| 58 | } |
| 59 | |
| 60 | $result->setResult(CommandResult::RESULT_SUCCESS); |
| 61 | $result->setMessage('Successfully logged out of Square account'); |
| 62 | $result->setData(['success' => true]); |
| 63 | |
| 64 | return $result; |
| 65 | } |
| 66 | } |
| 67 |