@@ -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