• Está acontecendo muito, por favor consertem esse bug, é um bug sério.

    Enviei email já, outros usuários também, mas até agora nada..

    • This topic was modified 5 months, 4 weeks ago by an0nbr.
Viewing 12 replies - 1 through 12 (of 12 total)
  • @bycoders @suporteppbr por favor ajudem a resolver este problema. Ele está gerando confus?o e problema nas vendas com paypal.

    Thread Starter an0nbr

    (@an0nbr)

    Provavelmente o erro está nessa fun??o, está pegando reembolsos que existiram, mas logando em pedidos aleatórios, pois n?o está pegando o order id direito

    public function handle( $event ) {
    global $wpdb;
    $method_name = 'handle_process_' . str_replace( '.', '_', strtolower( $event['event_type'] ) );
    $this->log( 'Handling process method: ' . $method_name );
    if ( method_exists( $this, $method_name ) ) {
    $resource_id = isset( $event['resource']['sale_id'] ) ? $event['resource']['sale_id'] : $event['resource']['id'];
    $this->log( 'Resource ID: ' . $resource_id );
    $order_id_query = $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key IN ('paypal_brasil_sale_id', 'wc_ppp_brasil_sale_id') AND meta_value = %s", $resource_id );
    $this->log( 'Order ID query: ' . $order_id_query );
    $order_id = $wpdb->get_var( $order_id_query );
    $this->log( 'Order ID: ' . $order_id );
    // If found the order ID with this sale ID.
    if ( $order_id ) {
    // Get the payment method to check if was processed by this gateway.
    $payment_method_query = $wpdb->prepare( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_payment_method' AND post_id = %s", $order_id );
    $this->log( 'Payment method query: ' . $payment_method_query );
    $payment_method = $wpdb->get_var( $payment_method_query );
    // If is this gateway, process the order.
    if ( $payment_method === $this->gateway_id ) {
    $this->log( 'Processing for payment method: ' . $payment_method );
    $order = new WC_Order( $order_id );
    $this->{$method_name}( $order, $event );
    } else {
    $this->log( 'Payment method not found: ' . $payment_method );
    }
    }
    } else {
    throw new Exception( 'Invalid method to handle.' );
    }
    }
    Thread Starter an0nbr

    (@an0nbr)

    é isso mesmo,no arquivo paypal-brasil-para-woocommerce\includes\handlers\class-paypal-brasil-webhooks-handler.php, ele está pegando o id do PayPal nessa linha

    $resource_id = isset( $event[‘resource’][‘sale_id’] ) ? $event[‘resource’][‘sale_id’] : $event[‘resource’][‘id’];

    E por algum motivo o SELECT está puxando o ID errado, diferente do qual o reembolso acontece.

    Se conseguir arrumar eu falo

    Thread Starter an0nbr

    (@an0nbr)

    Esse código abaixo pegando varios ids ao mesmo tempo:

    public function handle($event)
    {
    global $wpdb;
    $method_name = ‘handle_process_’ . str_replace(‘.’, ‘‘, strtolower($event[‘event_type’])); $method_name = str_replace(‘-‘, ‘‘, strtolower($method_name));
    $this->log(‘Handling process method: ‘ . $method_name);
    if (method_exists($this, $method_name)) {
    $this->log(‘Method name: ‘ . $method_name);
    $resource_id = isset($event[‘resource’][‘id’]) ? $event[‘resource’][‘id’] : null;
    $this->log(‘Resource ID: ‘ . $resource_id);
    /$order_id_query = $wpdb->prepare(“SELECT post_id FROM $wpdb->postmeta WHERE meta_key IN (‘paypal_brasil_sale_id’, ‘wc_ppp_brasil_sale_id’,’wc_bcdc_brasil_sale_id’) AND meta_value = %s”, $resource_id); $this->log(‘Order ID query: ‘ . $order_id_query); $order_id = $wpdb->get_var($order_id_query);/
    $order_ids = wc_get_orders(
    array(
    ‘meta_query’ => array(
    ‘relation’ => ‘OR’,
    array(
    ‘key’ => ‘paypal_brasil_sale_id’,
    ‘value’ => $resource_id,
    ‘compare’ => ‘=’
    ),
    array(
    ‘key’ => ‘wc_ppp_brasil_sale_id’,
    ‘value’ => $resource_id,
    ‘compare’ => ‘=’
    ),
    array(
    ‘key’ => ‘wc_bcdc_brasil_sale_id’,
    ‘value’ => $resource_id,
    ‘compare’ => ‘=’
    )
    ),
    ‘return’ => ‘ids’, // Especifica que queremos apenas IDs de pedidos
    ‘post_type’ => ‘shop_order’, // O tipo de post para pedidos do WooCommerce
    ‘posts_per_page’ => -1 // Recupera todos os pedidos que correspondem aos critérios
    )
    );

                // If found the order ID with this sale ID.
                if (!empty($order_ids)) {
                    $order_id = $order_ids[0];
                    $this->log('Order ID: ' . $order_id);
                    $order = wc_get_order($order_id);
    
                    $payment_method = !empty($order) ? $order->get_payment_method() : "";
                    $this->log('Payment method: ' . $payment_method);
    
                    // If is this gateway, process the order.
                    if ($payment_method === $this->gateway_id) {
                        $this->log('Processing for payment method: ' . $payment_method);
                        $this->{$method_name}($order, $event);
                    } else {
                        $this->log('Payment method not found: ' . $payment_method);
                    }
                }
            } else {
                throw new Exception('Invalid method to handle.');
            }
        }
    • This reply was modified 5 months, 4 weeks ago by an0nbr.
    • This reply was modified 5 months, 4 weeks ago by an0nbr.

    @an0nbr obrigado por compartilhar o erro. Este trecho de código resolveu o problema?

    Thread Starter an0nbr

    (@an0nbr)

    Encontrei o erro, editei e agora vou testar, o estagiario fez uma baita cagada, se funcionar volto aqui com a solu??o

    Thread Starter an0nbr

    (@an0nbr)

    Ou se quiser testar também eu já te mando a vers?o corrigida, quer que manda aqui?

    Tem gente voltando pra vers?o 1.49

    • This reply was modified 5 months, 2 weeks ago by an0nbr.

    Eu aceito sim @an0nbr. é um baita descaso do time aqui do Paypal, já foi informado e n?o fazem nada, nem d?o nenhum suporte.

    Thread Starter an0nbr

    (@an0nbr)

    Edite o arquivo /wp-content/plugins/paypal-brasil-para-woocommerce/includes/handlers/class-paypal-brasil-webhooks-handler.php, apague todo o texto do arquivo e coloque o código abaixo

    <?php
    
    // Exit if not in WordPress.
    if (!defined('ABSPATH')) {
    	exit;
    }
    
    // Check if class already exists before create.
    if (!class_exists('PayPal_Brasil_Webhooks_Handler')) {
    
    	/**
    	 * Class WC_PPP_Brasil_Webhooks_Handler.
    	 */
    	class PayPal_Brasil_Webhooks_Handler
    	{
    
    		private $gateway_id;
    
    		/**
    		 * @var PayPal_Brasil_Gateway
    		 */
    		private $gateway;
    
    		/**
    		 * WC_PPP_Brasil_Webhooks_Handler constructor.
    		 *
    		 * @param $gateway_id string
    		 * @param $gateway PayPal_Brasil_Gateway
    		 */
    		public function __construct($gateway_id, $gateway)
    		{
    			$this->gateway_id = $gateway_id;
    			$this->gateway = $gateway;
    		}
    
    		private function log($data)
    		{
    			if ($this->gateway) {
    				$this->gateway->log($data);
    			}
    		}
    
    		/**
    		 * Handle the event.
    		 *
    		 * @param $event
    		 *
    		 * @throws Exception
    		 */
    		public function handle($event){
    			global $wpdb;
    			$method_name = 'handle_process_' . str_replace('.', '_', strtolower($event['event_type']));
    			$method_name = str_replace('-', '_', strtolower($method_name));
    			$this->log('Handling process method: ' . $method_name);
    			if (method_exists($this, $method_name)) {
    				$this->log('Method name: ' . $method_name);
    				$resource_id = isset($event['resource']['sale_id']) ? $event['resource']['sale_id'] : $event['resource']['id'];
    				$this->log('Resource ID: ' . $resource_id);
    				
    				$order_id_query = $wpdb->prepare(
    					"SELECT post_id FROM $wpdb->postmeta WHERE meta_key IN ('paypal_brasil_sale_id', 'wc_ppp_brasil_sale_id','wc_bcdc_brasil_sale_id') AND meta_value = %s",
    					$resource_id
    				);
    				$this->log('Order ID query: ' . $order_id_query);
    				$order_id = $wpdb->get_var($order_id_query);
    
    				// If found the order ID with this sale ID.
    				if (!empty($order_id)) {
    					$this->log('Order ID: ' . $order_id);
    					$order = wc_get_order($order_id);
    					
    					$payment_method = !empty($order) ? $order->get_payment_method() : "";
    					$this->log('Payment method: ' . $payment_method);
    				
    					// If is this gateway, process the order.
    					if ($payment_method === $this->gateway_id) {
    						$this->log('Processing for payment method: ' . $payment_method);
    						$this->{$method_name}($order, $event);
    					} else {
    						$this->log('Payment method not found: ' . $payment_method);
    					}
    				}
    			} else {
    				throw new Exception('Invalid method to handle.');
    			}
    		}
    
    
    		/**
    		 * When payment is marked as completed.
    		 *
    		 * @param $order WC_Order
    		 */
    		public function handle_process_payment_sale_completed($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing completed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing completed initiated.');
    			// Check if the current status isn't processing or completed.
    			if (
    				!in_array($order->get_status(), array(
    					'processing',
    					'completed',
    					'refunded',
    					'cancelled'
    				), true)
    			) {
    				$order->add_order_note(__('PayPal: Paid transaction.', "paypal-brasil-para-woocommerce"));
    				$order->payment_complete();
    				$this->log('Processing completed finished.');
    			}
    		}
    
    		/**
    		 * When payment is denied.
    		 *
    		 * @param $order WC_Order
    		 */
    		public function handle_process_payment_sale_denied($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing denied was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing denied initiated.');
    			// Check if the current status isn't failed.
    			if (!in_array($order->get_status(), array('failed', 'completed', 'processing'), true)) {
    				$order->update_status('failed', __('PayPal: The transaction was rejected by the card company or for fraud.', "paypal-brasil-para-woocommerce"));
    				$this->log('Processing denied finished.');
    			} else {
    				$this->log('Processing denied did not change anything.');
    			}
    		}
    
    		/**
    		 * When payment is refunded.
    		 *
    		 * @param $order WC_Order
    		 *
    		 * @throws Exception
    		 */
    		public function handle_process_payment_sale_refunded($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing refunded was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing refunded initiated.');
    
    			// Check if is partial refund.
    			$partial_refund = paypal_brasil_money_format($order->get_total() - $order->get_total_refunded()) !== paypal_brasil_money_format($event['resource']['amount']['total']);
    
    			// Check if the current status isn't refunded.
    			if (!in_array($order->get_status(), array('refunded'), true)) {
    				// Check if is total refund
    				if ($partial_refund) {
    					$order->add_order_note(__('PayPal: The transaction was partially refunded.', "paypal-brasil-para-woocommerce"));
    				} else {
    					$order->update_status('refunded', __('PayPal: The transaction has been refunded in full.', "paypal-brasil-para-woocommerce"));
    				}
    
    				// Create the refund.
    				$refund = wc_create_refund(
    					array(
    						'amount' => wc_format_decimal($event['resource']['amount']['total']),
    						'reason' => $partial_refund ? __('PayPal: The transaction was partially refunded.', "paypal-brasil-para-woocommerce") : __('PayPal: transaction refunded in full.', "paypal-brasil-para-woocommerce"),
    						'order_id' => $order->get_id(),
    						'refund_payment' => false,
    					)
    				);
    
    				if (is_wp_error($refund)) {
    					$this->log('There was some error refunding.');
    					throw new Exception(sprintf(__('There was an error trying to make a refund: %s', "paypal-brasil-para-woocommerce"), $refund->get_error_message()));
    				}
    
    				$this->log('Processing refunded finished.');
    			} else {
    				$this->log('Processing refunded did not change anything.');
    
    				throw new Exception(__('This order has already been refunded.', "paypal-brasil-para-woocommerce"));
    			}
    		}
    
    		/**
    		 * When payment is reversed.
    		 *
    		 * @param $order WC_Order
    		 *
    		 * @throws Exception
    		 */
    		public function handle_process_payment_sale_reversed($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing reversed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing reversed initiated.');
    
    			// Check if the current status isn't refunded.
    			if (!in_array($order->get_status(), array('refunded'), true)) {
    				$order->update_status('refunded', __('PayPal: The transaction has been rolled back.', "paypal-brasil-para-woocommerce"));
    
    				$refund = wc_create_refund(
    					array(
    						'amount' => wc_format_decimal($order->get_total() - $order->get_total_refunded()),
    						'reason' => __('PayPal: reversed transaction.', "paypal-brasil-para-woocommerce"),
    						'order_id' => $order->get_id(),
    						'refund_payment' => false,
    					)
    				);
    
    				if (is_wp_error($refund)) {
    					$this->log('There was some error reversing.');
    
    					throw new Exception(sprintf(__('There was an error trying to make a refund: %s', "paypal-brasil-para-woocommerce"), $refund->get_error_message()));
    				}
    
    				$this->log('Processing reversed finished.');
    
    			} else {
    				$this->log('Processing reversed did not change anything.');
    
    				throw new Exception(__('This order has already been refunded.', "paypal-brasil-para-woocommerce"));
    			}
    		}
    
    		/**
    		 * When payment is marked as completed.
    		 *
    		 * @param $order WC_Order
    		 */
    		public function handle_process_checkout_order_approved($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing completed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing completed initiated.');
    			// Check if the current status isn't processing or completed.
    			if (
    				!in_array($order->get_status(), array(
    					'completed',
    					'refunded',
    					'cancelled'
    				), true)
    			) {
    				$order->add_order_note(__('PayPal: Paid transaction.', "paypal-brasil-para-woocommerce"));
    				$order->payment_complete();
    				$this->log('Processing completed finished.');
    			}
    		}
    
    		/**
    		 * When payment is reversed.
    		 *
    		 * @param $order WC_Order
    		 *
    		 * @throws Exception
    		 */
    		public function handle_process_checkout_payment_approval_reversed($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing reversed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing reversed initiated.');
    
    			// Check if the current status isn't refunded.
    			if (!in_array($order->get_status(), array('refunded'), true)) {
    				$order->update_status('refunded', __('PayPal: The transaction has been rolled back.', "paypal-brasil-para-woocommerce"));
    
    				$refund = wc_create_refund(
    					array(
    						'amount' => wc_format_decimal($order->get_total() - $order->get_total_refunded()),
    						'reason' => __('PayPal: reversed transaction.', "paypal-brasil-para-woocommerce"),
    						'order_id' => $order->get_id(),
    						'refund_payment' => false,
    					)
    				);
    
    				if (is_wp_error($refund)) {
    					$this->log('There was some error reversing.');
    
    					throw new Exception(sprintf(__('There was an error trying to make a refund: %s', "paypal-brasil-para-woocommerce"), $refund->get_error_message()));
    				}
    
    				$this->log('Processing reversed finished.');
    
    			} else {
    				$this->log('Processing reversed did not change anything.');
    
    				throw new Exception(__('This order has already been refunded.', "paypal-brasil-para-woocommerce"));
    			}
    		}
    
    		/**
    		 * When payment is cancelled.
    		 *
    		 * @param $order WC_Order
    		 *
    		 * @throws Exception
    		 */
    		public function handle_process_payment_order_cancelled($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing reversed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing reversed initiated.');
    
    			// Check if the current status isn't refunded.
    			if (!in_array($order->get_status(), array('refunded'), true)) {
    				$order->update_status('refunded', __('PayPal: The transaction has been rolled back.', "paypal-brasil-para-woocommerce"));
    
    				$refund = wc_create_refund(
    					array(
    						'amount' => wc_format_decimal($order->get_total() - $order->get_total_refunded()),
    						'reason' => __('PayPal: reversed transaction.', "paypal-brasil-para-woocommerce"),
    						'order_id' => $order->get_id(),
    						'refund_payment' => false,
    					)
    				);
    
    				if (is_wp_error($refund)) {
    					$this->log('There was some error reversing.');
    
    					throw new Exception(sprintf(__('There was an error trying to make a refund: %s', "paypal-brasil-para-woocommerce"), $refund->get_error_message()));
    				}
    
    				$this->log('Processing reversed finished.');
    
    			} else {
    				$this->log('Processing reversed did not change anything.');
    
    				throw new Exception(__('This order has already been refunded.', "paypal-brasil-para-woocommerce"));
    			}
    		}
    
    
    		/**
    		 * When payment is marked as completed.
    		 *
    		 * @param $order WC_Order
    		 */
    		public function handle_process_payment_capture_completed($order, $event)
    		{
    			// Check if order exists.
    			if (!$order) {
    				$this->log('Processing completed was not initiated because there is no order.');
    
    				return;
    			}
    
    			$this->log('Processing completed initiated.');
    			// Check if the current status isn't processing or completed.
    			if (
    				!in_array($order->get_status(), array(
    					'completed',
    					'refunded',
    					'cancelled'
    				), true)
    			) {
    				$order->add_order_note(__('PayPal: Paid transaction.', "paypal-brasil-para-woocommerce"));
    				$order->payment_complete();
    				$this->log('Processing completed finished.');
    			}
    		}
    
    
    
    	}
    
    
    
    
    }
    tgoribas

    (@tgoribas)

    @renancomn Você testou a corre??o, deu certo ?

    Thread Starter an0nbr

    (@an0nbr)

    Parou de botar mensagem de reembolso em pedido aleatorio sim

    renandepaula

    (@renancomn)

    O código postado pelo @an0nbr funciona perfeitamente na vers?o 1.5.0 do plugin

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.