17
17
use WC_Payment_Gateway ;
18
18
use WC_Shipping_Zone ;
19
19
20
- require_once WC_PAYU_PLUGIN_PATH . 'includes/lib/openpayu.php ' ;
21
-
22
20
abstract class WC_Payu_Gateways extends WC_Payment_Gateway implements WC_PayuGateway {
23
21
public static $ paymethods = [];
24
22
25
- public $ pos_id ;
26
- public $ pos_widget_key ;
23
+ public string $ pos_id ;
24
+ public string $ pos_widget_key ;
27
25
public $ enable_for_shipping ;
28
26
public $ enable_for_virtual ;
29
27
@@ -305,7 +303,8 @@ private function get_form_field_config( array $currencies = [] ): array {
305
303
if ( count ( $ currencies ) < 2 ) {
306
304
$ currencies = [ '' ];
307
305
}
308
- $ config = [];
306
+ $ config = [];
307
+ $ payuSettings = get_option ( 'payu_settings_option_name ' , [] );
309
308
310
309
foreach ( $ currencies as $ code ) {
311
310
$ idSuffix = ( $ code ? '_ ' : '' ) . $ code ;
@@ -321,8 +320,8 @@ private function get_form_field_config( array $currencies = [] ): array {
321
320
'desc_tip ' => true ,
322
321
'custom_attributes ' => [
323
322
'data-global ' => 'can-be-global ' ,
324
- 'global-value ' => $ this -> get_payu_option ( [ 'payu_settings_option_name ' , ' global_ ' . $ field ] ) ,
325
- 'local-value ' => $ this -> get_payu_option ( [ ' woocommerce_ ' . $ this -> id . ' _settings ' , $ field ] )
323
+ 'global-value ' => $ payuSettings [ 'global_ ' . $ field ] ?? '' ,
324
+ 'local-value ' => $ payuSettings [ $ field ] ?? ''
326
325
],
327
326
];
328
327
}
@@ -332,25 +331,6 @@ private function get_form_field_config( array $currencies = [] ): array {
332
331
return $ config ;
333
332
}
334
333
335
- /**
336
- * @param array $key
337
- *
338
- * @return string|false
339
- */
340
- public function get_payu_option ( $ key ) {
341
- if ( ! is_array ( $ key ) ) {
342
- return false ;
343
- }
344
-
345
- $ option = get_option ( $ key [0 ] );
346
-
347
- if ( ! is_array ( $ option ) || ! array_key_exists ( $ key [1 ], $ option ) ) {
348
- return false ;
349
- }
350
-
351
- return $ option [ $ key [1 ] ];
352
- }
353
-
354
334
private function get_form_field_info (): array {
355
335
return [
356
336
'description ' => [
@@ -470,13 +450,9 @@ private function is_accessing_settings() {
470
450
}
471
451
472
452
/**
473
- * @param string|null $currency
474
- *
475
- * @return void
476
453
* @throws
477
- *
478
454
*/
479
- public function init_OpenPayU ( $ currency = null ) {
455
+ public function init_OpenPayU ( string $ currency = null ): void {
480
456
$ isSandbox = 'yes ' === $ this ->get_option ( 'sandbox ' );
481
457
482
458
if ( woocommerce_payu_is_wmpl_active_and_configure () || woocommerce_payu_is_currency_custom_config () ) {
@@ -486,39 +462,27 @@ public function init_OpenPayU( $currency = null ) {
486
462
}
487
463
488
464
$ optionPrefix = $ isSandbox ? 'sandbox_ ' : '' ;
465
+ $ payuSettings = get_option ( 'payu_settings_option_name ' , [] );
489
466
490
467
OpenPayU_Configuration::setEnvironment ( $ isSandbox ? 'sandbox ' : 'secure ' );
491
- if ( $ this ->get_option ( 'use_global ' ) === 'yes ' || ! $ this ->get_option ( 'use_global ' ) ) {
492
- $ this ->pos_id = $ this ->get_payu_option ( [
493
- 'payu_settings_option_name ' ,
494
- 'global_ ' . $ optionPrefix . 'pos_id ' . $ optionSuffix
495
- ] );
496
- $ client_secret = $ this ->get_payu_option ( [
497
- 'payu_settings_option_name ' ,
498
- 'global_ ' . $ optionPrefix . 'client_secret ' . $ optionSuffix
499
- ] );
468
+ if ( $ this ->get_option ( 'use_global ' , 'yes ' ) === 'yes ' ) {
469
+ $ this ->pos_id = $ payuSettings [ 'global_ ' . $ optionPrefix . 'pos_id ' . $ optionSuffix ] ?? '' ;
470
+ $ client_secret = $ payuSettings [ 'global_ ' . $ optionPrefix . 'client_secret ' . $ optionSuffix ] ?? '' ;
500
471
$ this ->pos_widget_key = substr ( $ client_secret , 0 , 2 );
501
472
OpenPayU_Configuration::setMerchantPosId ( $ this ->pos_id );
502
- OpenPayU_Configuration::setSignatureKey ( $ this ->get_payu_option ( [
503
- 'payu_settings_option_name ' ,
504
- 'global_ ' . $ optionPrefix . 'md5 ' . $ optionSuffix
505
- ] ) );
506
- OpenPayU_Configuration::setOauthClientId ( $ this ->get_payu_option ( [
507
- 'payu_settings_option_name ' ,
508
- 'global_ ' . $ optionPrefix . 'client_id ' . $ optionSuffix
509
- ] ) );
473
+ OpenPayU_Configuration::setSignatureKey ( $ payuSettings [ 'global_ ' . $ optionPrefix . 'md5 ' . $ optionSuffix ] ?? '' );
474
+ OpenPayU_Configuration::setOauthClientId ( $ payuSettings [ 'global_ ' . $ optionPrefix . 'client_id ' . $ optionSuffix ] ?? '' );
510
475
OpenPayU_Configuration::setOauthClientSecret ( $ client_secret );
511
476
} else {
512
- $ this ->pos_id = $ this ->get_option ( $ optionPrefix . 'pos_id ' . $ optionSuffix );
513
- $ client_secret = $ this ->get_option ( $ optionPrefix . 'client_secret ' . $ optionSuffix );
477
+ $ this ->pos_id = $ this ->get_option ( $ optionPrefix . 'pos_id ' . $ optionSuffix, '' );
478
+ $ client_secret = $ this ->get_option ( $ optionPrefix . 'client_secret ' . $ optionSuffix, '' );
514
479
$ this ->pos_widget_key = substr ( $ client_secret , 0 , 2 );
515
480
OpenPayU_Configuration::setMerchantPosId ( $ this ->pos_id );
516
- OpenPayU_Configuration::setSignatureKey ( $ this ->get_option ( $ optionPrefix . 'md5 ' . $ optionSuffix ) );
517
- OpenPayU_Configuration::setOauthClientId ( $ this ->get_option ( $ optionPrefix . 'client_id ' . $ optionSuffix ) );
481
+ OpenPayU_Configuration::setSignatureKey ( $ this ->get_option ( $ optionPrefix . 'md5 ' . $ optionSuffix, '' ) );
482
+ OpenPayU_Configuration::setOauthClientId ( $ this ->get_option ( $ optionPrefix . 'client_id ' . $ optionSuffix, '' ) );
518
483
OpenPayU_Configuration::setOauthClientSecret ( $ client_secret );
519
484
}
520
485
521
-
522
486
OpenPayU_Configuration::setOauthTokenCache ( new OauthCache () );
523
487
OpenPayU_Configuration::setSender ( 'Wordpress ver ' . get_bloginfo ( 'version ' ) . ' / WooCommerce ver ' . WC ()->version . ' / Plugin ver ' . PAYU_PLUGIN_VERSION );
524
488
}
@@ -878,10 +842,7 @@ private function getThreeDsAuthentication( $order, $orderData ) {
878
842
}
879
843
}
880
844
881
- if ( isset ( $ orderData ['payMethods ' ]['payMethod ' ]['type ' ] ) && $ orderData ['payMethods ' ]['payMethod ' ]['type ' ] === 'CARD_TOKEN '
882
- && isset ( $ _POST ['payu_browser ' ] )
883
- && is_array ( $ _POST ['payu_browser ' ] )
884
- ) {
845
+ if ( isset ( $ orderData ['payMethods ' ]['payMethod ' ]['type ' ] ) && $ orderData ['payMethods ' ]['payMethod ' ]['type ' ] === 'CARD_TOKEN ' ) {
885
846
$ possibleBrowserData = [
886
847
'screenWidth ' ,
887
848
'javaEnabled ' ,
@@ -891,22 +852,35 @@ private function getThreeDsAuthentication( $order, $orderData ) {
891
852
'colorDepth ' ,
892
853
'language '
893
854
];
894
- $ browserData = [
895
- 'requestIP ' => $ this ->getIP ()
896
- ];
897
855
898
- foreach ( $ possibleBrowserData as $ bd ) {
899
- $ browserData [ $ bd ] = isset ( $ _POST ['payu_browser ' ][ $ bd ] ) ? sanitize_text_field ( $ _POST ['payu_browser ' ][ $ bd ] ) : '' ;
900
- }
856
+ $ browserData = [];
901
857
902
- if ( empty ( $ browserData ['userAgent ' ] ) ) {
903
- $ headers = array_change_key_case ( getallheaders (), CASE_LOWER );
904
- if ( $ headers ['user-agent ' ] ) {
905
- $ browserData ['userAgent ' ] = $ headers ['user-agent ' ];
858
+ if ( isset ( $ _POST ['payu_browser ' ] ) && is_array ( $ _POST ['payu_browser ' ] ) ) {
859
+ foreach ( $ possibleBrowserData as $ bd ) {
860
+ $ browserData [ $ bd ] = isset ( $ _POST ['payu_browser ' ][ $ bd ] ) ? sanitize_text_field ( $ _POST ['payu_browser ' ][ $ bd ] ) : '' ;
861
+ }
862
+ } else {
863
+ foreach ( $ possibleBrowserData as $ bd ) {
864
+ $ name = strtolower ( 'payuBrowser_ ' . $ bd );
865
+ if ( isset ( $ _POST [ $ name ] ) ) {
866
+ $ browserData [ $ bd ] = sanitize_text_field ( $ _POST [ $ name ] );
867
+ }
906
868
}
907
869
}
908
870
909
- $ threeDsAuthentication ['browser ' ] = $ browserData ;
871
+ if ( count ( $ browserData ) > 0 ) {
872
+ $ browserData ['requestIP ' ] = $ this ->getIP ();
873
+
874
+
875
+ if ( empty ( $ browserData ['userAgent ' ] ) ) {
876
+ $ headers = array_change_key_case ( getallheaders (), CASE_LOWER );
877
+ if ( $ headers ['user-agent ' ] ) {
878
+ $ browserData ['userAgent ' ] = $ headers ['user-agent ' ];
879
+ }
880
+ }
881
+
882
+ $ threeDsAuthentication ['browser ' ] = $ browserData ;
883
+ }
910
884
}
911
885
912
886
return $ threeDsAuthentication ;
0 commit comments