Skip to content

Commit 0a8ad1c

Browse files
committed
Merge branch 'release/4.50.0'
2 parents 1141c8f + 89e11db commit 0a8ad1c

File tree

5 files changed

+91
-29
lines changed

5 files changed

+91
-29
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "ricardomartins/pagbank-woocommerce",
33
"description": "Integração PagBank (PagSeguro) WooCommerce com desconto nas taxas oficiais",
44
"type": "wordpress-plugin",
5-
"version": "4.49.0",
5+
"version": "4.50.0",
66
"license": "GPL-3.0",
77
"autoload": {
88
"psr-4": {

readme.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Donate link: https://github.com/sponsors/r-martins
55
Requires at least: 4.0
66
Tested up to: 6.9
77
Requires PHP: 7.4
8-
Stable tag: 4.49.0
8+
Stable tag: 4.50.0
99
License: GPLv3
1010
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1111
PagBank com PIX, Cartão de Crédito, Boleto, Recorrência + Envio Fácil e com Menos Taxas no PagSeguro.
@@ -239,6 +239,9 @@ A confirmação é exibida ainda na tela de sucesso, e pode opcionalmente dispar
239239
Sim! Você pode [configurar descontos percentuais ou fixos](https://ajuda.pbintegracoes.com/hc/pt-br/articles/19945430928909-Oferecer-Desconto-Pix-e-Boleto) para PIX e Boleto diretamente nas configurações do plugin.
240240

241241
== Changelog ==
242+
= 4.50.0 =
243+
* Melhoria: na geração de boletos, quando nome da empresa e CNPJ forem informados, usaremos estas informações como dados do pagador.
244+
* Correção que impedia integração com Dokan ser ativada em alguns cenarios
242245

243246
= 4.49.0=
244247
* Melhoria: agora é possível filtrar assinaturas por e-mail do cliente

rm-pagbank.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Plugin Name: PagBank Connect
1212
* Plugin URI: https://pbintegracoes.com
1313
* Description: Integra seu WooCommerce com as APIs PagSeguro v4 através da aplicação de Ricardo Martins (com descontos nas taxas oficiais), com suporte a PIX transparente e muito mais.
14-
* Version: 4.49.0
14+
* Version: 4.50.0
1515
* Requires at least: 5.2
1616
* Tested up to: 6.9
1717
* Requires PHP: 7.4
@@ -33,7 +33,7 @@
3333
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
3434

3535
// Plugin constants.
36-
define( 'WC_PAGSEGURO_CONNECT_VERSION', '4.49.0' );
36+
define( 'WC_PAGSEGURO_CONNECT_VERSION', '4.50.0' );
3737
define( 'WC_PAGSEGURO_CONNECT_PLUGIN_FILE', __FILE__ );
3838
define( 'WC_PAGSEGURO_CONNECT_BASE_DIR', __DIR__ );
3939
define( 'WC_PAGSEGURO_CONNECT_TEMPLATES_DIR', WC_PAGSEGURO_CONNECT_BASE_DIR . '/src/templates/' );
@@ -91,17 +91,25 @@
9191
$fields = include WC_PAGSEGURO_CONNECT_BASE_DIR.'/admin/views/settings/dokan-split-fields.php';
9292

9393
foreach ($fields as $key => $field) {
94+
// HTML form uses $key as name attribute, so we need to check $_POST[$key]
95+
// Skip title fields as they don't have values
96+
if ($field['type'] === 'title') {
97+
continue;
98+
}
99+
94100
if ($field['type'] === 'checkbox') {
95-
$integrations_settings[$key] = isset($_POST[$field['id']]) ? 'yes' : 'no';
101+
$integrations_settings[$key] = isset($_POST[$key]) ? 'yes' : 'no';
96102
} else {
97-
$integrations_settings[$key] = isset($_POST[$field['id']]) ? sanitize_text_field($_POST[$field['id']]) : '';
103+
$integrations_settings[$key] = isset($_POST[$key]) ? sanitize_text_field($_POST[$key]) : '';
98104
}
99105
}
100106

101107
// Check mutual exclusivity with Split Payments
102108
$dokan_split_enabled = $integrations_settings['dokan_split_enabled'] ?? 'no';
103-
$gateway = new Connect\Gateway();
104-
$split_payments_enabled = $gateway->get_option('split_payments_enabled', 'no');
109+
// Read directly from database to ensure we get the most recent value
110+
// This is important because the Gateway instance might have cached/old values
111+
$gateway_settings = get_option('woocommerce_rm-pagbank_settings', []);
112+
$split_payments_enabled = $gateway_settings['split_payments_enabled'] ?? 'no';
105113

106114
if ($dokan_split_enabled === 'yes' && $split_payments_enabled === 'yes') {
107115
add_settings_error(

src/Connect/Gateway.php

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,7 @@ public function process_admin_options()
9595
'info'
9696
);
9797

98-
// Check mutual exclusivity with Dokan Split
99-
$integrations_settings = get_option('woocommerce_rm-pagbank-integrations_settings', []);
100-
$dokan_split_enabled = $integrations_settings['dokan_split_enabled'] ?? 'no';
101-
102-
if ($split_enabled === 'yes' && $dokan_split_enabled === 'yes') {
103-
WC_Admin_Settings::add_error(
104-
__('Não é possível ativar Divisão de Pagamentos enquanto o Split Dokan estiver ativo. Desative o Split Dokan primeiro.', 'pagbank-connect')
105-
);
106-
// Don't save split payments if Dokan is enabled
107-
$split_enabled = 'no';
108-
$this->update_option('split_payments_enabled', 'no');
109-
}
98+
// Mutual exclusivity check is now handled by validate_split_payments_enabled_field()
11099

111100
// Fetch Account ID from API when split is being enabled
112101
$primary_account_id_to_save = null;
@@ -246,11 +235,23 @@ public function process_admin_options()
246235
// Remove from POST to prevent any other processing
247236
unset($_POST[$field_key]);
248237

249-
// Call parent to process other fields
238+
// Call parent to process other fields (this will call validate_split_payments_enabled_field)
250239
parent::process_admin_options();
251240

252-
// Save Account ID if it was fetched from API
253-
if ($primary_account_id_to_save !== null) {
241+
// After parent processes, read the validated value
242+
$validated_split_enabled = $this->get_option('split_payments_enabled', 'no');
243+
244+
// If validation rejected the split (returned 'no'), clear receivers
245+
if ($validated_split_enabled !== 'yes' && $split_enabled === 'yes') {
246+
$this->update_option('split_payments_receivers', []);
247+
\RM_PagBank\Helpers\Functions::log(
248+
'Gateway::process_admin_options - Split de pagamentos foi rejeitado pela validação, limpando receivers',
249+
'info'
250+
);
251+
}
252+
253+
// Save Account ID if it was fetched from API and split is still enabled
254+
if ($primary_account_id_to_save !== null && $validated_split_enabled === 'yes') {
254255
$this->update_option('split_payments_primary_account_id', $primary_account_id_to_save);
255256
\RM_PagBank\Helpers\Functions::log(
256257
'Gateway::process_admin_options - Account ID Principal salvo após process_admin_options: ' . $primary_account_id_to_save,
@@ -450,7 +451,32 @@ public function validate_recurring_enabled_field($key, $recurring_enabled): stri
450451
return $recurring_enabled ? 'yes' : 'no';
451452
}
452453

453-
454+
/**
455+
* Validates split payments enabled field - checks mutual exclusivity with Dokan Split
456+
*
457+
* @param string $key
458+
* @param mixed $value
459+
* @return string
460+
* @noinspection PhpUnused
461+
* @noinspection PhpUnusedParameterInspection
462+
*/
463+
public function validate_split_payments_enabled_field($key, $value): string
464+
{
465+
$split_enabled = $value ? 'yes' : 'no';
466+
467+
// Check mutual exclusivity with Dokan Split
468+
$integrations_settings = get_option('woocommerce_rm-pagbank-integrations_settings', []);
469+
$dokan_split_enabled = $integrations_settings['dokan_split_enabled'] ?? 'no';
470+
471+
if ($split_enabled === 'yes' && $dokan_split_enabled === 'yes') {
472+
WC_Admin_Settings::add_error(
473+
__('Não é possível ativar Divisão de Pagamentos enquanto o Split Dokan estiver ativo. Desative o Split Dokan primeiro.', 'pagbank-connect')
474+
);
475+
return 'no';
476+
}
477+
478+
return $split_enabled;
479+
}
454480

455481
/**
456482
* Validates the inputed connect key and save additional information like public key and sandbox mode

src/Connect/Payments/Boleto.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,39 @@ public function prepare(): array
9393
$boleto->setInstructionLines($instruction_lines);
9494

9595
//cpf or cnpj
96-
$customerData = $this->getCustomerData();
97-
$taxId = $customerData->getTaxId();
98-
if (wc_string_to_bool($this->order->get_meta('_rm_pagbank_checkout_blocks'))) {
99-
$taxId = $this->order->get_meta('_rm_pagbank_customer_document');
96+
$billingCompany = $this->order->get_billing_company();
97+
$taxId = null;
98+
99+
// Always check for CNPJ first (independent of company name)
100+
$taxId = Functions::getParamFromOrderMetaOrPost($this->order, '_billing_cnpj', 'billing_cnpj');
101+
102+
// If CNPJ not found in order meta/post, try from customer meta (only if customer exists)
103+
if (empty($taxId) && $this->order->get_customer_id()) {
104+
$wcCustomer = new \WC_Customer($this->order->get_customer_id());
105+
$taxId = $wcCustomer->get_meta('billing_cnpj');
106+
}
107+
108+
// If still no taxId (no CNPJ found), use the standard customer data method (checks CPF first, then CNPJ)
109+
if (empty($taxId)) {
110+
$customerData = $this->getCustomerData();
111+
$taxId = $customerData->getTaxId();
112+
if (wc_string_to_bool($this->order->get_meta('_rm_pagbank_checkout_blocks'))) {
113+
$taxId = $this->order->get_meta('_rm_pagbank_customer_document');
114+
}
115+
}
116+
117+
// Clean taxId (remove non-numeric characters)
118+
if (!empty($taxId)) {
119+
$taxId = Params::removeNonNumeric($taxId);
100120
}
101121

102122
$holder = new Holder();
103-
$holder->setName($this->order->get_billing_first_name() . ' ' . $this->order->get_billing_last_name());
123+
// Use company name if available, otherwise use person name
124+
if (!empty($billingCompany)) {
125+
$holder->setName(trim($billingCompany));
126+
} else {
127+
$holder->setName($this->order->get_billing_first_name() . ' ' . $this->order->get_billing_last_name());
128+
}
104129
$holder->setTaxId($taxId);
105130
$holder->setEmail($this->order->get_billing_email());
106131

0 commit comments

Comments
 (0)