Skip to content

Commit c05ce2a

Browse files
Merge pull request #121 from devellop-labs/staging
Release 3DS
2 parents 89c348b + 53f26f1 commit c05ce2a

13 files changed

+268
-85
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
applyTo: "**/*.php,**/*.inc,**/*.phtml"
3+
excludeAgent: "coding-agent"
4+
---
5+
6+
# Copilot Code Review Instructions (WordPress + WooCommerce + PHP 8)
7+
8+
Você é um revisor de PRs para um repositório de plugins WordPress/WooCommerce em PHP 8.
9+
Seu objetivo é encontrar problemas reais (bugs, segurança, performance, compatibilidade e padrões do ecossistema) e sugerir correções com alta chance de aprovação.
10+
11+
## Prioridades (ordem)
12+
1) Segurança e integridade de dados
13+
2) Bugs funcionais / regressões
14+
3) Performance e escalabilidade (DB, hooks, requests, assets)
15+
4) Padrões WordPress/WooCommerce (plugin conventions, APIs, hooks)
16+
5) Qualidade de código (clareza, manutenção, testes, legibilidade)
17+
18+
## Como escrever seus comentários
19+
- Classifique cada ponto como: **[BLOCKER] [HIGH] [MED] [LOW]**
20+
- Sempre cite o **arquivo + trecho** (função/método/linha aproximada) e explique o impacto.
21+
- Quando possível, inclua **patch sugerido** (trecho de código) e uma alternativa simples.
22+
- Evite bikeshedding: estilo só importa se afetar segurança, compatibilidade, DX ou manutenção.
23+
- Se um ponto depende do “contexto do produto”, faça a pergunta, mas ainda assim proponha um padrão seguro.
24+
25+
---
26+
27+
# 1) Padrões WordPress (Plugin)
28+
## 1.1 Segurança (obrigatório)
29+
### Entrada → Validar + Sanitizar
30+
- Nunca confie em `$_GET`, `$_POST`, `$_REQUEST`, `$_COOKIE`, headers, payload REST, dados de DB ou APIs externas.
31+
- **Valide tipo/forma** (ex.: `is_string`, `is_numeric`, `absint`, whitelist) e **sanitize** antes de salvar/usar.
32+
- Lembre do `wp_unslash()` ao ler `$_POST/$_GET` em contextos onde o WP aplicou slashes.
33+
34+
### Saída → Escapar sempre (escape late)
35+
- Qualquer dado vindo de usuário/DB/API deve ser escapado na saída:
36+
- HTML: `esc_html()`
37+
- Atributo: `esc_attr()`
38+
- URL: `esc_url()`
39+
- HTML permitido: `wp_kses()` / `wp_kses_post()`
40+
- JS inline: `esc_js()` (e preferir evitar inline)
41+
- Strings traduzíveis também devem ser escapadas (ex.: `esc_html__()` / `esc_attr__()`).
42+
43+
### Nonce + Capability (CSRF e autorização)
44+
- Para qualquer ação que altera estado (CRUD, settings, AJAX, admin-post, endpoints):
45+
- **Nonce**: `check_admin_referer()` / `check_ajax_referer()` / `wp_verify_nonce()`
46+
- **Capability**: `current_user_can()` (nonce não é autorização)
47+
- Em REST API: exigir `permission_callback` correto e validar payload.
48+
49+
### SQL / DB
50+
- Proibido concatenar input em SQL.
51+
- Sempre usar `$wpdb->prepare()` com placeholders (`%d %f %s` e `%i` quando aplicável).
52+
- Cuidado com LIKE: usar `$wpdb->esc_like()` e passar o wildcard via argumento.
53+
- Não aceitar “partes da query” vindas do usuário (tabela/coluna/order by) sem whitelist.
54+
55+
### Arquivos / Includes
56+
- Evitar includes dinâmicos com input.
57+
- Validar caminhos, usar paths conhecidos do plugin, negar traversal.
58+
- Se lidar com upload: validar mime/extensão, usar APIs WP.
59+
60+
## 1.2 Convenções de plugin
61+
- Prefixar funções, hooks, constants, option keys, meta keys, transient keys com o prefixo do plugin.
62+
- Evitar colisões de nomes (especialmente funções globais).
63+
- Hooks: declarar callback e depois registrar `add_action/add_filter` (padrão comum do ecossistema).
64+
- Não criar “god class”: preferir classes coesas e responsabilidades claras.
65+
- Admin pages/Settings: usar Settings API quando fizer sentido; validar/sanitizar tudo.
66+
67+
## 1.3 Padrão de código (WPCS)
68+
- Seguir WordPress Coding Standards para PHP:
69+
- visibilidade sempre explícita
70+
- evitar shorthand tags
71+
- práticas seguras (não é só estilo)
72+
- Se o repo usa PHPCS/WPCS, a review deve exigir que o PR **não quebre** esses checks.
73+
74+
---
75+
76+
# 2) Padrões WooCommerce (Plugin)
77+
## 2.1 CRUD e compatibilidade
78+
- Preferir **CRUD objects** do WooCommerce para entidades (orders/products/customers) em vez de manipular post/meta direto quando existir API.
79+
- Evitar bypass de camada de dados (especialmente em Orders) porque pode quebrar compatibilidade e caches internos.
80+
- Para Orders/HPOS e caching: evitar mexer direto em tabelas/meta sem usar a API adequada.
81+
82+
## 2.2 Segurança específica Woo
83+
- Em endpoints/admin actions que mudam dados de pedido:
84+
- capability + nonce
85+
- validação de IDs (absint) e ownership quando aplicável
86+
- Não expor dados sensíveis (order notes privadas, tokens, PII) em responses, logs ou HTML.
87+
88+
## 2.3 Performance específica Woo
89+
- Não carregar assets do plugin em todas as páginas. Enfileirar scripts/styles **condicionalmente**.
90+
- Evitar queries em loops e N+1:
91+
- buscar em batch quando possível
92+
- limitar campos e resultados
93+
- Ser compatível com caching (não limpar caches de forma agressiva sem motivo).
94+
95+
---
96+
97+
# 3) PHP 8 (boas práticas)
98+
## 3.1 Segurança
99+
- Senhas: usar `password_hash()` e `password_verify()` (nada de hash caseiro).
100+
- SQL: prepared statements (quando fora do WPDB) e nunca interpolar variável.
101+
- Validar tipos e tratar exceções:
102+
- PHP 8 levanta mais TypeError/ValueError em situações antes “silenciosas”.
103+
- Não vazar dados sensíveis em logs/exceptions (PII, tokens).
104+
105+
## 3.2 Qualidade e compatibilidade
106+
- Declarar tipos onde fizer sentido, sem “quebrar” convenções WP (muitos plugins ainda são flexíveis).
107+
- Evitar `@` (error suppression).
108+
- Cuidado com `json_decode()` (checar erro, tipo retornado).
109+
- Em arrays/strings, evitar notices/warnings com checks explícitos.
110+
111+
---
112+
113+
# 4) Checklist do Review (use como roteiro)
114+
## [BLOCKER] Segurança
115+
- Falta de escape/sanitize/validate em qualquer caminho de input/output?
116+
- Falta de nonce/capability em ações mutáveis?
117+
- SQL injection possível (query montada, placeholders errados, ORDER BY sem whitelist)?
118+
- XSS possível (echo de dados sem escaper correto)?
119+
- SSRF/file inclusion/path traversal?
120+
- Vazamento de PII/tokens em HTML/logs/responses?
121+
122+
## [HIGH] Performance / Escala
123+
- Hooks pesados em `init`, `wp_loaded`, `the_content`, `woocommerce_*` sem cache?
124+
- Queries em loop / N+1 / sem índices / sem LIMIT?
125+
- Assets carregando em todas as páginas?
126+
- Chamadas remotas sem timeout/retry/backoff ou sem cache?
127+
128+
## [MED] Padrões WP/Woo
129+
- Uso incorreto de APIs WP/Woo (ex.: bypass de CRUD quando existe)?
130+
- Prefixos ausentes (risco de conflito)?
131+
- i18n: strings sem text domain / sem funções de tradução?
132+
133+
## [LOW] Manutenibilidade
134+
- Código confuso, nomes ruins, duplicação, responsabilidades misturadas.
135+
- Falta de testes onde o repo exige.
136+
- Comentários desnecessários ou “clever code”.
137+
138+
---
139+
140+
# 5) Regras de ouro para sugestões
141+
- Sugira sempre o caminho mais “WordPress way”:
142+
- sanitize/escape com funções WP
143+
- nonces e capabilities
144+
- `$wpdb->prepare()`
145+
- APIs Woo (CRUD) quando aplicável
146+
- Se você não tiver certeza, **assuma o mais seguro** e peça ajuste do autor do PR.
147+
148+
Fim.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ _Funcionalidades_
100100
- Checkout Card View
101101
- Authorize Only
102102
- Authorize and Capture
103-
- Authentication 3DS 2.0
103+
- Authentication 3DS 2.2 (Exceto cartões Elo e Amex)
104104
- Anti Fraud
105105
- Credit Card Token
106106

@@ -122,7 +122,7 @@ _Funcionalidades_
122122

123123
_Funcionalidades_
124124

125-
- Authenticate 3DS 2.0
125+
- Authenticate 3DS 2.2 (Exceto cartões Elo e Amex)
126126
- Checkout Card View
127127

128128
#### Boleto

assets/js/braspag.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var braspagDefaultCardRegexFormat = /(\d{1,4})/g;
66
var braspagCards = [
77
{
88
type: 'naranja-nevada',
9-
typeTitle: 'Naranja e Nevada',
9+
typeName: 'Naranja e Nevada',
1010
patterns: [5895],
1111
regex_include: '^(589562)',
1212
regex_exclude: '',
@@ -16,9 +16,9 @@ var braspagCards = [
1616
luhn: true
1717
}, {
1818
type: 'elo',
19-
typeTitle: 'Elo',
20-
patterns: [6363, 4389, 5041, 4514, 6362, 5067, 4576, 4011],
21-
regex_include: '',
19+
typeName: 'Elo',
20+
patterns: [6363, 4389, 5041, 4514, 6362, 5067, 4576],
21+
regex_include: '^(40117[89]|431274|438935|451416|457393|45763[12]|504175|506(699|7[0-6][0-9]|77[0-8])|509[0-9]{3}|636297|636368|6500(31|33|3[5-9]|4[0-9]|5[01])|6504(0[5-9]|[1-3][0-9])|650(48[5-9]|49[0-9]|5[0-2][0-9]|53[0-8])|650(54[1-9]|5[5-8][0-9]|59[0-8])|650(70[0-9]|71[0-8])|65072[0-7]|650(90[1-9]|91[0-9]|920)|651(65[2-9]|6[6-7][0-9])|6550[01][0-9]|655(02[1-9]|0[3-4][0-9]|05[0-8]))',
2222
regex_exclude: '',
2323
format: braspagDefaultCardRegexFormat,
2424
length: [16],
@@ -98,8 +98,8 @@ var braspagCards = [
9898
type: 'discover',
9999
typeName: 'Discover',
100100
patterns: [6011, 622, 64, 65],
101-
regex_include: '',
102-
regex_exclude: '',
101+
regex_include: '^(6011|65|64[4-9]|622)',
102+
regex_exclude: '^(6500(31|33|3[5-9]|4[0-9]|5[01])|6504(0[5-9]|[1-3][0-9])|650(48[5-9]|49[0-9]|5[0-2][0-9]|53[0-8])|650(54[1-9]|5[5-8][0-9]|59[0-8])|650(70[0-9]|71[0-8])|65072[0-7]|650(90[1-9]|91[0-9]|920)|651(65[2-9]|6[6-7][0-9])|6550[01][0-9]|655(02[1-9]|0[3-4][0-9]|05[0-8]))',
103103
format: braspagDefaultCardRegexFormat,
104104
length: [16],
105105
cvcLength: [3],

changelog.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,13 @@
118118

119119
= 2.3.5.40 - 2026-01-28 =
120120
* Hotfix when send hostname to 3DS in WP new version
121+
122+
= 2.3.5.41 - 2026-01-28 =
123+
* Added default case for unhandled failure types.
124+
* We changed the condition for providers other than Cielo.
125+
* Added early return when appendMpi
126+
* Updated the 3DS authentication version from 2.0 to 2.2
127+
* Add into documentation indicating that Elo and Amex cards are not supported.
128+
* Fixed a critical bug where the quantity of items in the cart was accessed as an object property instead of an array element.
129+
* Enabled the execution of anti-fraud analysis simultaneously with 3DS authentication.
130+
* Validation logic with handling of 3DS failure and error cases.

includes/admin/braspag-creditcard-settings.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,55 +106,55 @@
106106
'options' => wc_get_order_statuses()
107107
),
108108
'auth3ds20' => array(
109-
'title' => "<hr>" . __('Authentication 3DS 2.0 for Credit Card', 'woocommerce-braspag'),
109+
'title' => "<hr>" . __('Authentication 3DS 2.2 for Credit Card', 'woocommerce-braspag'),
110110
'type' => 'title',
111111
'description' => '',
112112
),
113113
'auth3ds20_mpi_is_active' => array(
114114
'title' => __('Enable', 'woocommerce-braspag'),
115115
'label' => __('Enable', 'woocommerce-braspag'),
116116
'type' => 'checkbox',
117-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 for Credit Card.',
117+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 for Credit Card.',
118118
'default' => 'no',
119119
'desc_tip' => true,
120120
),
121121
'auth3ds20_mpi_mastercard_notify_only' => array(
122122
'title' => __('MasterCard Notify Only', 'woocommerce-braspag'),
123123
'label' => __('Enable', 'woocommerce-braspag'),
124124
'type' => 'checkbox',
125-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 MasterCard Notify Only for Credit Card.',
125+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 MasterCard Notify Only for Credit Card.',
126126
'default' => 'no',
127127
'desc_tip' => true,
128128
),
129129
'auth3ds20_mpi_authorize_on_error' => array(
130130
'title' => __('Authorization On Error', 'woocommerce-braspag'),
131131
'label' => __('Enable', 'woocommerce-braspag'),
132132
'type' => 'checkbox',
133-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Error for Credit Card.',
133+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Error for Credit Card.',
134134
'default' => 'no',
135135
'desc_tip' => true,
136136
),
137137
'auth3ds20_mpi_authorize_on_failure' => array(
138138
'title' => __('Authorization On Failure', 'woocommerce-braspag'),
139139
'label' => __('Enable', 'woocommerce-braspag'),
140140
'type' => 'checkbox',
141-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Failure for Credit Card.',
141+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Failure for Credit Card.',
142142
'default' => 'no',
143143
'desc_tip' => true,
144144
),
145145
'auth3ds20_mpi_authorize_on_unenrolled' => array(
146146
'title' => __('Authorization On Unenrolled', 'woocommerce-braspag'),
147147
'label' => __('Enable', 'woocommerce-braspag'),
148148
'type' => 'checkbox',
149-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Unenrolled for Credit Card.',
149+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Unenrolled for Credit Card.',
150150
'default' => 'no',
151151
'desc_tip' => true,
152152
),
153153
'auth3ds20_mpi_authorize_on_unsupported_brand' => array(
154154
'title' => __('Authorization On Unsupported Brand', 'woocommerce-braspag'),
155155
'label' => __('Enable', 'woocommerce-braspag'),
156156
'type' => 'checkbox',
157-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Unsupported Brand for Credit Card.',
157+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Unsupported Brand for Credit Card.',
158158
'default' => 'no',
159159
'desc_tip' => true,
160160
)

includes/admin/braspag-debitcard-settings.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,55 +70,55 @@
7070
'desc_tip' => false,
7171
),
7272
'auth3ds20' => array(
73-
'title' => "<hr>" . __('Authentication 3DS 2.0 for Debit Card', 'woocommerce-braspag'),
73+
'title' => "<hr>" . __('Authentication 3DS 2.2 for Debit Card', 'woocommerce-braspag'),
7474
'type' => 'title',
7575
'description' => '',
7676
),
7777
'auth3ds20_mpi_is_active' => array(
7878
'title' => __('Enable', 'woocommerce-braspag'),
7979
'label' => __('Enable', 'woocommerce-braspag'),
8080
'type' => 'checkbox',
81-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 for Debit Card.',
81+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 for Debit Card.',
8282
'default' => 'no',
8383
'desc_tip' => true,
8484
),
8585
'auth3ds20_mpi_mastercard_notify_only' => array(
8686
'title' => __('MasterCard Notify Only', 'woocommerce-braspag'),
8787
'label' => __('Enable', 'woocommerce-braspag'),
8888
'type' => 'checkbox',
89-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 MasterCard Notify Only for Debit Card.',
89+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 MasterCard Notify Only for Debit Card.',
9090
'default' => 'no',
9191
'desc_tip' => true,
9292
),
9393
'auth3ds20_mpi_authorize_on_error' => array(
9494
'title' => __('Authorization On Error', 'woocommerce-braspag'),
9595
'label' => __('Enable', 'woocommerce-braspag'),
9696
'type' => 'checkbox',
97-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Error for Debit Card.',
97+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Error for Debit Card.',
9898
'default' => 'no',
9999
'desc_tip' => true,
100100
),
101101
'auth3ds20_mpi_authorize_on_failure' => array(
102102
'title' => __('Authorization On Failure', 'woocommerce-braspag'),
103103
'label' => __('Enable', 'woocommerce-braspag'),
104104
'type' => 'checkbox',
105-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Failure for Debit Card.',
105+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Failure for Debit Card.',
106106
'default' => 'no',
107107
'desc_tip' => true,
108108
),
109109
'auth3ds20_mpi_authorize_on_unenrolled' => array(
110110
'title' => __('Authorization On Unenrolled', 'woocommerce-braspag'),
111111
'label' => __('Enable', 'woocommerce-braspag'),
112112
'type' => 'checkbox',
113-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Unenrolled for Debit Card.',
113+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Unenrolled for Debit Card.',
114114
'default' => 'no',
115115
'desc_tip' => true,
116116
),
117117
'auth3ds20_mpi_authorize_on_unsupported_brand' => array(
118118
'title' => __('Authorization On Unsupported Brand', 'woocommerce-braspag'),
119119
'label' => __('Enable', 'woocommerce-braspag'),
120120
'type' => 'checkbox',
121-
'description' => 'Choose whether you wish to enable Authentication 3ds 2.0 Authorization On Unsupported Brand for Debit Card.',
121+
'description' => 'Choose whether you wish to enable Authentication 3ds 2.2 Authorization On Unsupported Brand for Debit Card.',
122122
'default' => 'no',
123123
'desc_tip' => true,
124124
)

includes/admin/braspag-settings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,21 @@
300300
'desc_tip' => true,
301301
),
302302
'auth3ds20' => array(
303-
'title' => "<hr>" . __('Authentication 3DS 2.0', 'woocommerce-braspag'),
303+
'title' => "<hr>" . __('Authentication 3DS 2.2', 'woocommerce-braspag'),
304304
'type' => 'title',
305305
'description' => '',
306306
),
307307
'auth3ds20_oauth_authentication_client_id' => array(
308308
'title' => __('Client ID', 'woocommerce-braspag'),
309309
'type' => 'text',
310-
'description' => __('Get your Authentication 3DS 2.0 OAuth Client ID from Braspag Support.', 'woocommerce-braspag'),
310+
'description' => __('Get your Authentication 3DS 2.2 OAuth Client ID from Braspag Support.', 'woocommerce-braspag'),
311311
'default' => '',
312312
'desc_tip' => true,
313313
),
314314
'auth3ds20_oauth_authentication_client_secret' => array(
315315
'title' => __('Client Secret', 'woocommerce-braspag'),
316316
'type' => 'text',
317-
'description' => __('Get your Authentication 3DS 2.0 Client Secret from Braspag Support.', 'woocommerce-braspag'),
317+
'description' => __('Get your Authentication 3DS 2.2 Client Secret from Braspag Support.', 'woocommerce-braspag'),
318318
'default' => '',
319319
'desc_tip' => true,
320320
)

includes/class-wc-gateway-braspag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function get_braspag_auth3ds20_elements($fields)
163163
<input type="hidden" class="bpmpi_currency" value="BRL"/>
164164
<input type="hidden" class="bpmpi_ordernumber" value="' . (WC()->cart->get_cart_hash()) . '"/>
165165
<input type="hidden" class="bpmpi_transaction_mode" value=""/>
166-
<input type="hidden" class="bpmpi_merchant_url" value="' . wp_parse_url( home_url(), PHP_URL_HOST ) . '"/>
166+
<input type="hidden" class="bpmpi_merchant_url" value="' . wp_parse_url(home_url(), PHP_URL_HOST) . '"/>
167167
</div>
168168
169169
<div id="bpmpi_data_billto">

0 commit comments

Comments
 (0)