|
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; |
|
|
|
|
|
|
11
|
|
|
use Generated\Shared\Transfer\PayoneKlarnaTransfer; |
|
|
|
|
|
|
12
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface; |
|
13
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
14
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
|
15
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
16
|
|
|
use Symfony\Component\Form\FormInterface; |
|
17
|
|
|
use Symfony\Component\Form\FormView; |
|
18
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method \SprykerEco\Yves\Payone\PayoneConfig getConfig() |
|
22
|
|
|
*/ |
|
23
|
|
|
class KlarnaSubForm extends AbstractPayoneSubForm |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var string |
|
27
|
|
|
*/ |
|
28
|
|
|
public const PAY_METHOD_CHOICES = 'pay_methods'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
*/ |
|
33
|
|
|
public const WIDGET_PAY_METHODS = 'widget_pay_methods'; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
public const BILLING_ADDRESS_DATA = 'billing_address_data'; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var string |
|
42
|
|
|
*/ |
|
43
|
|
|
public const CUSTOMER_DATA = 'customer_data'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var string |
|
47
|
|
|
*/ |
|
48
|
|
|
public const PAYMENT_METHOD = 'klarna'; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var string |
|
52
|
|
|
*/ |
|
53
|
|
|
protected const FIELD_PAY_METHOD_TYPE = 'payMethod'; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected const FIELD_PAY_METHOD_TOKEN = 'payMethodToken'; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return string |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getName(): string |
|
64
|
|
|
{ |
|
65
|
|
|
return PaymentTransfer::PAYONE_KLARNA; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return string |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getPropertyPath(): string |
|
72
|
|
|
{ |
|
73
|
|
|
return PaymentTransfer::PAYONE_KLARNA; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
78
|
|
|
* @param array $options |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->addPayMethodField( |
|
85
|
|
|
$builder, |
|
86
|
|
|
$options[SubFormInterface::OPTIONS_FIELD_NAME][static::PAY_METHOD_CHOICES], |
|
87
|
|
|
); |
|
88
|
|
|
$this->addPayMethodTokenField($builder); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
|
93
|
|
|
* |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
|
97
|
|
|
{ |
|
98
|
|
|
$resolver->setDefaults([ |
|
99
|
|
|
'data_class' => PayoneKlarnaTransfer::class, |
|
100
|
|
|
])->setRequired(SubFormInterface::OPTIONS_FIELD_NAME); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
|
105
|
|
|
* |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setDefaultOptions(OptionsResolver $resolver): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->configureOptions($resolver); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
115
|
|
|
* @param array $choices |
|
116
|
|
|
* |
|
117
|
|
|
* @return $this |
|
118
|
|
|
*/ |
|
119
|
|
|
protected function addPayMethodField(FormBuilderInterface $builder, array $choices) |
|
120
|
|
|
{ |
|
121
|
|
|
$choices = ['Choose payment category' => ''] + $choices; |
|
122
|
|
|
|
|
123
|
|
|
$builder->add( |
|
124
|
|
|
static::FIELD_PAY_METHOD_TYPE, |
|
125
|
|
|
ChoiceType::class, |
|
126
|
|
|
[ |
|
127
|
|
|
'label' => false, |
|
128
|
|
|
'required' => true, |
|
129
|
|
|
'choices' => $choices, |
|
130
|
|
|
'data' => '', |
|
131
|
|
|
'choice_attr' => function ($val) { |
|
132
|
|
|
return $val === '' ? ['disabled' => 'disabled', 'selected' => 'selected'] : ['disabled' => 'disabled']; |
|
133
|
|
|
}, |
|
134
|
|
|
], |
|
135
|
|
|
); |
|
136
|
|
|
|
|
137
|
|
|
return $this; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
142
|
|
|
* |
|
143
|
|
|
* @return $this |
|
144
|
|
|
*/ |
|
145
|
|
|
protected function addPayMethodTokenField(FormBuilderInterface $builder) |
|
146
|
|
|
{ |
|
147
|
|
|
$builder->add( |
|
148
|
|
|
static::FIELD_PAY_METHOD_TOKEN, |
|
149
|
|
|
HiddenType::class, |
|
150
|
|
|
[ |
|
151
|
|
|
'label' => false, |
|
152
|
|
|
'required' => true, |
|
153
|
|
|
'data' => [], |
|
154
|
|
|
], |
|
155
|
|
|
); |
|
156
|
|
|
|
|
157
|
|
|
return $this; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param \Symfony\Component\Form\FormView $view |
|
162
|
|
|
* @param \Symfony\Component\Form\FormInterface $form |
|
163
|
|
|
* @param array $options |
|
164
|
|
|
* |
|
165
|
|
|
* @return void |
|
166
|
|
|
*/ |
|
167
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options): void |
|
168
|
|
|
{ |
|
169
|
|
|
parent::buildView($view, $form, $options); |
|
170
|
|
|
|
|
171
|
|
|
$view->vars[static::BILLING_ADDRESS_DATA] = $options[SubFormInterface::OPTIONS_FIELD_NAME][static::BILLING_ADDRESS_DATA]; |
|
172
|
|
|
$view->vars[static::CUSTOMER_DATA] = $options[SubFormInterface::OPTIONS_FIELD_NAME][static::CUSTOMER_DATA]; |
|
173
|
|
|
$view->vars[static::WIDGET_PAY_METHODS] = $options[SubFormInterface::OPTIONS_FIELD_NAME][static::WIDGET_PAY_METHODS]; |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths