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