@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * @param \DateTime $data |
| 41 | - * @return VenderResponse |
|
| 41 | + * @return CancelarVendaResponse |
|
| 42 | 42 | */ |
| 43 | 43 | public function setData($data) |
| 44 | 44 | { |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * @param IntencaoVenda $intencaoVenda |
| 59 | - * @return VenderResponse |
|
| 59 | + * @return CancelarVendaResponse |
|
| 60 | 60 | */ |
| 61 | 61 | public function setIntencaoVenda($intencaoVenda) |
| 62 | 62 | { |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | { |
| 63 | 63 | $this->intencaoVenda = $intencaoVenda; |
| 64 | 64 | |
| 65 | - if(is_array($this->intencaoVenda)) |
|
| 65 | + if (is_array($this->intencaoVenda)) |
|
| 66 | 66 | $this->intencaoVenda = SerializerHelper::denormalize($this->intencaoVenda, IntencaoVenda::class); |
| 67 | 67 | |
| 68 | 68 | return $this; |
@@ -62,8 +62,9 @@ |
||
| 62 | 62 | { |
| 63 | 63 | $this->intencaoVenda = $intencaoVenda; |
| 64 | 64 | |
| 65 | - if(is_array($this->intencaoVenda)) |
|
| 66 | - $this->intencaoVenda = SerializerHelper::denormalize($this->intencaoVenda, IntencaoVenda::class); |
|
| 65 | + if(is_array($this->intencaoVenda)) { |
|
| 66 | + $this->intencaoVenda = SerializerHelper::denormalize($this->intencaoVenda, IntencaoVenda::class); |
|
| 67 | + } |
|
| 67 | 68 | |
| 68 | 69 | return $this; |
| 69 | 70 | } |
@@ -42,19 +42,19 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function vender(Contracts\Venda\VenderRequest $venderRequest) |
| 44 | 44 | { |
| 45 | - try{ |
|
| 45 | + try { |
|
| 46 | 46 | |
| 47 | - if(empty($venderRequest->getTerminalId())) |
|
| 47 | + if (empty($venderRequest->getTerminalId())) |
|
| 48 | 48 | $venderRequest->setTerminalId( |
| 49 | 49 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID) |
| 50 | 50 | ); |
| 51 | 51 | |
| 52 | - if(empty($venderRequest->getFormaPagamentoId())) |
|
| 52 | + if (empty($venderRequest->getFormaPagamentoId())) |
|
| 53 | 53 | $venderRequest->setFormaPagamentoId( |
| 54 | 54 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID) |
| 55 | 55 | ); |
| 56 | 56 | |
| 57 | - if(empty($venderRequest->isAguardarTefIniciarTransacao())) |
|
| 57 | + if (empty($venderRequest->isAguardarTefIniciarTransacao())) |
|
| 58 | 58 | $venderRequest->setAguardarTefIniciarTransacao( |
| 59 | 59 | boolval( |
| 60 | 60 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF) |
@@ -63,13 +63,13 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | foreach ($venderRequest->getProdutosVendidos() as $key => $produto) |
| 65 | 65 | { |
| 66 | - if(empty($produto->getId())) |
|
| 67 | - $venderRequest->getProdutosVendidos()[$key]->setId( |
|
| 66 | + if (empty($produto->getId())) |
|
| 67 | + $venderRequest->getProdutosVendidos()[ $key ]->setId( |
|
| 68 | 68 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID) |
| 69 | 69 | ); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - $this->response = $this->_httpClient->post(__FUNCTION__,[ |
|
| 72 | + $this->response = $this->_httpClient->post(__FUNCTION__, [ |
|
| 73 | 73 | 'body' => json_encode($venderRequest), |
| 74 | 74 | ]); |
| 75 | 75 | |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | ); |
| 80 | 80 | }catch (RequestException $ex) { |
| 81 | 81 | $this->requestException($ex); |
| 82 | - }catch (\Exception $ex){ |
|
| 82 | + }catch (\Exception $ex) { |
|
| 83 | 83 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 84 | 84 | } |
| 85 | 85 | } |
@@ -91,10 +91,10 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function venderComPedido(Contracts\Venda\VenderComPedidoRequest $venderComPedidoRequest) |
| 93 | 93 | { |
| 94 | - try{ |
|
| 94 | + try { |
|
| 95 | 95 | $response = $this->pedidoApi->insert($venderComPedidoRequest->getPedidoInserirRequest()); |
| 96 | 96 | |
| 97 | - if(empty($response->getPedido()->getId())) |
|
| 97 | + if (empty($response->getPedido()->getId())) |
|
| 98 | 98 | throw new \Exception("Falha ao inserir pedido"); |
| 99 | 99 | |
| 100 | 100 | $venderComPedidoRequest->getInventarioVenderRequest()->setPedidoId( |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | return $this->vender($venderComPedidoRequest->getInventarioVenderRequest()); |
| 105 | 105 | }catch (RequestException $ex) { |
| 106 | 106 | $this->requestException($ex); |
| 107 | - }catch (\Exception $ex){ |
|
| 107 | + }catch (\Exception $ex) { |
|
| 108 | 108 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 109 | 109 | } |
| 110 | 110 | } |
@@ -116,19 +116,19 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | public function cancelarVenda(Contracts\Venda\CancelarVendaRequest $cancelarVendaRequest) |
| 118 | 118 | { |
| 119 | - try{ |
|
| 119 | + try { |
|
| 120 | 120 | |
| 121 | - if(empty($cancelarVendaRequest->getTerminalId())) |
|
| 121 | + if (empty($cancelarVendaRequest->getTerminalId())) |
|
| 122 | 122 | $cancelarVendaRequest->setTerminalId( |
| 123 | 123 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID) |
| 124 | 124 | ); |
| 125 | 125 | |
| 126 | - if(empty($cancelarVendaRequest->getSenhaTecnica())) |
|
| 126 | + if (empty($cancelarVendaRequest->getSenhaTecnica())) |
|
| 127 | 127 | $cancelarVendaRequest->setSenhaTecnica( |
| 128 | 128 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA) |
| 129 | 129 | ); |
| 130 | 130 | |
| 131 | - if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao())) |
|
| 131 | + if (empty($cancelarVendaRequest->isAguardarTefIniciarTransacao())) |
|
| 132 | 132 | $cancelarVendaRequest->setAguardarTefIniciarTransacao( |
| 133 | 133 | boolval( |
| 134 | 134 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF) |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | ); |
| 137 | 137 | |
| 138 | 138 | |
| 139 | - $this->response = $this->_httpClient->post(__FUNCTION__,[ |
|
| 139 | + $this->response = $this->_httpClient->post(__FUNCTION__, [ |
|
| 140 | 140 | 'body' => json_encode($cancelarVendaRequest), |
| 141 | 141 | ]); |
| 142 | 142 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | ); |
| 147 | 147 | }catch (RequestException $ex) { |
| 148 | 148 | $this->requestException($ex); |
| 149 | - }catch (\Exception $ex){ |
|
| 149 | + }catch (\Exception $ex) { |
|
| 150 | 150 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -44,29 +44,33 @@ discard block |
||
| 44 | 44 | { |
| 45 | 45 | try{ |
| 46 | 46 | |
| 47 | - if(empty($venderRequest->getTerminalId())) |
|
| 48 | - $venderRequest->setTerminalId( |
|
| 47 | + if(empty($venderRequest->getTerminalId())) { |
|
| 48 | + $venderRequest->setTerminalId( |
|
| 49 | 49 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID) |
| 50 | 50 | ); |
| 51 | + } |
|
| 51 | 52 | |
| 52 | - if(empty($venderRequest->getFormaPagamentoId())) |
|
| 53 | - $venderRequest->setFormaPagamentoId( |
|
| 53 | + if(empty($venderRequest->getFormaPagamentoId())) { |
|
| 54 | + $venderRequest->setFormaPagamentoId( |
|
| 54 | 55 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID) |
| 55 | 56 | ); |
| 57 | + } |
|
| 56 | 58 | |
| 57 | - if(empty($venderRequest->isAguardarTefIniciarTransacao())) |
|
| 58 | - $venderRequest->setAguardarTefIniciarTransacao( |
|
| 59 | + if(empty($venderRequest->isAguardarTefIniciarTransacao())) { |
|
| 60 | + $venderRequest->setAguardarTefIniciarTransacao( |
|
| 59 | 61 | boolval( |
| 60 | 62 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF) |
| 61 | 63 | ) |
| 62 | 64 | ); |
| 65 | + } |
|
| 63 | 66 | |
| 64 | 67 | foreach ($venderRequest->getProdutosVendidos() as $key => $produto) |
| 65 | 68 | { |
| 66 | - if(empty($produto->getId())) |
|
| 67 | - $venderRequest->getProdutosVendidos()[$key]->setId( |
|
| 69 | + if(empty($produto->getId())) { |
|
| 70 | + $venderRequest->getProdutosVendidos()[$key]->setId( |
|
| 68 | 71 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID) |
| 69 | 72 | ); |
| 73 | + } |
|
| 70 | 74 | } |
| 71 | 75 | |
| 72 | 76 | $this->response = $this->_httpClient->post(__FUNCTION__,[ |
@@ -77,9 +81,9 @@ discard block |
||
| 77 | 81 | $this->response->json(), |
| 78 | 82 | Contracts\Venda\VenderResponse::class |
| 79 | 83 | ); |
| 80 | - }catch (RequestException $ex) { |
|
| 84 | + } catch (RequestException $ex) { |
|
| 81 | 85 | $this->requestException($ex); |
| 82 | - }catch (\Exception $ex){ |
|
| 86 | + } catch (\Exception $ex){ |
|
| 83 | 87 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 84 | 88 | } |
| 85 | 89 | } |
@@ -94,17 +98,18 @@ discard block |
||
| 94 | 98 | try{ |
| 95 | 99 | $response = $this->pedidoApi->insert($venderComPedidoRequest->getPedidoInserirRequest()); |
| 96 | 100 | |
| 97 | - if(empty($response->getPedido()->getId())) |
|
| 98 | - throw new \Exception("Falha ao inserir pedido"); |
|
| 101 | + if(empty($response->getPedido()->getId())) { |
|
| 102 | + throw new \Exception("Falha ao inserir pedido"); |
|
| 103 | + } |
|
| 99 | 104 | |
| 100 | 105 | $venderComPedidoRequest->getInventarioVenderRequest()->setPedidoId( |
| 101 | 106 | $response->getPedido()->getId() |
| 102 | 107 | ); |
| 103 | 108 | |
| 104 | 109 | return $this->vender($venderComPedidoRequest->getInventarioVenderRequest()); |
| 105 | - }catch (RequestException $ex) { |
|
| 110 | + } catch (RequestException $ex) { |
|
| 106 | 111 | $this->requestException($ex); |
| 107 | - }catch (\Exception $ex){ |
|
| 112 | + } catch (\Exception $ex){ |
|
| 108 | 113 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 109 | 114 | } |
| 110 | 115 | } |
@@ -118,22 +123,25 @@ discard block |
||
| 118 | 123 | { |
| 119 | 124 | try{ |
| 120 | 125 | |
| 121 | - if(empty($cancelarVendaRequest->getTerminalId())) |
|
| 122 | - $cancelarVendaRequest->setTerminalId( |
|
| 126 | + if(empty($cancelarVendaRequest->getTerminalId())) { |
|
| 127 | + $cancelarVendaRequest->setTerminalId( |
|
| 123 | 128 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID) |
| 124 | 129 | ); |
| 130 | + } |
|
| 125 | 131 | |
| 126 | - if(empty($cancelarVendaRequest->getSenhaTecnica())) |
|
| 127 | - $cancelarVendaRequest->setSenhaTecnica( |
|
| 132 | + if(empty($cancelarVendaRequest->getSenhaTecnica())) { |
|
| 133 | + $cancelarVendaRequest->setSenhaTecnica( |
|
| 128 | 134 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA) |
| 129 | 135 | ); |
| 136 | + } |
|
| 130 | 137 | |
| 131 | - if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao())) |
|
| 132 | - $cancelarVendaRequest->setAguardarTefIniciarTransacao( |
|
| 138 | + if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao())) { |
|
| 139 | + $cancelarVendaRequest->setAguardarTefIniciarTransacao( |
|
| 133 | 140 | boolval( |
| 134 | 141 | $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF) |
| 135 | 142 | ) |
| 136 | 143 | ); |
| 144 | + } |
|
| 137 | 145 | |
| 138 | 146 | |
| 139 | 147 | $this->response = $this->_httpClient->post(__FUNCTION__,[ |
@@ -144,9 +152,9 @@ discard block |
||
| 144 | 152 | $this->response->json(), |
| 145 | 153 | Contracts\Venda\CancelarVendaResponse::class |
| 146 | 154 | ); |
| 147 | - }catch (RequestException $ex) { |
|
| 155 | + } catch (RequestException $ex) { |
|
| 148 | 156 | $this->requestException($ex); |
| 149 | - }catch (\Exception $ex){ |
|
| 157 | + } catch (\Exception $ex){ |
|
| 150 | 158 | throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
| 151 | 159 | } |
| 152 | 160 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function getParameter($key) |
| 72 | 72 | { |
| 73 | - return isset($this->_params[$key]) ? $this->_params[$key] : null; |
|
| 73 | + return isset($this->_params[ $key ]) ? $this->_params[ $key ] : null; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function setParameter($key, $value) |
| 84 | 84 | { |
| 85 | - $this->_params[$key] = $value; |
|
| 85 | + $this->_params[ $key ] = $value; |
|
| 86 | 86 | $this->loadParameters($this->_params, $this->authentication); |
| 87 | 87 | return $this; |
| 88 | 88 | } |
@@ -96,23 +96,23 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | private function loadParameters($params, IAuthentication $authentication = null) |
| 98 | 98 | { |
| 99 | - $this->_params[ControlPayParameterConst::CONTROLPAY_HOST] = getenv('CONTROLPAY_HOST'); |
|
| 100 | - $this->_params[ControlPayParameterConst::CONTROLPAY_TIMEOUT] = getenv('CONTROLPAY_TIMEOUT'); |
|
| 101 | - $this->_params[ControlPayParameterConst::CONTROLPAY_USER] = getenv('CONTROLPAY_USER'); |
|
| 102 | - $this->_params[ControlPayParameterConst::CONTROLPAY_PWD] = getenv('CONTROLPAY_PWD'); |
|
| 103 | - $this->_params[ControlPayParameterConst::CONTROLPAY_KEY] = getenv('CONTROLPAY_KEY'); |
|
| 104 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID] = getenv('CONTROLPAY_DEFAULT_PESSOA_ID'); |
|
| 105 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID] = getenv('CONTROLPAY_DEFAULT_TERMINAL_ID'); |
|
| 106 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID] = getenv('CONTROLPAY_DEFAULT_PRODUTO_ID'); |
|
| 107 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID] = getenv('CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID'); |
|
| 108 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF] = getenv('CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF'); |
|
| 109 | - $this->_params[ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA] = getenv('CONTROLPAY_DEFAULT_SENHA_TECNICA'); |
|
| 110 | - $this->_params[ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE] = KeyQueryStringAuthentication::class; |
|
| 111 | - |
|
| 112 | - if(!is_null($params)) |
|
| 99 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_HOST ] = getenv('CONTROLPAY_HOST'); |
|
| 100 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_TIMEOUT ] = getenv('CONTROLPAY_TIMEOUT'); |
|
| 101 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_USER ] = getenv('CONTROLPAY_USER'); |
|
| 102 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_PWD ] = getenv('CONTROLPAY_PWD'); |
|
| 103 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_KEY ] = getenv('CONTROLPAY_KEY'); |
|
| 104 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_PESSOA_ID ] = getenv('CONTROLPAY_DEFAULT_PESSOA_ID'); |
|
| 105 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID ] = getenv('CONTROLPAY_DEFAULT_TERMINAL_ID'); |
|
| 106 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID ] = getenv('CONTROLPAY_DEFAULT_PRODUTO_ID'); |
|
| 107 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID ] = getenv('CONTROLPAY_DEFAULT_FORMA_PAGAMENTO_ID'); |
|
| 108 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF ] = getenv('CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF'); |
|
| 109 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA ] = getenv('CONTROLPAY_DEFAULT_SENHA_TECNICA'); |
|
| 110 | + $this->_params[ ControlPayParameterConst::CONTROLPAY_OAUTH_TYPE ] = KeyQueryStringAuthentication::class; |
|
| 111 | + |
|
| 112 | + if (!is_null($params)) |
|
| 113 | 113 | foreach ($params as $key => $param) |
| 114 | 114 | { |
| 115 | - if(!in_array($key, [ |
|
| 115 | + if (!in_array($key, [ |
|
| 116 | 116 | ControlPayParameterConst::CONTROLPAY_HOST, |
| 117 | 117 | ControlPayParameterConst::CONTROLPAY_TIMEOUT, |
| 118 | 118 | ControlPayParameterConst::CONTROLPAY_USER, |
@@ -129,11 +129,11 @@ discard block |
||
| 129 | 129 | throw new \Exception(sprintf("Parâmetro %s inválido", $key)); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if(!is_null($params) && is_array($params)) |
|
| 132 | + if (!is_null($params) && is_array($params)) |
|
| 133 | 133 | foreach ($params as $key => $value) |
| 134 | - $this->_params[$key] = $value; |
|
| 134 | + $this->_params[ $key ] = $value; |
|
| 135 | 135 | |
| 136 | - if(is_null($authentication)) |
|
| 136 | + if (is_null($authentication)) |
|
| 137 | 137 | { |
| 138 | 138 | $this->authentication = AuthenticationFactory::getInstance($this->_params, $this); |
| 139 | 139 | return; |