-
Notifications
You must be signed in to change notification settings - Fork 11
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 #8 from giansalex/feature/cdr-status-service
CDR status service
- Loading branch information
Showing
9 changed files
with
314 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<definitions xmlns:tns="http://service.sunat.gob.pe" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.sunat.gob.pe"> | ||
<types> | ||
<xsd:schema> | ||
<xsd:import namespace="http://service.sunat.gob.pe" schemaLocation="billConsultService.xsd"/> | ||
</xsd:schema> | ||
</types> | ||
<message name="getStatus"> | ||
<part name="parameters" element="tns:getStatus"/> | ||
</message> | ||
<message name="getStatusResponse"> | ||
<part name="parameters" element="tns:getStatusResponse"/> | ||
</message> | ||
<message name="getStatusCdr"> | ||
<part name="parameters" element="tns:getStatusCdr"/> | ||
</message> | ||
<message name="getStatusCdrResponse"> | ||
<part name="parameters" element="tns:getStatusCdrResponse"/> | ||
</message> | ||
<portType name="billService"> | ||
<operation name="getStatus"> | ||
<input xmlns:ns1="http://www.w3.org/2007/05/addressing/metadata" ns1:Action="urn:getStatus" message="tns:getStatus"/> | ||
<output xmlns:ns2="http://www.w3.org/2007/05/addressing/metadata" ns2:Action="http://service.sunat.gob.pe/billService/getStatusResponse" message="tns:getStatusResponse"/> | ||
</operation> | ||
<operation name="getStatusCdr"> | ||
<input xmlns:ns3="http://www.w3.org/2007/05/addressing/metadata" ns3:Action="urn:getStatusCdr" message="tns:getStatusCdr"/> | ||
<output xmlns:ns4="http://www.w3.org/2007/05/addressing/metadata" ns4:Action="http://service.sunat.gob.pe/billService/getStatusCdrResponse" message="tns:getStatusCdrResponse"/> | ||
</operation> | ||
</portType> | ||
</definitions> |
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,30 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://service.ws.consulta.comppago.electronico.registro.servicio2.sunat.gob.pe/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://service.ws.consulta.comppago.electronico.registro.servicio2.sunat.gob.pe/" name="billConsultService"> | ||
<import namespace="http://service.sunat.gob.pe" location="billConsultService.ns1.wsdl"/> | ||
<binding xmlns:ns1="http://service.sunat.gob.pe" name="BillConsultServicePortBinding" type="ns1:billService"> | ||
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/> | ||
<operation name="getStatusCdr"> | ||
<soap:operation soapAction="urn:getStatusCdr"/> | ||
<input> | ||
<soap:body use="literal"/> | ||
</input> | ||
<output> | ||
<soap:body use="literal"/> | ||
</output> | ||
</operation> | ||
<operation name="getStatus"> | ||
<soap:operation soapAction="urn:getStatus"/> | ||
<input> | ||
<soap:body use="literal"/> | ||
</input> | ||
<output> | ||
<soap:body use="literal"/> | ||
</output> | ||
</operation> | ||
</binding> | ||
<service name="billConsultService"> | ||
<port name="BillConsultServicePort" binding="tns:BillConsultServicePortBinding"> | ||
<soap:address location="https://e-factura.sunat.gob.pe/ol-it-wsconscpegem/billConsultService"/> | ||
</port> | ||
</service> | ||
</definitions> |
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,41 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<xsd:schema xmlns:ns0="http://service.sunat.gob.pe" xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
targetNamespace="http://service.sunat.gob.pe"> | ||
<xsd:complexType name="getStatus"> | ||
<xsd:sequence> | ||
<xsd:element name="rucComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="tipoComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="serieComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="numeroComprobante" type="xsd:int" minOccurs="0"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
<xsd:complexType name="getStatusResponse"> | ||
<xsd:sequence> | ||
<xsd:element name="status" type="ns0:statusResponse" minOccurs="0"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
<xsd:complexType name="getStatusCdrResponse"> | ||
<xsd:sequence> | ||
<xsd:element name="statusCdr" type="ns0:statusResponse" minOccurs="0"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
<xsd:complexType name="statusResponse"> | ||
<xsd:sequence> | ||
<xsd:element name="content" type="xsd:base64Binary" minOccurs="0"/> | ||
<xsd:element name="statusCode" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="statusMessage" type="xsd:string" minOccurs="0"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
<xsd:complexType name="getStatusCdr"> | ||
<xsd:sequence> | ||
<xsd:element name="rucComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="tipoComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="serieComprobante" type="xsd:string" minOccurs="0"/> | ||
<xsd:element name="numeroComprobante" type="xsd:int" minOccurs="0"/> | ||
</xsd:sequence> | ||
</xsd:complexType> | ||
<xsd:element name="getStatus" type="ns0:getStatus"/> | ||
<xsd:element name="getStatusResponse" type="ns0:getStatusResponse"/> | ||
<xsd:element name="getStatusCdrResponse" type="ns0:getStatusCdrResponse"/> | ||
<xsd:element name="getStatusCdr" type="ns0:getStatusCdr"/> | ||
</xsd:schema> |
File renamed without changes.
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,77 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Administrador | ||
* Date: 02/10/2017 | ||
* Time: 10:10 AM. | ||
*/ | ||
|
||
namespace Greenter\Ws\Services; | ||
|
||
use Greenter\Model\Response\StatusCdrResult; | ||
|
||
/** | ||
* Class ConsultCdrService. | ||
*/ | ||
class ConsultCdrService extends BaseSunat | ||
{ | ||
/** | ||
* Obtiene el estado del comprobante. | ||
* | ||
* @param string $ruc | ||
* @param string $tipo | ||
* @param string $serie | ||
* @param int $numero | ||
* | ||
* @return StatusCdrResult | ||
*/ | ||
public function getStatus($ruc, $tipo, $serie, $numero) | ||
{ | ||
return $this->getStatusResult('getStatus', 'status', $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', 'statusCdr', $ruc, $tipo, $serie, $numero); | ||
} | ||
|
||
private function getStatusResult($method, $resultName, $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->{$resultName}; | ||
|
||
$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; | ||
} | ||
} |
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,61 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Giansalex | ||
* Date: 09/09/2018 | ||
* Time: 15:16 | ||
*/ | ||
|
||
namespace Tests\Greenter\Ws\Services; | ||
|
||
class ConsultCdrServiceTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
use ConsultCdrServiceTrait; | ||
|
||
public function testGetStatusInvalidUser() | ||
{ | ||
$service = $this->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()); | ||
} | ||
} |
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,71 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Giansalex | ||
* Date: 09/09/2018 | ||
* Time: 15:19 | ||
*/ | ||
|
||
namespace Tests\Greenter\Ws\Services; | ||
|
||
use Greenter\Ws\Services\ConsultCdrService; | ||
use Greenter\Ws\Services\SoapClient; | ||
use Greenter\Ws\Services\SunatEndpoints; | ||
use Greenter\Ws\Services\WsClientInterface; | ||
|
||
/** | ||
* Trait ConsultCdrServiceTrait | ||
* | ||
* @method \PHPUnit_Framework_MockObject_MockBuilder getMockBuilder($className) | ||
*/ | ||
trait ConsultCdrServiceTrait | ||
{ | ||
/** | ||
* @return ConsultCdrService | ||
*/ | ||
private function getConsultService() | ||
{ | ||
$client = new SoapClient(__DIR__.'/../../../src/Resources/wsdl/billConsultService.wsdl'); | ||
$client->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; | ||
} | ||
} |