Completed
Push — master ( 5bc038...a8048c )
by Adriano
06:06
created
src/Integracao/ControlPay/API/VendaApi.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -42,40 +42,40 @@  discard block
 block discarded – undo
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)
61 61
                     )
62 62
                 );
63 63
 
64
-            if(!empty($venderRequest->getProdutosVendidos()))
64
+            if (!empty($venderRequest->getProdutosVendidos()))
65 65
                 foreach ($venderRequest->getProdutosVendidos() as $key => $produto)
66 66
                 {
67
-                    if(empty($produto->getId()))
68
-                        $venderRequest->getProdutosVendidos()[$key]->setId(
67
+                    if (empty($produto->getId()))
68
+                        $venderRequest->getProdutosVendidos()[ $key ]->setId(
69 69
                             $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID)
70 70
                         );
71 71
 
72
-                    if(empty($produto->getQuantidade()))
73
-                        $venderRequest->getProdutosVendidos()[$key]->setQuantidade(
72
+                    if (empty($produto->getQuantidade()))
73
+                        $venderRequest->getProdutosVendidos()[ $key ]->setQuantidade(
74 74
                             $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_QTDE)
75 75
                         );
76 76
                 }
77 77
 
78
-            $this->response = $this->_httpClient->post(__FUNCTION__,[
78
+            $this->response = $this->_httpClient->post(__FUNCTION__, [
79 79
                 'body' => json_encode($venderRequest),
80 80
             ]);
81 81
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
             );
86 86
         }catch (RequestException $ex) {
87 87
             $this->requestException($ex);
88
-        }catch (\Exception $ex){
88
+        }catch (\Exception $ex) {
89 89
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
90 90
         }
91 91
     }
@@ -97,10 +97,10 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function venderComPedido(Contracts\Venda\VenderComPedidoRequest $venderComPedidoRequest)
99 99
     {
100
-        try{
100
+        try {
101 101
             $response = $this->pedidoApi->insert($venderComPedidoRequest->getPedidoInserirRequest());
102 102
 
103
-            if(empty($response->getPedido()->getId()))
103
+            if (empty($response->getPedido()->getId()))
104 104
                 throw new \Exception("Falha ao inserir pedido");
105 105
 
106 106
             $venderComPedidoRequest->getInventarioVenderRequest()->setPedidoId(
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
             return $this->vender($venderComPedidoRequest->getInventarioVenderRequest());
111 111
         }catch (RequestException $ex) {
112 112
             $this->requestException($ex);
113
-        }catch (\Exception $ex){
113
+        }catch (\Exception $ex) {
114 114
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
115 115
         }
116 116
     }
@@ -122,19 +122,19 @@  discard block
 block discarded – undo
122 122
      */
123 123
     public function cancelarVenda(Contracts\Venda\CancelarVendaRequest $cancelarVendaRequest)
124 124
     {
125
-        try{
125
+        try {
126 126
 
127
-            if(empty($cancelarVendaRequest->getTerminalId()))
127
+            if (empty($cancelarVendaRequest->getTerminalId()))
128 128
                 $cancelarVendaRequest->setTerminalId(
129 129
                     $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID)
130 130
                 );
131 131
 
132
-            if(empty($cancelarVendaRequest->getSenhaTecnica()))
132
+            if (empty($cancelarVendaRequest->getSenhaTecnica()))
133 133
                 $cancelarVendaRequest->setSenhaTecnica(
134 134
                     $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA)
135 135
                 );
136 136
 
137
-            if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao()))
137
+            if (empty($cancelarVendaRequest->isAguardarTefIniciarTransacao()))
138 138
                 $cancelarVendaRequest->setAguardarTefIniciarTransacao(
139 139
                     boolval(
140 140
                         $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF)
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
                 );
143 143
 
144 144
 
145
-            $this->response = $this->_httpClient->post(__FUNCTION__,[
145
+            $this->response = $this->_httpClient->post(__FUNCTION__, [
146 146
                 'body' => json_encode($cancelarVendaRequest),
147 147
             ]);
148 148
 
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
             );
153 153
         }catch (RequestException $ex) {
154 154
             $this->requestException($ex);
155
-        }catch (\Exception $ex){
155
+        }catch (\Exception $ex) {
156 156
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
157 157
         }
158 158
     }
Please login to merge, or discard this patch.
Braces   +33 added lines, -24 removed lines patch added patch discarded remove patch
@@ -44,35 +44,40 @@  discard block
 block discarded – undo
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
-            if(!empty($venderRequest->getProdutosVendidos()))
65
-                foreach ($venderRequest->getProdutosVendidos() as $key => $produto)
67
+            if(!empty($venderRequest->getProdutosVendidos())) {
68
+                            foreach ($venderRequest->getProdutosVendidos() as $key => $produto)
66 69
                 {
67 70
                     if(empty($produto->getId()))
68 71
                         $venderRequest->getProdutosVendidos()[$key]->setId(
69 72
                             $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_ID)
70 73
                         );
74
+            }
71 75
 
72
-                    if(empty($produto->getQuantidade()))
73
-                        $venderRequest->getProdutosVendidos()[$key]->setQuantidade(
76
+                    if(empty($produto->getQuantidade())) {
77
+                                            $venderRequest->getProdutosVendidos()[$key]->setQuantidade(
74 78
                             $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_PRODUTO_QTDE)
75 79
                         );
80
+                    }
76 81
                 }
77 82
 
78 83
             $this->response = $this->_httpClient->post(__FUNCTION__,[
@@ -83,9 +88,9 @@  discard block
 block discarded – undo
83 88
                 $this->response->json(),
84 89
                 Contracts\Venda\VenderResponse::class
85 90
             );
86
-        }catch (RequestException $ex) {
91
+        } catch (RequestException $ex) {
87 92
             $this->requestException($ex);
88
-        }catch (\Exception $ex){
93
+        } catch (\Exception $ex){
89 94
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
90 95
         }
91 96
     }
@@ -100,17 +105,18 @@  discard block
 block discarded – undo
100 105
         try{
101 106
             $response = $this->pedidoApi->insert($venderComPedidoRequest->getPedidoInserirRequest());
102 107
 
103
-            if(empty($response->getPedido()->getId()))
104
-                throw new \Exception("Falha ao inserir pedido");
108
+            if(empty($response->getPedido()->getId())) {
109
+                            throw new \Exception("Falha ao inserir pedido");
110
+            }
105 111
 
106 112
             $venderComPedidoRequest->getInventarioVenderRequest()->setPedidoId(
107 113
                 $response->getPedido()->getId()
108 114
             );
109 115
 
110 116
             return $this->vender($venderComPedidoRequest->getInventarioVenderRequest());
111
-        }catch (RequestException $ex) {
117
+        } catch (RequestException $ex) {
112 118
             $this->requestException($ex);
113
-        }catch (\Exception $ex){
119
+        } catch (\Exception $ex){
114 120
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
115 121
         }
116 122
     }
@@ -124,22 +130,25 @@  discard block
 block discarded – undo
124 130
     {
125 131
         try{
126 132
 
127
-            if(empty($cancelarVendaRequest->getTerminalId()))
128
-                $cancelarVendaRequest->setTerminalId(
133
+            if(empty($cancelarVendaRequest->getTerminalId())) {
134
+                            $cancelarVendaRequest->setTerminalId(
129 135
                     $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_TERMINAL_ID)
130 136
                 );
137
+            }
131 138
 
132
-            if(empty($cancelarVendaRequest->getSenhaTecnica()))
133
-                $cancelarVendaRequest->setSenhaTecnica(
139
+            if(empty($cancelarVendaRequest->getSenhaTecnica())) {
140
+                            $cancelarVendaRequest->setSenhaTecnica(
134 141
                     $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_SENHA_TECNICA)
135 142
                 );
143
+            }
136 144
 
137
-            if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao()))
138
-                $cancelarVendaRequest->setAguardarTefIniciarTransacao(
145
+            if(empty($cancelarVendaRequest->isAguardarTefIniciarTransacao())) {
146
+                            $cancelarVendaRequest->setAguardarTefIniciarTransacao(
139 147
                     boolval(
140 148
                         $this->_client->getParameter(ControlPayParameterConst::CONTROLPAY_DEFAULT_FORMA_AGUARDA_TEF)
141 149
                     )
142 150
                 );
151
+            }
143 152
 
144 153
 
145 154
             $this->response = $this->_httpClient->post(__FUNCTION__,[
@@ -150,9 +159,9 @@  discard block
 block discarded – undo
150 159
                 $this->response->json(),
151 160
                 Contracts\Venda\CancelarVendaResponse::class
152 161
             );
153
-        }catch (RequestException $ex) {
162
+        } catch (RequestException $ex) {
154 163
             $this->requestException($ex);
155
-        }catch (\Exception $ex){
164
+        } catch (\Exception $ex){
156 165
             throw new \Exception($ex->getMessage(), $ex->getCode(), $ex);
157 166
         }
158 167
     }
Please login to merge, or discard this patch.