ameliabooking
/
src
/
Application
/
Commands
/
Square
/
DisconnectFromSquareAccountCommandHandler.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
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 |