'redsys-about-page' ), 'admin.php' ) ) ); wp_safe_redirect( $seurredirect ); exit; } } add_action( 'admin_init', 'redsys_welcome_splash', 1 ); /** * Redsys CSS. */ function redsys_css_lite() { global $post_type; $current_screen = get_current_screen(); if ( 'woocommerce_page_wc-settings' === $current_screen->id ) { wp_register_style( 'redsys-css', plugins_url( 'assets/css/redsys-css.css', __FILE__ ), array(), REDSYS_WOOCOMMERCE_VERSION ); wp_enqueue_style( 'redsys-css' ); } } add_action( 'admin_enqueue_scripts', 'redsys_css_lite' ); /** * Redsys init. * Copyright: (C) 2013 - 2021 José Conti */ function woocommerce_gateway_redsys_init() { if ( ! class_exists( 'WC_Payment_Gateway' ) ) { return; } /** * Redsys menu */ function redsys_menu() { global $redsys_about; $redsys_about = add_submenu_page( 'woocommerce', __( 'About Redsys', 'woo-redsys-gateway-light' ), __( 'About Redsys', 'woo-redsys-gateway-light' ), 'manage_options', 'redsys-about-page', 'redsys_about_page' ); } add_action( 'admin_menu', 'redsys_menu' ); /** * WCRedL magic funcuton. * Copyright: (C) 2013 - 2021 José Conti */ function WCRedL() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid /** * Copyright: (C) 2013 - 2021 José Conti */ require_once REDSYS_PLUGIN_CLASS_PATH . 'class-wc-gateway-redsys-global-lite.php'; // Global class for global functions. return new WC_Gateway_Redsys_Global_Lite(); } /** * WCPSD2L magic funcuton. * Copyright: (C) 2013 - 2021 José Conti */ function WCPSD2L() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid require_once REDSYS_PLUGIN_CLASS_PATH . 'class-wc-gateway-redsys-psd2-light.php'; // PSD2 class for Redsys. return new WC_Gateway_Redsys_PSD2_Light(); } /** * Gateway class */ add_action( 'admin_notices', function () { WC_Gateway_Redsys::admin_notice_mcrypt_encrypt(); } ); /** * Redsys Notice version. */ function redsys_lite_add_notice_new_version() { $version = get_option( 'hide-new-version-redsys-notice' ); if ( REDSYS_WOOCOMMERCE_VERSION !== $version ) { if ( isset( $_REQUEST['redsys-hide-new-version'] ) && 'hide-new-version-redsys' === $_REQUEST['redsys-hide-new-version'] ) { $nonce = sanitize_text_field( $_REQUEST['_redsys_hide_new_version_nonce'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotValidated if ( wp_verify_nonce( $nonce, 'redsys_hide_new_version_nonce' ) ) { update_option( 'hide-new-version-redsys-notice', REDSYS_WOOCOMMERCE_VERSION ); } } else { ?>

get_id(); if ( WCRedL()->is_redsys_order( $order_id ) ) { $date = WCRedL()->get_order_date( $order_id ); $hour = WCRedL()->get_order_hour( $order_id ); $auth = WCRedL()->get_order_auth( $order_id ); $number = WCRedL()->get_order_mumber( $order_id ); echo '

' . esc_html__( 'Payment Details', 'woo-redsys-gateway-light' ) . '

'; echo '

' . esc_html__( 'Paid with', 'woo-redsys-gateway-light' ) . ':
' . esc_html( WCRedL()->get_gateway( $order_id ) ) . '

'; if ( $number ) { echo '

' . esc_html__( 'Redsys Order Number', 'woo-redsys-gateway-light' ) . ':
' . esc_html( $number ) . '

'; } if ( $date ) { echo '

' . esc_html__( 'Redsys Date', 'woo-redsys-gateway-light' ) . ':
' . esc_html( $date ) . '

'; } if ( $hour ) { echo '

' . esc_html__( 'Redsys Hour', 'woo-redsys-gateway-light' ) . ':
' . esc_html( $hour ) . '

'; } if ( $auth ) { echo '

' . esc_html__( 'Redsys Authorisation Code', 'woo-redsys-gateway-light' ) . ':
' . esc_html( $auth ) . '

'; } } } add_action( 'woocommerce_admin_order_data_after_billing_address', 'add_redsys_meta_box' ); /** * Redsys head text. */ function redsys_lite_add_head_text() { echo ''; } add_action( 'wp_head', 'redsys_lite_add_head_text' ); /** * Phugin absolute path. */ function plugin_abspath_redsys() { return trailingslashit( plugin_dir_path( __FILE__ ) ); } /** * Plugin URL. */ function plugin_url_redsys() { return untrailingslashit( plugins_url( '/', __FILE__ ) ); } require_once REDSYS_PLUGIN_CLASS_PATH . 'class-wc-gateway-redsys.php'; // Redsys redirection 1.0. require_once REDSYS_PLUGIN_CLASS_PATH . 'class-wc-gateway-bizum-redsys.php'; // Bizum Version 3.0. require_once REDSYS_PLUGIN_CLASS_PATH . 'class-wc-gateway-googlepay-redirection-redsys.php'; // Google Pay redirection 6.0. /** * Redsys block support. */ function woocommerce_gateway_redsys_lite_block_support() { if ( class_exists( 'Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType' ) ) { require_once 'includes/blocks/class-wc-gateway-redsys-lite-support.php'; require_once 'includes/blocks/class-wc-gateway-bizum-lite-support.php'; require_once 'includes/blocks/class-wc-gateway-googlepay-redirection-redsys-support.php'; add_action( 'woocommerce_blocks_payment_method_type_registration', function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new WC_Gateway_Redsys_Lite_Support() ); } ); add_action( 'woocommerce_blocks_payment_method_type_registration', function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new WC_Gateway_Bizum_Lite_Support() ); } ); add_action( 'woocommerce_blocks_payment_method_type_registration', function ( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $payment_method_registry ) { $payment_method_registry->register( new WC_Gateway_GooglePay_Redirection_Redsys_Support() ); } ); } } add_action( 'woocommerce_blocks_loaded', 'woocommerce_gateway_redsys_lite_block_support' ); } /** * Mark order as paid. * * @param int $order_id Order ID. */ function redsyslite_mark_order_as_paid( $order_id ) { // Este sleep es para evitar que se ejecute el código antes de que se haya procesado el pago en el caso en que llegue la notificación IPN. sleep( 5 ); $is_redsys_order = WCRedL()->is_redsys_order( $order_id ); $is_paid = WCRedL()->is_paid( $order_id ); $order = wc_get_order( $order_id ); if ( ( $order && $is_redsys_order && ! $is_paid ) ) { // Check the Redsys URL. if ( isset( $_GET['Ds_MerchantParameters'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $params = array( 'Ds_MerchantParameters' => sanitize_text_field( wp_unslash( $_GET['Ds_MerchantParameters'] ) ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended 'Ds_Signature' => isset( $_GET['Ds_Signature'] ) ? sanitize_text_field( wp_unslash( $_GET['Ds_Signature'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended ); $payment_method = $order->get_payment_method(); $payment_gateway = WC_Payment_Gateways::instance()->payment_gateways()[ $payment_method ]; if ( $payment_gateway && method_exists( $payment_gateway, 'successful_request' ) ) { $payment_gateway->successful_request( $params ); } } } } /** * Ejecuta redsys_mark_order_as_paid desde wp_head si estamos en la página de "order received" * y hay una key válida en la URL. */ add_action( 'wp_head', 'redsyslite_force_mark_order_as_paid_on_thankyou_page' ); /** * Force mark order as paid on thank you page. * * @return void */ function redsyslite_force_mark_order_as_paid_on_thankyou_page() { if ( ! is_order_received_page() ) { return; } if ( isset( $_GET['key'], $_GET['Ds_MerchantParameters'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $order_key = sanitize_text_field( wp_unslash( $_GET['key'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $order_id = wc_get_order_id_by_order_key( $order_key ); if ( $order_id && is_numeric( $order_id ) ) { redsyslite_mark_order_as_paid( $order_id ); } } } /** * Redsys add method. * * @param string $text Text in order. * @param obj $order Order information. */ function mostrar_numero_autentificacion( $text, $order ) { if ( ! empty( $order ) ) { $is_redsys_order = WCRedL()->is_redsys_order( $order->get_id() ); $is_paid = WCRedL()->is_paid( $order->get_id() ); if ( $order && $is_redsys_order && $is_paid ) { $order_id = $order->get_id(); $website = get_site_url(); $fuc = WCRedL()->get_order_meta( $order_id, '_order_fuc_redsys', true ); $numero_autorizacion = WCRedL()->get_order_auth( $order_id ); $commerce_name = get_bloginfo( 'name' ); $date = WCRedL()->get_order_date( $order_id ); $hour = WCRedL()->get_order_hour( $order_id ); $text = __( 'Thanks for your purchase, the details of your transaction are: ', 'woo-redsys-gateway-light' ) . '
'; $text .= __( 'Website: ', 'woo-redsys-gateway-light' ) . esc_url( $website ) . '
'; $text .= __( 'FUC: ', 'woo-redsys-gateway-light' ) . $fuc . '
'; $text .= __( 'Authorization Number: ', 'woo-redsys-gateway-light' ) . $numero_autorizacion . '
'; $text .= __( 'Commerce Name: ', 'woo-redsys-gateway-light' ) . $commerce_name . '
'; $text .= __( 'Date: ', 'woo-redsys-gateway-light' ) . $date . '
'; $text .= __( 'Hour: ', 'woo-redsys-gateway-light' ) . $hour . '
'; } } return $text; } add_filter( 'woocommerce_thankyou_order_received_text', 'mostrar_numero_autentificacion', 20, 2 );