Skip to content

Commit

Permalink
Merge pull request #97 from henriqueccruz/master
Browse files Browse the repository at this point in the history
Fix: Não foi possível gerar um ID único para a requisição
  • Loading branch information
henriqueccruz authored Feb 15, 2025
2 parents 9ca7693 + dcc73e8 commit 99afff1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 45 deletions.
36 changes: 7 additions & 29 deletions includes/class-wc-paghiper-transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ public function has_issued_valid_transaction() {
$paghiper_data = $this->order->get_meta( 'wc_paghiper_data' ) ;
$paghiper_data['order_transaction_due_date'] = $current_billet_due_date->format( 'Y-m-d' );

$update = $this->order->update_meta_data( 'wc_paghiper_data', $paghiper_data );
$save = $this->order->save();
$this->order->update_meta_data( 'wc_paghiper_data', $paghiper_data );
$this->order->save();

if(function_exists('update_meta_cache'))
update_meta_cache( 'shop_order', $this->order_id );

$this->order_data = $paghiper_data;

if($update && $save) {
$this->order->add_order_note( sprintf( __( 'Data de vencimento ajustada para %s', 'woo_paghiper' ), $current_billet_due_date->format('d/m/Y') ) );
} else {
$this->order->add_order_note( sprintf( __( 'Data de vencimento deveria ser ajustada para %s mas houve um erro ao salvar a nova data.', 'woo_paghiper' ), $current_billet_due_date->format('d/m/Y') ) );
}
$this->order->add_order_note( sprintf( __( 'Data de vencimento ajustada para %s', 'woo_paghiper' ), $current_billet_due_date->format('d/m/Y') ) );

$log_message = 'Pedido #%s: Data de vencimento do boleto não bate com a informada no pedido. Cheque a opção "Vencimento em finais de semana" no <a href="https://www.paghiper.com/painel/prazo-vencimento-boleto/" target="_blank">Painel da PagHiper</a>.';
wc_paghiper_add_log( $this->log, sprintf( $log_message, $this->order_id ) );
Expand Down Expand Up @@ -207,20 +202,12 @@ public function determine_due_date() {
$this->order_data = $order_data;


$update = $this->order->update_meta_data( 'wc_paghiper_data', $order_data );
$save = $order->save();
$this->order->update_meta_data( 'wc_paghiper_data', $order_data );
$order->save();

if(function_exists('update_meta_cache'))
update_meta_cache( 'shop_order', $this->order_id );

if(!$update || !$save) {
if ( $this->log ) {
wc_paghiper_add_log( $this->log, sprintf( 'Não foi possível guardar a data de vencimento: %s', var_export( $update, true) ) );
wc_paghiper_add_log( $this->log, sprintf( 'Dados a guardar: %s', var_export( $order_data, true) ) );
}
}


}

$maybe_add_workdays = ($this->gateway_id == 'paghiper_pix') ? null : $this->gateway_settings['skip_non_workdays'];
Expand Down Expand Up @@ -496,23 +483,14 @@ public function create_transaction() {
$order_data = (is_array($this->order_data)) ? $this->order_data : array();
$data = array_merge($this->order_data, $current_billet);

$update = $this->order->update_meta_data( 'wc_paghiper_data', $data );
$save = $this->order->save();
$this->order->update_meta_data( 'wc_paghiper_data', $data );
$this->order->save();

if(function_exists('update_meta_cache'))
update_meta_cache( 'shop_order', $this->order_id );

$this->order_data = $data;

if(!$update || !$save) {
if ( $this->log ) {
wc_paghiper_add_log( $this->log, sprintf( 'Não foi possível guardar os dados do boleto: %s', var_export( $update, true) ) );
wc_paghiper_add_log( $this->log, sprintf( 'Dados a guardar: %s', var_export( $data, true) ) );
wc_paghiper_add_log( $this->log, sprintf( 'Operação update_meta_data retornou: %s', var_export( $update, true) ) );
wc_paghiper_add_log( $this->log, sprintf( 'Operação order->save() retornou: %s', var_export( $save, true) ) );
}
}

// Don't try downloading PDF files for PIX transacitons
if(in_array($this->gateway_id, ['paghiper_billet', 'paghiper'])) {

Expand Down
14 changes: 3 additions & 11 deletions includes/wc-paghiper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,12 @@ function wc_paghiper_add_workdays( $due_date, $order, $format, $workday_settings
$paghiper_data = (is_array($paghiper_data_query)) ? $paghiper_data_query : [];
$paghiper_data['order_transaction_due_date'] = $due_date->format( 'Y-m-d' );

$update = $order->update_meta_data( 'wc_paghiper_data', $paghiper_data );
$save = $order->save();
$order->update_meta_data( 'wc_paghiper_data', $paghiper_data );
$order->add_order_note( sprintf( __( 'Data de vencimento ajustada para %s', 'woo_paghiper' ), $due_date->format('d/m/Y') ) );
$order->save();

if(function_exists('update_meta_cache'))
update_meta_cache( 'shop_order', $order->get_id() );

if($update && $save) {
$order->add_order_note( sprintf( __( 'Data de vencimento ajustada para %s', 'woo_paghiper' ), $due_date->format('d/m/Y') ) );
} else {
$log = wc_paghiper_initialize_log( 'yes' );
wc_paghiper_add_log( $log, sprintf( 'Pedido #%s: Erro ao salvar data de vencimento: .', $order->get_id(), var_export($update, TRUE) ) );

$order->add_order_note( sprintf( __( 'Data de vencimento deveria ser ajustada para %s mas houve um erro ao salvar a nova data.', 'woo_paghiper' ), $due_date->format('d/m/Y') ) );
}
}

}
Expand Down
11 changes: 8 additions & 3 deletions includes/wc-paghiper-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,29 @@ function woocommerce_paghiper_valid_ipn_request($return, $order_no, $settings) {
// Resolvemos disputas entre notifications enviadas simultaneamente
$request_bytes = openssl_random_pseudo_bytes(16, $is_strong);
$request_id = bin2hex($request_bytes);
$store_request_id = $order->update_meta_data( 'wc_paghiper_ipn_request_id', $request_id );

if(!$request_id || !$is_strong || !$store_request_id) {
$order->update_meta_data( 'wc_paghiper_ipn_request_id', $request_id );
$order->save();

if(!$request_id || !$is_strong) {
if ( $paghiper_log ) {
wc_paghiper_add_log( $paghiper_log, sprintf('Pedido #%s: Não foi possível gerar um ID único para a requisição. O pedido não será processado.', $order_no) );
wc_paghiper_add_log( $paghiper_log, sprintf('Request ID: %s', var_export($request_id, TRUE)) );
wc_paghiper_add_log( $paghiper_log, sprintf('Request ID contem chave forte? %s', var_export($is_strong, TRUE)) );
wc_paghiper_add_log( $paghiper_log, sprintf('Request ID for armazenado corretamente?: %s', var_export($store_request_id, TRUE)) );
}
return;
}

if(function_exists('update_meta_cache'))
update_meta_cache( 'shop_order', $order_no );

sleep(3);

$last_request_id = $order->get_meta( 'wc_paghiper_ipn_request_id' );
if($request_id !== $last_request_id) {
if ( $paghiper_log ) {
wc_paghiper_add_log( $paghiper_log, sprintf('Pedido #%s: Requisição de notificação duplicada. O pedido não será processado.', $order_no) );
wc_paghiper_add_log( $paghiper_log, sprintf('Request atual: %s. Request esperado: %s.', $request_id, $last_request_id) );
}
return;
}
Expand Down
4 changes: 2 additions & 2 deletions woocommerce-paghiper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Ofereça a seus clientes pagamento por PIX e boleto bancário com a PagHiper. Fácil, prático e rapido!
* Author: PagHiper Pagamentos
* Author URI: https://www.paghiper.com
* Version: 2.4.2-rc1
* Version: 2.4.2-rc2
* Tested up to: 6.7.2
* License: GPLv3
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -33,7 +33,7 @@ class WC_Paghiper {
*
* @var string
*/
const VERSION = '2.4.2-rc1';
const VERSION = '2.4.2-rc2';

/**
* Instance of this class.
Expand Down

0 comments on commit 99afff1

Please sign in to comment.