|
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\PayoneBankAccountCheckTransfer; |
|
|
|
|
|
|
12
|
|
|
use Generated\Shared\Transfer\PayonePaymentOnlinetransferTransfer; |
|
|
|
|
|
|
13
|
|
|
use Spryker\Yves\StepEngine\Dependency\Form\SubFormInterface; |
|
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
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
|
20
|
|
|
|
|
21
|
|
|
abstract class OnlineTransferSubForm extends AbstractPayoneSubForm |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
public const PAYMENT_METHOD = 'online_transfer'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
public const FIELD_IBAN = 'iban'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
public const FIELD_BIC = 'bic'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
*/ |
|
41
|
|
|
public const FIELD_BANK_COUNTRY = 'bankcountry'; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var string |
|
45
|
|
|
*/ |
|
46
|
|
|
public const FIELD_BANK_ACCOUNT = 'bankaccount'; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string |
|
50
|
|
|
*/ |
|
51
|
|
|
public const FIELD_BANK_CODE = 'bankcode'; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var string |
|
55
|
|
|
*/ |
|
56
|
|
|
public const FIELD_BANK_BRANCH_CODE = 'bankbranchcode'; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var string |
|
60
|
|
|
*/ |
|
61
|
|
|
public const FIELD_BANK_CHECK_DIGIT = 'bankcheckdigit'; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @var string |
|
65
|
|
|
*/ |
|
66
|
|
|
public const FIELD_ONLINE_BANK_TRANSFER_TYPE = 'onlinebanktransfertype'; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @var string |
|
70
|
|
|
*/ |
|
71
|
|
|
public const FIELD_BANK_GROUP_TYPE = 'bankgrouptype'; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @var string |
|
75
|
|
|
*/ |
|
76
|
|
|
public const OPTION_BANK_GROUP_TYPES = 'online bank transfer types'; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @var string |
|
80
|
|
|
*/ |
|
81
|
|
|
public const OPTION_BANK_COUNTRIES = ''; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @var string |
|
85
|
|
|
*/ |
|
86
|
|
|
protected const BANK_ACCOUNT_UNKNOWN_ERROR_MESSAGE = 'payone.bank_account.unknown_error'; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
90
|
|
|
* @param array $options |
|
91
|
|
|
* |
|
92
|
|
|
* @return $this |
|
93
|
|
|
*/ |
|
94
|
|
|
abstract public function addOnlineBankTransferType(FormBuilderInterface $builder, array $options); |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* @return string |
|
98
|
|
|
*/ |
|
99
|
|
|
public function getName(): string |
|
100
|
|
|
{ |
|
101
|
|
|
return PaymentTransfer::PAYONE_ONLINE_TRANSFER; |
|
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' => PayonePaymentOnlinetransferTransfer::class, |
|
113
|
|
|
'constraints' => [ |
|
114
|
|
|
// Add Callback constraint for bank account check in ancestor classes |
|
115
|
|
|
// new Callback(['methods' => [[$this, 'checkBankAccount']]]) |
|
116
|
|
|
], |
|
117
|
|
|
])->setRequired(SubFormInterface::OPTIONS_FIELD_NAME); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver |
|
122
|
|
|
* |
|
123
|
|
|
* @return void |
|
124
|
|
|
*/ |
|
125
|
|
|
public function setDefaultOptions(OptionsResolver $resolver): void |
|
126
|
|
|
{ |
|
127
|
|
|
$this->configureOptions($resolver); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
132
|
|
|
* @param array $options |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options): void |
|
137
|
|
|
{ |
|
138
|
|
|
$this->addOnlineBankTransferType($builder, $options) |
|
139
|
|
|
->addBankCountry($builder, $options); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
144
|
|
|
* |
|
145
|
|
|
* @return $this |
|
146
|
|
|
*/ |
|
147
|
|
|
protected function addBankAccount(FormBuilderInterface $builder) |
|
148
|
|
|
{ |
|
149
|
|
|
$builder->add( |
|
150
|
|
|
static::FIELD_BANK_ACCOUNT, |
|
151
|
|
|
TextType::class, |
|
152
|
|
|
[ |
|
153
|
|
|
'label' => false, |
|
154
|
|
|
'required' => true, |
|
155
|
|
|
'constraints' => [ |
|
156
|
|
|
], |
|
157
|
|
|
], |
|
158
|
|
|
); |
|
159
|
|
|
|
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
165
|
|
|
* |
|
166
|
|
|
* @return $this |
|
167
|
|
|
*/ |
|
168
|
|
|
protected function addBankCode(FormBuilderInterface $builder) |
|
169
|
|
|
{ |
|
170
|
|
|
$builder->add( |
|
171
|
|
|
static::FIELD_BANK_CODE, |
|
172
|
|
|
TextType::class, |
|
173
|
|
|
[ |
|
174
|
|
|
'label' => false, |
|
175
|
|
|
'required' => true, |
|
176
|
|
|
'constraints' => [ |
|
177
|
|
|
], |
|
178
|
|
|
], |
|
179
|
|
|
); |
|
180
|
|
|
|
|
181
|
|
|
return $this; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
186
|
|
|
* |
|
187
|
|
|
* @return $this |
|
188
|
|
|
*/ |
|
189
|
|
|
protected function addBankBranchCode(FormBuilderInterface $builder) |
|
190
|
|
|
{ |
|
191
|
|
|
$builder->add( |
|
192
|
|
|
static::FIELD_BANK_BRANCH_CODE, |
|
193
|
|
|
TextType::class, |
|
194
|
|
|
[ |
|
195
|
|
|
'label' => false, |
|
196
|
|
|
'required' => true, |
|
197
|
|
|
'constraints' => [ |
|
198
|
|
|
], |
|
199
|
|
|
], |
|
200
|
|
|
); |
|
201
|
|
|
|
|
202
|
|
|
return $this; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
207
|
|
|
* |
|
208
|
|
|
* @return $this |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function addBankCheckDigit(FormBuilderInterface $builder) |
|
211
|
|
|
{ |
|
212
|
|
|
$builder->add( |
|
213
|
|
|
static::FIELD_BANK_CHECK_DIGIT, |
|
214
|
|
|
TextType::class, |
|
215
|
|
|
[ |
|
216
|
|
|
'label' => false, |
|
217
|
|
|
'required' => true, |
|
218
|
|
|
'constraints' => [ |
|
219
|
|
|
], |
|
220
|
|
|
], |
|
221
|
|
|
); |
|
222
|
|
|
|
|
223
|
|
|
return $this; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
228
|
|
|
* |
|
229
|
|
|
* @return $this |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function addIban(FormBuilderInterface $builder) |
|
232
|
|
|
{ |
|
233
|
|
|
$builder->add( |
|
234
|
|
|
static::FIELD_IBAN, |
|
235
|
|
|
TextType::class, |
|
236
|
|
|
[ |
|
237
|
|
|
'label' => false, |
|
238
|
|
|
'required' => true, |
|
239
|
|
|
'constraints' => [ |
|
240
|
|
|
], |
|
241
|
|
|
], |
|
242
|
|
|
); |
|
243
|
|
|
|
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
249
|
|
|
* @param array $options |
|
250
|
|
|
* |
|
251
|
|
|
* @return $this |
|
252
|
|
|
*/ |
|
253
|
|
|
protected function addBankCountry(FormBuilderInterface $builder, array $options) |
|
254
|
|
|
{ |
|
255
|
|
|
if (count($options[static::OPTIONS_FIELD_NAME][static::OPTION_BANK_COUNTRIES]) == 1) { |
|
256
|
|
|
$builder->add( |
|
257
|
|
|
static::FIELD_BANK_COUNTRY, |
|
258
|
|
|
HiddenType::class, |
|
259
|
|
|
[ |
|
260
|
|
|
'label' => false, |
|
261
|
|
|
'data' => array_keys($options[static::OPTIONS_FIELD_NAME][static::OPTION_BANK_COUNTRIES])[0], |
|
262
|
|
|
], |
|
263
|
|
|
); |
|
264
|
|
|
} else { |
|
265
|
|
|
$builder->add( |
|
266
|
|
|
static::FIELD_BANK_COUNTRY, |
|
267
|
|
|
ChoiceType::class, |
|
268
|
|
|
[ |
|
269
|
|
|
'label' => false, |
|
270
|
|
|
'required' => true, |
|
271
|
|
|
'expanded' => false, |
|
272
|
|
|
'multiple' => false, |
|
273
|
|
|
'placeholder' => false, |
|
274
|
|
|
'choices' => array_flip($options[static::OPTIONS_FIELD_NAME][static::OPTION_BANK_COUNTRIES]), |
|
275
|
|
|
'constraints' => [ |
|
276
|
|
|
], |
|
277
|
|
|
], |
|
278
|
|
|
); |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
return $this; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* @param \Symfony\Component\Form\FormBuilderInterface $builder |
|
286
|
|
|
* |
|
287
|
|
|
* @return $this |
|
288
|
|
|
*/ |
|
289
|
|
|
protected function addBic(FormBuilderInterface $builder) |
|
290
|
|
|
{ |
|
291
|
|
|
$builder->add( |
|
292
|
|
|
static::FIELD_BIC, |
|
293
|
|
|
TextType::class, |
|
294
|
|
|
[ |
|
295
|
|
|
'label' => false, |
|
296
|
|
|
'required' => true, |
|
297
|
|
|
'constraints' => [ |
|
298
|
|
|
], |
|
299
|
|
|
], |
|
300
|
|
|
); |
|
301
|
|
|
|
|
302
|
|
|
return $this; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
/** |
|
306
|
|
|
* @param \Generated\Shared\Transfer\PayonePaymentOnlinetransferTransfer $data |
|
307
|
|
|
* @param \Symfony\Component\Validator\Context\ExecutionContextInterface $context |
|
308
|
|
|
* |
|
309
|
|
|
* @return void |
|
310
|
|
|
*/ |
|
311
|
|
|
public function checkBankAccount(PayonePaymentOnlinetransferTransfer $data, ExecutionContextInterface $context) |
|
312
|
|
|
{ |
|
313
|
|
|
$quoteTransfer = $context->getRoot()->getData(); |
|
314
|
|
|
if ($quoteTransfer->getPayment()->getPaymentSelection() != $this->getPropertyPath()) { |
|
315
|
|
|
return; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
$bankAccountCheckTransfer = new PayoneBankAccountCheckTransfer(); |
|
319
|
|
|
$bankAccountCheckTransfer->setBankCountry($data->getBankcountry()); |
|
320
|
|
|
$bankAccountCheckTransfer->setBankAccount($data->getBankaccount()); |
|
321
|
|
|
$bankAccountCheckTransfer->setBankCode($data->getBankcode()); |
|
322
|
|
|
$bankAccountCheckTransfer->setBankBranchCode($data->getBankbranchcode()); |
|
323
|
|
|
$bankAccountCheckTransfer->setBankCheckDigit($data->getBankcheckdigit()); |
|
324
|
|
|
$bankAccountCheckTransfer->setIban($data->getIban()); |
|
325
|
|
|
$bankAccountCheckTransfer->setBic($data->getBic()); |
|
326
|
|
|
|
|
327
|
|
|
$response = $this->getClient()->bankAccountCheck($bankAccountCheckTransfer); |
|
328
|
|
|
if ($response->getStatus() == 'ERROR' || $response->getStatus() == 'INVALID') { |
|
329
|
|
|
$context->addViolation($response->getCustomerErrorMessage() ?? static::BANK_ACCOUNT_UNKNOWN_ERROR_MESSAGE); |
|
330
|
|
|
} |
|
331
|
|
|
} |
|
332
|
|
|
} |
|
333
|
|
|
|
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