CreditCard3DSubForm::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
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 CreditCard3DSubForm 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_LIBRARY_URL = 'secureFieldsLibraryUrl';
46
47
    /**
48
     * @var string
49
     */
50
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
51
52
    /**
53
     * @var string
54
     */
55
    protected const PAYMENT_METHOD = 'credit-card-3d';
56
57
    /**
58
     * @var string
59
     */
60
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
61
62
    /**
63
     * @var string
64
     */
65
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'CC3D';
66
67
    /**
68
     * @var string
69
     */
70
    protected const FORM_FIELD_PAYMENT_INSTRUMENT_ID = 'paymentInstrumentId';
71
72
    /**
73
     * @return string
74
     */
75
    public function getProviderName(): string
76
    {
77
        return CrefoPayConfig::PROVIDER_NAME;
78
    }
79
80
    /**
81
     * @return string
82
     */
83
    public function getName(): string
84
    {
85
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getPropertyPath(): string
92
    {
93
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
94
    }
95
96
    /**
97
     * @return string
98
     */
99
    public function getTemplatePath(): string
100
    {
101
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
102
    }
103
104
    /**
105
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
106
     *
107
     * @return void
108
     */
109
    public function configureOptions(OptionsResolver $resolver): void
110
    {
111
        $resolver->setDefaults([
112
            'data_class' => CrefoPayPaymentTransfer::class,
113
        ])->setRequired(static::OPTIONS_FIELD_NAME);
114
    }
115
116
    /**
117
     * @param \Symfony\Component\Form\FormView $view The view
118
     * @param \Symfony\Component\Form\FormInterface $form The form
119
     * @param array $options The options
120
     *
121
     * @return void
122
     */
123
    public function buildView(FormView $view, FormInterface $form, array $options): void
124
    {
125
        parent::buildView($view, $form, $options);
126
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
127
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
128
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
129
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
130
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
131
    }
132
133
    /**
134
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
135
     * @param array $options
136
     *
137
     * @return void
138
     */
139
    public function buildForm(FormBuilderInterface $builder, array $options): void
140
    {
141
        $this->addPaymentMethod($builder)
142
            ->addPaymentInstrumentId($builder);
143
    }
144
145
    /**
146
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
147
     *
148
     * @return $this
149
     */
150
    protected function addPaymentMethod(FormBuilderInterface $builder)
151
    {
152
        $builder->add(
153
            static::FORM_FIELD_PAYMENT_METHOD,
154
            ChoiceType::class,
155
            [
156
                'choices' => [static::FORM_FIELD_PAYMENT_METHOD_DATA],
157
                'expanded' => true,
158
            ],
159
        );
160
161
        return $this;
162
    }
163
164
    /**
165
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
166
     *
167
     * @return $this
168
     */
169
    protected function addPaymentInstrumentId(FormBuilderInterface $builder)
170
    {
171
        $builder->add(
172
            static::FORM_FIELD_PAYMENT_INSTRUMENT_ID,
173
            HiddenType::class,
174
            ['label' => false],
175
        );
176
177
        return $this;
178
    }
179
}
180