|
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
|
|
|
|