1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PH\Bundle\CoreBundle\Form\Extension; |
6
|
|
|
|
7
|
|
|
use PH\Component\Core\Model\PaymentMethodInterface; |
8
|
|
|
use Sylius\Bundle\PaymentBundle\Form\Type\PaymentMethodType; |
9
|
|
|
use Sylius\Bundle\PayumBundle\Form\Type\GatewayConfigType; |
10
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
11
|
|
|
use Symfony\Component\Form\AbstractTypeExtension; |
12
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
13
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
14
|
|
|
use Symfony\Component\Form\FormEvent; |
15
|
|
|
use Symfony\Component\Form\FormEvents; |
16
|
|
|
|
17
|
|
|
final class PaymentMethodTypeExtension extends AbstractTypeExtension |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
23
|
|
|
{ |
24
|
|
|
$gatewayFactory = $options['data']->getGatewayConfig(); |
25
|
|
|
|
26
|
|
|
$builder |
27
|
|
|
->add('gatewayConfig', GatewayConfigType::class, [ |
28
|
|
|
'label' => false, |
29
|
|
|
'data' => $gatewayFactory, |
30
|
|
|
]) |
31
|
|
|
->add('supportsRecurring', CheckboxType::class) |
32
|
|
|
->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) { |
33
|
|
|
$paymentMethod = $event->getData(); |
34
|
|
|
|
35
|
|
|
if (!$paymentMethod instanceof PaymentMethodInterface) { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$gatewayConfig = $paymentMethod->getGatewayConfig(); |
40
|
|
|
if (null === $gatewayConfig->getGatewayName()) { |
41
|
|
|
$gatewayConfig->setGatewayName(StringInflector::nameToLowercaseCode($paymentMethod->getName())); |
42
|
|
|
} |
43
|
|
|
}) |
44
|
|
|
; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function getExtendedType() |
51
|
|
|
{ |
52
|
|
|
return PaymentMethodType::class; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|