Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1.        
  2.  
  3.  
  4.  
  5.         eNotasGW::configure(array(
  6.             'apiKey' => '<api key>'
  7.         ));
  8.  
  9.         $empresaId = 'a9f9d282-fdb9-4259-a7b8-2f19be4da06d';
  10.  
  11.         try {
  12.             $nfeId = 'ab765f39-a2e0-4c4b-88b4-4b6b4a2baace';
  13.             eNotasGW::$NFeServicoApi->cancelar($empresaId, $nfeId);
  14.  
  15.             /** Quando é cancelada a Nota Fiscal, o status é atualizado para Nota Cancelada. */
  16.             $this->Nfse->NfStatus->contain();
  17.             $options = array('conditions' => array('NfStatus.status' => 'Nota Cancelada', 'NfStatus.group_id' => $this->Session->read('Group.id')));
  18.             $nfStatus = $this->Nfse->NfStatus->find('first', $options);
  19.  
  20.             /** Atualiza no banco de dados com o id da nota inserida e novo Status da Nota (Nota Cancelada) no sistema. */
  21.             $this->Nfse->id = $id;
  22.             $this->Nfse->save(array('enotas_nfse_id' => $nfeId, 'nf_status_id' => $nfStatus['NfStatus']['id']));
  23.  
  24.             $this->Session->setFlash(__('A Nota Fiscal de Serviço foi cancelada.'), 'flash_sucess');
  25.             $this->redirect(array('action' => 'index'));
  26.             /**
  27.               //descomentar caso não possua o id único e queira efetuar o cancelamento pelo id externo
  28.               $idExterno = '1';
  29.               eNotasGW::$NFeApi->cancelarPorIdExterno($empresaId, $idExterno);
  30.              */
  31.         } catch (Exceptions\invalidApiKeyException $ex) {
  32.             $this->Session->setFlash(__('Erro de autenticação: ' . $ex->getMessage()), 'flash_error');
  33.             $this->redirect(array('action' => 'index'));
  34.         } catch (Exceptions\unauthorizedException $ex) {
  35.             $this->Session->setFlash(__('Acesso negado: ' . $ex->getMessage()), 'flash_error');
  36.             $this->redirect(array('action' => 'index'));
  37.         } catch (Exceptions\apiException $ex) {
  38.             $this->Session->setFlash(__('Erro de validação: ' . $ex->getMessage()), 'flash_error');
  39.             $this->redirect(array('action' => 'index'));
  40.         } catch (Exceptions\requestException $ex) {
  41.             $msg = 'Erro na requisição web: ' . $ex->getMessage()
  42.                     . 'Requested url: ' . $ex->requestedUrl
  43.                     . '</br>'
  44.                     . 'Response Code: ' . $ex->getCode()
  45.                     . '</br>'
  46.                     . 'Message: ' . $ex->getMessage()
  47.                     . '</br>'
  48.                     . 'Response Body: ' . $ex->responseBody;
  49.             $this->Session->setFlash(__($msg), 'flash_error');
  50.             $this->redirect(array('action' => 'index'));
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement