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 / SquareRefundWebhookCommandHandler.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
SquareRefundWebhookCommandHandler.php
72 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\Infrastructure\Common\Exceptions\NotFoundException;
11 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
12 use AmeliaBooking\Infrastructure\Repository\Payment\PaymentRepository;
13 use Interop\Container\Exception\ContainerException;
14
15 /**
16 * Class SquareRefundWebhookCommandHandler
17 *
18 * @package AmeliaBooking\Application\Commands\Square
19 */
20 class SquareRefundWebhookCommandHandler extends CommandHandler
21 {
22 /**
23 * @param SquareRefundWebhookCommand $command
24 *
25 * @return CommandResult
26 * @throws AccessDeniedException
27 * @throws NotFoundException
28 * @throws QueryExecutionException
29 * @throws ContainerException
30 * @throws InvalidArgumentException
31 * @throws \Exception
32 */
33 public function handle(SquareRefundWebhookCommand $command)
34 {
35 /** @var PaymentRepository $paymentRepository */
36 $paymentRepository = $this->container->get('domain.payment.repository');
37
38 $data = $command->getField('data');
39
40 if (!ValidationService::verifySignature(json_encode($data), 'middleware', $command->getField('signature'))) {
41 throw new AccessDeniedException('Signature mismatch.');
42 }
43
44 $result = new CommandResult();
45
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 $result->setResult(CommandResult::RESULT_ERROR);
52 $result->setMessage('Cannot find payment');
53 $result->setData(['success' => false]);
54
55 return $result;
56 }
57
58 foreach ($payments->toArray() as $payment) {
59 // if (floatval($payment['amount']) <= floatval($data['object']['refund']['amount_money']['amount']/100)) {
60 $paymentRepository->updateFieldById($payment['id'], 'refunded', 'status');
61 // }
62 }
63 }
64
65 $result->setResult(CommandResult::RESULT_SUCCESS);
66 $result->setMessage('Successfully updated payment status');
67 $result->setData(['success' => true]);
68
69 return $result;
70 }
71 }
72