Passed
Push — feature/eco-2300/crefopay-cred... ( 3c5e73...5287a1 )
by Aleksey
01:15
created

CreditCard3DSubForm::addPaymentMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 15
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...orm\AbstractSubFormType 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;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...y\Form\SubFormInterface 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...
13
use Spryker\Yves\StepEngine\Dependency\Form\SubFormProviderNameInterface;
0 ignored issues
show
Bug introduced by
The type Spryker\Yves\StepEngine\...rmProviderNameInterface 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...
14
use SprykerEco\Shared\CrefoPay\CrefoPayConfig;
15
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\E...on\Core\Type\HiddenType 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...
16
use Symfony\Component\Form\FormBuilderInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormBuilderInterface 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...
17
use Symfony\Component\Form\FormInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormInterface 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...
18
use Symfony\Component\Form\FormView;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Form\FormView 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...
19
use Symfony\Component\OptionsResolver\OptionsResolver;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\OptionsResolver\OptionsResolver 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...
20
21
class CreditCard3DSubForm extends AbstractSubFormType implements SubFormInterface, SubFormProviderNameInterface
22
{
23
    public const CREFO_PAY_SHOP_PUBLIC_KEY = 'shopPublicKey';
24
    public const CREFO_PAY_ORDER_ID = 'orderID';
25
    public const CREFO_PAY_SECURE_FIELDS_API_ENDPOINT = 'secureFieldsApiEndpoint';
26
    public const CREFO_PAY_SECURE_FIELDS_LIBRARY_URL = 'secureFieldsLibraryUrl';
27
    public const CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS = 'secureFieldsPlaceholders';
28
29
    protected const PAYMENT_METHOD = 'credit-card-3d';
30
    protected const FORM_FIELD_PAYMENT_METHOD = 'paymentMethod';
31
    protected const FORM_FIELD_PAYMENT_METHOD_DATA = 'CC3D';
32
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME = 'data-crefopay';
33
    protected const FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE = 'paymentMethod';
34
    protected const FORM_FIELD_PAYMENT_INSTRUMENT_ID = 'paymentInstrumentId';
35
36
    /**
37
     * @return string
38
     */
39
    public function getProviderName(): string
40
    {
41
        return CrefoPayConfig::PROVIDER_NAME;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getName(): string
48
    {
49
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getPropertyPath(): string
56
    {
57
        return CrefoPayConfig::CREFO_PAY_PAYMENT_METHOD_CREDIT_CARD_3D;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getTemplatePath(): string
64
    {
65
        return CrefoPayConfig::PROVIDER_NAME . DIRECTORY_SEPARATOR . static::PAYMENT_METHOD;
66
    }
67
68
    /**
69
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
70
     *
71
     * @return void
72
     */
73
    public function configureOptions(OptionsResolver $resolver): void
74
    {
75
        $resolver->setDefaults([
76
            'data_class' => CrefoPayPaymentTransfer::class,
77
        ])->setRequired(static::OPTIONS_FIELD_NAME);
78
    }
79
80
    /**
81
     * @param \Symfony\Component\Form\FormView $view The view
82
     * @param \Symfony\Component\Form\FormInterface $form The form
83
     * @param array $options The options
84
     *
85
     * @return void
86
     */
87
    public function buildView(FormView $view, FormInterface $form, array $options): void
88
    {
89
        parent::buildView($view, $form, $options);
90
        $selectedOptions = $options[static::OPTIONS_FIELD_NAME];
91
        $view->vars[static::CREFO_PAY_SHOP_PUBLIC_KEY] = $selectedOptions[static::CREFO_PAY_SHOP_PUBLIC_KEY];
92
        $view->vars[static::CREFO_PAY_ORDER_ID] = $selectedOptions[static::CREFO_PAY_ORDER_ID];
93
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_API_ENDPOINT];
94
        $view->vars[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS] = $selectedOptions[static::CREFO_PAY_SECURE_FIELDS_PLACEHOLDERS];
95
    }
96
97
    /**
98
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
99
     * @param array $options
100
     *
101
     * @return void
102
     */
103
    public function buildForm(FormBuilderInterface $builder, array $options): void
104
    {
105
        $this->addPaymentMethod($builder)
106
            ->addPaymentInstrumentId($builder);
107
    }
108
109
    /**
110
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
111
     *
112
     * @return $this
113
     */
114
    protected function addPaymentMethod(FormBuilderInterface $builder)
115
    {
116
        $builder->add(
117
            static::FORM_FIELD_PAYMENT_METHOD,
118
            HiddenType::class,
119
            [
120
                'label' => false,
121
                'data' => static::FORM_FIELD_PAYMENT_METHOD_DATA,
122
                'attr' => [
123
                    static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_NAME => static::FORM_FIELD_ATTRIBUTE_DATA_CREFO_PAY_VALUE,
124
                ],
125
            ]
126
        );
127
128
        return $this;
129
    }
130
131
    /**
132
     * @param \Symfony\Component\Form\FormBuilderInterface $builder
133
     *
134
     * @return $this
135
     */
136
    protected function addPaymentInstrumentId(FormBuilderInterface $builder)
137
    {
138
        $builder->add(
139
            static::FORM_FIELD_PAYMENT_INSTRUMENT_ID,
140
            HiddenType::class,
141
            ['label' => false]
142
        );
143
144
        return $this;
145
    }
146
}
147