-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from eclipxe13/version-1.1.0
Soporte para RET 2.0 (versión 1.1.0)
- Loading branch information
Showing
19 changed files
with
355 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phive xmlns="https://phar.io/phive"> | ||
<phar name="phpcs" version="^3.6.2" installed="3.6.2" location="./tools/phpcs" copy="false"/> | ||
<phar name="phpcbf" version="^3.6.2" installed="3.6.2" location="./tools/phpcbf" copy="false"/> | ||
<phar name="php-cs-fixer" version="^3.8.0" installed="3.8.0" location="./tools/php-cs-fixer" copy="false"/> | ||
<phar name="phpstan" version="^1.6.8" installed="1.6.8" location="./tools/phpstan" copy="false"/> | ||
<phar name="phpcs" version="^3.7.1" installed="3.7.1" location="./tools/phpcs" copy="false"/> | ||
<phar name="phpcbf" version="^3.7.1" installed="3.7.1" location="./tools/phpcbf" copy="false"/> | ||
<phar name="php-cs-fixer" version="^3.9.2" installed="3.9.2" location="./tools/php-cs-fixer" copy="false"/> | ||
<phar name="phpstan" version="^1.8.0" installed="1.8.0" location="./tools/phpstan" copy="false"/> | ||
</phive> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Internal; | ||
|
||
use DOMDocument; | ||
use DOMXPath; | ||
|
||
/** @internal */ | ||
final class RetentionReader10 extends RetentionReaderXpath | ||
{ | ||
public function __construct(DOMDocument $document) | ||
{ | ||
$xpath = new DOMXPath($document); | ||
$xpath->registerNamespace('r', 'http://www.sat.gob.mx/esquemas/retencionpago/1'); | ||
$xpath->registerNamespace('t', 'http://www.sat.gob.mx/TimbreFiscalDigital'); | ||
|
||
parent::__construct( | ||
$xpath, | ||
'/r:Retenciones/@Version', | ||
'1.0', | ||
'/r:Retenciones/r:Complemento/t:TimbreFiscalDigital/@UUID', | ||
'/r:Retenciones/r:Emisor/@RFCEmisor', | ||
'/r:Retenciones/r:Receptor/r:Nacional/@RFCRecep' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Internal; | ||
|
||
use DOMDocument; | ||
use DOMXPath; | ||
|
||
/** @internal */ | ||
final class RetentionReader20 extends RetentionReaderXpath | ||
{ | ||
public function __construct(DOMDocument $document) | ||
{ | ||
$xpath = new DOMXPath($document); | ||
$xpath->registerNamespace('r', 'http://www.sat.gob.mx/esquemas/retencionpago/2'); | ||
$xpath->registerNamespace('t', 'http://www.sat.gob.mx/TimbreFiscalDigital'); | ||
|
||
parent::__construct( | ||
$xpath, | ||
'/r:Retenciones/@Version', | ||
'2.0', | ||
'/r:Retenciones/r:Complemento/t:TimbreFiscalDigital/@UUID', | ||
'/r:Retenciones/r:Emisor/@RfcE', | ||
'/r:Retenciones/r:Receptor/r:Nacional/@RfcR' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Internal; | ||
|
||
/** @internal */ | ||
interface RetentionReaderInterface | ||
{ | ||
public function matchDocument(): bool; | ||
|
||
public function obtainUUID(): string; | ||
|
||
public function obtainRfcIssuer(): string; | ||
|
||
public function obtainRfcReceiver(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Internal; | ||
|
||
use DOMNodeList; | ||
use DOMXPath; | ||
|
||
/** @internal */ | ||
abstract class RetentionReaderXpath implements RetentionReaderInterface | ||
{ | ||
private DOMXPath $xpath; | ||
|
||
private string $queryVersion; | ||
|
||
private string $expectedVersion; | ||
|
||
private string $queryUuid; | ||
|
||
private string $queryRfcIssuer; | ||
|
||
private string $queryRfcReceiver; | ||
|
||
public function __construct( | ||
DOMXPath $xpath, | ||
string $queryVersion, | ||
string $expectedVersion, | ||
string $queryUuid, | ||
string $queryRfcIssuer, | ||
string $queryRfcReceiver | ||
) { | ||
$this->xpath = $xpath; | ||
$this->queryVersion = $queryVersion; | ||
$this->expectedVersion = $expectedVersion; | ||
$this->queryUuid = $queryUuid; | ||
$this->queryRfcIssuer = $queryRfcIssuer; | ||
$this->queryRfcReceiver = $queryRfcReceiver; | ||
} | ||
|
||
public function matchDocument(): bool | ||
{ | ||
return ($this->expectedVersion === $this->obtainFirstAttributeValue($this->queryVersion)); | ||
} | ||
|
||
public function obtainUUID(): string | ||
{ | ||
return $this->obtainFirstAttributeValue($this->queryUuid); | ||
} | ||
|
||
public function obtainRfcIssuer(): string | ||
{ | ||
return $this->obtainFirstAttributeValue($this->queryRfcIssuer); | ||
} | ||
|
||
public function obtainRfcReceiver(): string | ||
{ | ||
return $this->obtainFirstAttributeValue($this->queryRfcReceiver); | ||
} | ||
|
||
private function obtainFirstAttributeValue(string $xquery): string | ||
{ | ||
$attributes = $this->xpath->query($xquery, null, false) ?: new DOMNodeList(); | ||
$attribute = $attributes->item(0); | ||
if (null === $attribute) { | ||
return ''; | ||
} | ||
return $attribute->nodeValue ?? ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Tests\Unit\Internal; | ||
|
||
use DOMDocument; | ||
use PhpCfdi\SatEstadoRetenciones\Internal\RetentionReader10; | ||
use PhpCfdi\SatEstadoRetenciones\Internal\RetentionReaderInterface; | ||
use PhpCfdi\SatEstadoRetenciones\Internal\RetentionReaderXpath; | ||
use PhpCfdi\SatEstadoRetenciones\Tests\TestCase; | ||
|
||
final class RetentionReader10Test extends TestCase | ||
{ | ||
public function testRetentionReaderDefinitionTest(): void | ||
{ | ||
$document = new DOMDocument(); | ||
$reader = new RetentionReader10($document); | ||
$this->assertInstanceOf(RetentionReaderInterface::class, $reader); | ||
$this->assertInstanceOf(RetentionReaderXpath::class, $reader); | ||
} | ||
|
||
public function testReadCfdiRetention(): void | ||
{ | ||
$document = new DOMDocument(); | ||
$document->load($this->filePath('ret10-mexican-real.xml')); | ||
$reader = new RetentionReader10($document); | ||
|
||
$this->assertSame('48C4CE37-E218-4AAE-97BE-20634A36C628', $reader->obtainUUID()); | ||
$this->assertSame('DCM991109KR2', $reader->obtainRfcIssuer()); | ||
$this->assertSame('SAZD861013FU2', $reader->obtainRfcReceiver()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpCfdi\SatEstadoRetenciones\Tests\Unit\Internal; | ||
|
||
use DOMDocument; | ||
use PhpCfdi\SatEstadoRetenciones\Internal\RetentionReader20; | ||
use PhpCfdi\SatEstadoRetenciones\Internal\RetentionReaderInterface; | ||
use PhpCfdi\SatEstadoRetenciones\Tests\TestCase; | ||
|
||
final class RetentionReader20Test extends TestCase | ||
{ | ||
public function testRetentionReaderDefinitionTest(): void | ||
{ | ||
$document = new DOMDocument(); | ||
$reader = new RetentionReader20($document); | ||
$this->assertInstanceOf(RetentionReaderInterface::class, $reader); | ||
} | ||
|
||
public function testReadCfdiRetentionMexican(): void | ||
{ | ||
$document = new DOMDocument(); | ||
$document->load($this->filePath('ret20-mexican-fake.xml')); | ||
$reader = new RetentionReader20($document); | ||
|
||
$this->assertSame('4E3DD8EA-5220-8C42-85A8-E37F9D7502F8', $reader->obtainUUID()); | ||
$this->assertSame('AAA010101AAA', $reader->obtainRfcIssuer()); | ||
$this->assertSame('SUL010720JN8', $reader->obtainRfcReceiver()); | ||
} | ||
|
||
public function testReadCfdiRetentionForeign(): void | ||
{ | ||
$document = new DOMDocument(); | ||
$document->load($this->filePath('ret20-foreign-fake.xml')); | ||
$reader = new RetentionReader20($document); | ||
|
||
$this->assertSame('4E3DD8EA-5220-8C42-85A8-E37F9D7502F8', $reader->obtainUUID()); | ||
$this->assertSame('AAA010101AAA', $reader->obtainRfcIssuer()); | ||
$this->assertSame('', $reader->obtainRfcReceiver()); | ||
} | ||
} |
Oops, something went wrong.