Skip to content

Commit

Permalink
Retificado ATM.
Browse files Browse the repository at this point in the history
  • Loading branch information
icompsoftcleiton committed Jun 10, 2022
1 parent 8620bd6 commit b351aa3
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/local
./composer.lock
/.idea
/composer.lock
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"php" : ">=7.0",
"php" : "^7|^8",
"nfephp-org/sped-common" : "^5.0"
},
"require-dev": {
Expand Down
51 changes: 51 additions & 0 deletions examples/fixtures/Atm/request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:ATMWebSvr">
<soapenv:Body>
<averbaCTe>
<usuario>WS</usuario>
<senha>usuario</senha>
<codatm>sua_senha</codatm>
<xmlCTe>
xml
</infCTeSupl>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<Reference URI="#CTe51220628125153000184570010000000831803406418">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<DigestValue>nwUjcJGlCmjRfnVM+c743OODCXo=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>
V62qis3PiCULV0F9+qJmmPmXsRaBM0F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DBKAvEy0yOTA3MTk4MjA2OTcyMjI0OTc3MDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDCgFwYFYEwBAwegDhMMMDAwMDAwMDAwMDAwMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDBDAJBgNVHRMEAjAAMA0GCSqGSIb3DQEBCwUAA4ICAQCXeHBSNs3E87Hticui6ePW4k+1PIBzHUYYBLcAbYf4QoG92wPQluSvbYKyYtU0k36bF1PPNciEW4maA2wmyjIu6y9YpU2gcnzP48d8cZLf+1AWQ5qdCANxv0kYRY41e0AsCGz4K/FkAqxBh3dP8qSMTanr8HxBoaGyEfbVSKP289LfGSTkMO+bDDCmfXReuEu5Xyj8/E6YjVh+ZFMuPRGvgH5BXejFPpWpmkZMXUgkkImAyBL88ZV4skBQ3mIcdNaIngUJy2zpTfy3gb/kSByvFXnfX1gcxbSKVmHQf/8WZ8gTv3R/GjSh2LXYZVzn2MjVTTnzkD7kkTeqZQxSq4dcp6wQPMlm2xv3aJjBx62HjgkuIYaqK8zcI+uugMiOFsJD4Z/42z1z763IRZsEEIAt/iIo4INCCnrz2GQDYyPXnyxHPjHrcuj6UjK/sI0vLDqk1qvKUWu2s6uNLcdV0yOYllq5vI1Et8RFhsBCi6x0Q92AGIRWKdp4Vyq8f78nVA0a78tVd77qFfm16MfuKCMDeRQho3Er2r+WWyv7NZTDN7cLLrth9+RP3Ht2XMV9oUaZMyUfbSZXD4NKOUwxYcqfiaA3DVzuMSOAyvPIwSOVz5HYxCCUMMMeZ3yMHKlzY3EFTtHSSbpRZIlAi/O6UTZZb6a+oS/MNrFiEoJ2JzMdrw==
</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</CTe>
<protCTe versao="3.00">
<infProt>
<tpAmb>1</tpAmb>
<verAplic>3.00</verAplic>
<chCTe>51220628125153000184570010000000831803406418</chCTe>
<dhRecbto>2022-06-10T09:37:44-04:00</dhRecbto>
<nProt>151220539988820</nProt>
<digVal>nwUjcJGlCmjRfnVM+c743OODCXo=</digVal>
<cStat>100</cStat>
<xMotivo>Autorizado o uso da CT-e</xMotivo>
</infProt>
</protCTe>
</cteProc>]]></xmlCTe></averbaCTe></soapenv:Body></soapenv:Envelope>
112 changes: 112 additions & 0 deletions examples/fixtures/Atm/response.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:averbaCTeResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<Response>
<Filial></Filial>
<CNPJCli></CNPJCli>
<Erros>
<Erro>
<Codigo>904</Codigo>
<Descricao>Acesso nao autorizado</Descricao>
</Erro>
</Erros>
</Response>
</ns1:averbaCTeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
<faultactor xsi:type="xsd:string"></faultactor>
<faultstring xsi:type="xsd:string">error in msg parsing:
XML error parsing SOAP payload on line 4: Mismatched tag
</faultstring>
<detail xsi:type="xsd:string"></detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:averbaCTeResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<Response>
<Numero></Numero>
<Serie></Serie>
<Filial></Filial>
<Erros>
<Erro>
<Codigo>912</Codigo>
<Descricao>XML invalido para utilizacao neste webserver</Descricao>
</Erro>
</Erros>
</Response>
</ns1:averbaCTeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:averbaCTeResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<Response>
<Numero>83</Numero>
<Serie>1</Serie>
<Filial></Filial>
<CNPJCli>28125153000184</CNPJCli>
<TpDoc>2</TpDoc>
<Averbado>
<dhAverbacao>2022-06-10T12:04:25</dhAverbacao>
<Protocolo>CUE4FQ52NI4XN47D18518D9Y6QQXS</Protocolo>
<DadosSeguro>
<NumeroAverbacao>0651310222812515300018457001000000083120</NumeroAverbacao>
</DadosSeguro>
</Averbado>
<Infos>
<Info>
<Codigo>001</Codigo>
<Descricao>Documento ja averbado</Descricao>
</Info>
</Infos>
</Response>
</ns1:averbaCTeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

<?xml version="1.0" encoding="utf-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:averbaCTeResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<Response>
<Numero>1</Numero>
<Serie>3</Serie>
<Filial></Filial>
<CNPJCli>14491024000103</CNPJCli>
<TpDoc>6</TpDoc>
<Erros>
<Erro>
<Codigo>033</Codigo>
<Descricao>CNPJ emissor nao autorizado para averbar...</Descricao>
<ValorInformado>014491024000103</ValorInformado>
</Erro>
</Erros>
</Response>
</ns1:averbaCTeResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
29 changes: 14 additions & 15 deletions src/Atm.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@
* @link http://github.com/nfephp-org/sped-averbacao for the canonical source repository
*/

use NFePHP\Common\Strings;
use NFePHP\Common\Signer;
use NFePHP\Averbacao\Common\Tools as ToolsCommon;
use RuntimeException;
use InvalidArgumentException;
use NFePHP\Common\Strings;

class Atm extends ToolsCommon
{
/**
* @var string
*/
public $cUsuario = '';

/**
* @var string
*/
Expand Down Expand Up @@ -59,7 +56,7 @@ public function __construct($cUsuario, $cSenha, $cCodigo, $tpAmb)
$this->cCodigo = $cCodigo;
$this->tpAmb = $tpAmb;
}

/**
* Request authorization to issue XML in batch with one or more documents
* @param $cXml of CTe or MDFe
Expand Down Expand Up @@ -106,22 +103,24 @@ public function averbaXml($cXml, $cTipo)
$this->cUrl = 'http://homologaws.averba.com.br/20/index.soap?wsdl';
$this->cHost = 'homologaws.averba.com.br';
}
$cXml = htmlentities($cXml);
$request = "<$cTagAction>"
. "<usuario>$this->cUsuario</usuario>"
. "<senha>$this->cSenha</senha>"
. "<codatm>$this->cCodigo</codatm>"
. "<$cTagXml><![CDATA[$cXml]]></$cTagXml>"
. "<$cTagXml>$cXml</$cTagXml>"
. "</$cTagAction>";
$request = Strings::clearXmlString($request, true);
$cXmlSoap = '<?xml version="1.0" encoding="utf-8"?>';
$cXmlSoap .= '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
$cXmlSoap = '<?xml version="1.0" encoding="utf-8"?>';
$cXmlSoap .= '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:urn="urn:ATMWebSvr">';
$cXmlSoap .= '<soapenv:Body>';
$cXmlSoap .= $request;
$cXmlSoap .= '</soapenv:Body>';
$cXmlSoap .= '</soapenv:Envelope>';
$cXmlSoap .= '<soapenv:Body>';
$cXmlSoap .= $request;
$cXmlSoap .= '</soapenv:Body>';
$cXmlSoap .= '</soapenv:Envelope>';
$this->lastRequest = $cXmlSoap;
$this->lastResponse = $this->sendRequest($cXmlSoap);
return $this->lastResponse;
}
Expand Down
28 changes: 16 additions & 12 deletions src/Common/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,37 @@

namespace NFePHP\Averbacao\Common;

use DOMDocument;
use InvalidArgumentException;
use RuntimeException;
use NFePHP\Common\Signer;
use NFePHP\Averbacao\Common\Soap\SoapCurl;
use NFePHP\Common\Strings;
use NFePHP\Common\Soap\SoapInterface;

class Tools
{
/**
* @var string
*/
public $cAction ;
public $cAction;
/**
* @var string
*/
public $cUrl ;
public $cUrl;
/**
* @var string
*/
public $cHost ;
public $cHost;
/**
* soap class
* @var SoapInterface
*/
public $soap;

/**
* @var string
*/
public $lastRequest;
/**
* @var string
*/
public $lastResponse;

/**
* Send request message to webservice
* @param array $parameters
Expand All @@ -38,7 +42,7 @@ class Tools
protected function sendRequest($request)
{
$this->checkSoap();
return (string) $this->soap->send(
return (string)$this->soap->send(
$this->cUrl,
$request,
$this->cAction,
Expand All @@ -54,10 +58,10 @@ protected function checkSoap()
}
}

protected function sendRequestELTSEG($cUrl,$cXml)
protected function sendRequestELTSEG($cUrl, $cXml)
{
$this->soap = new SoapCurl();
return (string) $this->soap->sendELTSEG(
return (string)$this->soap->sendELTSEG(
$cUrl,
$cXml
);
Expand Down
14 changes: 4 additions & 10 deletions src/EltSeg.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
* @link http://github.com/nfephp-org/sped-averbacao for the canonical source repository
*/

use NFePHP\Common\Strings;
use NFePHP\Common\Signer;
use NFePHP\Averbacao\Common\Tools as ToolsCommon;
use RuntimeException;
use InvalidArgumentException;

class EltSeg extends ToolsCommon
{
Expand All @@ -35,7 +31,7 @@ class EltSeg extends ToolsCommon
public function __construct()
{
}

/**
* Request authorization to issue XML in batch with one or more documents
* @param $cXml of CTe/MDFe or NFe
Expand All @@ -48,11 +44,9 @@ public function averbaXml($cXml, $cFileName, $cCNPJ)
if (empty($cXml)) {
throw new \InvalidArgumentException('Um XML do (CTe,MDFe,NFe), protocolado deve ser passado.');
}

$nSize = strlen($cXml);
$cUrl = "http://www.eltseg05.com.br/eltws/eltws.svc/FileUploadXML?FileName=$cFileName&CNPJ=$cCNPJ&Length=$nSize";

$this->lastResponse = $this->sendRequestELTSEG($cUrl,$cXml);
$nSize = strlen($cXml);
$cUrl = "http://www.eltseg05.com.br/eltws/eltws.svc/FileUploadXML?FileName=$cFileName&CNPJ=$cCNPJ&Length=$nSize";
$this->lastResponse = $this->sendRequestELTSEG($cUrl, $cXml);
return $this->lastResponse;
}
}
Loading

0 comments on commit b351aa3

Please sign in to comment.