PaymentPartialEventListener::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file has been created by developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * You can find more information about us on https://bitbag.io and write us
7
 * an email on [email protected].
8
 */
9
10
declare(strict_types=1);
11
12
namespace BitBag\SyliusMolliePlugin\EventListener;
13
14
use BitBag\SyliusMolliePlugin\Exceptions\InvalidRefundAmountException;
15
use BitBag\SyliusMolliePlugin\Logger\MollieLoggerActionInterface;
16
use BitBag\SyliusMolliePlugin\Order\OrderPaymentRefundInterface;
17
use Sylius\RefundPlugin\Event\UnitsRefunded;
18
use Symfony\Component\Messenger\Exception\HandlerFailedException;
19
20
final class PaymentPartialEventListener
21
{
22
    /** @var OrderPaymentRefundInterface */
23
    private $orderPaymentRefund;
24
25
    /** @var MollieLoggerActionInterface */
26
    private $loggerAction;
27
28
    public function __construct(
29
        OrderPaymentRefundInterface $orderPaymentRefund,
30
        MollieLoggerActionInterface $loggerAction
31
    ) {
32
        $this->orderPaymentRefund = $orderPaymentRefund;
33
        $this->loggerAction = $loggerAction;
34
    }
35
36
    public function __invoke(UnitsRefunded $unitRefunded): void
37
    {
38
        try {
39
            $this->orderPaymentRefund->refund($unitRefunded);
40
        } catch (InvalidRefundAmountException $exception) {
41
            $this->loggerAction->addNegativeLog($exception->getMessage());
42
        } catch (HandlerFailedException $exception) {
43
            /** @var \Exception $previousException */
44
            $previousException = $exception->getPrevious();
45
46
            $this->loggerAction->addNegativeLog($previousException->getMessage());
47
        }
48
    }
49
}
50