|
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\Form\Type; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Form\AbstractType; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
16
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
17
|
|
|
use Symfony\Component\Form\FormEvent; |
|
18
|
|
|
use Symfony\Component\Form\FormEvents; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
20
|
|
|
use Symfony\Component\Validator\Constraints\Iban; |
|
21
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
|
22
|
|
|
|
|
23
|
|
|
final class DirectDebitType extends AbstractType |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var SessionInterface */ |
|
26
|
|
|
private $session; |
|
27
|
|
|
|
|
28
|
|
|
/** @param SessionInterface $session */ |
|
29
|
|
|
public function __construct(SessionInterface $session) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->session = $session; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
35
|
|
|
{ |
|
36
|
|
|
$builder |
|
37
|
|
|
->add('consumerName', TextType::class, [ |
|
38
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.consumer_name', |
|
39
|
|
|
'constraints' => [ |
|
40
|
|
|
new NotBlank([ |
|
41
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.consumer_name.not_blank', |
|
42
|
|
|
'groups' => ['sylius'], |
|
43
|
|
|
]), |
|
44
|
|
|
], |
|
45
|
|
|
'data' => $this->session->get('mollie_direct_debit_data')['consumerName'] ?? null, |
|
46
|
|
|
]) |
|
47
|
|
|
->add('iban', TextType::class, [ |
|
48
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.iban', |
|
49
|
|
|
'constraints' => [ |
|
50
|
|
|
new NotBlank([ |
|
51
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.iban.not_blank', |
|
52
|
|
|
'groups' => ['sylius'], |
|
53
|
|
|
]), |
|
54
|
|
|
new Iban([ |
|
55
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.iban.incorrect', |
|
56
|
|
|
'groups' => ['sylius'], |
|
57
|
|
|
]), |
|
58
|
|
|
], |
|
59
|
|
|
'data' => $this->session->get('mollie_direct_debit_data')['iban'] ?? null, |
|
60
|
|
|
]) |
|
61
|
|
|
->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { |
|
62
|
|
|
$data = $event->getData(); |
|
63
|
|
|
|
|
64
|
|
|
$this->session->set('mollie_direct_debit_data', $data); |
|
65
|
|
|
}) |
|
66
|
|
|
; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|