PaymentSurchargeFeeType::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
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\Entity\PaymentSurchargeFee;
15
use BitBag\SyliusMolliePlugin\Payments\PaymentTerms\Options;
16
use Symfony\Component\Form\AbstractType;
17
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
18
use Symfony\Component\Form\Extension\Core\Type\NumberType;
19
use Symfony\Component\Form\FormBuilderInterface;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
use Symfony\Component\Validator\Constraints\GreaterThan;
22
23
final class PaymentSurchargeFeeType extends AbstractType
24
{
25
    public function buildForm(FormBuilderInterface $builder, array $options): void
26
    {
27
        $builder
28
            ->add('type', ChoiceType::class, [
29
                'label' => 'bitbag_sylius_mollie_plugin.ui.payment_fee_type',
30
                'choices' => ['bitbag_sylius_mollie_plugin.ui.no_fee' => 'no_fee'] + Options::getAvailablePaymentSurchargeFeeType(),
31
            ])
32
            ->add('fixedAmount', NumberType::class, [
33
                'label' => 'bitbag_sylius_mollie_plugin.ui.fix_amount_surcharge',
34
                'attr' => ['class' => 'bitbag-mollie-payment_fee-fixedAmount'],
35
                'constraints' => [
36
                    new GreaterThan([
37
                        'value' => 0,
38
                        'message' => 'bitbag_sylius_mollie_plugin.form.error.greater_than',
39
                        'groups' => ['sylius'],
40
                    ]),
41
                ],
42
            ])
43
            ->add('percentage', NumberType::class, [
44
                'label' => 'bitbag_sylius_mollie_plugin.ui.percentage_surcharge',
45
                'constraints' => [
46
                    new GreaterThan([
47
                        'value' => 0,
48
                        'message' => 'bitbag_sylius_mollie_plugin.form.error.greater_than',
49
                        'groups' => ['sylius'],
50
                    ]),
51
                ],
52
            ])
53
            ->add('surchargeLimit', NumberType::class, [
54
                'label' => 'bitbag_sylius_mollie_plugin.ui.surcharge_limit',
55
                'constraints' => [
56
                    new GreaterThan([
57
                        'value' => 0,
58
                        'message' => 'bitbag_sylius_mollie_plugin.form.error.greater_than',
59
                        'groups' => ['sylius'],
60
                    ]),
61
                ],
62
            ]);
63
    }
64
65
    public function configureOptions(OptionsResolver $resolver): void
66
    {
67
        $resolver
68
            ->setDefaults([
69
                'data_class' => PaymentSurchargeFee::class,
70
            ]);
71
    }
72
}
73