1 | <?php |
||||
2 | |||||
3 | namespace Pronamic\WordPress\Pay\Gateways\Buckaroo; |
||||
4 | |||||
5 | /** |
||||
6 | * Title: Buckaroo client |
||||
7 | * Description: |
||||
8 | * Copyright: 2005-2019 Pronamic |
||||
9 | * Company: Pronamic |
||||
10 | * |
||||
11 | * @author Remco Tolsma |
||||
12 | * @version 2.0.0 |
||||
13 | * @since 1.0.0 |
||||
14 | */ |
||||
15 | class Client { |
||||
16 | /** |
||||
17 | * Gateway URL |
||||
18 | * |
||||
19 | * @var string |
||||
20 | */ |
||||
21 | const GATEWAY_URL = 'https://checkout.buckaroo.nl/html/'; |
||||
22 | |||||
23 | /** |
||||
24 | * Gateway test URL |
||||
25 | * |
||||
26 | * @var string |
||||
27 | */ |
||||
28 | const GATEWAY_TEST_URL = 'https://testcheckout.buckaroo.nl/html/'; |
||||
29 | |||||
30 | /** |
||||
31 | * Gateway Name-Value-Pair URL |
||||
32 | * |
||||
33 | * @var string |
||||
34 | */ |
||||
35 | const GATEWAY_NVP_URL = 'https://checkout.buckaroo.nl/nvp/'; |
||||
36 | |||||
37 | /** |
||||
38 | * Gateway Name-Value-Pair test URL |
||||
39 | * |
||||
40 | * @var string |
||||
41 | */ |
||||
42 | const GATEWAY_NVP_TEST_URL = 'https://testcheckout.buckaroo.nl/nvp/'; |
||||
43 | |||||
44 | /** |
||||
45 | * Indicator for the iDEAL payment method |
||||
46 | * |
||||
47 | * @var string |
||||
48 | */ |
||||
49 | const PAYMENT_METHOD_IDEAL = 'ideal'; |
||||
50 | |||||
51 | /** |
||||
52 | * The payment server URL |
||||
53 | * |
||||
54 | * @var string |
||||
55 | */ |
||||
56 | private $payment_server_url; |
||||
57 | |||||
58 | /** |
||||
59 | * The amount |
||||
60 | * |
||||
61 | * @var int |
||||
62 | */ |
||||
63 | private $amount; |
||||
64 | |||||
65 | /** |
||||
66 | * The website key |
||||
67 | * |
||||
68 | * @var string |
||||
69 | */ |
||||
70 | private $website_key; |
||||
71 | |||||
72 | /** |
||||
73 | * The secret key |
||||
74 | * |
||||
75 | * @var string |
||||
76 | */ |
||||
77 | private $secret_key; |
||||
78 | |||||
79 | /** |
||||
80 | * The payment method |
||||
81 | * |
||||
82 | * @var string |
||||
83 | */ |
||||
84 | private $payment_method; |
||||
85 | |||||
86 | /** |
||||
87 | * The iDEAL issuer |
||||
88 | * |
||||
89 | * @since 1.2.4 |
||||
90 | * @var string |
||||
91 | */ |
||||
92 | private $ideal_issuer; |
||||
93 | |||||
94 | /** |
||||
95 | * The country code (culture) |
||||
96 | * |
||||
97 | * @var string |
||||
98 | */ |
||||
99 | private $culture; |
||||
100 | |||||
101 | /** |
||||
102 | * The currency |
||||
103 | * |
||||
104 | * @var string |
||||
105 | */ |
||||
106 | private $currency; |
||||
107 | |||||
108 | /** |
||||
109 | * The invoice number |
||||
110 | * |
||||
111 | * @var string |
||||
112 | */ |
||||
113 | private $invoice_number; |
||||
114 | |||||
115 | /** |
||||
116 | * The description |
||||
117 | * |
||||
118 | * @var string |
||||
119 | */ |
||||
120 | private $description; |
||||
121 | |||||
122 | /** |
||||
123 | * The return url |
||||
124 | * |
||||
125 | * @var string |
||||
126 | */ |
||||
127 | private $return_url; |
||||
128 | |||||
129 | /** |
||||
130 | * The return reject url |
||||
131 | * |
||||
132 | * @var string |
||||
133 | */ |
||||
134 | private $return_reject_url; |
||||
135 | |||||
136 | /** |
||||
137 | * The return error url |
||||
138 | * |
||||
139 | * @var string |
||||
140 | */ |
||||
141 | private $return_error_url; |
||||
142 | |||||
143 | /** |
||||
144 | * The return cancel url |
||||
145 | * |
||||
146 | * @var string |
||||
147 | */ |
||||
148 | private $return_cancel_url; |
||||
149 | |||||
150 | /** |
||||
151 | * Push URL |
||||
152 | * |
||||
153 | * @var string |
||||
154 | */ |
||||
155 | private $push_url; |
||||
156 | |||||
157 | /** |
||||
158 | * Requested services |
||||
159 | * |
||||
160 | * @var array |
||||
161 | */ |
||||
162 | private $requested_services; |
||||
163 | |||||
164 | /** |
||||
165 | * Excluded services |
||||
166 | * |
||||
167 | * @var array |
||||
168 | */ |
||||
169 | private $excluded_services; |
||||
170 | |||||
171 | /** |
||||
172 | * Pronamic payment ID |
||||
173 | * |
||||
174 | * @var array |
||||
175 | */ |
||||
176 | private $payment_id; |
||||
177 | |||||
178 | /** |
||||
179 | * Constructs and initialize a iDEAL kassa object |
||||
180 | */ |
||||
181 | public function __construct() { |
||||
182 | $this->set_payment_server_url( self::GATEWAY_URL ); |
||||
183 | |||||
184 | $this->requested_services = array(); |
||||
185 | } |
||||
186 | |||||
187 | /** |
||||
188 | * Get the payment server URL |
||||
189 | * |
||||
190 | * @return string the payment server URL |
||||
191 | 1 | */ |
|||
192 | 1 | public function get_payment_server_url() { |
|||
193 | return $this->payment_server_url; |
||||
194 | 1 | } |
|||
195 | 1 | ||||
196 | /** |
||||
197 | * Set the payment server URL |
||||
198 | * |
||||
199 | * @param string $url an URL |
||||
200 | */ |
||||
201 | public function set_payment_server_url( $url ) { |
||||
202 | $this->payment_server_url = $url; |
||||
203 | } |
||||
204 | |||||
205 | public function get_website_key() { |
||||
206 | return $this->website_key; |
||||
207 | } |
||||
208 | |||||
209 | public function set_website_key( $website_key ) { |
||||
210 | $this->website_key = $website_key; |
||||
211 | } |
||||
212 | |||||
213 | public function get_secret_key() { |
||||
214 | return $this->secret_key; |
||||
215 | } |
||||
216 | |||||
217 | public function set_secret_key( $secret_key ) { |
||||
218 | $this->secret_key = $secret_key; |
||||
219 | } |
||||
220 | |||||
221 | 1 | public function get_payment_method() { |
|||
222 | 1 | return $this->payment_method; |
|||
223 | 1 | } |
|||
224 | |||||
225 | 1 | public function set_payment_method( $payment_method ) { |
|||
226 | 1 | $this->payment_method = $payment_method; |
|||
227 | } |
||||
228 | |||||
229 | 1 | /** |
|||
230 | 1 | * Get iDEAL issuer. |
|||
231 | 1 | * |
|||
232 | * @since 1.2.4 |
||||
233 | 1 | * @return string |
|||
234 | 1 | */ |
|||
235 | public function get_ideal_issuer() { |
||||
236 | return $this->ideal_issuer; |
||||
237 | 1 | } |
|||
238 | 1 | ||||
239 | 1 | /** |
|||
240 | * Set iDEAL issuer. |
||||
241 | * |
||||
242 | * @since 1.2.4 |
||||
243 | * |
||||
244 | * @param string $issuer |
||||
245 | */ |
||||
246 | public function set_ideal_issuer( $issuer ) { |
||||
247 | $this->ideal_issuer = $issuer; |
||||
248 | } |
||||
249 | |||||
250 | public function get_requested_services() { |
||||
251 | return $this->requested_services; |
||||
252 | } |
||||
253 | |||||
254 | public function add_requested_service( $service ) { |
||||
255 | $this->requested_services[] = $service; |
||||
256 | } |
||||
257 | |||||
258 | public function get_excluded_services() { |
||||
259 | return $this->excluded_services; |
||||
260 | } |
||||
261 | |||||
262 | public function set_excluded_services( $service ) { |
||||
263 | $this->excluded_services = $service; |
||||
264 | } |
||||
265 | |||||
266 | public function get_culture() { |
||||
267 | return $this->culture; |
||||
268 | } |
||||
269 | |||||
270 | public function set_culture( $culture ) { |
||||
271 | $this->culture = $culture; |
||||
272 | } |
||||
273 | |||||
274 | public function get_currency() { |
||||
275 | return $this->currency; |
||||
276 | } |
||||
277 | |||||
278 | public function set_currency( $currency ) { |
||||
279 | $this->currency = $currency; |
||||
280 | } |
||||
281 | |||||
282 | public function get_invoice_number() { |
||||
283 | return $this->invoice_number; |
||||
284 | } |
||||
285 | |||||
286 | public function set_invoice_number( $invoice_number ) { |
||||
287 | $this->invoice_number = $invoice_number; |
||||
288 | } |
||||
289 | |||||
290 | public function get_description() { |
||||
291 | return $this->description; |
||||
292 | } |
||||
293 | |||||
294 | public function set_description( $description ) { |
||||
295 | $this->description = $description; |
||||
296 | } |
||||
297 | |||||
298 | /** |
||||
299 | * Get amount. |
||||
300 | * |
||||
301 | * @return int |
||||
302 | */ |
||||
303 | public function get_amount() { |
||||
304 | return $this->amount; |
||||
305 | } |
||||
306 | |||||
307 | /** |
||||
308 | * Set amount. |
||||
309 | * |
||||
310 | * @param int $amount Amount. |
||||
311 | */ |
||||
312 | public function set_amount( $amount ) { |
||||
313 | $this->amount = $amount; |
||||
314 | } |
||||
315 | |||||
316 | /** |
||||
317 | * Get return URL |
||||
318 | * |
||||
319 | * @return string |
||||
320 | */ |
||||
321 | public function get_return_url() { |
||||
322 | return $this->return_url; |
||||
323 | } |
||||
324 | |||||
325 | /** |
||||
326 | * Set return URL |
||||
327 | * |
||||
328 | * @param string $url Return URL. |
||||
329 | */ |
||||
330 | public function set_return_url( $url ) { |
||||
331 | $this->return_url = $url; |
||||
332 | } |
||||
333 | |||||
334 | /** |
||||
335 | * Get return reject URL |
||||
336 | * |
||||
337 | * @return string |
||||
338 | */ |
||||
339 | public function get_return_reject_url() { |
||||
340 | return $this->return_reject_url; |
||||
341 | } |
||||
342 | |||||
343 | /** |
||||
344 | * Set return reject URL |
||||
345 | * |
||||
346 | * @param string $url Return reject URL. |
||||
347 | */ |
||||
348 | public function set_return_reject_url( $url ) { |
||||
349 | $this->return_reject_url = $url; |
||||
350 | } |
||||
351 | |||||
352 | /** |
||||
353 | * Get return error URL |
||||
354 | * |
||||
355 | * @return string |
||||
356 | */ |
||||
357 | public function get_return_error_url() { |
||||
358 | return $this->return_error_url; |
||||
359 | } |
||||
360 | |||||
361 | /** |
||||
362 | * Set return error URL |
||||
363 | * |
||||
364 | * @param string $url Return error URL. |
||||
365 | */ |
||||
366 | public function set_return_error_url( $url ) { |
||||
367 | $this->return_error_url = $url; |
||||
368 | } |
||||
369 | |||||
370 | /** |
||||
371 | * Get return cancel URL |
||||
372 | * |
||||
373 | * @return string |
||||
374 | */ |
||||
375 | public function get_return_cancel_url() { |
||||
376 | return $this->return_cancel_url; |
||||
377 | } |
||||
378 | |||||
379 | /** |
||||
380 | * Set return cancel URL |
||||
381 | * |
||||
382 | * @param string $url Return cancel URL. |
||||
383 | */ |
||||
384 | public function set_return_cancel_url( $url ) { |
||||
385 | $this->return_cancel_url = $url; |
||||
386 | } |
||||
387 | |||||
388 | /** |
||||
389 | * Get push URL |
||||
390 | * |
||||
391 | * @return string |
||||
392 | */ |
||||
393 | public function get_push_url() { |
||||
394 | return $this->push_url; |
||||
395 | } |
||||
396 | |||||
397 | /** |
||||
398 | * Set push URL |
||||
399 | * |
||||
400 | * @param string $url Push URL. |
||||
401 | */ |
||||
402 | public function set_push_url( $url ) { |
||||
403 | $this->push_url = $url; |
||||
404 | } |
||||
405 | |||||
406 | /** |
||||
407 | * Get Pronamic payment ID |
||||
408 | * |
||||
409 | * @return string |
||||
410 | */ |
||||
411 | public function get_payment_id() { |
||||
412 | return $this->payment_id; |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
413 | } |
||||
414 | |||||
415 | /** |
||||
416 | * Set Pronamic payment ID |
||||
417 | * |
||||
418 | * @param string $payment_id Payment ID. |
||||
419 | */ |
||||
420 | public function set_payment_id( $payment_id ) { |
||||
421 | $this->payment_id = $payment_id; |
||||
0 ignored issues
–
show
It seems like
$payment_id of type string is incompatible with the declared type array of property $payment_id .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..
Loading history...
|
|||||
422 | } |
||||
423 | |||||
424 | /** |
||||
425 | * Get issuers |
||||
426 | * |
||||
427 | * @since 1.2.4 |
||||
428 | * @link http://support.buckaroo.nl/index.php/Service_iDEAL#iDEAL_banken_lijst_opvragen |
||||
429 | * @return array |
||||
430 | */ |
||||
431 | public function get_issuers() { |
||||
432 | $issuers = array(); |
||||
433 | |||||
434 | $url = add_query_arg( 'op', 'TransactionRequestSpecification', self::GATEWAY_NVP_TEST_URL ); |
||||
435 | |||||
436 | $data = array( |
||||
437 | 'brq_websitekey' => $this->get_website_key(), |
||||
438 | 'brq_services' => 'ideal', |
||||
439 | 'brq_latestversiononly' => 'True', |
||||
440 | ); |
||||
441 | |||||
442 | $signature = Security::create_signature( $data, $this->get_secret_key() ); |
||||
443 | |||||
444 | $data[ Parameters::SIGNATURE ] = $signature; |
||||
445 | |||||
446 | $result = wp_remote_post( |
||||
447 | $url, |
||||
448 | array( |
||||
449 | 'body' => http_build_query( $data ), |
||||
450 | ) |
||||
451 | 1 | ); |
|||
452 | 1 | ||||
453 | $body = wp_remote_retrieve_body( $result ); |
||||
0 ignored issues
–
show
It seems like
$result can also be of type WP_Error ; however, parameter $response of wp_remote_retrieve_body() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
454 | 1 | ||||
455 | wp_parse_str( $body, $data ); |
||||
456 | |||||
457 | 1 | $data = Util::transform_flat_response( $data ); |
|||
458 | 1 | ||||
459 | 1 | $error_msg = __( 'Unable to retrieve issuers from Buckaroo.', 'pronamic_ideal' ); |
|||
460 | |||||
461 | if ( 200 !== wp_remote_retrieve_response_code( $result ) ) { |
||||
0 ignored issues
–
show
It seems like
$result can also be of type WP_Error ; however, parameter $response of wp_remote_retrieve_response_code() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
462 | 1 | throw new \Pronamic\WordPress\Pay\GatewayException( 'buckaroo', $error_msg, $data ); |
|||
0 ignored issues
–
show
The type
Pronamic\WordPress\Pay\GatewayException 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||||
463 | } |
||||
464 | 1 | ||||
465 | if ( isset( $data['BRQ_APIRESULT'] ) && 'Fail' === $data['BRQ_APIRESULT'] ) { |
||||
466 | 1 | if ( isset( $data['BRQ_APIERRORMESSAGE'] ) ) { |
|||
467 | 1 | $error_msg = sprintf( '%s %s', $error_msg, $data['BRQ_APIERRORMESSAGE'] ); |
|||
468 | } |
||||
469 | 1 | ||||
470 | throw new \Pronamic\WordPress\Pay\GatewayException( 'buckaroo', $error_msg, $data ); |
||||
471 | } |
||||
472 | |||||
473 | 1 | if ( ! isset( $data['BRQ_SERVICES'] ) ) { |
|||
474 | return $issuers; |
||||
475 | 1 | } |
|||
476 | |||||
477 | 1 | foreach ( $data['BRQ_SERVICES'] as $service ) { |
|||
478 | if ( ! isset( $service['NAME'], $service['VERSION'], $service['ACTIONDESCRIPTION'] ) ) { |
||||
479 | 1 | return $issuers; |
|||
480 | } |
||||
481 | 1 | ||||
482 | if ( PaymentMethods::IDEAL !== $service['NAME'] ) { |
||||
483 | continue; |
||||
484 | } |
||||
485 | |||||
486 | foreach ( $service['ACTIONDESCRIPTION'] as $action ) { |
||||
487 | 1 | if ( ! isset( $action['NAME'], $action['REQUESTPARAMETERS'] ) ) { |
|||
488 | 1 | return $issuers; |
|||
489 | 1 | } |
|||
490 | |||||
491 | if ( 'Pay' !== $action['NAME'] ) { |
||||
492 | 1 | continue; |
|||
493 | } |
||||
494 | 1 | ||||
495 | foreach ( $action['REQUESTPARAMETERS'] as $parameter ) { |
||||
496 | |||||
497 | if ( ! isset( $parameter['NAME'], $parameter['LISTITEMDESCRIPTION'] ) ) { |
||||
498 | return $issuers; |
||||
499 | } |
||||
500 | |||||
501 | if ( 'issuer' !== $parameter['NAME'] ) { |
||||
502 | continue; |
||||
503 | } |
||||
504 | |||||
505 | foreach ( $parameter['LISTITEMDESCRIPTION'] as $issuer ) { |
||||
506 | $issuers[ $issuer['VALUE'] ] = $issuer['DESCRIPTION']; |
||||
507 | } |
||||
508 | |||||
509 | break; |
||||
510 | } |
||||
511 | } |
||||
512 | } |
||||
513 | |||||
514 | return $issuers; |
||||
515 | } |
||||
516 | |||||
517 | /** |
||||
518 | * Get HTML fields |
||||
519 | * |
||||
520 | * @since 1.1.1 |
||||
521 | * @return string |
||||
522 | */ |
||||
523 | public function get_fields() { |
||||
524 | $data = array( |
||||
525 | Parameters::ADD_PRONAMIC_PAYMENT_ID => $this->get_payment_id(), |
||||
526 | Parameters::WEBSITE_KEY => $this->get_website_key(), |
||||
527 | Parameters::INVOICE_NUMBER => $this->get_invoice_number(), |
||||
528 | Parameters::AMOUNT => number_format( $this->get_amount(), 2, '.', '' ), |
||||
529 | Parameters::CURRENCY => $this->get_currency(), |
||||
530 | Parameters::CULTURE => $this->get_culture(), |
||||
531 | Parameters::DESCRIPTION => $this->get_description(), |
||||
532 | Parameters::PAYMENT_METHOD => $this->get_payment_method(), |
||||
533 | Parameters::RETURN_URL => $this->get_return_url(), |
||||
534 | Parameters::RETURN_REJECT_URL => $this->get_return_reject_url(), |
||||
535 | Parameters::RETURN_ERROR_URL => $this->get_return_error_url(), |
||||
536 | Parameters::RETURN_CANCEL_URL => $this->get_return_cancel_url(), |
||||
537 | Parameters::PUSH_URL => $this->get_push_url(), |
||||
538 | Parameters::PUSH_FAILURE_URL => $this->get_push_url(), |
||||
539 | Parameters::REQUESTED_SERVICES => implode( ',', $this->get_requested_services() ), |
||||
540 | Parameters::EXCLUDED_SERVICES => $this->get_excluded_services(), |
||||
541 | Parameters::IDEAL_ISSUER => $this->get_ideal_issuer(), |
||||
542 | ); |
||||
543 | |||||
544 | $signature = Security::create_signature( $data, $this->get_secret_key() ); |
||||
545 | |||||
546 | $data[ Parameters::SIGNATURE ] = $signature; |
||||
547 | |||||
548 | return $data; |
||||
0 ignored issues
–
show
|
|||||
549 | } |
||||
550 | |||||
551 | /** |
||||
552 | * Verify request Buckaroo |
||||
553 | */ |
||||
554 | public function verify_request( $data ) { |
||||
555 | $result = false; |
||||
556 | |||||
557 | $signature = Security::get_signature( $data ); |
||||
0 ignored issues
–
show
Are you sure the assignment to
$signature is correct as Pronamic\WordPress\Pay\G...y::get_signature($data) targeting Pronamic\WordPress\Pay\G...curity::get_signature() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.
Loading history...
|
|||||
558 | |||||
559 | $signature_check = Security::create_signature( $data, $this->get_secret_key() ); |
||||
560 | |||||
561 | if ( 0 === strcasecmp( $signature, $signature_check ) ) { |
||||
562 | $data = array_change_key_case( $data, CASE_LOWER ); |
||||
563 | |||||
564 | $result = filter_var_array( |
||||
565 | $data, |
||||
566 | array( |
||||
567 | Parameters::ADD_PRONAMIC_PAYMENT_ID => FILTER_SANITIZE_STRING, |
||||
568 | Parameters::PAYMENT => FILTER_SANITIZE_STRING, |
||||
569 | Parameters::PAYMENT_METHOD => FILTER_SANITIZE_STRING, |
||||
570 | Parameters::STATUS_CODE => FILTER_VALIDATE_INT, |
||||
571 | Parameters::STATUS_CODE_DETAIL => FILTER_SANITIZE_STRING, |
||||
572 | Parameters::STATUS_MESSAGE => FILTER_SANITIZE_STRING, |
||||
573 | Parameters::INVOICE_NUMBER => FILTER_SANITIZE_STRING, |
||||
574 | Parameters::AMOUNT => FILTER_VALIDATE_FLOAT, |
||||
575 | Parameters::CURRENCY => FILTER_SANITIZE_STRING, |
||||
576 | Parameters::TIMESTAMP => FILTER_SANITIZE_STRING, |
||||
577 | Parameters::SERVICE_IDEAL_CONSUMER_ISSUER => FILTER_SANITIZE_STRING, |
||||
578 | Parameters::SERVICE_IDEAL_CONSUMER_NAME => FILTER_SANITIZE_STRING, |
||||
579 | Parameters::SERVICE_IDEAL_CONSUMER_IBAN => FILTER_SANITIZE_STRING, |
||||
580 | Parameters::SERVICE_IDEAL_CONSUMER_BIC => FILTER_SANITIZE_STRING, |
||||
581 | Parameters::TRANSACTIONS => FILTER_SANITIZE_STRING, |
||||
582 | ) |
||||
583 | ); |
||||
584 | } |
||||
585 | |||||
586 | return $result; |
||||
587 | } |
||||
588 | } |
||||
589 |