PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 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 / SquareRefundWebhookCommandHandler.php
ameliabooking / src / Application / Commands / Square Last commit date
DisconnectFromSquareAccountCommand.php 2 years ago DisconnectFromSquareAccountCommandHandler.php 7 months ago DisconnectFromSquareAccountDirectlyCommand.php 7 months ago DisconnectFromSquareAccountDirectlyCommandHandler.php 7 months ago FetchAccessTokenSquareCommand.php 1 year ago FetchAccessTokenSquareCommandHandler.php 7 months ago GetSquareAuthURLCommand.php 11 months ago GetSquareAuthURLCommandHandler.php 11 months ago SquareRefundWebhookCommand.php 1 year ago SquareRefundWebhookCommandHandler.php 1 week ago
SquareRefundWebhookCommandHandler.php
78 lines
1 <?php
2
3 namespace AmeliaBooking\Application\Commands\Square;
4
5 use AmeliaBooking\Domain\Services\Logger\LoggerInterface;
6 use AmeliaBooking\Application\Commands\CommandHandler;
7 use AmeliaBooking\Application\Commands\CommandResult;
8 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
9 use AmeliaBooking\Application\Services\Validation\ValidationService;
10 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
11 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
12 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
13 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
14 use Interop\Container\Exception\ContainerException;
15
16 /**
17 * Class SquareRefundWebhookCommandHandler
18 *
19 * @package AmeliaBooking\Application\Commands\Square
20 */
21 class SquareRefundWebhookCommandHandler extends CommandHandler
22 {
23 /**
24 * @param SquareRefundWebhookCommand $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(SquareRefundWebhookCommand $command)
35 {
36 /** @var PaymentRepository $paymentRepository */
37 $paymentRepository = $this->container->get('domain.payment.repository');
38
39 $data = $command->getField('data');
40
41 if (!ValidationService::verifySignature(json_encode($data), 'middleware', $command->getField('signature'))) {
42 throw new AccessDeniedException('Signature mismatch.');
43 }
44
45 $result = new CommandResult();
46
47 if ($data && !empty($data['object']['refund']['payment_id'])) {
48 $payments = $paymentRepository->getByEntityId($data['object']['refund']['payment_id'], 'transactionId');
49
50 if ($payments->length() === 0) {
51 $this->container->getLoggerService()->channel(LoggerInterface::CHANNEL_PAYMENT)->error(
52 'Square refund webhook processing failed',
53 [
54 'paymentId' => $data['object']['refund']['payment_id'],
55 'reason' => 'Cannot find payment',
56 ]
57 );
58
59 $result->setResult(CommandResult::RESULT_ERROR);
60 $result->setMessage('Cannot find payment');
61 $result->setData(['success' => false]);
62
63 return $result;
64 }
65
66 foreach ($payments->toArray() as $payment) {
67 $paymentRepository->updateFieldById($payment['id'], 'refunded', 'status');
68 }
69 }
70
71 $result->setResult(CommandResult::RESULT_SUCCESS);
72 $result->setMessage('Successfully updated payment status');
73 $result->setData(['success' => true]);
74
75 return $result;
76 }
77 }
78