Skip to content

Commit 383e493

Browse files
committed
v. 4.42.2
* Correção: Em alguns cenários onde o form de cartão era atualizado (ex: alteração de algum dado de frete) a parcela selecionada era perdida. * No admin, ao habilitar o Checkout PagBank (redirect), era possível não marcar nenhum meio de pagamento e isso causaria erro posterior. Agora validamos isso antes de salvar. * Correção: em lojas com 3D ativado, clientes tinham dificuldade em concluir um pagamento de um pedido em aberto finalizado anteriormente, pois na página de pagamento avulso o telefone do cliente não está disponível. Merge branch 'release/4.42.2'
2 parents c7ac26a + 56267bd commit 383e493

File tree

12 files changed

+142
-17
lines changed

12 files changed

+142
-17
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.42.1",
5+
"version": "4.42.2",
66
"license": "GPL-3.0",
77
"autoload": {
88
"psr-4": {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
jQuery(function($){
2+
// Field selectors
3+
var $enabled = $('#woocommerce_rm-pagbank-redirect_enabled');
4+
var $methods = $('#woocommerce_rm-pagbank-redirect_redirect_payment_methods');
5+
var $form = $enabled.closest('form');
6+
7+
function validateMethodsRequired() {
8+
if ($enabled.is(':checked')) {
9+
var val = $methods.val();
10+
if (!val || val.length === 0) {
11+
$methods.closest('tr').addClass('woocommerce-invalid');
12+
$methods[0].setCustomValidity('Selecione pelo menos um método de pagamento.');
13+
return false;
14+
} else {
15+
$methods.closest('tr').removeClass('woocommerce-invalid');
16+
$methods[0].setCustomValidity('');
17+
return true;
18+
}
19+
} else {
20+
$methods.closest('tr').removeClass('woocommerce-invalid');
21+
$methods[0].setCustomValidity('');
22+
return true;
23+
}
24+
}
25+
26+
$enabled.on('change', validateMethodsRequired);
27+
$methods.on('change', validateMethodsRequired);
28+
$form.on('submit', function(e){
29+
if (!validateMethodsRequired()) {
30+
$methods.focus();
31+
e.preventDefault();
32+
e.stopImmediatePropagation();
33+
alert('Selecione pelo menos um método de pagamento para habilitar o PagBank.');
34+
return false;
35+
}
36+
});
37+
});

public/js/creditcard.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,20 @@ jQuery(document).ready(function ($) {
344344
var billing_phone = checkoutFormDataObj['billing_cellphone']?.length ? checkoutFormDataObj['billing_cellphone'] : checkoutFormDataObj['billing_phone'] ?? null;
345345

346346
if (!billing_phone) {
347-
alert('Por favor, preencha o campo Telefone ou Celular para continuar com o pagamento.');
347+
const phones = typeof pagBankOrderDetails !== 'undefined' ? pagBankOrderDetails?.data?.customer?.phones : [];
348+
// If no phone is provided in the form, try to get it from the order details
349+
if (Array.isArray(phones) && phones.length > 0) {
350+
// ordem manual (pay_for_order)
351+
const { area, number } = phones[0];
352+
billing_phone = area + number;
353+
}
354+
355+
if (!billing_phone) {
356+
alert(
357+
"Por favor, preencha o campo Telefone ou Celular para continuar com o pagamento."
358+
);
348359
return false;
360+
}
349361
}
350362

351363
let orderData = typeof pagBankOrderDetails !== 'undefined'
@@ -563,6 +575,8 @@ jQuery(document).ready(function ($) {
563575
success: (response)=>{
564576
let select = jQuery('#rm-pagbank-card-installments');
565577
select.empty();
578+
let found = false;
579+
let previouslySelected = window.ps_cc_selected_installment || jQuery('#rm-pagbank-card-installments').val();
566580
for (let i = 0; i < response.length; i++) {
567581
let option = jQuery('<option></option>');
568582
option.attr('value', response[i].installments);
@@ -573,8 +587,19 @@ jQuery(document).ready(function ($) {
573587

574588
option.text(text + additional_text);
575589
select.append(option);
590+
if (previouslySelected == response[i].installments) {
591+
found = true;
592+
}
576593
}
577594
window.ps_cc_installments = response;
595+
596+
// if previously selected installment is found, select it
597+
if (found) {
598+
select.val(previouslySelected);
599+
} else if (response?.length > 0 && typeof window.ps_cc_selected_installment !== 'undefined') {
600+
// If the previously selected installment is not found, select the last one
601+
select.val(response[response.length-1].installments);
602+
}
578603
},
579604
error: (response)=>{
580605
alert('Erro ao calcular parcelas. Verifique os dados do cartão e tente novamente.');
@@ -602,3 +627,7 @@ jQuery(document.body).on('checkout_error', function(event, error_data) {
602627
rmPagbankCcForm.prepend(retry3dsInput);
603628
}
604629
});
630+
631+
jQuery(document).on("change", "#rm-pagbank-card-installments", function () {
632+
window.ps_cc_selected_installment = jQuery(this).val();
633+
});

readme.txt

Lines changed: 6 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.8
77
Requires PHP: 7.4
8-
Stable tag: 4.42.1
8+
Stable tag: 4.42.2
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.
@@ -203,6 +203,11 @@ Você deve fazer isso através de Pull Requests ao [repositório oficial no gith
203203

204204
== Changelog ==
205205

206+
= 4.42.2 =
207+
* Correção: Em alguns cenários onde o form de cartão era atualizado (ex: alteração de algum dado de frete) a parcela selecionada era perdida.
208+
* No admin, ao habilitar o Checkout PagBank (redirect), era possível não marcar nenhum meio de pagamento e isso causaria erro posterior. Agora validamos isso antes de salvar.
209+
* Correção: em lojas com 3D ativado, clientes tinham dificuldade em concluir um pagamento de um pedido em aberto finalizado anteriormente, pois na página de pagamento avulso o telefone do cliente não está disponível.
210+
206211
= 4.42.1 =
207212
* Desconto PIX não era exibido na página de produto em alguns temas quando determinada variação de preço ocorria.
208213
* Em lojas cuja config de links permanentes era a padrão (sem url's amigáveis), alguns links de ações de assinaturas, como cancelar e atualizar cartão não eram exibidos corretamente, resultando em 404 (Não encontrado).

rm-pagbank.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @wordpress-plugin
1111
* Plugin Name: PagBank Connect
1212
* 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.
13-
* Version: 4.42.1
13+
* Version: 4.42.2
1414
* Requires at least: 5.2
1515
* Tested up to: 6.8
1616
* Requires PHP: 7.4
@@ -32,7 +32,7 @@
3232
defined( 'ABSPATH' ) || die( 'No direct script access allowed!' );
3333

3434
// Plugin constants.
35-
define( 'WC_PAGSEGURO_CONNECT_VERSION', '4.42.1' );
35+
define( 'WC_PAGSEGURO_CONNECT_VERSION', '4.42.2' );
3636
define( 'WC_PAGSEGURO_CONNECT_PLUGIN_FILE', __FILE__ );
3737
define( 'WC_PAGSEGURO_CONNECT_BASE_DIR', __DIR__ );
3838
define( 'WC_PAGSEGURO_CONNECT_TEMPLATES_DIR', WC_PAGSEGURO_CONNECT_BASE_DIR . '/src/templates/' );

src/Connect/Payments/CreditCard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public static function orderPayScript($template_name)
265265
$billingNeighborhood = !empty($order->get_meta('_billing_neighborhood')) ? $order->get_meta(
266266
'_billing_neighborhood'
267267
) : 'n/d';
268-
268+
$phone = !empty($order->get_meta('billing_cellphone')) ? $order->get_meta('billing_cellphone') : $order->get_billing_phone();
269269
$orderDetails = [
270270
'data' => [
271271
'customer' => [
@@ -274,8 +274,8 @@ public static function orderPayScript($template_name)
274274
'phones' => [
275275
[
276276
'country' => '55',
277-
'area' => substr(Params::removeNonNumeric($order->get_billing_phone()), 0, 2),
278-
'number' => substr(Params::removeNonNumeric($order->get_billing_phone()), 2),
277+
'area' => substr(Params::removeNonNumeric($phone), 0, 2),
278+
'number' => substr(Params::removeNonNumeric($phone), 2),
279279
'type' => 'MOBILE'
280280
]
281281
],

src/Connect/Recurring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,7 @@ public function updateUserRestrictions($userId)
17591759
}
17601760

17611761
/**
1762-
* @param $uscerId
1762+
* @param $userId
17631763
* @param $restrictedPages
17641764
* @param $restrictedCategories
17651765
*

src/Connect/Standalone/CreditCard.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,14 @@ public function process_payment($order_id): array
329329
'message' => $message
330330
];
331331
}
332+
333+
// region If payment method is credit card and charge was approved, check if it is a subscription
334+
if(isset($_POST['rm-pagbank-card-set-default']) && $_POST['rm-pagbank-card-set-default'] == '1') {
335+
$orderParent = $order->get_parent_id() ? wc_get_order($order->get_parent_id()) : $order;
336+
$recurring = new \RM_PagBank\Connect\Recurring();
337+
$subscription = $recurring->getSubscriptionFromOrder($orderParent);
338+
$recurring->changePaymentMethodSubscriptionAction($subscription);
339+
}
332340
}
333341
// endregion
334342

src/Connect/Standalone/Redirect.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function __construct()
6262
add_action('wp_enqueue_scripts', [$this, 'addScripts']);
6363
add_action('admin_enqueue_scripts', [$this, 'addAdminStyles'], 10, 1);
6464
add_action('admin_enqueue_scripts', [$this, 'addAdminScripts'], 10, 1);
65+
add_action('admin_enqueue_scripts', [$this, 'addScriptRedirectSettings'], 20, 1);
6566
}
6667

6768
public function init_form_fields()
@@ -246,4 +247,16 @@ public static function changePaymentLink($pay_url, $order)
246247
}
247248
return $pay_url;
248249
}
250+
251+
public function addScriptRedirectSettings($hook) {
252+
if ($hook === 'woocommerce_page_wc-settings') {
253+
wp_enqueue_script(
254+
'pagbank-redirect-admin',
255+
plugins_url('public/js/admin/ps-redirect-admin.js', WC_PAGSEGURO_CONNECT_PLUGIN_FILE),
256+
['jquery'],
257+
WC_PAGSEGURO_CONNECT_VERSION,
258+
true
259+
);
260+
}
261+
}
249262
}

src/Helpers/Recurring.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,8 @@ public function isCartRecurring(WC_Cart $cart = null): bool
9292

9393
foreach ($cart->get_cart() as $cartItem) {
9494
$product = $cartItem['data'];
95-
$is_recurring = $product->get_meta('_recurring_enabled') == 'yes';
96-
if ($parentId = $product->get_parent_id()) {
97-
//if the product is a variation, we need to check the parent product
98-
$product_variable = wc_get_product($parentId);
99-
$is_recurring = $product_variable->get_meta('_recurring_enabled') == 'yes';
100-
}
101-
return $is_recurring;
95+
//if the product is a variation, we need to check the parent product
96+
return $this->isProductRecurring($product);
10297
}
10398

10499
return false;
@@ -517,4 +512,24 @@ public static function subscriptionActionUrl($endpoint, $subscription)
517512
// Friendly permalinks
518513
return WC()->api_request_url('rm-pagbank-subscription-edit') . $action_param . 'action=' . $endpoint . '&id=' . $subscription->id;
519514
}
515+
516+
/**
517+
* Checks if a product or its parent is recurring
518+
* @param WC_Product|null $product
519+
* @return bool
520+
*/
521+
public function isProductRecurring($product): bool
522+
{
523+
if(!$product || !is_a($product, 'WC_Product')) {
524+
return false;
525+
}
526+
527+
$is_recurring = $product->get_meta('_recurring_enabled') == 'yes';
528+
if ($parentId = $product->get_parent_id()) {
529+
//if the product is a variation, we need to check the parent product
530+
$product_variable = wc_get_product($parentId);
531+
$is_recurring = $product_variable->get_meta('_recurring_enabled') == 'yes';
532+
}
533+
return $is_recurring;
534+
}
520535
}

0 commit comments

Comments
 (0)