|
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 BitBag\SyliusMolliePlugin\Documentation\DocumentationLinksInterface; |
|
15
|
|
|
use BitBag\SyliusMolliePlugin\Payments\PaymentTerms\Options; |
|
16
|
|
|
use Symfony\Component\Form\AbstractType; |
|
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
18
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
19
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
20
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
21
|
|
|
use Symfony\Component\Form\FormEvent; |
|
22
|
|
|
use Symfony\Component\Form\FormEvents; |
|
23
|
|
|
use Symfony\Component\Validator\Constraints\Length; |
|
24
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
|
25
|
|
|
use Symfony\Component\Validator\Constraints\Regex; |
|
26
|
|
|
|
|
27
|
|
|
final class MollieGatewayConfigurationType extends AbstractType |
|
28
|
|
|
{ |
|
29
|
|
|
public const API_KEY_LIVE = 'api_key_live'; |
|
30
|
|
|
|
|
31
|
|
|
public const API_KEY_TEST = 'api_key_test'; |
|
32
|
|
|
|
|
33
|
|
|
/** @var DocumentationLinksInterface */ |
|
34
|
|
|
private $documentationLinks; |
|
35
|
|
|
|
|
36
|
|
|
public function __construct(DocumentationLinksInterface $documentationLinks) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->documentationLinks = $documentationLinks; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
42
|
|
|
{ |
|
43
|
|
|
$builder |
|
44
|
|
|
->add('environment', ChoiceType::class, [ |
|
45
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.environment', |
|
46
|
|
|
'choices' => [ |
|
47
|
|
|
'bitbag_sylius_mollie_plugin.ui.api_key_choice_test' => null, |
|
48
|
|
|
'bitbag_sylius_mollie_plugin.ui.api_key_choice_live' => true, |
|
49
|
|
|
], |
|
50
|
|
|
]) |
|
51
|
|
|
->add('profile_id', TextType::class, [ |
|
52
|
|
|
'label' => $this->documentationLinks->getProfileIdDoc(), |
|
53
|
|
|
'constraints' => [ |
|
54
|
|
|
new NotBlank([ |
|
55
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.profile_id.not_blank', |
|
56
|
|
|
'groups' => ['sylius'], |
|
57
|
|
|
]), |
|
58
|
|
|
], |
|
59
|
|
|
]) |
|
60
|
|
|
->add(self::API_KEY_TEST, PasswordType::class, [ |
|
61
|
|
|
'always_empty' => false, |
|
62
|
|
|
'label' => $this->documentationLinks->getApiKeyDoc(), |
|
63
|
|
|
'help' => ' ', |
|
64
|
|
|
'constraints' => [ |
|
65
|
|
|
new NotBlank([ |
|
66
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.api_key.not_blank', |
|
67
|
|
|
'groups' => ['sylius'], |
|
68
|
|
|
]), |
|
69
|
|
|
new Regex([ |
|
70
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.api_key.invalid_test', |
|
71
|
|
|
'groups' => ['sylius'], |
|
72
|
|
|
'pattern' => '/^(test)_\w{0,}$/', |
|
73
|
|
|
]), |
|
74
|
|
|
new Length([ |
|
75
|
|
|
'minMessage' => 'bitbag_sylius_mollie_plugin.api_key.min_length', |
|
76
|
|
|
'groups' => ['sylius'], |
|
77
|
|
|
'min' => 35, |
|
78
|
|
|
]), |
|
79
|
|
|
], |
|
80
|
|
|
]) |
|
81
|
|
|
->add(self::API_KEY_LIVE, PasswordType::class, [ |
|
82
|
|
|
'always_empty' => false, |
|
83
|
|
|
'required' => true, |
|
84
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.api_key_live', |
|
85
|
|
|
'constraints' => [ |
|
86
|
|
|
new Regex([ |
|
87
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.api_key.invalid_live', |
|
88
|
|
|
'groups' => ['sylius'], |
|
89
|
|
|
'pattern' => '/^(live)_\w{0,}$/', |
|
90
|
|
|
]), |
|
91
|
|
|
new Length([ |
|
92
|
|
|
'minMessage' => 'bitbag_sylius_mollie_plugin.api_key.min_length', |
|
93
|
|
|
'groups' => ['sylius'], |
|
94
|
|
|
'min' => 35, |
|
95
|
|
|
]), |
|
96
|
|
|
], |
|
97
|
|
|
]) |
|
98
|
|
|
->add('abandoned_email_enabled', CheckboxType::class, [ |
|
99
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.abandoned_email_enabled', |
|
100
|
|
|
'help' => 'bitbag_sylius_mollie_plugin.ui.abandoned_description', |
|
101
|
|
|
]) |
|
102
|
|
|
->add('abandoned_hours', ChoiceType::class, [ |
|
103
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.abandoned_hours', |
|
104
|
|
|
'choices' => array_combine( |
|
105
|
|
|
range(1, 200, 1), |
|
106
|
|
|
range(1, 200, 1) |
|
107
|
|
|
), |
|
108
|
|
|
]) |
|
109
|
|
|
->add('loggerLevel', ChoiceType::class, [ |
|
110
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.debug_level_log', |
|
111
|
|
|
'choices' => Options::getDebugLevels(), |
|
112
|
|
|
]) |
|
113
|
|
|
->add('components', CheckboxType::class, [ |
|
114
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.enable_components', |
|
115
|
|
|
'attr' => ['class' => 'bitbag-mollie-components'], |
|
116
|
|
|
'help' => $this->documentationLinks->getMollieComponentsDoc(), |
|
117
|
|
|
'help_html' => true, |
|
118
|
|
|
]) |
|
119
|
|
|
->add('single_click_enabled', CheckboxType::class, [ |
|
120
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.single_click_enabled', |
|
121
|
|
|
'attr' => ['class' => 'bitbag-single-click-payment'], |
|
122
|
|
|
'help' => $this->documentationLinks->getSingleClickDoc(), |
|
123
|
|
|
'help_html' => true, |
|
124
|
|
|
]) |
|
125
|
|
|
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
126
|
|
|
$data = $event->getData(); |
|
127
|
|
|
|
|
128
|
|
|
if (isset($data['components']) && true === $data['components']) { |
|
129
|
|
|
$data['single_click_enabled'] = false; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$data['payum.http_client'] = '@bitbag_sylius_mollie_plugin.mollie_api_client'; |
|
133
|
|
|
|
|
134
|
|
|
$event->setData($data); |
|
135
|
|
|
}); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function getBlockPrefix(): string |
|
139
|
|
|
{ |
|
140
|
|
|
return 'bitbag_mollie_gateway_configuration_type'; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|