PluginProbe
Booking for Appointments and Events Calendar – Amelia / 2.4.2
Booking for Appointments and Events Calendar – Amelia v2.4.2
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 All 59 releases
ameliabooking / src / Application / Commands / Square / SquareRefundWebhookCommandHandler.php

SquareRefundWebhookCommandHandler.php in Booking for Appointments and Events Calendar – Amelia 2.4.2, at src/Application/Commands/Square/SquareRefundWebhookCommandHandler.php

72 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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