|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Yves\Heidelpay\Form; |
|
9
|
|
|
|
|
10
|
|
|
use Generated\Shared\Transfer\HeidelpayDirectDebitPaymentTransfer; |
|
11
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\AbstractSubFormType; |
|
12
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface; |
|
13
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\SubFormProviderNameInterface; |
|
14
|
|
|
use SprykerEco\Shared\Heidelpay\HeidelpayConfig; |
|
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
16
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
17
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
18
|
|
|
use Symfony\Component\Validator\Constraint; |
|
19
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
|
20
|
|
|
|
|
21
|
|
|
class DirectDebitSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface |
|
22
|
|
|
{ |
|
23
|
|
|
public const DIRECT_DEBIT_PAYMENT_OPTIONS = 'direct_debit_payment_options'; |
|
24
|
|
|
|
|
25
|
|
|
protected const PAYMENT_METHOD_TEMPLATE_PATH = 'direct-debit'; |
|
26
|
|
|
protected const FIELD_DIRECT_DEBIT_PAYMENT_OPTION = 'selected_payment_option'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @return string |
|
30
|
|
|
*/ |
|
31
|
|
|
public function getProviderName(): string |
|
32
|
|
|
{ |
|
33
|
|
|
return HeidelpayConfig::PROVIDER_NAME; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getName(): string |
|
40
|
|
|
{ |
|
41
|
|
|
return HeidelpayConfig::PAYMENT_METHOD_DIRECT_DEBIT; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getPropertyPath(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return HeidelpayConfig::PAYMENT_METHOD_DIRECT_DEBIT; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getTemplatePath(): string |
|
56
|
|
|
{ |
|
57
|
|
|
return HeidelpayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD_TEMPLATE_PATH; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
|
62
|
|
|
* |
|
63
|
|
|
* @return void |
|
64
|
|
|
*/ |
|
65
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
|
66
|
|
|
{ |
|
67
|
|
|
$resolver->setDefaults([ |
|
68
|
|
|
'data_class' => HeidelpayDirectDebitPaymentTransfer::class, |
|
69
|
|
|
])->setRequired(static::OPTIONS_FIELD_NAME); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
74
|
|
|
* @param array $options |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
*/ |
|
78
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->addRegistrationSelectField($builder, $options); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
85
|
|
|
* @param array $options |
|
86
|
|
|
* |
|
87
|
|
|
* @return $this |
|
88
|
|
|
*/ |
|
89
|
|
|
protected function addRegistrationSelectField(FormBuilderInterface $builder, array $options) |
|
90
|
|
|
{ |
|
91
|
|
|
$builder->add( |
|
92
|
|
|
static::FIELD_DIRECT_DEBIT_PAYMENT_OPTION, |
|
93
|
|
|
ChoiceType::class, |
|
94
|
|
|
[ |
|
95
|
|
|
'choices' => array_flip($options[static::OPTIONS_FIELD_NAME][static::DIRECT_DEBIT_PAYMENT_OPTIONS]), |
|
96
|
|
|
'label' => false, |
|
97
|
|
|
'required' => true, |
|
98
|
|
|
'expanded' => true, |
|
99
|
|
|
'multiple' => false, |
|
100
|
|
|
'placeholder' => false, |
|
101
|
|
|
'constraints' => [ |
|
102
|
|
|
$this->createNotBlankConstraint(), |
|
103
|
|
|
], |
|
104
|
|
|
] |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
return $this; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return \Symfony\Component\Validator\Constraint |
|
112
|
|
|
*/ |
|
113
|
|
|
protected function createNotBlankConstraint(): Constraint |
|
114
|
|
|
{ |
|
115
|
|
|
return new NotBlank(['groups' => $this->getPropertyPath()]); |
|
116
|
|
|
} |
|
117
|
|
|
} |
|
118
|
|
|
|