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\Entity\MollieGatewayConfigInterface; |
16
|
|
|
use BitBag\SyliusMolliePlugin\Entity\ProductType; |
17
|
|
|
use BitBag\SyliusMolliePlugin\Options\Country\Options as CountryOptions; |
18
|
|
|
use BitBag\SyliusMolliePlugin\Payments\Methods\AbstractMethod; |
19
|
|
|
use BitBag\SyliusMolliePlugin\Payments\PaymentTerms\Options; |
20
|
|
|
use BitBag\SyliusMolliePlugin\Validator\Constraints\PaymentSurchargeType; |
21
|
|
|
use Sylius\Bundle\ProductBundle\Form\Type\ProductType as ProductFormType; |
22
|
|
|
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType; |
23
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
24
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
25
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
26
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CountryType; |
27
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
28
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
29
|
|
|
use Symfony\Component\Form\FormEvent; |
30
|
|
|
use Symfony\Component\Form\FormEvents; |
31
|
|
|
use Symfony\Component\Validator\Constraints\NotBlank; |
32
|
|
|
|
33
|
|
|
final class MollieGatewayConfigType extends AbstractResourceType |
34
|
|
|
{ |
35
|
|
|
/** @var DocumentationLinksInterface */ |
36
|
|
|
private $documentationLinks; |
37
|
|
|
|
38
|
|
|
public function __construct(string $dataClass, array $validationGroups = [], DocumentationLinksInterface $documentationLinks) |
39
|
|
|
{ |
40
|
|
|
parent::__construct($dataClass, $validationGroups); |
41
|
|
|
$this->documentationLinks = $documentationLinks; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
45
|
|
|
{ |
46
|
|
|
$builder |
47
|
|
|
->add('enabled', CheckboxType::class, [ |
48
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.enable', |
49
|
|
|
]) |
50
|
|
|
->add('applePayDirectButton', CheckboxType::class, [ |
51
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.enabled_buy_now_button', |
52
|
|
|
'help' => 'bitbag_sylius_mollie_plugin.form.enabled_buy_now_button_help', |
53
|
|
|
]) |
54
|
|
|
->add('defaultCategory', EntityType::class, [ |
55
|
|
|
'class' => ProductType::class, |
56
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.form.product_type_default', |
57
|
|
|
'placeholder' => 'bitbag_sylius_mollie_plugin.form.no_category', |
58
|
|
|
'empty_data' => null, |
59
|
|
|
'help' => 'bitbag_sylius_mollie_plugin.form.product_type_default_help', |
60
|
|
|
]) |
61
|
|
|
->add('name', TextType::class, [ |
62
|
|
|
'required' => true, |
63
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.payment_name', |
64
|
|
|
'constraints' => [ |
65
|
|
|
new NotBlank([ |
66
|
|
|
'message' => 'bitbag_sylius_mollie_plugin.payment_method.not_blank', |
67
|
|
|
'groups' => ['sylius'], |
68
|
|
|
]), |
69
|
|
|
], |
70
|
|
|
]) |
71
|
|
|
->add('paymentType', ChoiceType::class, [ |
72
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.payment_type', |
73
|
|
|
'choices' => Options::getAvailablePaymentType(), |
74
|
|
|
'help' => $this->documentationLinks->getPaymentMethodDoc(), |
75
|
|
|
'help_html' => true, |
76
|
|
|
]) |
77
|
|
|
->add('paymentDescription', TextType::class, [ |
78
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.form.payment_methods.payment_description', |
79
|
|
|
'help' => 'bitbag_sylius_mollie_plugin.form.payment_methods.payment_description_help', |
80
|
|
|
'empty_data' => '{ordernumber}', |
81
|
|
|
'attr' => [ |
82
|
|
|
'placeholder' => '{ordernumber}', |
83
|
|
|
], |
84
|
|
|
]) |
85
|
|
|
->add('paymentSurchargeFee', PaymentSurchargeFeeType::class, [ |
86
|
|
|
'label' => false, |
87
|
|
|
'constraints' => [new PaymentSurchargeType(['groups' => 'sylius'])], |
88
|
|
|
]) |
89
|
|
|
->add('customizeMethodImage', CustomizeMethodImageType::class, [ |
90
|
|
|
'label' => false, |
91
|
|
|
]) |
92
|
|
|
->add('country_restriction', ChoiceType::class, [ |
93
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.country_level_restriction', |
94
|
|
|
'choices' => CountryOptions::getCountriesConfigOptions(), |
95
|
|
|
]) |
96
|
|
|
->add('countryLevel_excluded', CountryType::class, [ |
97
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.country_level_exclude', |
98
|
|
|
'required' => false, |
99
|
|
|
'multiple' => true, |
100
|
|
|
]) |
101
|
|
|
->add('countryLevel_allowed', CountryType::class, [ |
102
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.country_level_allow', |
103
|
|
|
'required' => false, |
104
|
|
|
'multiple' => true, |
105
|
|
|
]) |
106
|
|
|
->add('countryLevel', CountryType::class, [ |
107
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.country_level_restriction', |
108
|
|
|
'required' => false, |
109
|
|
|
'multiple' => true, |
110
|
|
|
]) |
111
|
|
|
->add('orderExpiration', ChoiceType::class, [ |
112
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.order_expiration_days', |
113
|
|
|
'required' => false, |
114
|
|
|
'choices' => array_combine( |
115
|
|
|
range(1, 100, 1), |
116
|
|
|
range(1, 100, 1) |
117
|
|
|
), |
118
|
|
|
]) |
119
|
|
|
->add('loggerEnabled', CheckboxType::class, [ |
120
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.debug_level_enabled', |
121
|
|
|
]) |
122
|
|
|
->add('loggerLevel', ChoiceType::class, [ |
123
|
|
|
'label' => 'bitbag_sylius_mollie_plugin.ui.debug_level_log', |
124
|
|
|
'choices' => Options::getDebugLevels(), |
125
|
|
|
]) |
126
|
|
|
->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) { |
127
|
|
|
/** @var MollieGatewayConfigInterface $object */ |
128
|
|
|
$object = $event->getForm()->getData(); |
129
|
|
|
$data = $event->getData(); |
130
|
|
|
|
131
|
|
|
if (in_array($object->getMethodId(), Options::getOnlyOrderAPIMethods())) { |
132
|
|
|
$data['paymentType'] = AbstractMethod::ORDER_API; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
$event->setData($data); |
136
|
|
|
}); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function getBlockPrefix(): string |
140
|
|
|
{ |
141
|
|
|
return 'bitbag_mollie_payment_method'; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public static function getExtendedTypes(): array |
145
|
|
|
{ |
146
|
|
|
return [ProductFormType::class]; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|