Skip to content

Commit

Permalink
Merge pull request #5 from eclipxe13/master
Browse files Browse the repository at this point in the history
Target 0.5.0
  • Loading branch information
eclipxe13 authored Mar 28, 2019
2 parents 53e6765 + c7cfcf5 commit bf7d459
Show file tree
Hide file tree
Showing 46 changed files with 529 additions and 1,211 deletions.
2 changes: 1 addition & 1 deletion .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare(strict_types=1);

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setCacheFile(__DIR__.'/build/.php_cs.cache')
->setCacheFile(__DIR__ . '/build/.php_cs.cache')
->setRules([
'@PSR2' => true,
'@PHP70Migration' => true,
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build:
analysis:
environment:
php:
version: 7.3
version: "7.3"
project_setup:
override: true
tests:
Expand Down
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ sudo: false

# php compatibility
php:
- 7.2
- 7.3
- "7.2"
- "7.3"

cache:
- directories:
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Contributing

Contributions are welcome. We accept pull requests on [GitHub](https://github.com/PhpCfdi/SatEstadoCfdi).
Contributions are welcome. We accept pull requests on [GitHub](https://github.com/phpcfdi/sat-estado-cfdi).

This project adheres to a
[Contributor Code of Conduct](https://github.com/PhpCfdi/SatEstadoCfdi/blob/master/CODE_OF_CONDUCT.md).
[Contributor Code of Conduct](https://github.com/phpcfdi/sat-estado-cfdi/blob/master/CODE_OF_CONDUCT.md).
By participating in this project and its community, you are expected to uphold this code.

## Team members

* [Carlos C Soto](https://github.com/eclipxe13) - original author and maintainer
* [GitHub constributors](https://github.com/PhpCfdi/SatEstadoCfdi/graphs/contributors)
* [GitHub constributors](https://github.com/phpcfdi/sat-estado-cfdi/graphs/contributors)

## Communication Channels

You can find help and discussion in the following places:

* GitHub Issues: <https://github.com/PhpCfdi/SatEstadoCfdi/issues>
* GitHub Issues: <https://github.com/phpcfdi/sat-estado-cfdi/issues>

## Reporting Bugs

Bugs are tracked in our project's [issue tracker](https://github.com/PhpCfdi/SatEstadoCfdi/issues).
Bugs are tracked in our project's [issue tracker](https://github.com/phpcfdi/sat-estado-cfdi/issues).

When submitting a bug report, please include enough information for us to reproduce the bug.
A good bug report includes the following sections:
Expand All @@ -42,8 +42,8 @@ section below, you may create bugfix branches and send us pull requests.
## Adding New Features

If you have an idea for a new feature, it's a good idea to check out our
[issues](https://github.com/PhpCfdi/SatEstadoCfdi/issues) or active
[pull requests](https://github.com/PhpCfdi/SatEstadoCfdi/pulls)
[issues](https://github.com/phpcfdi/sat-estado-cfdi/issues) or active
[pull requests](https://github.com/phpcfdi/sat-estado-cfdi/pulls)
first to see if the feature is already being worked on.
If not, feel free to submit an issue first, asking whether the feature is beneficial to the project.
This will save you from doing a lot of development work only to have your feature rejected.
Expand Down
161 changes: 56 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PhpCfdi/SatEstadoCfdi
# phpcfdi/sat-estado-cfdi

[![Source Code][badge-source]][source]
[![Latest Version][badge-release]][release]
Expand Down Expand Up @@ -28,13 +28,6 @@ La documentación del proyecto está en español porque ese es el lenguaje de lo
- Por una razón desconocida -e inexplicable-, el WSDL ya no se encuentra disponible desde 2018.
Aunque sí se puede consumir el servicio.

Esta librería **no utiliza SOAP** para hacer la llamada, hace una llamada HTTP que construye e interpreta.

Para contactar al servicio utiliza [PSR-18: HTTP Client](https://www.php-fig.org/psr/psr-18/)
y [PSR-17: HTTP Factories](https://www.php-fig.org/psr/psr-17/).
De esta forma, tu puedes usar el cliente HTTP que mejor te convenga.


## Instalación

Usa [composer](https://getcomposer.org/)
Expand All @@ -43,24 +36,19 @@ Usa [composer](https://getcomposer.org/)
composer require phpcfdi/sat-estado-cfdi
```

Si tienes problemas para instalar es probable que no cuentes con paques que satisfagan las dependencias de
[`psr/http-client-implementation`](https://packagist.org/providers/psr/http-client-implementation),
[`psr/http-message-implementation`](https://packagist.org/providers/psr/http-message-implementation) y
[`psr/http-factory-implementation`](https://packagist.org/providers/psr/http-factory-implementation).
Instala alguno de esos paquetes también. [Ver ejemplo](#compatibilidad-con-psr-7-psr-17-y-psr-18)

## Ejemplo básico de uso

Los pasos básicos son:

- Crear la fábrica de objetos `WebServiceFactory` [Ver ejemplo](#compatibilidad-con-psr-7-psr-17-y-psr-18).
- Pedirle a la fábrica de objetos que nos entregue un consumidor `Consumer`.
- Solicitarle al consumidor que ejecute la petición sobre una expresión.
- Tener un cliente que implemente `ConsumerClientInterface`.
- Crear un consumidor del servicio `Consumer`
- Realizar la solicitud con una *expresión* definida.
- Usar el resultado

```php
<?php
/** @var \PhpCfdi\SatEstadoCfdi\WebServiceFactory $factory */
$consumer = $factory->getConsumer();
/** @var \PhpCfdi\SatEstadoCfdi\Contracts\ConsumerClientInterface $client */
$consumer = new \PhpCfdi\SatEstadoCfdi\Consumer($client);

$response = $consumer->execute('...expression');

Expand All @@ -71,28 +59,30 @@ if ($response->cancellable()->isNotCancellable()) {

### Expresiones (input)

El consumidor requiere una expresión para poder consultar. Las expresiones son diferentes para CFDI 3.2 y 3.3.

Ejemplo de expresión para CFDI 3.3:
El consumidor requiere una expresión para poder consultar.
La expresión es el texto que viene en el código QR de la representación impresa de un CFDI.

```text
https://verificacfdi.facturaelectronica.sat.gob.mx/default.aspx?id=CEE4BE01-ADFA-4DEB-8421-ADD60F0BEDAC&re=POT9207213D6&rr=DIM8701081LA&tt=2010.01&fe=/OAgdg==
```
Las expresiones son diferentes para CFDI 3.2, CFDI 3.3 y RET 1.0.
Tienen reglas específicas de formato y de la información que debe contener.

Si no cuentas con ella, puedes usar el objeto `CfdiExpressionBuilder` para fabricarla:
Si no cuentas con la expresión, te recomiendo usar la librería
[`phpcfdi/cfdi-expresiones`](https://github.com/phpcfdi/cfdi-expresiones) que puedes instalar
usando `composer require phpcfdi/cfdi-expresiones`.

```php
<?php
// lectura del contenido del CFDI
$cfdiContents = file_get_contents('cfdi.xml');
$builder = \PhpCfdi\SatEstadoCfdi\CfdiExpressionBuilder::createFromString($cfdiContents);
$parameters = $builder->build();
$expression = $parameters->expression();
$document = new DOMDocument();
$document->load('archivo-cfdi33.xml');

// creación de la expresión
$expressionExtractor = new \PhpCfdi\CfdiExpresiones\DiscoverExtractor();
$expression = $expressionExtractor->extract($document);
```

### Estados (salida)

Después de consumir el servicio, se responderá con un objeto con estados.
Después de consumir el servicio, se responderá con un objeto `CfdiStatus` que agrupa de los cuatro estados.

No compares directamente los valores de los estados, en su lugar utiliza los métodos `is*`,
por ejemplo `$response->active()->isCancelled()`.
Expand Down Expand Up @@ -147,73 +137,34 @@ Eso significa que podrías tener el CFDI en estado de cancelación *en proceso*
O, incluso, que la cancelación suceda meses después de lo esperado.


### Compatibilidad con PSR-7 PSR-17 y PSR-18

Esta librería busca alta compatibilidad con los estándares propuestos por el [PHP-FIG](https://www.php-fig.org/).
Por lo que utiliza los siguientes estándares.

- PSR-7: HTTP message interfaces: Interfaces de HTTP Request y Response.
<https://www.php-fig.org/psr/psr-7/>
- PSR-17: HTTP Factories: Interfaces de fábricas de HTTP Request y Response (para PSR-7).
<https://www.php-fig.org/psr/psr-17/>
- PSR-18: HTTP Client: Interfaces para clientes HTTP (el que hace la llamada POST).
<https://www.php-fig.org/psr/psr-18/>

Esta librería no contiene las implementaciones de los estándares,
las librerías que implementan las interfaces ya existen fuera del ámbito de la aplicación.

Te recomiendo usar las librerías de Sunrise
[`sunrise/http-client-curl`](https://github.com/sunrise-php/http-client-curl),
[`sunrise/http-factory`](https://github.com/sunrise-php/http-factory) y
[`sunrise/http-message`](https://github.com/sunrise-php/http-message).

```shell
# librerías para implementar PSR-18, PSR-17 y PSR-7
composer require sunrise/http-client-curl sunrise/http-factory sunrise/http-message
```

Y puedes crear tu cliente de esta forma:
## Clientes de conexión

```php
<?php
use PhpCfdi\SatEstadoCfdi\WebServiceFactory;

function createSunriseSatEstadoCfdiFactory(): WebServiceFactory {
$responseFactory = new Sunrise\Http\Factory\ResponseFactory();
$requestFactory = new Sunrise\Http\Factory\RequestFactory();
$streamFactory = new Sunrise\Http\Factory\StreamFactory();
$httpClient = new \Sunrise\Http\Client\Curl\Client($responseFactory, $streamFactory);
return new WebServiceFactory($httpClient, $requestFactory, $streamFactory);
}
Esta librería no es la que hace directamente las conexión al webservice del SAT.

$consumer = createSunriseSatEstadoCfdiFactory()->getConsumer();
```
Esta función se la delega a un objeto `ConsumerClientInterface`.

Tu puedes implementar tu cliente de conexión personalizado para tu entorno siempre que
implementes la interfaz `ConsumerClientInterface`.

### Compatibilidad con HTTP Plug
O si lo prefieres, existen los siguientes consumidores oficiales:

Si tu aplicación usa HTTP Plug o es compatible con
[`php-http/discovery`](http://docs.php-http.org/en/latest/discovery.html)
entonces podrías usar la clase `WebServiceDiscover`.
- [phpcfdi/sat-estado-cfdi-soap](https://github.com/phpcfdi/sat-estado-cfdi-soap):
Consume el webservice haciendo una llamada SOAP (sin WSDL) para obtener el resultado.
- [phpcfdi/sat-estado-cfdi-http-psr](https://github.com/phpcfdi/sat-estado-cfdi-http-psr)
Consume el webservice haciendo una HTTP utilizando objetos de PSR-7, PSR17 y PSR18 *que tu provees*.
- [phpcfdi/sat-estado-cfdi-http-sunrise](https://github.com/phpcfdi/sat-estado-cfdi-http-sunrise)
Consume el webservice haciendo una HTTP utilizando objetos de PSR-7, PSR17 y PSR18 con los paquetes de *sunrise*.

```php
<?php
$discover = new \PhpCfdi\SatEstadoCfdi\WebServiceDiscover();
$factory = $discover->createFactory();
$consumer = $factory->getConsumer();
```
### Prueba de cumplimiento de implementación

En el archivo [`tests/Discoverables/Sunrise.php`](tests/Discoverables/Sunrise.php)
puedes ver una clase para que las implementaciones de Sunrise sean automáticamente descubiertas.
Se incluye la clase `PhpCfdi\SatEstadoCfdi\ComplianceTester\ComplianceTester` que contacta al
webservice del SAT con datos conocidos y evalua la respuesta.

Para decirle al descubridor de componentes de HTTP Plug que las reconozca incluye las siguientes
líneas:
Los paquetes `phpcfdi/sat-estado-cfdi-soap` y `phpcfdi/sat-estado-cfdi-http-sunrise` implementan
un test para asegurarse que cumplen correctamente.

```php
<?php
\Http\Discovery\Psr17FactoryDiscovery::prependStrategy(\PhpCfdi\SatEstadoCfdi\Tests\Discoverables\Sunrise::class);
\Http\Discovery\Psr18ClientDiscovery::prependStrategy(\PhpCfdi\SatEstadoCfdi\Tests\Discoverables\Sunrise::class);
```
Si haces tu propia implementación, asegúrate de crear un test que lo cubra, puedes ver como ejemplo
<https://github.com/phpcfdi/sat-estado-cfdi-soap/blob/master/tests/Compliance/ComplianceTest.php>


## Compatilibilidad
Expand All @@ -227,32 +178,32 @@ sin temor a romper tu aplicación.

## Contribuciones

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


## Copyright and License

The PhpCfdi/SatEstadoCfdi library is copyright © [Carlos C Soto](http://eclipxe.com.mx/)
The phpcfdi/sat-estado-cfdi library is copyright © [Carlos C Soto](http://eclipxe.com.mx/)
and licensed for use under the MIT License (MIT). Please see [LICENSE][] for more information.


[contributing]: https://github.com/PhpCfdi/SatEstadoCfdi/blob/master/CONTRIBUTING.md
[changelog]: https://github.com/PhpCfdi/SatEstadoCfdi/blob/master/docs/CHANGELOG.md
[todo]: https://github.com/PhpCfdi/SatEstadoCfdi/blob/master/docs/TODO.md
[contributing]: https://github.com/phpcfdi/sat-estado-cfdi/blob/master/CONTRIBUTING.md
[changelog]: https://github.com/phpcfdi/sat-estado-cfdi/blob/master/docs/CHANGELOG.md
[todo]: https://github.com/phpcfdi/sat-estado-cfdi/blob/master/docs/TODO.md

[source]: https://github.com/PhpCfdi/SatEstadoCfdi
[release]: https://github.com/PhpCfdi/SatEstadoCfdi/releases
[license]: https://github.com/PhpCfdi/SatEstadoCfdi/blob/master/LICENSE
[build]: https://travis-ci.org/phpcfdi/SatEstadoCfdi?branch=master
[quality]: https://scrutinizer-ci.com/g/PhpCfdi/SatEstadoCfdi/
[coverage]: https://scrutinizer-ci.com/g/PhpCfdi/SatEstadoCfdi/code-structure/master/code-coverage
[source]: https://github.com/phpcfdi/sat-estado-cfdi
[release]: https://github.com/phpcfdi/sat-estado-cfdi/releases
[license]: https://github.com/phpcfdi/sat-estado-cfdi/blob/master/LICENSE
[build]: https://travis-ci.org/phpcfdi/sat-estado-cfdi?branch=master
[quality]: https://scrutinizer-ci.com/g/phpcfdi/sat-estado-cfdi/
[coverage]: https://scrutinizer-ci.com/g/phpcfdi/sat-estado-cfdi/code-structure/master/code-coverage
[downloads]: https://packagist.org/packages/phpcfdi/sat-estado-cfdi

[badge-source]: http://img.shields.io/badge/source-PhpCfdi/SatEstadoCfdi-blue.svg?style=flat-square
[badge-release]: https://img.shields.io/github/release/PhpCfdi/SatEstadoCfdi.svg?style=flat-square
[badge-source]: http://img.shields.io/badge/source-phpcfdi/sat--estado--cfdi-blue.svg?style=flat-square
[badge-release]: https://img.shields.io/github/release/phpcfdi/sat-estado-cfdi.svg?style=flat-square
[badge-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/phpcfdi/SatEstadoCfdi/master.svg?style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/PhpCfdi/SatEstadoCfdi/master.svg?style=flat-square
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/PhpCfdi/SatEstadoCfdi/master.svg?style=flat-square
[badge-build]: https://img.shields.io/travis/phpcfdi/sat-estado-cfdi/master.svg?style=flat-square
[badge-quality]: https://img.shields.io/scrutinizer/g/phpcfdi/sat-estado-cfdi/master.svg?style=flat-square
[badge-coverage]: https://img.shields.io/scrutinizer/coverage/g/phpcfdi/sat-estado-cfdi/master.svg?style=flat-square
[badge-downloads]: https://img.shields.io/packagist/dt/phpcfdi/sat-estado-cfdi.svg?style=flat-square
25 changes: 8 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "phpcfdi/sat-estado-cfdi",
"description": "Consulta el estado de un cfdi en el webservice del SAT",
"keywords": ["sat", "cfdi", "ConsultaCFDIService.svc"],
"homepage": "https://github.com/PhpCfdi/SatEstadoCfdi",
"keywords": ["phpcfdi", "sat", "cfdi", "ConsultaCFDIService.svc"],
"homepage": "https://github.com/phpcfdi/sat-estado-cfdi",
"license": "MIT",
"authors": [
{
Expand All @@ -21,30 +21,21 @@
"require": {
"php": ">=7.2",
"ext-dom": "*",
"eclipxe/enum": "^0.2",
"psr/http-client": "^1.0",
"psr/http-message": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-client-implementation": "^1.0",
"psr/http-message-implementation": "^1.0",
"psr/http-factory-implementation": "^1.0",
"php-http/discovery": "^1.6"
"eclipxe/enum": "^0.2"
},
"require-dev": {
"ext-curl": "*",
"sunrise/http-client-curl": "^1.0.3",
"sunrise/http-factory": "^1.0",
"sunrise/http-message": "^1.0",
"phpcfdi/cfdi-expresiones": "^2.0",
"phpunit/phpunit": "^8.0",
"overtrue/phplint": "^1.0",
"squizlabs/php_codesniffer": "^3.0",
"friendsofphp/php-cs-fixer": "^2.4",
"phpstan/phpstan-shim": "^0.11"
},
"suggest": {
"sunrise/http-client-curl": "PSR-18: HTTP Client implementation",
"sunrise/http-factory": "PSR-17: HTTP Factories implementation",
"sunrise/http-message": "PSR-7: HTTP message interfaces implementation"
"phpcfdi/cfdi-expresiones": "Utilería para crear expresiones de CFD 3.2, CFDI 3.3 y RET 1.0",
"phpcfdi/sat-estado-cfdi-soap": "Consume webservice using SOAP (ext-soap) without WSDL",
"phpcfdi/sat-estado-cfdi-http-psr": "Consume webservice using PSR-7, PSR17 y PSR18 (provided by you)",
"phpcfdi/sat-estado-cfdi-http-sunrise": "Consume webservice using PSR-7, PSR17 y PSR18 (sunrise based)"
},
"autoload": {
"psr-4": {
Expand Down
18 changes: 12 additions & 6 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
# CHANGELOG

## About SemVer
## Version 0.5.0 2019-03-28

In summary, [SemVer](https://semver.org/) can be viewed as ` Breaking . Feature . Fix `, where:
- Remove `CfdiExpression` and `CfdiExpressionBuilder` (now on its own project `phpcfdi/cfdi-expresiones`)
- Rename `ResponseStatus` to `CfdiStatus`
- Rename `ResponseStatusBuilder` to `Utils\CfdiStatusBuilder`
- Rename `ConsumerClientResponse` to `Utils\ConsumerClientResponse`
- Rename `WebServiceConsumer` to `Consumer`
- Document usage example on `README.md`.

- Breaking version = includes incompatible changes to the API
- Feature version = adds new feature(s) in a backwards-compatible manner
- Fix version = includes backwards-compatible bug fixes

**Version `0.x.x` doesn't have to apply any of the SemVer rules**
## Version 0.4.0 2019-03-25

- Split this package to separate concerns.
- More information about this separation of concerns inside `docs/DEVNOTES.md`.
- Rewrite `README.md`


## Version 0.3.0 2019-03-25
Expand Down
Loading

0 comments on commit bf7d459

Please sign in to comment.