CreditCardSubForm::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
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Yves\Payone\Form;
9
10
use Generated\Shared\Transfer\PaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentTransfer 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 Generated\Shared\Transfer\PayonePaymentCreditCardTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ymentCreditCardTransfer 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...
12
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface;
13
use SprykerEco\Shared\Payone\PayoneConstants;
14
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
15
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
16
use Symfony\Component\Form\Extension\Core\Type\TextType;
17
use Symfony\Component\Form\FormBuilderInterface;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
class CreditCardSubForm extends AbstractPayoneSubForm
21
{
22
    public const PAYMENT_METHOD = 'credit_card';
23
24
    public const FIELD_CARD_TYPE = 'cardtype';
25
    public const FIELD_CARD_NUMBER = 'cardpan';
26
    public const FIELD_NAME_ON_CARD = 'cardholder';
27
    public const FIELD_CARD_EXPIRES_MONTH = 'cardexpiredate_month';
28
    public const FIELD_CARD_EXPIRES_YEAR = 'cardexpiredate_year';
29
    public const FIELD_CARD_SECURITY_CODE = 'cardcvc2';
30
    public const FIELD_PSEUDO_CARD_NUMBER = 'pseudocardpan';
31
32
    public const OPTION_CARD_EXPIRES_CHOICES_MONTH = 'month choices';
33
    public const OPTION_CARD_EXPIRES_CHOICES_YEAR = 'year choices';
34
    public const OPTION_CARD_TYPES = 'card types';
35
36
    public const OPTION_PAYONE_SETTINGS = 'payone settings';
37
38
    /**
39
     * @return string
40
     */
41
    public function getName()
42
    {
43
        return PaymentTransfer::PAYONE_CREDIT_CARD;
44
    }
45
46
    /**
47
     * @return string
48
     */
49
    public function getPropertyPath()
50
    {
51
        return PaymentTransfer::PAYONE_CREDIT_CARD;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getTemplatePath()
58
    {
59
        return PayoneConstants::PROVIDER_NAME . '/' . self::PAYMENT_METHOD;
60
    }
61
62
    /**
63
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
64
     *
65
     * @return void
66
     */
67
    public function configureOptions(OptionsResolver $resolver)
68
    {
69
        $resolver->setDefaults([
70
            'data_class' => PayonePaymentCreditCardTransfer::class,
71
        ])->setRequired(SubFormInterface::OPTIONS_FIELD_NAME);
72
    }
73
74
    /**
75
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
76
     *
77
     * @return void
78
     */
79
    public function setDefaultOptions(OptionsResolver $resolver)
80
    {
81
        $this->configureOptions($resolver);
82
    }
83
84
    /**
85
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
86
     * @param array $options
87
     *
88
     * @return void
89
     */
90
    public function buildForm(FormBuilderInterface $builder, array $options)
91
    {
92
        $this->addNameOnCard($builder)
93
            ->addHiddenInputs($builder);
94
    }
95
96
    /**
97
     * @deprecated Card types from iFrame should be used instead.
98
     *
99
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
100
     * @param array $options
101
     *
102
     * @return $this
103
     */
104
    public function addCardType(FormBuilderInterface $builder, array $options)
105
    {
106
        $builder->add(
107
            self::FIELD_CARD_TYPE,
108
            ChoiceType::class,
109
            [
110
                'choices' => $options[self::OPTIONS_FIELD_NAME][self::OPTION_CARD_TYPES],
111
                'label' => false,
112
                'required' => true,
113
                'expanded' => false,
114
                'multiple' => false,
115
                'placeholder' => false,
116
                'constraints' => [
117
                    $this->createNotBlankConstraint(),
118
                ],
119
            ]
120
        );
121
122
        return $this;
123
    }
124
125
    /**
126
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
127
     *
128
     * @return $this
129
     */
130
    protected function addCardNumber(FormBuilderInterface $builder)
131
    {
132
        $builder->add(
133
            self::FIELD_CARD_NUMBER,
134
            TextType::class,
135
            [
136
                'label' => false,
137
                'required' => false,
138
            ]
139
        );
140
141
        return $this;
142
    }
143
144
    /**
145
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
146
     *
147
     * @return $this
148
     */
149
    protected function addNameOnCard(FormBuilderInterface $builder)
150
    {
151
        $builder->add(
152
            self::FIELD_NAME_ON_CARD,
153
            TextType::class,
154
            [
155
                'label' => false,
156
                'required' => true,
157
                'constraints' => [
158
                    $this->createNotBlankConstraint(),
159
                ],
160
            ]
161
        );
162
163
        return $this;
164
    }
165
166
    /**
167
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
168
     * @param array $options
169
     *
170
     * @return $this
171
     */
172
    protected function addCardExpiresMonth(FormBuilderInterface $builder, array $options)
173
    {
174
        $builder->add(
175
            self::FIELD_CARD_EXPIRES_MONTH,
176
            ChoiceType::class,
177
            [
178
                'label' => false,
179
                'choices' => $options[self::OPTIONS_FIELD_NAME][self::OPTION_CARD_EXPIRES_CHOICES_MONTH],
180
                'required' => true,
181
                'constraints' => [
182
                    $this->createNotBlankConstraint(),
183
                ],
184
            ]
185
        );
186
187
        return $this;
188
    }
189
190
    /**
191
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
192
     * @param array $options
193
     *
194
     * @return $this
195
     */
196
    protected function addCardExpiresYear(FormBuilderInterface $builder, array $options)
197
    {
198
        $builder->add(
199
            self::FIELD_CARD_EXPIRES_YEAR,
200
            ChoiceType::class,
201
            [
202
                'label' => false,
203
                'choices' => $options[self::OPTIONS_FIELD_NAME][self::OPTION_CARD_EXPIRES_CHOICES_YEAR],
204
                'required' => true,
205
                'attr' => [
206
                    'placeholder' => 'Expires year',
207
                ],
208
                'constraints' => [
209
                    $this->createNotBlankConstraint(),
210
                ],
211
            ]
212
        );
213
214
        return $this;
215
    }
216
217
    /**
218
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
219
     *
220
     * @return $this
221
     */
222
    protected function addCardSecurityCode(FormBuilderInterface $builder)
223
    {
224
        $builder->add(
225
            self::FIELD_CARD_SECURITY_CODE,
226
            TextType::class,
227
            [
228
                'label' => false,
229
                'required' => false,
230
            ]
231
        );
232
233
        return $this;
234
    }
235
236
    /**
237
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
238
     *
239
     * @return $this
240
     */
241
    protected function addHiddenInputs(FormBuilderInterface $builder)
242
    {
243
        parent::addHiddenInputs($builder);
244
245
        $builder->add(
246
            self::FIELD_PSEUDO_CARD_NUMBER,
247
            HiddenType::class,
248
            [
249
                'label' => false,
250
            ]
251
        );
252
253
        return $this;
254
    }
255
}
256