Skip to content

Commit 61445b6

Browse files
committed
Merge branch 'master' of github.com:apigatewaycl/apigateway-api-client-php
2 parents 21f5312 + 67c8dc8 commit 61445b6

60 files changed

Lines changed: 1061 additions & 487 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
php-version: ['8.4', '8.5']
16+
php-version: ['8.5']
1717

1818
steps:
1919
- name: Check out repository code
@@ -33,6 +33,7 @@ jobs:
3333
env:
3434
APIGATEWAY_API_TOKEN: ${{ secrets.APIGATEWAY_API_TOKEN }}
3535
TEST_CONTRIBUYENTE_RUT: ${{ vars.TEST_CONTRIBUYENTE_RUT }}
36+
ADD_SKIPPED: true
3637
run: |
3738
composer tests-readonly
3839

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ Enlaces
3333
- [Sitio web API Gateway](https://www.apigateway.cl).
3434
- [Código fuente en GitHub](https://github.com/apigatewaycl/apigateway-api-client-php).
3535
- [Paquete en Packagist](https://packagist.org/packages/apigatewaycl/apigateway-api-client).
36+
- [Documentación](https://api-client-php.docs.apigateway.cl/).

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
},
1818
"autoload": {
1919
"psr-4": {
20-
"apigatewaycl\\api_client\\": "src/"
20+
"apigatewaycl\\api_client\\": "src/",
21+
"Tests\\": "tests/"
2122
}
2223
},
2324
"require": {
24-
"php": "^8.4",
25+
"php": "^8.5",
2526
"guzzlehttp/guzzle": "^7.10"
2627
},
2728
"require-dev": {
2829
"friendsofphp/php-cs-fixer": "^3.94",
29-
"phpstan/phpstan": "^1.12",
30+
"phpstan/phpstan": "^2",
3031
"phpunit/phpunit": "^13.0",
31-
"vlucas/phpdotenv": "^5.6"
32+
"vlucas/phpdotenv": "^5.6",
33+
"phpstan/phpstan-phpunit": "^2"
3234
},
3335
"scripts": {
36+
"install-docs": "curl -L https://www.phpdoc.org/phpDocumentor.phar -o phpdoc.phar; chmod +x phpdoc.phar",
3437
"docs": "php tools/phpdocumentor run --config=phpdoc.xml",
3538
"tests": "vendor/bin/phpunit --configuration=phpunit.xml --no-coverage",
3639
"tests-readonly": "XDEBUG_MODE=coverage vendor/bin/phpunit --configuration=phpunit.xml --filter 'testListarActividadesEconomicas|testObtenerSituacionTributariaTercero|testListarUfAnual|testListarUfMensual|testListarUfDiario'",

docs/dev/unit-test.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,22 @@ Pruebas unitarias
55
Al ejecutar pruebas, deberás tener configuradas las variables de entorno necesarias en el archivo test.env. Favor de duplicar test.env-dist, cambiar su nombre a test.env y rellenar las variables necesarias.
66

77
Antes de empezar, debes configurar las siguientes variables de entorno:
8+
9+
Para utilizar v1:
10+
.. code-block:: shell
11+
APIGATEWAY_API_URL="https://legacy.apigateway.cl"
12+
APIGATEWAY_API_TOKEN="token-apigateway"
13+
APIGATEWAY_API_VERSION="v1"
14+
CONTRIBUYENTE_RUT="66666666-6"
15+
CONTRIBUYENTE_CLAVE="clave-sii"
16+
TEST_VERBOSE=true
17+
TEST_PERIODO=202401
18+
19+
Para utilizar v2:
820
.. code-block:: shell
921
APIGATEWAY_API_URL="https://legacy.apigateway.cl"
10-
API_GATEWAY_API_TOKEN="token-apigateway"
22+
APIGATEWAY_API_TOKEN="token-apigateway"
23+
APIGATEWAY_API_VERSION="v1"
1124
CONTRIBUYENTE_RUT="66666666-6"
1225
CONTRIBUYENTE_CLAVE="clave-sii"
1326
TEST_VERBOSE=true

docs/getting-started/setup.rst

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,106 @@
11
Configuración
22
=============
33

4-
Para utilizar el cliente de API de API Gateway, se debe tener un token de usuario, generado y obtenido desde la cuenta de API Gateway.
4+
Para utilizar el cliente de API de API Gateway, se debe tener un token de usuario generado desde la cuenta de API Gateway.
55

66
.. important::
7-
El archivo test.env sólo sirve para usar con los test. Por lo que se deberán definir las variables de entorno por los siguientes dos métodos: Directo por consola (temporal), o definirlas directamente en el entorno (persistente).
7+
El archivo ``test.env`` sólo sirve para usar con los test.
88

9-
En Linux o MacOS:
10-
-----------------
9+
Versiones de API
10+
----------------
1111

12-
El token se almacena en una variable de entorno. Para almacenar en una variable de entorno, se debe escribir lo siguiente en consola:
12+
El cliente permite utilizar dos versiones de la API mediante variables de entorno.
13+
14+
**API v1 (legacy)**
15+
16+
- URL: ``https://legacy.apigateway.cl``
17+
18+
**API v2 (recomendada)**
19+
20+
- URL: ``https://app.apigateway.cl``
21+
22+
.. note::
23+
Si no se define ``APIGATEWAY_API_VERSION`` el cliente utilizará automáticamente **v2**.
24+
25+
Variables de entorno
26+
--------------------
27+
28+
Las siguientes variables deben definirse en el sistema:
29+
30+
- ``APIGATEWAY_API_URL``
31+
- ``APIGATEWAY_API_VERSION``
32+
- ``APIGATEWAY_API_TOKEN``
33+
34+
``APIGATEWAY_API_TOKEN`` es una cadena extremadamente larga. Guárdala en un lugar seguro.
35+
36+
Linux o MacOS
37+
-------------
38+
39+
**Configuración para API v1**
1340

1441
.. code-block:: shell
42+
1543
export APIGATEWAY_API_URL="https://legacy.apigateway.cl"
44+
export APIGATEWAY_API_VERSION="v1"
1645
export APIGATEWAY_API_TOKEN="aqui-su-token-de-apigateway"
1746
18-
- ``APIGATEWAY_API_TOKEN`` es una cadena de caracteres extremadamente larga. Almacena ese token en un lugar seguro y no lo compartas con nadie.
47+
**Configuración para API v2**
48+
49+
.. code-block:: shell
50+
51+
export APIGATEWAY_API_URL="https://app.apigateway.cl"
52+
export APIGATEWAY_API_VERSION="v2"
53+
export APIGATEWAY_API_TOKEN="aqui-su-token-de-apigateway"
1954
20-
Introducir en consola las variables de entorno almacena temporalmente las variables, y alternativamente, se puede modificar el archivo de configuración de shell en Linux (que se explicará a continuación), y añadir al final del archivo los comandos previamente introducidos. Añadir variables de entorno de esta forma es más persistente y no se repite su definición.
55+
Para hacerlo persistente:
2156

22-
- Si se usa Linux, se deben añadir al archivo ``~/.bashrc`` los comandos previamente definidos.
23-
- Si se usa MacOS, se deben añadir al archivo ``~/.zshrc``.
57+
- Linux: añadir al archivo ``~/.bashrc``
58+
- MacOS: añadir al archivo ``~/.zshrc``
2459

25-
El paso siguiente sólo se hace para usuarios de MacOS. Por último, ejecutar el comando en cuestión para efectuar los cambios.
60+
Luego ejecutar:
2661

2762
.. code-block:: shell
63+
2864
source ~/.zshrc
2965
30-
En Windows:
31-
-----------
66+
Windows
67+
-------
3268

33-
Para almacenar en una variable de entorno en Windows, hay varias alternativas. La primera es utilizando cmd, y para almacenarlas utilizando cmd, ejecuta en el buscador de Windows "cmd", y ejecuta los siguientes comandos:
69+
**CMD – API v1**
3470

3571
.. code-block:: shell
72+
3673
setx APIGATEWAY_API_URL "https://legacy.apigateway.cl"
74+
setx APIGATEWAY_API_VERSION "v1"
75+
setx APIGATEWAY_API_TOKEN "aqui-su-token-de-apigateway"
76+
77+
**CMD – API v2**
78+
79+
.. code-block:: shell
80+
81+
setx APIGATEWAY_API_URL "https://app.apigateway.cl"
82+
setx APIGATEWAY_API_VERSION "v2"
3783
setx APIGATEWAY_API_TOKEN "aqui-su-token-de-apigateway"
3884
39-
También se pueden definir utilizando Windows PowerShell, de una manera similar. Ejecuta en el buscador de Windows "PowerShell", y ejecuta los siguientes comandos:
85+
**PowerShell – API v1**
4086

4187
.. code-block:: shell
88+
4289
$Env:APIGATEWAY_API_URL = "https://legacy.apigateway.cl"
90+
$Env:APIGATEWAY_API_VERSION = "v1"
4391
$Env:APIGATEWAY_API_TOKEN = "aqui-su-token-de-apigateway"
4492
45-
Como alternativa para almacenar las variables de manera persistente, debes seguir los siguientes pasos:
93+
**PowerShell – API v2**
94+
95+
.. code-block:: shell
96+
97+
$Env:APIGATEWAY_API_URL = "https://app.apigateway.cl"
98+
$Env:APIGATEWAY_API_VERSION = "v2"
99+
$Env:APIGATEWAY_API_TOKEN = "aqui-su-token-de-apigateway"
100+
101+
.. important::
102+
Como alternativa para almacenar las variables de manera persistente, debes seguir los siguientes pasos:
46103

47-
1. Abre el Panel de Control > Sistema > Configuración avanzada del sistema.
48-
2. En la pestaña Opciones avanzadas, selecciona Variables de entorno.
49-
3. Añade o modifica las variables en la sección de "Variables de usuario" o "Variables del sistema".
104+
1. Abre el Panel de Control > Sistema > Configuración avanzada del sistema.
105+
2. En la pestaña Opciones avanzadas, selecciona Variables de entorno.
106+
3. Añade o modifica las variables en la sección de "Variables de usuario" o "Variables del sistema".

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ Enlaces
4444
- `Sitio web API Gateway <https://www.apigateway.cl>`_
4545
- `Código fuente en GitHub <https://github.com/apigatewaycl/apigateway-api-client-php>`_
4646
- `Paquete en Packagist <https://packagist.org/packages/apigatewaycl/apigateway-api-client>`_
47-
- `Documentación <https://developers.apigateway.cl/>`_
47+
- `Documentación <https://api-client-php.docs.apigateway.cl/>`_

phpdoc.phar

28.6 MB
Binary file not shown.

phpunit.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
beStrictAboutCoverageMetadata="true"
1111
beStrictAboutOutputDuringTests="false"
1212
beStrictAboutChangesToGlobalState="true"
13-
stopOnError="true"
14-
stopOnFailure="true"
15-
stopOnWarning="true"
16-
stopOnDeprecation="true"
17-
stopOnNotice="true"
18-
failOnEmptyTestSuite="true"
19-
failOnWarning="true"
20-
failOnRisky="true"
21-
failOnDeprecation="true"
22-
failOnPhpunitDeprecation="true"
23-
failOnNotice="true"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
stopOnWarning="false"
16+
stopOnDeprecation="false"
17+
stopOnNotice="false"
18+
failOnEmptyTestSuite="false"
19+
failOnWarning="false"
20+
failOnRisky="false"
21+
failOnDeprecation="false"
22+
failOnPhpunitDeprecation="false"
23+
failOnNotice="false"
2424
>
2525
<source>
2626
<include>

src/ApiBase.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class ApiBase extends ApiClient
4444
*/
4545
public function __construct(
4646
array $credenciales = [],
47-
string $token = null,
48-
string $url = null
47+
?string $token = null,
48+
?string $url = null
4949
) {
5050
parent::__construct($token, $url);
5151
$this->setupAuth($credenciales);
@@ -62,7 +62,11 @@ public function __construct(
6262
private function setupAuth(array $credenciales): void
6363
{
6464
$tipo = key($credenciales); // Detecta si es 'pass' o 'cert'
65-
$datos = $credenciales[$tipo] ?? [];
65+
$datos = [];
66+
67+
if ($tipo !== null && isset($credenciales[$tipo])) {
68+
$datos = $credenciales[$tipo];
69+
}
6670

6771
$identificador = $datos['rut'] ??
6872
$datos['cert-data'] ??
@@ -129,9 +133,9 @@ private function setupAuth(array $credenciales): void
129133
* @return bool true si el RUT tiene un formato válido,false en caso
130134
* contrario.
131135
*/
132-
private function isAuthPass(string $rut): bool
136+
private function isAuthPass(?string $rut): bool
133137
{
134-
if (is_null($rut)) {
138+
if ($rut === null) {
135139
return false;
136140
}
137141
// Expresión regular para validar el formato del RUT chileno
@@ -146,9 +150,9 @@ private function isAuthPass(string $rut): bool
146150
* @return bool true si la cadena es válida en Base64, false en caso
147151
* contrario.
148152
*/
149-
private function isAuthFileData(string $firmaElectronicaBase64): bool
153+
private function isAuthFileData(?string $firmaElectronicaBase64): bool
150154
{
151-
if (is_null($firmaElectronicaBase64)) {
155+
if ($firmaElectronicaBase64 === null) {
152156
return false;
153157
}
154158
// Asegúrate de que la longitud de la cadena sea múltiplo de 4
@@ -189,9 +193,9 @@ private function isAuthFileData(string $firmaElectronicaBase64): bool
189193
* @param string $pemStr La cadena a validar.
190194
* @return bool true si la cadena tiene formato PEM válido, false en caso contrario.
191195
*/
192-
private function isAuthCertData(string $pemStr): bool
196+
private function isAuthCertData(?string $pemStr): bool
193197
{
194-
if (is_null($pemStr)) {
198+
if ($pemStr === null) {
195199
return false;
196200
}
197201
// Expresión regular para validar el formato PEM

0 commit comments

Comments
 (0)