Skip to content

Commit df13eb5

Browse files
committed
PayU - secureform via WooCommerce Blocks, version update
1 parent 1377424 commit df13eb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3852
-4414
lines changed

Payu/Blocks/PayuSecureFormBlock.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Payu\PaymentGateway\Blocks;
4+
5+
class PayuSecureFormBlock extends PayuBlocks {
6+
protected $name = 'payusecureform';
7+
8+
public function __construct() {
9+
parent::__construct( true );
10+
}
11+
}

includes/WC_Gateway_PayuSecureForm.php Payu/Gateways/WC_Gateway_PayuSecureForm.php

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
<?php
22

3-
use Payu\PaymentGateway\Gateways\WC_Payu_Gateways;
3+
namespace Payu\PaymentGateway\Gateways;
4+
5+
use OpenPayU_Result;
46

57
class WC_Gateway_PayuSecureForm extends WC_Payu_Gateways {
68
protected string $paytype = 'c';
9+
private string $payu_sdk_url;
710

811
function __construct() {
912
parent::__construct( 'payusecureform' );
1013

14+
$this->payu_sdk_url = $this->sandbox ? 'https://secure.snd.payu.com/javascript/sdk' : 'https://secure.payu.com/javascript/sdk';
15+
1116
if ( $this->is_enabled() ) {
1217
$this->icon = apply_filters( 'woocommerce_payu_icon', plugins_url( '/assets/images/card-visa-mc.svg', PAYU_PLUGIN_FILE ) );
1318

@@ -28,10 +33,16 @@ public function is_available(): bool {
2833
return parent::is_available();
2934
}
3035

31-
/**
32-
* @return null
33-
*/
34-
function minicart_checkout_refresh_script() {
36+
// Additional data for Blocks
37+
public function get_additional_data(): array {
38+
return [
39+
'posId' => $this->pos_id,
40+
'sdkUrl' => $this->payu_sdk_url,
41+
'lang' => explode( '_', get_locale() )[0]
42+
];
43+
}
44+
45+
function minicart_checkout_refresh_script(): void {
3546
if ( is_checkout() || is_wc_endpoint_url() ) :
3647
?>
3748
<script type="text/javascript">
@@ -63,12 +74,7 @@ public function payment_fields(): void {
6374
}
6475
}
6576

66-
/**
67-
* @param OpenPayU_Result $response
68-
*
69-
* @return null
70-
*/
71-
private function retrieve_methods( $response ) {
77+
private function retrieve_methods( OpenPayU_Result $response ): void {
7278
$payMethods = $response->getResponse();
7379
if ( $payMethods->payByLinks ) {
7480
$payByLinks = $this->process_pay_methods( $payMethods->payByLinks );
@@ -114,13 +120,10 @@ private function retrieve_methods( $response ) {
114120
protected function get_payu_pay_method(): array {
115121
$token = sanitize_text_field( $_POST['payu_sf_token'] );
116122

117-
return $this->get_payu_pay_method_array( 'CARD_TOKEN', $token ? $token : - 1, $this->paytype );
123+
return $this->get_payu_pay_method_array( 'CARD_TOKEN', $token );
118124
}
119125

120-
/**
121-
* @return void
122-
*/
123-
public function include_payu_sf_scripts() {
126+
public function include_payu_sf_scripts(): void {
124127
$payu_sdk_url = $this->sandbox ? 'https://secure.snd.payu.com/javascript/sdk' : 'https://secure.payu.com/javascript/sdk';
125128
wp_enqueue_script( 'payu-sfsdk', $payu_sdk_url, [], null );
126129
wp_enqueue_script( 'payu-promise-polyfill', plugins_url( '/assets/js/es6-promise.auto.min.js', PAYU_PLUGIN_FILE ), [], null );

Payu/Gateways/WC_Payu_Gateways.php

+42-68
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
use WC_Payment_Gateway;
1818
use WC_Shipping_Zone;
1919

20-
require_once WC_PAYU_PLUGIN_PATH . 'includes/lib/openpayu.php';
21-
2220
abstract class WC_Payu_Gateways extends WC_Payment_Gateway implements WC_PayuGateway {
2321
public static $paymethods = [];
2422

25-
public $pos_id;
26-
public $pos_widget_key;
23+
public string $pos_id;
24+
public string $pos_widget_key;
2725
public $enable_for_shipping;
2826
public $enable_for_virtual;
2927

@@ -305,7 +303,8 @@ private function get_form_field_config( array $currencies = [] ): array {
305303
if ( count( $currencies ) < 2 ) {
306304
$currencies = [ '' ];
307305
}
308-
$config = [];
306+
$config = [];
307+
$payuSettings = get_option( 'payu_settings_option_name', [] );
309308

310309
foreach ( $currencies as $code ) {
311310
$idSuffix = ( $code ? '_' : '' ) . $code;
@@ -321,8 +320,8 @@ private function get_form_field_config( array $currencies = [] ): array {
321320
'desc_tip' => true,
322321
'custom_attributes' => [
323322
'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 ] ?? ''
326325
],
327326
];
328327
}
@@ -332,25 +331,6 @@ private function get_form_field_config( array $currencies = [] ): array {
332331
return $config;
333332
}
334333

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-
354334
private function get_form_field_info(): array {
355335
return [
356336
'description' => [
@@ -470,13 +450,9 @@ private function is_accessing_settings() {
470450
}
471451

472452
/**
473-
* @param string|null $currency
474-
*
475-
* @return void
476453
* @throws
477-
*
478454
*/
479-
public function init_OpenPayU( $currency = null ) {
455+
public function init_OpenPayU( string $currency = null ): void {
480456
$isSandbox = 'yes' === $this->get_option( 'sandbox' );
481457

482458
if ( woocommerce_payu_is_wmpl_active_and_configure() || woocommerce_payu_is_currency_custom_config() ) {
@@ -486,39 +462,27 @@ public function init_OpenPayU( $currency = null ) {
486462
}
487463

488464
$optionPrefix = $isSandbox ? 'sandbox_' : '';
465+
$payuSettings = get_option( 'payu_settings_option_name', [] );
489466

490467
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 ] ?? '';
500471
$this->pos_widget_key = substr( $client_secret, 0, 2 );
501472
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 ] ?? '' );
510475
OpenPayU_Configuration::setOauthClientSecret( $client_secret );
511476
} 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, '' );
514479
$this->pos_widget_key = substr( $client_secret, 0, 2 );
515480
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, '' ) );
518483
OpenPayU_Configuration::setOauthClientSecret( $client_secret );
519484
}
520485

521-
522486
OpenPayU_Configuration::setOauthTokenCache( new OauthCache() );
523487
OpenPayU_Configuration::setSender( 'Wordpress ver ' . get_bloginfo( 'version' ) . ' / WooCommerce ver ' . WC()->version . ' / Plugin ver ' . PAYU_PLUGIN_VERSION );
524488
}
@@ -878,10 +842,7 @@ private function getThreeDsAuthentication( $order, $orderData ) {
878842
}
879843
}
880844

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' ) {
885846
$possibleBrowserData = [
886847
'screenWidth',
887848
'javaEnabled',
@@ -891,22 +852,35 @@ private function getThreeDsAuthentication( $order, $orderData ) {
891852
'colorDepth',
892853
'language'
893854
];
894-
$browserData = [
895-
'requestIP' => $this->getIP()
896-
];
897855

898-
foreach ( $possibleBrowserData as $bd ) {
899-
$browserData[ $bd ] = isset( $_POST['payu_browser'][ $bd ] ) ? sanitize_text_field( $_POST['payu_browser'][ $bd ] ) : '';
900-
}
856+
$browserData = [];
901857

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+
}
906868
}
907869
}
908870

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+
}
910884
}
911885

912886
return $threeDsAuthentication;

assets/css/payu-gateway.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/payu-gateway.scss

+37
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,40 @@ label[for*="payment_method_payu"] {
252252
}
253253
}
254254
}
255+
256+
.block-payu-card {
257+
display: flex;
258+
flex-wrap: wrap;
259+
gap: 0 10px;
260+
margin: 10px 0;
261+
padding: 10px;
262+
263+
.payu-sf-validation-error {
264+
color: #b21b0f;
265+
font-size: 13px;
266+
}
267+
268+
> .block-payu-card-number {
269+
flex: 1 0 100%;
270+
}
271+
272+
> .block-payu-card-date, .block-payu-card-cvv {
273+
flex: 1 0 calc(50% - 10px);
274+
}
275+
276+
.payu-card-form {
277+
background-color: #FFFFFF;
278+
border: 1px solid #999999;
279+
border-radius: 5px;
280+
padding: 8px 6px;
281+
282+
&.payu-secure-form-focus {
283+
border-color: #666666;
284+
box-shadow: 0 0 0 1px #666666;
285+
}
286+
287+
&.payu-secure-form-invalid:not(.payu-secure-form-focus) {
288+
border-color: #cc1818;
289+
}
290+
}
291+
}

blocks_translates_map.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2-
"src/js/payublik.js": "build/js/payublik.js",
3-
"src/js/payulistbanks.js": "build/js/payulistbanks.js"
2+
"src/js/payublik.js": "build/js/payublik.js",
3+
"src/js/payulistbanks.js": "build/js/payulistbanks.js",
4+
"src/js/payusecureform.js": "build/js/payusecureform.js"
45
}

changelog.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
*** Changelog ***
2+
= 2.6.0 - 2024-09-21 =
3+
* [Add] PayU - secure form via WooCommerce Blocks
4+
25
= 2.5.0 - 2024-07-23 =
36
* [Add] PayU - bank list via WooCommerce Blocks
47

composer.json

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
{
2-
"name": "payu/payment_gateway",
3-
"version": "2.5.0",
4-
"description": "PayU GPO Payment for WooCommerce",
5-
"type": "woocommerce-plugin",
6-
"license": "Apache License 2.0",
7-
"autoload": {
8-
"psr-4": {
9-
"Payu\\PaymentGateway\\": "Payu/"
10-
}
11-
},
12-
"authors": [
13-
{
14-
"name": "PayU GPO"
15-
}
16-
],
17-
"config": {
18-
"optimize-autoloader": true
19-
}
2+
"name": "payu/payment_gateway",
3+
"version": "2.6.0",
4+
"description": "PayU GPO Payment for WooCommerce",
5+
"type": "woocommerce-plugin",
6+
"license": "Apache License 2.0",
7+
"autoload": {
8+
"psr-4": {
9+
"Payu\\PaymentGateway\\": "Payu/"
10+
}
11+
},
12+
"authors": [
13+
{
14+
"name": "PayU GPO"
15+
}
16+
],
17+
"config": {
18+
"optimize-autoloader": true
19+
},
20+
"require": {
21+
"openpayu/openpayu": "2.3.*"
22+
}
2023
}

0 commit comments

Comments
 (0)