Skip to content

Commit 380989c

Browse files
authored
Merge pull request #11 from eclipxe13/master
Better dev experience (0.2.4)
2 parents b2547c4 + 3ee8bf3 commit 380989c

19 files changed

+114
-95
lines changed

.gitattributes

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
* text=auto
33

44
# Do not put this files on a distribution package (by .gitignore)
5-
/vendor export-ignore
6-
/build export-ignore
5+
/vendor/ export-ignore
76
/composer.lock export-ignore
87

98
# Do not put this files on a distribution package
9+
/build/ export-ignore
1010
/tests/ export-ignore
1111
/.gitattributes export-ignore
1212
/.gitignore export-ignore
1313
/.php_cs.dist export-ignore
14-
/.phplint.yml export-ignore
1514
/.scrutinizer.yml export-ignore
1615
/.travis.yml export-ignore
1716
/phpcs.xml.dist export-ignore

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# do not include this files on git
2-
/vendor
3-
/build
2+
/vendor/
43
/composer.lock

.phplint.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.scrutinizer.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ filter:
44
- 'vendor/'
55

66
build:
7+
dependencies:
8+
before:
9+
- pecl install zip
10+
override:
11+
- composer self-update --no-interaction --no-progress
12+
- composer install --no-interaction
713
nodes:
8-
php73:
9-
environment:
10-
php:
11-
version: "7.3"
12-
pecl_extensions:
13-
- "zip"
14+
php:
1415
tests:
1516
override:
1617
- php-scrutinizer-run --enable-security-analysis

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,15 @@ env:
1111
- PHP_CS_FIXER_FUTURE_MODE=1
1212
- PHP_CS_FIXER_IGNORE_ENV=1
1313

14-
matrix:
15-
allow_failures:
16-
- php: "7.4snapshot"
17-
1814
cache:
1915
- directories:
2016
- $HOME/.composer
2117

2218
before_script:
2319
- phpenv config-rm xdebug.ini || true
2420
- travis_retry composer install --no-interaction --prefer-dist
25-
- mkdir -p build
2621

2722
script:
28-
- vendor/bin/phplint
2923
- vendor/bin/php-cs-fixer fix --verbose --dry-run
3024
- vendor/bin/phpcs --colors -sp src/ tests/
3125
- vendor/bin/phpunit --testdox --verbose

CONTRIBUTING.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ If any of these do not pass, it will result in a complete build failure.
7474
Before you can run these, be sure to `composer install` or `composer update`.
7575

7676
```shell
77-
vendor/bin/parallel-lint src/ tests/
7877
vendor/bin/phpcs -sp src/ tests/
7978
vendor/bin/php-cs-fixer fix -v --dry-run
8079
vendor/bin/phpunit --coverage-text
81-
vendor/bin/phpstan.phar analyse --no-progress --level max src/ tests/
80+
vendor/bin/phpstan analyse --no-progress --level max src/ tests/
8281
```

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ También te esperamos en el [canal #phpcfdi de discord](https://discord.gg/aFGYX
1919
Esta librería contiene un cliente (consumidor) del servicio del SAT de
2020
**Servicio Web de Descarga Masiva de CFDI y Retenciones**.
2121

22+
## Instalación
2223

23-
## Installation
24+
Utiliza [composer](https://getcomposer.org/), instala de la siguiente forma:
2425

25-
Use [composer](https://getcomposer.org/), please run
2626
```shell
2727
composer require phpcfdi/sat-ws-descarga-masiva
2828
```
2929

30-
31-
## Basic usage
30+
## Ejemplo básico de uso
3231

3332
```php
3433
<?php
@@ -41,16 +40,24 @@ use PhpCfdi\SatWsDescargaMasiva\Shared\DateTimePeriod;
4140
use PhpCfdi\SatWsDescargaMasiva\Shared\DownloadType;
4241
use PhpCfdi\SatWsDescargaMasiva\Shared\Fiel;
4342
use PhpCfdi\SatWsDescargaMasiva\Shared\RequestType;
44-
use PhpCfdi\SatWsDescargaMasiva\WebClient\WebClientInterface;
43+
use PhpCfdi\SatWsDescargaMasiva\WebClient\GuzzleWebClient;
4544

46-
// Creación de la fiel
45+
// Creación de la fiel, puede leer archivos DER (como los envía el SAT) o PEM (convertidos)
4746
$fiel = Fiel::create(
48-
file_get_contents('llaveprivada.key.pem'), // en formato PEM
49-
file_get_contents('certificado.cer'), // en formato PEM o DER
47+
file_get_contents('certificado.cer'),
48+
file_get_contents('llaveprivada.key'),
5049
'12345678a'
5150
);
5251

53-
/** @var WebClientInterface $webClient */
52+
// verificar que la fiel sea válida (no sea CSD y sea vigente acorde a la fecha del sistema)
53+
if (! $fiel->isValid()) {
54+
return;
55+
}
56+
57+
// creación del web client basado en Guzzle que implementa WebClientInterface
58+
// para usarlo necesitas instalar guzzlehttp/guzzle pues no es una dependencia directa
59+
$webClient = new GuzzleWebClient();
60+
5461
// Creación del servicio
5562
$service = new Service($fiel, $webClient);
5663

@@ -83,36 +90,31 @@ $metadataReader = new MetadataPackageReader($zipfile);
8390
foreach ($metadataReader->metadata() as $metadata) {
8491
echo $metadata->uuid, PHP_EOL;
8592
}
86-
8793
```
8894

89-
9095
### Acerca de la interfaz `WebClientInterface`
9196

9297
Para hacer esta librería compatible con diferentes formas de comunicación se utiliza una interfaz de cliente HTTP.
93-
Tu *debes* crear tu implementación para poderla utilizar, si así lo prefieres, podrías usar la clase
94-
[`GuzzleWebClient`](https://github.com/phpcfdi/sat-ws-descarga-masiva/blob/master/tests/WebClient/GuzzleWebClient.php)
95-
96-
En este momento no se provee esta implementación por defecto, es posible que en un futuro se incluya por default
97-
una clase que utilice [PSR-18 - HTTP Client](https://www.php-fig.org/psr/psr-18/).
98-
98+
Tu *puedes* crear tu implementación para poderla utilizar.
99+
100+
Si lo prefieres -como en el ejemplo de uso- podrías instalar Guzzle `composer require guzzlehttp/guzzle` y usar la clase
101+
[`GuzzleWebClient`](https://github.com/phpcfdi/sat-ws-descarga-masiva/blob/master/src/WebClient/GuzzleWebClient.php).
99102

100103
### Recomendación de fábrica del servicio
101104

102105
Te recomendamos configurar el framework de tu aplicación (Dependency Injection Container) o crear una clase que
103106
fabrique los objetos `Service`, `Fiel` y `WebClient` usando tus propias configuraciones de certificado, llave privada
104107
y contraseña.
105108

106-
107109
## Acerca del Servicio Web de Descarga Masiva de CFDI y Retenciones
108110

109111
El servicio se compone de 4 partes:
110112

111113
1. Autenticación: Esto se hace con tu fiel y la libería oculta la lógica de obtener y usar el Token.
112-
2. Solicitud: Presentar una solicitud incluyendo la fecha de inicio, fecha de fin, tipo de solicitud emitidas/recibidas
113-
y tipo de información solicitada (cfdi o metadata)
114-
3. Verificación: pregunta al SAT si ya tiene disponible la solicitud
115-
4. Descargar la solicitud.
114+
2. Solicitud: Presentar una solicitud incluyendo la fecha de inicio, fecha de fin, tipo de solicitud
115+
emitidas/recibidas y tipo de información solicitada (cfdi o metadata).
116+
3. Verificación: pregunta al SAT si ya tiene disponible la solicitud.
117+
4. Descargar los paquetes emitidos por la solicitud.
116118

117119
La mejor manera de entenderlo es la siguiente, imagina que el servicio del SAT se compone de tres ventanillas con tres
118120
personas diferentes atendiendo cada una de estas ventanillas.
@@ -148,22 +150,19 @@ Notas importantes del web service:
148150
- Podrás recuperar hasta 200 mil registros por petición y hasta un millón en metadata.
149151
- No existe limitante en cuanto al número de solicitudes siempre que no se descargue en más de una ocasión un XML.
150152

151-
152153
## Compatilibilidad
153154

154155
Esta librería se mantendrá compatible con al menos la versión con
155-
[soporte activo de PHP](http://php.net/supported-versions.php) más reciente.
156+
[soporte activo de PHP](https://www.php.net/supported-versions.php) más reciente.
156157

157158
También utilizamos [Versionado Semántico 2.0.0](https://semver.org/lang/es/)
158159
por lo que puedes usar esta librería sin temor a romper tu aplicación.
159160

160-
161161
## Contribuciones
162162

163163
Las contribuciones con bienvenidas. Por favor lee [CONTRIBUTING][] para más detalles
164164
y recuerda revisar el archivo de tareas pendientes [TODO][] y el [CHANGELOG][].
165165

166-
167166
## Copyright and License
168167

169168
The `phpcfdi/sat-ws-descarga-masiva` library is copyright © [PhpCfdi](https://www.phpcfdi.com)
@@ -183,7 +182,7 @@ and licensed for use under the MIT License (MIT). Please see [LICENSE][] for mor
183182
[coverage]: https://scrutinizer-ci.com/g/phpcfdi/sat-ws-descarga-masiva/code-structure/master/code-coverage/src/
184183
[downloads]: https://packagist.org/packages/phpcfdi/sat-ws-descarga-masiva
185184

186-
[badge-source]: http://img.shields.io/badge/source-phpcfdi/sat--ws--descarga--masiva-blue?style=flat-square
185+
[badge-source]: https://img.shields.io/badge/source-phpcfdi/sat--ws--descarga--masiva-blue?style=flat-square
187186
[badge-discord]: https://img.shields.io/discord/459860554090283019?logo=discord&style=flat-square
188187
[badge-release]: https://img.shields.io/github/release/phpcfdi/sat-ws-descarga-masiva?style=flat-square
189188
[badge-license]: https://img.shields.io/github/license/phpcfdi/sat-ws-descarga-masiva?style=flat-square

build/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,20 @@
2525
"ext-dom": "*",
2626
"ext-json": "*",
2727
"ext-zip": "*",
28-
"phpcfdi/credentials": "^1.0",
28+
"phpcfdi/credentials": "^1.1",
2929
"eclipxe/enum": "^0.2.0"
3030
},
3131
"require-dev": {
3232
"guzzlehttp/guzzle": "^6.3",
33-
"robrichards/xmlseclibs": "^3.0",
33+
"robrichards/xmlseclibs": "^3.0.4",
3434
"phpunit/phpunit": "^8.0",
35-
"overtrue/phplint": "^1.0",
3635
"squizlabs/php_codesniffer": "^3.0",
3736
"friendsofphp/php-cs-fixer": "^2.4",
3837
"phpstan/phpstan-shim": "^0.11"
3938
},
39+
"suggest": {
40+
"guzzlehttp/guzzle": "To use GuzzleWebClient implementation"
41+
},
4042
"autoload": {
4143
"psr-4": {
4244
"PhpCfdi\\SatWsDescargaMasiva\\": "src/"
@@ -58,7 +60,6 @@
5860
"vendor/bin/phpcbf --colors -sp src/ tests/"
5961
],
6062
"dev:test": [
61-
"vendor/bin/phplint",
6263
"@dev:check-style",
6364
"vendor/bin/phpunit --testdox --verbose --stop-on-failure",
6465
"vendor/bin/phpstan analyse --verbose --no-progress --level max src/ tests/"
@@ -71,7 +72,7 @@
7172
"dev:build": "DEV: run dev:fix-style dev:tests and dev:docs, run before pull request",
7273
"dev:check-style": "DEV: search for code style errors using php-cs-fixer and phpcs",
7374
"dev:fix-style": "DEV: fix code style errors using php-cs-fixer and phpcbf",
74-
"dev:test": "DEV: run phplint, phpunit and phpstan",
75+
"dev:test": "DEV: run @dev:check-style, phpunit and phpstan",
7576
"dev:coverage": "DEV: run phpunit with xdebug and storage coverage in build/coverage/html/"
7677
}
7778
}

docs/CHANGELOG.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,27 @@ In summary, [SemVer](https://semver.org/) can be viewed as ` Breaking . Feature
1010

1111
**Version `0.x.x` doesn't have to apply any of the SemVer rules**
1212

13-
14-
## **TO BE RELEASED**: Include this changes on next release, currently on `master` branch
15-
16-
- Development environment (Travis CI):
17-
- Fix code style issues.
18-
- Add `PHP_CS_FIXER_FUTURE_MODE` and `PHP_CS_FIXER_IGNORE_ENV` to run `php-cs-fixer` on PHP 7.4.
19-
- Remove deprecated config `sudo: false`.
13+
## Importante:
14+
15+
- En Travis-CI pasar de `7.4snapshot` a `7.4` cuando se corrija el bug de construcción.
16+
<https://travis-ci.community/t/some-extensions-are-missing-in-php-7-4-0-zip-gmp-sodium/6320/9>.
17+
18+
## Version 0.2.4 2019-12-06
19+
20+
- Se agrega la clase `PhpCfdi\SatWsDescargaMasiva\WebClient\GuzzleWebClient` que estaba en testing
21+
a el código distribuible, aunque no se agrega la dependencia `guzzlehttp/guzzle`.
22+
- Se documenta el uso de `GuzzleWebClient`.
23+
- Forzar la dependencia de `phpcfdi/credentials` a `^1.1` para leer llaves privadas en formato DER.
24+
- Forzar la dependencia de `robrichards/xmlseclibs` a `^3.0.4` por reporte de seguridad `CVE-2019-3465`.
25+
- Agregar ejemplo en la documentación para crear y verificar un objeto `Fiel`.
26+
- Corrección en la documentación al crear una fiel, tenía los parámetros invertidos.
27+
- Integración continua (Travis CI):
28+
- Se remueve la configuración `sudo: false`.
29+
- No se permite el fallo del build en PHP `7.4snapshot`.
30+
- Integración continua (Scrutinizer):
31+
- Se instala la extensión `zip` con `pecl`.
32+
- Se elimina la información de la versión fija.
33+
- Se modifica el archivo de configuración para que actualice `composer`.
2034

2135

2236
## Version 0.2.3 2019-09-23

docs/TODO.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# phpcfdi/sat-ws-descarga-masiva To Do List
22

3+
- Traducir CHANGELOG.md a español
4+
35
- Mover el script de consumo con credenciales válidas a su propio proyecto dependiente de este.
46

57
- Llevar el code coverage a 100% con test unitarios
8+
2019-12-06: Cersion 0.2.4 92%
9+
2019-09-23: Version 0.2.3 93%
610
2019-08-23: Current 93%
711
2019-08-09: Current 86%
812
2019-08-08: Current 84%

src/Shared/Fiel.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@ public function __construct(Credential $credential)
1616
$this->credential = $credential;
1717
}
1818

19-
public static function create(string $certificate, string $privateKey, string $passPhrase): self
19+
/**
20+
* Create a Fiel based on certificate and private key contents
21+
*
22+
* @param string $certificateContents Contents of X.509 formats PEM, DER or DER as base64
23+
* @param string $privateKeyContents Contents of PKCS#8 DER, PKCS#8 PEM or PKCS#5 PEM
24+
* @param string $passPhrase Private key pass phrase
25+
* @return static
26+
*/
27+
public static function create(string $certificateContents, string $privateKeyContents, string $passPhrase): self
2028
{
21-
$credential = Credential::create($certificate, $privateKey, $passPhrase);
29+
$credential = Credential::create($certificateContents, $privateKeyContents, $passPhrase);
2230
return new self($credential);
2331
}
2432

0 commit comments

Comments
 (0)