From d8a71b65ef9606a35872a7d9db5032266da35c80 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 9 Sep 2018 15:02:30 -0500 Subject: [PATCH 1/5] add status cdr consult service --- src/Ws/Services/ConsultCdrService.php | 77 +++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Ws/Services/ConsultCdrService.php diff --git a/src/Ws/Services/ConsultCdrService.php b/src/Ws/Services/ConsultCdrService.php new file mode 100644 index 0000000..cae5400 --- /dev/null +++ b/src/Ws/Services/ConsultCdrService.php @@ -0,0 +1,77 @@ +getStatusResult('getStatus', $ruc, $tipo, $serie, $numero); + } + + /** + * Obtiene el CDR del comprobante. + * + * @param string $ruc + * @param string $tipo + * @param string $serie + * @param int $numero + * + * @return StatusCdrResult + */ + public function getStatusCdr($ruc, $tipo, $serie, $numero) + { + return $this->getStatusResult('getStatusCdr', $ruc, $tipo, $serie, $numero); + } + + private function getStatusResult($method, $ruc, $tipo, $serie, $numero) + { + $client = $this->getClient(); + $result = new StatusCdrResult(); + + try { + $params = [ + 'rucComprobante' => $ruc, + 'tipoComprobante' => $tipo, + 'serieComprobante' => $serie, + 'numeroComprobante' => $numero, + ]; + $response = $client->call($method, ['parameters' => $params]); + $statusCdr = $response->statusCdr; + + $result->setCode($statusCdr->statusCode) + ->setMessage($statusCdr->statusMessage) + ->setCdrZip($statusCdr->content) + ->setSuccess(true); + + if ($statusCdr->content) { + $result->setCdrResponse($this->extractResponse($statusCdr->content)); + } + } catch (\SoapFault $e) { + $result->setError($this->getErrorFromFault($e)); + } + + return $result; + } +} From bea722337c75d720602af7c98315f88bb39944ff Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 9 Sep 2018 15:04:10 -0500 Subject: [PATCH 2/5] deprecated ExtService::getCdrStatus --- src/Ws/Services/ExtService.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Ws/Services/ExtService.php b/src/Ws/Services/ExtService.php index 2af876a..904f1d6 100644 --- a/src/Ws/Services/ExtService.php +++ b/src/Ws/Services/ExtService.php @@ -52,10 +52,12 @@ public function getStatus($ticket) } /** + * @deprecated Use instead \Greenter\Ws\Services\ConsultCdrService + * * @param string $ruc * @param string $tipo * @param string $serie - * @param string $numero + * @param int $numero * * @return StatusCdrResult */ From bcdba6b4e1038bbbed0dc7020614ae3945c62655 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 9 Sep 2018 15:38:25 -0500 Subject: [PATCH 3/5] add wsdl consult service --- .../wsdl/billConsultService.ns1.wsdl | 30 ++++++++++++++ src/Resources/wsdl/billConsultService.wsdl | 30 ++++++++++++++ src/Resources/wsdl/billConsultService.xsd | 41 +++++++++++++++++++ .../wsdl/{ns1.wsdl => billService.ns1.wsdl} | 0 src/Resources/wsdl/billService.wsdl | 2 +- 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 src/Resources/wsdl/billConsultService.ns1.wsdl create mode 100644 src/Resources/wsdl/billConsultService.wsdl create mode 100644 src/Resources/wsdl/billConsultService.xsd rename src/Resources/wsdl/{ns1.wsdl => billService.ns1.wsdl} (100%) diff --git a/src/Resources/wsdl/billConsultService.ns1.wsdl b/src/Resources/wsdl/billConsultService.ns1.wsdl new file mode 100644 index 0000000..6923f5a --- /dev/null +++ b/src/Resources/wsdl/billConsultService.ns1.wsdl @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resources/wsdl/billConsultService.wsdl b/src/Resources/wsdl/billConsultService.wsdl new file mode 100644 index 0000000..ed306e0 --- /dev/null +++ b/src/Resources/wsdl/billConsultService.wsdl @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resources/wsdl/billConsultService.xsd b/src/Resources/wsdl/billConsultService.xsd new file mode 100644 index 0000000..ace3eda --- /dev/null +++ b/src/Resources/wsdl/billConsultService.xsd @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Resources/wsdl/ns1.wsdl b/src/Resources/wsdl/billService.ns1.wsdl similarity index 100% rename from src/Resources/wsdl/ns1.wsdl rename to src/Resources/wsdl/billService.ns1.wsdl diff --git a/src/Resources/wsdl/billService.wsdl b/src/Resources/wsdl/billService.wsdl index db735b3..b448a8e 100644 --- a/src/Resources/wsdl/billService.wsdl +++ b/src/Resources/wsdl/billService.wsdl @@ -1,7 +1,7 @@ - + From 1ee4f31d889dde69b6c5c8d4093307f702317934 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 9 Sep 2018 15:38:57 -0500 Subject: [PATCH 4/5] fix result object name --- src/Ws/Services/ConsultCdrService.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Ws/Services/ConsultCdrService.php b/src/Ws/Services/ConsultCdrService.php index cae5400..46c212f 100644 --- a/src/Ws/Services/ConsultCdrService.php +++ b/src/Ws/Services/ConsultCdrService.php @@ -27,7 +27,7 @@ class ConsultCdrService extends BaseSunat */ public function getStatus($ruc, $tipo, $serie, $numero) { - return $this->getStatusResult('getStatus', $ruc, $tipo, $serie, $numero); + return $this->getStatusResult('getStatus', 'status', $ruc, $tipo, $serie, $numero); } /** @@ -42,10 +42,10 @@ public function getStatus($ruc, $tipo, $serie, $numero) */ public function getStatusCdr($ruc, $tipo, $serie, $numero) { - return $this->getStatusResult('getStatusCdr', $ruc, $tipo, $serie, $numero); + return $this->getStatusResult('getStatusCdr', 'statusCdr', $ruc, $tipo, $serie, $numero); } - private function getStatusResult($method, $ruc, $tipo, $serie, $numero) + private function getStatusResult($method, $resultName, $ruc, $tipo, $serie, $numero) { $client = $this->getClient(); $result = new StatusCdrResult(); @@ -58,7 +58,7 @@ private function getStatusResult($method, $ruc, $tipo, $serie, $numero) 'numeroComprobante' => $numero, ]; $response = $client->call($method, ['parameters' => $params]); - $statusCdr = $response->statusCdr; + $statusCdr = $response->{$resultName}; $result->setCode($statusCdr->statusCode) ->setMessage($statusCdr->statusMessage) From 816036f263240c5508360981febd808bb4e20b06 Mon Sep 17 00:00:00 2001 From: Giancarlos Salas Date: Sun, 9 Sep 2018 15:39:13 -0500 Subject: [PATCH 5/5] add consult cdr service Tests --- tests/Ws/Services/ConsultCdrServiceTest.php | 61 +++++++++++++++++ tests/Ws/Services/ConsultCdrServiceTrait.php | 71 ++++++++++++++++++++ 2 files changed, 132 insertions(+) create mode 100644 tests/Ws/Services/ConsultCdrServiceTest.php create mode 100644 tests/Ws/Services/ConsultCdrServiceTrait.php diff --git a/tests/Ws/Services/ConsultCdrServiceTest.php b/tests/Ws/Services/ConsultCdrServiceTest.php new file mode 100644 index 0000000..e2bddae --- /dev/null +++ b/tests/Ws/Services/ConsultCdrServiceTest.php @@ -0,0 +1,61 @@ +getConsultService(); + + $result = $service->getStatus('20000000001', '01','F001', 1); + + $this->assertFalse($result->isSuccess()); + $this->assertNotNull($result->getError()); + $this->assertEquals('00103', $result->getError()->getCode()); + } + + public function testGetStatusCdrInvalidUser() + { + $service = $this->getConsultService(); + + $result = $service->getStatusCdr('20000000001', '01','F001', 1); + + $this->assertFalse($result->isSuccess()); + $this->assertNull($result->getCdrZip()); + $this->assertNotNull($result->getError()); + $this->assertEquals('00103', $result->getError()->getCode()); + } + + public function testGetStatus() + { + $wss = $this->getConsultSender(); + $result = $wss->getStatus('20000000001', '01', 'F001', '1'); + + $this->assertTrue($result->isSuccess()); + $this->assertEquals('0', $result->getCode()); + $this->assertNotEmpty($result->getMessage()); + $this->assertNull($result->getCdrResponse()); + $this->assertContains('aceptada', strtolower($result->getMessage())); + } + + public function testGetCdrStatus() + { + $wss = $this->getConsultSender(); + $result = $wss->getStatusCdr('20000000001', '01', 'F001', '1'); + + $this->assertTrue($result->isSuccess()); + $this->assertEquals('0', $result->getCode()); + $this->assertNotEmpty($result->getMessage()); + $this->assertNotNull($result->getCdrResponse()); + $this->assertContains('aceptada', $result->getCdrResponse()->getDescription()); + } +} \ No newline at end of file diff --git a/tests/Ws/Services/ConsultCdrServiceTrait.php b/tests/Ws/Services/ConsultCdrServiceTrait.php new file mode 100644 index 0000000..620690b --- /dev/null +++ b/tests/Ws/Services/ConsultCdrServiceTrait.php @@ -0,0 +1,71 @@ +setService(SunatEndpoints::FE_CONSULTA_CDR); + $client->setCredentials('20000000001MODATOS', 'modatos'); + + $sunat = new ConsultCdrService(); + $sunat->setClient($client); + + return $sunat; + } + + /** + * @return ConsultCdrService + */ + private function getConsultSender() + { + $stub = $this->getMockBuilder(WsClientInterface::class) + ->getMock(); + + $stub->method('call') + ->will($this->returnCallback(function ($func, $params) { + $obj = new \stdClass(); + if ($func == 'getStatus') { + $obj->status = new \stdClass(); + $obj->status->statusCode = '0'; + $obj->status->statusMessage = 'ACEPTADA'; + $obj->status->content = null; + } elseif ($func == 'getStatusCdr') { + $zipContent = file_get_contents(__DIR__.'/../../Resources/cdrBaja.zip'); + $obj->statusCdr = new \stdClass(); + $obj->statusCdr->statusCode = '0'; + $obj->statusCdr->statusMessage = 'ACEPTADA'; + $obj->statusCdr->content = $zipContent; + } + + return $obj; + })); + + /**@var $stub WsClientInterface */ + $sunat = new ConsultCdrService(); + $sunat->setClient($stub); + + return $sunat; + } +} \ No newline at end of file