-
Notifications
You must be signed in to change notification settings - Fork 0
Bugfix/v4.4.1 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v4.4
Are you sure you want to change the base?
Changes from all commits
7b8e5e5
3dea3c1
6e2537e
532ca2a
c1ee1e9
5270c6d
57d295a
444bbb6
ce227fc
0a04561
967f82a
aa8e7ee
613b71c
051b586
223b51c
c278f0c
4431a91
3816356
88a53e5
2eb5219
5e07107
ea7dbe8
25aa82b
351bd70
d259b0b
f10f714
81f6dbf
ceab7a5
ad49b61
92f7acd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| # Modulo para hacer comprobar estado de los comprobantes | ||
| # Modulo para hacer comprobar estado de los comprobantes y su estado de recepcion | ||
|
|
||
| Se envia: | ||
|
|
||
| * `w` : consultar | ||
| * `r` : consultarCom | ||
| * `r` : recepcion o comprobante | ||
| * `clave` : Clave numerica del comprobante | ||
| * `token`: Token funcional para enviar en el header | ||
| * `token`: Token obtenido de Hacienda | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,10 +16,10 @@ | |||||||||||||||||||||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function consutar() | ||||||||||||||||||||||
| function consultarRecepcion() | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| $curl = curl_init(); | ||||||||||||||||||||||
| $clave = params_get('clave'); | ||||||||||||||||||||||
| $curl = curl_init(); | ||||||||||||||||||||||
| $clave = params_get('clave'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($clave == "" || strlen($clave) == 0) | ||||||||||||||||||||||
| return "La clave no puede ser en blanco"; | ||||||||||||||||||||||
|
|
@@ -31,45 +31,179 @@ function consutar() | |||||||||||||||||||||
| $url = "https://api.comprobanteselectronicos.go.cr/recepcion/v1/recepcion/"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($url == null) | ||||||||||||||||||||||
| return "Ha ocurrido un error en el client_id."; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| curl_setopt_array($curl, array( | ||||||||||||||||||||||
| CURLOPT_URL => $url . $clave, | ||||||||||||||||||||||
| CURLOPT_RETURNTRANSFER => true, | ||||||||||||||||||||||
| CURLOPT_ENCODING => "", | ||||||||||||||||||||||
| CURLOPT_MAXREDIRS => 10, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYHOST => 0, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYPEER => 0, | ||||||||||||||||||||||
| CURLOPT_TIMEOUT => 30, | ||||||||||||||||||||||
| CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||||||||||||||||||||||
| CURLOPT_CUSTOMREQUEST => "GET", | ||||||||||||||||||||||
| CURLOPT_HTTPHEADER => array( | ||||||||||||||||||||||
| return "El client_id proporcionado (" . params_get("client_id") . ") no es válido. "; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
Comment on lines
33
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo and return a structured error for invalid client_id. Keep responses consistent and correct the Spanish typo. - if ($url == null)
- return "El client_id proprocionado (".params_get("client_id").") no es válido. ";
+ if ($url == null) {
+ return array(
+ "Status" => 400,
+ "to" => null,
+ "text" => "El client_id proporcionado (" . params_get("client_id") . ") no es válido."
+ );
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| $args = array( | ||||||||||||||||||||||
| CURLOPT_URL => $url . $clave, | ||||||||||||||||||||||
| CURLOPT_RETURNTRANSFER => true, | ||||||||||||||||||||||
| CURLOPT_HEADER => true, | ||||||||||||||||||||||
| CURLOPT_ENCODING => "", | ||||||||||||||||||||||
| CURLOPT_MAXREDIRS => 10, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYHOST => 0, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYPEER => 0, | ||||||||||||||||||||||
| CURLOPT_TIMEOUT => 30, | ||||||||||||||||||||||
| CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||||||||||||||||||||||
| CURLOPT_CUSTOMREQUEST => "GET", | ||||||||||||||||||||||
| CURLOPT_HTTPHEADER => array( | ||||||||||||||||||||||
| "Authorization: Bearer " . params_get('token'), | ||||||||||||||||||||||
| "Cache-Control: no-cache", | ||||||||||||||||||||||
| "Content-Type: application/x-www-form-urlencoded", | ||||||||||||||||||||||
| "Postman-Token: bf8dc171-5bb7-fa54-7416-56c5cda9bf5c" | ||||||||||||||||||||||
| "Content-Type: application/x-www-form-urlencoded" | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| )); | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| curl_setopt_array($curl, $args); | ||||||||||||||||||||||
| $response = curl_exec($curl); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | ||||||||||||||||||||||
| $headers = substr($response, 0, $header_size); | ||||||||||||||||||||||
| $body = substr($response, $header_size); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $response = curl_exec($curl); | ||||||||||||||||||||||
| $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||||||||||||||||||||||
| $err = curl_error($curl); | ||||||||||||||||||||||
| $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||||||||||||||||||||||
| $err = curl_error($curl); | ||||||||||||||||||||||
| curl_close($curl); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($err) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| if ($err) { | ||||||||||||||||||||||
| $arrayResp = array( | ||||||||||||||||||||||
| "Status" => $status, | ||||||||||||||||||||||
| "to" => $apiTo, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $err | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return $arrayResp; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| else | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| $response = json_decode($response); | ||||||||||||||||||||||
| return $response; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $responseObj = json_decode($body); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (is_object($responseObj)) { | ||||||||||||||||||||||
| // si hay respuesta de hacienda, procesar detalle de mensaje | ||||||||||||||||||||||
| if (isset($responseObj->{'respuesta-xml'})) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $xmlRespuesta = base64_decode($responseObj->{'respuesta-xml'}); | ||||||||||||||||||||||
| $xmlRespuesta = preg_replace('/>\s+</', '><', $xmlRespuesta); | ||||||||||||||||||||||
| $startLength = strlen("tiene los siguientes errores: ") + 7; | ||||||||||||||||||||||
| $startPos = strpos($xmlRespuesta, "tiene los siguientes errores: ", 0); | ||||||||||||||||||||||
| if (!$startPos) { | ||||||||||||||||||||||
| // si no hay errores, retornar la respuesta normal | ||||||||||||||||||||||
| return $responseObj; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| $endPos = strpos($xmlRespuesta, "</DetalleMensaje>", $startPos); | ||||||||||||||||||||||
| $detalleMensaje = substr($xmlRespuesta, $startPos + $startLength, $endPos - ($startPos + $startLength + 1)); | ||||||||||||||||||||||
| $separadorMensaje = " \n"; | ||||||||||||||||||||||
| $responseObj->{'DetalleMensaje'} = explode($separadorMensaje, trim($detalleMensaje, $separadorMensaje)); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return array( | ||||||||||||||||||||||
| "Status" => $status, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $responseObj | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (empty($body)) { | ||||||||||||||||||||||
| $header_lines = explode("\r\n", trim($headers)); | ||||||||||||||||||||||
| $header_array = []; | ||||||||||||||||||||||
| foreach ($header_lines as $line) { | ||||||||||||||||||||||
| if (strpos($line, ':') !== false) { | ||||||||||||||||||||||
| list($key, $value) = explode(': ', $line, 2); | ||||||||||||||||||||||
| $header_array[$key] = $value; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return array( | ||||||||||||||||||||||
| "Status" => $header_array['x-http-status'], | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $header_array['x-error-cause'] | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return array( | ||||||||||||||||||||||
| "Status" => $status, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $body | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function consultarComprobante() | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| $curl = curl_init(); | ||||||||||||||||||||||
| $clave = params_get('clave'); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($clave == "" || strlen($clave) == 0) { | ||||||||||||||||||||||
| return "La clave no puede ser en blanco"; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $url = null; | ||||||||||||||||||||||
| if (params_get("client_id") == 'api-stag') | ||||||||||||||||||||||
| $url = "https://api-sandbox.comprobanteselectronicos.go.cr/recepcion/v1/comprobantes/"; | ||||||||||||||||||||||
| else if (params_get("client_id") == 'api-prod') | ||||||||||||||||||||||
| $url = "https://api.comprobanteselectronicos.go.cr/recepcion/v1/comprobantes/"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($url == null) { | ||||||||||||||||||||||
| return "El client_id proporcionado (" . params_get("client_id") . ") no es válido. "; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $args = array( | ||||||||||||||||||||||
| CURLOPT_URL => $url . $clave, | ||||||||||||||||||||||
| CURLOPT_RETURNTRANSFER => true, | ||||||||||||||||||||||
| CURLOPT_HEADER => true, | ||||||||||||||||||||||
| CURLOPT_ENCODING => "", | ||||||||||||||||||||||
| CURLOPT_MAXREDIRS => 10, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYHOST => 0, | ||||||||||||||||||||||
| CURLOPT_SSL_VERIFYPEER => 0, | ||||||||||||||||||||||
| CURLOPT_TIMEOUT => 30, | ||||||||||||||||||||||
| CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||||||||||||||||||||||
| CURLOPT_CUSTOMREQUEST => "GET", | ||||||||||||||||||||||
| CURLOPT_HTTPHEADER => array( | ||||||||||||||||||||||
| "Authorization: Bearer " . params_get('token') | ||||||||||||||||||||||
| ), | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| curl_setopt_array($curl, $args); | ||||||||||||||||||||||
| $response = curl_exec($curl); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); | ||||||||||||||||||||||
| $headers = substr($response, 0, $header_size); | ||||||||||||||||||||||
| $body = substr($response, $header_size); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); | ||||||||||||||||||||||
| $err = curl_error($curl); | ||||||||||||||||||||||
| curl_close($curl); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if ($err) { | ||||||||||||||||||||||
| $arrayResp = array( | ||||||||||||||||||||||
| "Status" => $status, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $err | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return tools_reply($arrayResp, true); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if (empty($body)) { | ||||||||||||||||||||||
| $header_lines = explode("\r\n", trim($headers)); | ||||||||||||||||||||||
| $header_array = []; | ||||||||||||||||||||||
| foreach ($header_lines as $line) { | ||||||||||||||||||||||
| if (strpos($line, ':') !== false) { | ||||||||||||||||||||||
| list($key, $value) = explode(': ', $line, 2); | ||||||||||||||||||||||
| $header_array[$key] = $value; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| return tools_reply(array( | ||||||||||||||||||||||
| "Status" => $header_array['x-http-status'] ?? $status, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $header_array['x-error-cause'] | ||||||||||||||||||||||
| ), true); | ||||||||||||||||||||||
|
Comment on lines
+192
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard x-error-cause access consistently. Line 193 correctly guards Apply this diff: return tools_reply(array(
"Status" => $header_array['x-http-status'] ?? $status,
"to" => $url,
- "text" => $header_array['x-error-cause']
+ "text" => $header_array['x-error-cause'] ?? 'Error desconocido'
), true);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
Comment on lines
+192
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The function 🔍 Detailed AnalysisThe function 💡 Suggested FixIn 🤖 Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews. |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $responseObj = json_decode($body); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return tools_reply(array( | ||||||||||||||||||||||
| "Status" => $status, | ||||||||||||||||||||||
| "to" => $url, | ||||||||||||||||||||||
| "text" => $body | ||||||||||||||||||||||
| ), true); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ?> | ||||||||||||||||||||||
| ?> | ||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,7 +134,7 @@ function companny_users_generateSessionKey($idUser, $idMasterUser) { | |
| $q = sprintf("delete from " . db_escape($idMasterUser) . "_master_sessions where idUser='" . db_escape($idUser) . "'"); | ||
| db_query($q, 0); | ||
|
|
||
| $sessionKey = password_hash(time() * rand(0, 1000), PASSWORD_DEFAULT); | ||
| $sessionKey = password_hash(time() * rand(0, 1000), PASSWORD_ARGON2ID); | ||
|
|
||
| $q = sprintf("INSERT INTO " . db_escape($idMasterUser) . "_master_sessions (idUser, sessionKey, ip, lastAccess) " | ||
| . "VALUES('%s', '%s', '%s', '%s')", db_escape($idUser), db_escape($sessionKey), db_escape($_SERVER['REMOTE_ADDR']), time()); | ||
|
|
@@ -409,7 +409,7 @@ function companny_users_getMyDetails() { | |
| * Helper function to actually create a new user and register it in the db | ||
| */ | ||
| function _companny_users_register($compannyUserDets, $idMasterUser) { | ||
| $pwd = password_hash($compannyUserDets['pwd'], PASSWORD_DEFAULT); | ||
| $pwd = password_hash($compannyUserDets['pwd'], PASSWORD_ARGON2ID); | ||
| $q = sprintf("INSERT INTO " . db_escape($idMasterUser) . "_master_users (idMasterUser,fullName, userName, email, about, country, status, timestamp, lastAccess, pwd, avatar,settings) | ||
| VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", db_escape($idMasterUser), db_escape($compannyUserDets['fullName']), db_escape($compannyUserDets['userName']), db_escape($compannyUserDets['email']), db_escape(addslashes($compannyUserDets['about'])), db_escape($compannyUserDets['country']), db_escape($compannyUserDets['status']), db_escape($compannyUserDets['timestamp']), db_escape($compannyUserDets['lastAccess']), db_escape($pwd), db_escape($compannyUserDets['avatar']), db_escape($compannyUserDets['settings']) | ||
| ); | ||
|
|
@@ -511,7 +511,7 @@ function companny_users_recoverPwd() { | |
|
|
||
| $temp = rand(0, 1000) + time(); | ||
|
|
||
| $compannyUser->pwd = password_hash($temp, PASSWORD_DEFAULT); | ||
| $compannyUser->pwd = password_hash($temp, PASSWORD_ARGON2ID); | ||
| grace_debug("New tmp pwd: " . $compannyUser->pwd); | ||
|
|
||
|
Comment on lines
512
to
516
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t email a new plaintext password; issue a time-bound reset token instead. Current flow generates and emails a password, which is insecure and hard to audit. Prefer a reset token + link. Minimal improvement if you must keep this flow:
Better approach (recommended):
|
||
| # Update account | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix Spanish spelling and grammar issues.
The header has spelling errors that should be corrected.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[misspelling] ~1-~1: Si es adjetivo o nombre, se escribe con tilde.
Context: # Modulo para hacer comprobar estado de los comp...
(DIACRITICS_02)
[uncategorized] ~1-~1: Probablemente falta un determinante.
Context: # Modulo para hacer comprobar estado de los comprobantes y su estado de rece...
(AI_ES_GGEC_MISSING_DETERMINER)
[uncategorized] ~1-~1: Probablemente falta un signo diacrítico.
Context: ...tado de los comprobantes y su estado de recepcion Se envia: *
w: consultar *r: r...(AI_ES_GGEC_MISSING_ORTHOGRAPHY_DIACRITIC)
🤖 Prompt for AI Agents