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 / DisconnectFromSquareAccountCommandHandler.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
DisconnectFromSquareAccountCommandHandler.php
68 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\Validation\ValidationService;
9 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
10 use AmeliaBooking\Domain\Services\Settings\SettingsService;
11 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Services\Payment\SquareService;
14 use Slim\Exception\ContainerException;
15
16 /**
17 * Class DisconnectFromSquareAccountCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Square
20 */
21 class DisconnectFromSquareAccountCommandHandler extends CommandHandler
22 {
23 /**
24 * @param DisconnectFromSquareAccountCommand $command
25 *
26 * @return CommandResult
27 * @throws AccessDeniedException
28 * @throws NotFoundException
29 * @throws QueryExecutionException
30 * @throws ContainerException
31 * @throws InvalidArgumentException
32 * @throws \Exception
33 */
34 public function handle(DisconnectFromSquareAccountCommand $command)
35 {
36 $data = $command->getField('data');
37
38 if (!ValidationService::verifySignature(json_encode($data), 'middleware', $command->getField('signature'))) {
39 throw new AccessDeniedException('Signature mismatch.');
40 }
41
42 /** @var SquareService $squareService */
43 $squareService = $this->container->get('infrastructure.payment.square.service');
44
45 /** @var SettingsService $settingsService */
46 $settingsService = $this->container->get('domain.settings.service');
47
48 $result = new CommandResult();
49
50 if (
51 !empty($settingsService->getCategorySettings('payments')['square']['accessToken']) &&
52 !$squareService->disconnectAccount(true)
53 ) {
54 $result->setResult(CommandResult::RESULT_ERROR);
55 $result->setMessage('Unable to disconnect from Square account.');
56 $result->setData(['success' => false]);
57
58 return $result;
59 }
60
61 $result->setResult(CommandResult::RESULT_SUCCESS);
62 $result->setMessage('Successfully logged out of Square account');
63 $result->setData(['success' => true]);
64
65 return $result;
66 }
67 }
68