1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file was created by developers working at BitBag |
||
5 | * Do you need more information about us and what we do? Visit our https://bitbag.io website! |
||
6 | * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
||
7 | */ |
||
8 | |||
9 | declare(strict_types=1); |
||
10 | |||
11 | namespace BitBag\SyliusMultiSafepayPlugin\PaymentProcessing; |
||
12 | |||
13 | use BitBag\SyliusMultiSafepayPlugin\ApiClient\MultiSafepayApiClientInterface; |
||
14 | use BitBag\SyliusMultiSafepayPlugin\MultiSafepayGatewayFactory; |
||
15 | use Psr\Log\LoggerInterface; |
||
16 | use Sylius\Bundle\PayumBundle\Model\GatewayConfigInterface; |
||
17 | use Sylius\Component\Core\Model\PaymentInterface; |
||
18 | use Sylius\Component\Core\Model\PaymentMethodInterface; |
||
19 | use Sylius\Component\Resource\Exception\UpdateHandlingException; |
||
20 | use Symfony\Component\HttpFoundation\Session\Session; |
||
21 | |||
22 | final class RefundPaymentProcessor implements PaymentProcessorInterface |
||
23 | { |
||
24 | /** @var Session */ |
||
25 | private $session; |
||
26 | |||
27 | /** @var MultiSafepayApiClientInterface */ |
||
28 | private $multiSafepayApiClient; |
||
29 | |||
30 | /** @var LoggerInterface */ |
||
31 | private $logger; |
||
32 | |||
33 | public function __construct( |
||
34 | Session $session, |
||
35 | MultiSafepayApiClientInterface $multiSafepayApiClient, |
||
36 | LoggerInterface $logger |
||
37 | ) { |
||
38 | $this->session = $session; |
||
39 | $this->multiSafepayApiClient = $multiSafepayApiClient; |
||
40 | $this->logger = $logger; |
||
41 | } |
||
42 | |||
43 | public function process(PaymentInterface $payment): void |
||
44 | { |
||
45 | /** @var PaymentMethodInterface $paymentMethod */ |
||
46 | $paymentMethod = $payment->getMethod(); |
||
47 | |||
48 | $details = $payment->getDetails(); |
||
49 | |||
50 | /** @var GatewayConfigInterface $gatewayConfig */ |
||
51 | $gatewayConfig = $paymentMethod->getGatewayConfig(); |
||
52 | |||
53 | if ( |
||
54 | MultiSafepayGatewayFactory::FACTORY_NAME !== $gatewayConfig->getFactoryName() || |
||
0 ignored issues
–
show
|
|||
55 | (isset($details['status']) && MultiSafepayApiClientInterface::STATUS_REFUNDED === $details['status']) |
||
56 | ) { |
||
57 | return; |
||
58 | } |
||
59 | |||
60 | if (!isset($details['orderId'])) { |
||
61 | $this->session->getFlashBag()->add('info', 'The payment refund was made only locally.'); |
||
62 | |||
63 | return; |
||
64 | } |
||
65 | |||
66 | $gatewayConfig = $gatewayConfig->getConfig(); |
||
67 | |||
68 | $this->multiSafepayApiClient->initialise( |
||
69 | $gatewayConfig['apiKey'], |
||
70 | $gatewayConfig['type'], |
||
71 | $gatewayConfig['sandbox'] |
||
72 | ); |
||
73 | |||
74 | try { |
||
75 | $this->multiSafepayApiClient->refund($details['orderId'], (int) $payment->getAmount(), (string) $payment->getCurrencyCode()); |
||
76 | } catch (\Exception $exception) { |
||
77 | $message = $exception->getMessage(); |
||
78 | |||
79 | $this->session->getFlashBag()->add('error', htmlspecialchars($message)); |
||
80 | |||
81 | throw new UpdateHandlingException(); |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.