Skip to content

Commit 4e2daab

Browse files
authored
Merge pull request #5 from tecnospeed/feature/downloadXml
Feature/download xml
2 parents 1a4898c + 1766f32 commit 4e2daab

File tree

5 files changed

+565
-6
lines changed

5 files changed

+565
-6
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# Changelog
22
Alterações na biblioteca
33

4+
## [1.4.0] - 14/03/2019
5+
### Adicionado
6+
7+
Download do XML e aumento na cobertura de testes.
8+
9+
### Corrigido
10+
11+
Busca dos dados do cancelamento e cancelamento.
12+
413
## [1.3.0] - 12/03/2019
514
### Adicionado
615

examples/resposta.tmp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
object(TecnoSpeed\Plugnotas\Communication\Response)#35 (2) {
2+
["body"]=>
3+
array(1) {
4+
[0]=>
5+
object(stdClass)#33 (15) {
6+
["id"]=>
7+
string(24) "5c8953d3fb7f3bd47aee1535"
8+
["emissao"]=>
9+
string(10) "13/03/2019"
10+
["tipoAutorizacao"]=>
11+
string(10) "WEBSERVICE"
12+
["situacao"]=>
13+
string(9) "CONCLUIDO"
14+
["prestador"]=>
15+
string(14) "17406193000188"
16+
["tomador"]=>
17+
string(11) "01652836616"
18+
["valorServico"]=>
19+
int(350)
20+
["numeroNfse"]=>
21+
string(5) "17085"
22+
["serie"]=>
23+
string(3) "LAL"
24+
["lote"]=>
25+
int(290008)
26+
["codigoVerificacao"]=>
27+
string(9) "5278FE6A7"
28+
["autorizacao"]=>
29+
string(10) "13/03/2019"
30+
["mensagem"]=>
31+
string(26) "RPS Autorizada com sucesso"
32+
["pdf"]=>
33+
string(66) "http://api.sandbox.erphub.com.br/nfse/pdf/5c8953d3fb7f3bd47aee1535"
34+
["xml"]=>
35+
string(66) "http://api.sandbox.erphub.com.br/nfse/xml/5c8953d3fb7f3bd47aee1535"
36+
}
37+
}
38+
["statusCode"]=>
39+
int(200)
40+
}
41+
object(TecnoSpeed\Plugnotas\Communication\Response)#35 (2) {
42+
["body"]=>
43+
array(1) {
44+
[0]=>
45+
object(stdClass)#33 (15) {
46+
["id"]=>
47+
string(24) "5c891f537b4b9b54a4a51155"
48+
["emissao"]=>
49+
string(10) "13/03/2019"
50+
["tipoAutorizacao"]=>
51+
string(10) "WEBSERVICE"
52+
["situacao"]=>
53+
string(9) "CONCLUIDO"
54+
["prestador"]=>
55+
string(14) "17406193000188"
56+
["tomador"]=>
57+
string(11) "01652836616"
58+
["valorServico"]=>
59+
int(0)
60+
["numeroNfse"]=>
61+
string(5) "25419"
62+
["serie"]=>
63+
string(3) "LAL"
64+
["lote"]=>
65+
int(290008)
66+
["codigoVerificacao"]=>
67+
string(9) "5278FE6A7"
68+
["autorizacao"]=>
69+
string(10) "13/03/2019"
70+
["mensagem"]=>
71+
string(26) "RPS Autorizada com sucesso"
72+
["pdf"]=>
73+
string(66) "http://api.sandbox.erphub.com.br/nfse/pdf/5c891f537b4b9b54a4a51155"
74+
["xml"]=>
75+
string(66) "http://api.sandbox.erphub.com.br/nfse/xml/5c891f537b4b9b54a4a51155"
76+
}
77+
}
78+
["statusCode"]=>
79+
int(200)
80+
}

src/Interfaces/IDfe.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface IDfe
99
public function cancel($id);
1010
public function download($id);
1111
public function find($id);
12-
public function send(Configuration $configuration);
12+
public function send($configuration = null);
1313
public function toArray();
1414
public function validate();
1515
public static function fromArray($items);

src/Nfse.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,15 @@ public function validate()
173173
return true;
174174
}
175175

176-
public function send(Configuration $configuration)
176+
public function send($configuration = null)
177177
{
178178
$this->validate();
179179

180-
$communication = new CallApi($configuration);
180+
if ($configuration) {
181+
$this->setConfiguration($configuration);
182+
}
183+
184+
$communication = $this->getCallApiInstance($this->configuration);
181185
return $communication->send('POST', '/nfse', [$this->toArray(true)]);
182186
}
183187

@@ -236,7 +240,7 @@ public function findCancel($id)
236240

237241
public function download($id)
238242
{
239-
return $this->downloadPdf($id);
243+
return $this->downloadXml($id);
240244
}
241245

242246
public function downloadPdf($id)
@@ -270,6 +274,37 @@ public function downloadPdfByCnpjAndIdIntegracao($cnpj, $idIntegracao)
270274
);
271275
}
272276

277+
public function downloadXml($id)
278+
{
279+
$communication = $this->getCallApiInstance($this->configuration);
280+
if (!$this->configuration->getNfseDownloadDirectory()) {
281+
throw new RequiredError('É necessário setar o diretório para download do XML.');
282+
}
283+
284+
return $communication->download(
285+
'GET',
286+
"/nfse/xml/${id}",
287+
null,
288+
$this->configuration->getNfseDownloadDirectory() . '/' . $id . '.xml'
289+
);
290+
}
291+
292+
public function downloadXmlByCnpjAndIdIntegracao($cnpj, $idIntegracao)
293+
{
294+
$communication = $this->getCallApiInstance($this->configuration);
295+
296+
if (!$this->configuration->getNfseDownloadDirectory()) {
297+
throw new RequiredError('É necessário setar o diretório para download do XML.');
298+
}
299+
300+
return $communication->download(
301+
'GET',
302+
"/nfse/xml/${idIntegracao}/${cnpj}",
303+
null,
304+
$this->configuration->getNfseDownloadDirectory() . '/' . $cnpj . '-' . $idIntegracao . '.xml'
305+
);
306+
}
307+
273308
public function cancel($id)
274309
{
275310
$communication = $this->getCallApiInstance($this->configuration);
@@ -279,12 +314,12 @@ public function cancel($id)
279314
public function cancelByCnpjAndIdIntegracao($cnpj, $idIntegracao)
280315
{
281316
$communication = $this->getCallApiInstance($this->configuration);
282-
return $communication->send('POST', "/nfse/pdf/${idIntegracao}/${cnpj}", null);
317+
return $communication->send('POST', "/nfse/cancelar/${idIntegracao}/${cnpj}", null);
283318
}
284319

285320
public function cancelStatus($id)
286321
{
287322
$communication = $this->getCallApiInstance($this->configuration);
288-
return $communication->send('POST', "/nfse/cancelar/status/${id}", null);
323+
return $communication->send('GET', "/nfse/cancelar/status/${id}", null);
289324
}
290325
}

0 commit comments

Comments
 (0)