PaymentRefund   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 14
c 1
b 0
f 0
dl 0
loc 30
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A refund() 0 9 3
A __construct() 0 8 1
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\Refund;
13
14
use BitBag\SyliusMolliePlugin\Creator\PaymentRefundCommandCreatorInterface;
15
use BitBag\SyliusMolliePlugin\Exceptions\InvalidRefundAmountException;
16
use BitBag\SyliusMolliePlugin\Logger\MollieLoggerActionInterface;
17
use Mollie\Api\Resources\Payment;
18
use Symfony\Component\Messenger\Exception\HandlerFailedException;
19
use Symfony\Component\Messenger\MessageBusInterface;
20
21
final class PaymentRefund implements PaymentRefundInterface
22
{
23
    /** @var MessageBusInterface */
24
    private $commandBus;
25
26
    /** @var PaymentRefundCommandCreatorInterface */
27
    private $commandCreator;
28
29
    /** @var MollieLoggerActionInterface */
30
    private $loggerAction;
31
32
    public function __construct(
33
        MessageBusInterface $commandBus,
34
        PaymentRefundCommandCreatorInterface $commandCreator,
35
        MollieLoggerActionInterface $loggerAction
36
    ) {
37
        $this->commandBus = $commandBus;
38
        $this->commandCreator = $commandCreator;
39
        $this->loggerAction = $loggerAction;
40
    }
41
42
    public function refund(Payment $payment): void
43
    {
44
        try {
45
            $refundUnits = $this->commandCreator->fromPayment($payment);
46
            $this->commandBus->dispatch($refundUnits);
47
        } catch (InvalidRefundAmountException $e) {
48
            $this->loggerAction->addNegativeLog($e->getMessage());
49
        } catch (HandlerFailedException $e) {
50
            $this->loggerAction->addNegativeLog($e->getMessage());
51
        }
52
    }
53
}
54