PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / Square / DisconnectFromSquareAccountDirectlyCommandHandler.php
ameliabooking / src / Application / Commands / Square Last commit date
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