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\Validator\Constraints; |
13
|
|
|
|
14
|
|
|
use BitBag\SyliusMolliePlugin\Factory\MollieGatewayFactory; |
15
|
|
|
use Payum\Core\Model\GatewayConfigInterface; |
16
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
17
|
|
|
use Sylius\Component\Order\Context\CartContextInterface; |
18
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
19
|
|
|
use Symfony\Component\Validator\Constraint; |
20
|
|
|
use Symfony\Component\Validator\ConstraintValidator; |
21
|
|
|
|
22
|
|
|
final class PaymentMethodCheckoutValidator extends ConstraintValidator |
23
|
|
|
{ |
24
|
|
|
/** @var CartContextInterface */ |
25
|
|
|
private $cartContext; |
26
|
|
|
|
27
|
|
|
/** @var Session */ |
28
|
|
|
private $session; |
29
|
|
|
|
30
|
|
|
public function __construct( |
31
|
|
|
CartContextInterface $cartContext, |
32
|
|
|
Session $session |
33
|
|
|
) { |
34
|
|
|
$this->cartContext = $cartContext; |
35
|
|
|
$this->session = $session; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function validate($value, Constraint $constraint) |
39
|
|
|
{ |
40
|
|
|
$order = $this->cartContext->getCart(); |
41
|
|
|
|
42
|
|
|
/** @var PaymentInterface $payment */ |
43
|
|
|
$payment = $order->getPayments()->last(); |
|
|
|
|
44
|
|
|
/** @var GatewayConfigInterface $gateway */ |
45
|
|
|
$gateway = $payment->getMethod()->getGatewayConfig(); |
|
|
|
|
46
|
|
|
|
47
|
|
|
if (MollieGatewayFactory::FACTORY_NAME !== $gateway->getFactoryName() || null !== $value) { |
|
|
|
|
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->session->getFlashBag()->add('error', 'bitbag_sylius_mollie_plugin.empty_payment_method_checkout'); |
52
|
|
|
$this->context->buildViolation($constraint->message)->setTranslationDomain('messages')->addViolation(); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|