DirectDebitSubForm::getPropertyPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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\CrefoPay\Form;
9
10
use Generated\Shared\Transfer\CrefoPayPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CrefoPayPaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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\CrefoPay\CrefoPayConfig;
15
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
16
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
17
use Symfony\Component\Form\FormBuilderInterface;
18
use Symfony\Component\Form\FormInterface;
19
use Symfony\Component\Form\FormView;
20
use Symfony\Component\OptionsResolver\OptionsResolver;
21
22
/**
23
 * @method \SprykerEco\Yves\CrefoPay\CrefoPayConfig getConfig()
24
 */
25
class DirectDebitSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface
26
{
27
    /**
28
     * @var string
29
     */
30
    public const CREFO_PAY_SHOP_PUBLIC_KEY = 'shopPublicKey';
31
32
    /**
33
     * @var string
34
     */
35
    public const CREFO_PAY_ORDER_ID = 'orderID';
36
37
    /**
38
     * @var string
39
     */
40
    public const CREFO_PAY_SECURE_FIELDS_API_ENDPOINT = 'secureFieldsApiEndpoint';
41
42
    /**
43
     * @var string
44
     */
45
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
46
47
    /**
48
     * @var string
49
     */
50
    protected const PAYMENT_METHOD = 'direct-debit';
51
52
    /**
53
     * @var string
54
     */
55
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
56
57
    /**
58
     * @var string
59
     */
60
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'DD';
61
62
    /**
63
     * @var string
64
     */
65
    protected const FORM_FIELD_PAYMENT_INSTRUMENT_ID = 'paymentInstrumentId';
66
67
    /**
68
     * @return string
69
     */
70
    public function getProviderName(): string
71
    {
72
        return CrefoPayConfig::PROVIDER_NAME;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getName(): string
79
    {
80
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_DIRECT_DEBIT;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getPropertyPath(): string
87
    {
88
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_DIRECT_DEBIT;
89
    }
90
91
    /**
92
     * @return string
93
     */
94
    public function getTemplatePath(): string
95
    {
96
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
97
    }
98
99
    /**
100
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
101
     *
102
     * @return void
103
     */
104
    public function configureOptions(OptionsResolver $resolver): void
105
    {
106
        $resolver->setDefaults([
107
            'data_class' => CrefoPayPaymentTransfer::class,
108
        ])->setRequired(static::OPTIONS_FIELD_NAME);
109
    }
110
111
    /**
112
     * @param \Symfony\Component\Form\FormView $view The view
113
     * @param \Symfony\Component\Form\FormInterface $form The form
114
     * @param array $options The options
115
     *
116
     * @return void
117
     */
118
    public function buildView(FormView $view, FormInterface $form, array $options): void
119
    {
120
        parent::buildView($view, $form, $options);
121
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
122
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
123
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
124
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
125
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
126
    }
127
128
    /**
129
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
130
     * @param array $options
131
     *
132
     * @return void
133
     */
134
    public function buildForm(FormBuilderInterface $builder, array $options): void
135
    {
136
        $this->addPaymentMethod($builder)
137
            ->addPaymentInstrumentId($builder);
138
    }
139
140
    /**
141
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
142
     *
143
     * @return $this
144
     */
145
    protected function addPaymentMethod(FormBuilderInterface $builder)
146
    {
147
        $builder->add(
148
            static::FORM_FIELD_PAYMENT_METHOD,
149
            ChoiceType::class,
150
            [
151
                'choices' => [static::FORM_FIELD_PAYMENT_METHOD_DATA],
152
                'expanded' => true,
153
            ],
154
        );
155
156
        return $this;
157
    }
158
159
    /**
160
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
161
     *
162
     * @return $this
163
     */
164
    protected function addPaymentInstrumentId(FormBuilderInterface $builder)
165
    {
166
        $builder->add(
167
            static::FORM_FIELD_PAYMENT_INSTRUMENT_ID,
168
            HiddenType::class,
169
            ['label' => false],
170
        );
171
172
        return $this;
173
    }
174
}
175