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
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMolliePlugin\Processor; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Entity\MollieGatewayConfig; |
16
|
|
|
use BitBag\SyliusMolliePlugin\PaymentFee\Calculate; |
17
|
|
|
use Payum\Core\Model\PaymentInterface; |
18
|
|
|
use Sylius\Component\Order\Model\OrderInterface; |
19
|
|
|
use Sylius\Component\Payment\Model\PaymentMethodInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
21
|
|
|
|
22
|
|
|
final class PaymentSurchargeProcessor implements PaymentSurchargeProcessorInterface |
23
|
|
|
{ |
24
|
|
|
/** @var Calculate */ |
25
|
|
|
private $calculate; |
26
|
|
|
|
27
|
|
|
/** @var SessionInterface */ |
28
|
|
|
private $session; |
29
|
|
|
|
30
|
|
|
public function __construct(Calculate $calculate, SessionInterface $session) |
31
|
|
|
{ |
32
|
|
|
$this->calculate = $calculate; |
33
|
|
|
$this->session = $session; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function process(OrderInterface $order): void |
37
|
|
|
{ |
38
|
|
|
/** @var PaymentInterface $payment */ |
39
|
|
|
$payment = $order->getPayments()->first(); |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** @var PaymentMethodInterface $paymentMethod */ |
42
|
|
|
$paymentMethod = $payment->getMethod(); |
|
|
|
|
43
|
|
|
|
44
|
|
|
if ($paymentMethod->getGatewayConfig()->getFactoryName() !== 'mollie') { |
|
|
|
|
45
|
|
|
return; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
$data = $this->session->get('mollie_payment_options', null); |
49
|
|
|
$molliePaymentMethod = $data['molliePaymentMethods']; |
50
|
|
|
|
51
|
|
|
$paymentSurcharge = $this->getMolliePaymentSurcharge($paymentMethod, $molliePaymentMethod); |
52
|
|
|
|
53
|
|
|
if (null === $paymentSurcharge) { |
54
|
|
|
return; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$this->calculate->calculateFromCart($order, $paymentSurcharge); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function getMolliePaymentSurcharge(PaymentMethodInterface $paymentMethod, string $molliePaymentMethod): ?MollieGatewayConfig |
61
|
|
|
{ |
62
|
|
|
$configMethods = $paymentMethod->getGatewayConfig()->getMollieGatewayConfig(); |
63
|
|
|
foreach ($configMethods as $configMethod) { |
64
|
|
|
/** @var MollieGatewayConfig $configMethod */ |
65
|
|
|
if ($configMethod->getMethodId() === $molliePaymentMethod) { |
66
|
|
|
return $configMethod; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|