From 590ce88785467889e9f47f97f520d59f64a51a97 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Tue, 6 Nov 2018 00:16:00 -0500 Subject: [PATCH 1/5] check code 98 - En Proceso --- src/Ws/Services/ExtService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Ws/Services/ExtService.php b/src/Ws/Services/ExtService.php index bc17e9b..30aaedc 100644 --- a/src/Ws/Services/ExtService.php +++ b/src/Ws/Services/ExtService.php @@ -8,6 +8,7 @@ namespace Greenter\Ws\Services; +use Greenter\Model\Response\Error; use Greenter\Model\Response\StatusResult; /** @@ -44,6 +45,14 @@ public function getStatus($ticket) ->setCdrZip($cdrZip); $code = $result->getCdrResponse()->getCode(); + } else if ('98' == $code) { + $error = new Error(); + $error->setCode($code) + ->setMessage('El procesamiento del comprobante aún no ha terminado'); + + $result + ->setSuccess(false) + ->setError($error); } if ($this->isExceptionCode($code)) { From 5f1c78d1544af5628627bf15ee12f0b932b12138 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Tue, 6 Nov 2018 00:23:49 -0500 Subject: [PATCH 2/5] conditional descriptive --- src/Ws/Services/ExtService.php | 42 ++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Ws/Services/ExtService.php b/src/Ws/Services/ExtService.php index 30aaedc..3feb625 100644 --- a/src/Ws/Services/ExtService.php +++ b/src/Ws/Services/ExtService.php @@ -39,20 +39,18 @@ public function getStatus($ticket) ->setCode($code) ->setSuccess(true); - if ('0' == $code || '99' == $code) { + if ($this->isPending($code)) { + $this->loadCustomError($code, $result); + + return $result; + } + + if ($this->isProcessed($code)) { $result ->setCdrResponse($this->extractResponse($cdrZip)) ->setCdrZip($cdrZip); $code = $result->getCdrResponse()->getCode(); - } else if ('98' == $code) { - $error = new Error(); - $error->setCode($code) - ->setMessage('El procesamiento del comprobante aún no ha terminado'); - - $result - ->setSuccess(false) - ->setError($error); } if ($this->isExceptionCode($code)) { @@ -64,4 +62,30 @@ public function getStatus($ticket) return $result; } + + /** + * @param string $code + * @param StatusResult $result + */ + private function loadCustomError($code, StatusResult $result) + { + $error = new Error(); + $error->setCode($code) + ->setMessage('El procesamiento del comprobante aún no ha terminado'); + + $result + ->setSuccess(false) + ->setError($error); + } + + private function isProcessed($code) + { + return '0' == $code || '99' == $code; + } + + private function isPending($code) + { + return '98' == $code; + } + } From 3e0f44e7a360b9df8ea18d7ce3bfb80eed78966c Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Tue, 6 Nov 2018 00:35:32 -0500 Subject: [PATCH 3/5] get custom error --- src/Ws/Services/ExtService.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Ws/Services/ExtService.php b/src/Ws/Services/ExtService.php index 3feb625..832fad6 100644 --- a/src/Ws/Services/ExtService.php +++ b/src/Ws/Services/ExtService.php @@ -32,21 +32,20 @@ public function getStatus($ticket) ]; $response = $client->call('getStatus', ['parameters' => $params]); $status = $response->status; - $cdrZip = $status->content; $code = $status->statusCode; - $result - ->setCode($code) - ->setSuccess(true); + $result->setCode($code); if ($this->isPending($code)) { - $this->loadCustomError($code, $result); + $result->setError($this->getCustomError($code)); return $result; } if ($this->isProcessed($code)) { + $cdrZip = $status->content; $result + ->setSuccess(true) ->setCdrResponse($this->extractResponse($cdrZip)) ->setCdrZip($cdrZip); @@ -65,17 +64,15 @@ public function getStatus($ticket) /** * @param string $code - * @param StatusResult $result + * @return Error */ - private function loadCustomError($code, StatusResult $result) + private function getCustomError($code) { $error = new Error(); $error->setCode($code) ->setMessage('El procesamiento del comprobante aún no ha terminado'); - $result - ->setSuccess(false) - ->setError($error); + return $error; } private function isProcessed($code) @@ -87,5 +84,4 @@ private function isPending($code) { return '98' == $code; } - } From 0c74a1cd46b78c9a6d425bb954f1e3ffbc8c9ac2 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Tue, 6 Nov 2018 00:35:59 -0500 Subject: [PATCH 4/5] test pending code --- tests/Ws/Services/FeSunatTest.php | 12 ++++++++++++ tests/Ws/Services/FeSunatTestBase.php | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tests/Ws/Services/FeSunatTest.php b/tests/Ws/Services/FeSunatTest.php index 9d8fc52..016ab44 100644 --- a/tests/Ws/Services/FeSunatTest.php +++ b/tests/Ws/Services/FeSunatTest.php @@ -133,6 +133,18 @@ public function testGetStatus() $this->assertContains('aceptada', $result->getCdrResponse()->getDescription()); } + public function testGetStatusPending() + { + $service = $this->getExtServicePendingProcess(); + + $result = $service->getStatus('223123123213'); + + $this->assertFalse($result->isSuccess()); + $this->assertNull($result->getCdrResponse()); + $this->assertNotNull($result->getError()); + $this->assertNotEmpty($result->getError()->getMessage()); + } + /** * @dataProvider codeProvider * @param $code diff --git a/tests/Ws/Services/FeSunatTestBase.php b/tests/Ws/Services/FeSunatTestBase.php index f3e92fe..5887264 100644 --- a/tests/Ws/Services/FeSunatTestBase.php +++ b/tests/Ws/Services/FeSunatTestBase.php @@ -212,4 +212,25 @@ private function getErrorCodeProvider() /**@var $stub ErrorCodeProviderInterface */ return $stub; } + + /** + * @return ExtService + */ + protected function getExtServicePendingProcess() + { + $stub = $this->getMockBuilder(WsClientInterface::class) + ->getMock(); + $obj = new \stdClass(); + $obj->status = new \stdClass(); + $obj->status->statusCode = '98'; + + $stub->method('call') + ->willReturn($obj); + + /**@var $stub WsClientInterface */ + $sunat = new ExtService(); + $sunat->setClient($stub); + + return $sunat; + } } \ No newline at end of file From 4a5a242eb7142d39fa058bcdd18cf7f0b4163655 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Tue, 6 Nov 2018 00:37:09 -0500 Subject: [PATCH 5/5] remove cdr code from ExtService --- tests/Ws/Services/FeSunatTestBase.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/Ws/Services/FeSunatTestBase.php b/tests/Ws/Services/FeSunatTestBase.php index 5887264..4f16621 100644 --- a/tests/Ws/Services/FeSunatTestBase.php +++ b/tests/Ws/Services/FeSunatTestBase.php @@ -34,19 +34,12 @@ protected function getExtSender() ->getMock(); $stub->method('call') - ->will($this->returnCallback(function ($func, $params) { + ->will($this->returnCallback(function () { $zipContent = file_get_contents(__DIR__.'/../../Resources/cdrBaja.zip'); $obj = new \stdClass(); - if ($func == 'getStatus') { - $obj->status = new \stdClass(); - $obj->status->statusCode = '0'; - $obj->status->content = $zipContent; - } elseif ($func == 'getStatusCdr') { - $obj->statusCdr = new \stdClass(); - $obj->statusCdr->statusCode = '0'; - $obj->statusCdr->statusMessage = 'ACEPTADA'; - $obj->statusCdr->content = $zipContent; - } + $obj->status = new \stdClass(); + $obj->status->statusCode = '0'; + $obj->status->content = $zipContent; return $obj; }));