@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | * Requeridas. |
48 | 48 | */ |
49 | 49 | public function __construct($keyId, $publicKeyId) { |
50 | - if ( empty($keyId) || empty($publicKeyId) ) { |
|
51 | - throw new Exceptions\InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.'); |
|
52 | - } |
|
53 | - $this->publicKeyId = $publicKeyId; |
|
54 | - $this->keyId = $keyId; |
|
50 | + if ( empty($keyId) || empty($publicKeyId) ) { |
|
51 | + throw new Exceptions\InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.'); |
|
52 | + } |
|
53 | + $this->publicKeyId = $publicKeyId; |
|
54 | + $this->keyId = $keyId; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | */ |
65 | 65 | public function directPayment($fields) |
66 | 66 | { |
67 | - return $this->payment('2', $fields); |
|
67 | + return $this->payment('2', $fields); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function reservePayment($fields) |
79 | 79 | { |
80 | - return $this->payment('1', $fields); |
|
80 | + return $this->payment('1', $fields); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -92,26 +92,26 @@ discard block |
||
92 | 92 | |
93 | 93 | private function payment($type, $fields) { |
94 | 94 | |
95 | - (new Validator())->payment()->validate($fields); |
|
95 | + (new Validator())->payment()->validate($fields); |
|
96 | 96 | |
97 | - $fields = [ |
|
98 | - 'KeyID' => $this->keyId, |
|
99 | - 'PublicKeyId' => $this->publicKeyId, |
|
100 | - 'amount' => $fields['amount'], |
|
101 | - 'description' => $fields['description'], |
|
102 | - 'cardHolder' => $fields['card_holder'], |
|
103 | - 'cardHolderId' => $fields['card_holder_id'], |
|
104 | - 'cardNumber' => $fields['card_number'], |
|
105 | - 'cvc' => $fields['cvc'], |
|
106 | - 'expirationDate' => $fields['expiration'], |
|
107 | - 'statusId' => $type, |
|
108 | - 'IP' => $fields['ip'], |
|
109 | - ]; |
|
97 | + $fields = [ |
|
98 | + 'KeyID' => $this->keyId, |
|
99 | + 'PublicKeyId' => $this->publicKeyId, |
|
100 | + 'amount' => $fields['amount'], |
|
101 | + 'description' => $fields['description'], |
|
102 | + 'cardHolder' => $fields['card_holder'], |
|
103 | + 'cardHolderId' => $fields['card_holder_id'], |
|
104 | + 'cardNumber' => $fields['card_number'], |
|
105 | + 'cvc' => $fields['cvc'], |
|
106 | + 'expirationDate' => $fields['expiration'], |
|
107 | + 'statusId' => $type, |
|
108 | + 'IP' => $fields['ip'], |
|
109 | + ]; |
|
110 | 110 | |
111 | - $obj = $this->curlTransaccion('payment', $fields, 'POST'); |
|
112 | - $result = $this->checkResponseCode($obj); |
|
111 | + $obj = $this->curlTransaccion('payment', $fields, 'POST'); |
|
112 | + $result = $this->checkResponseCode($obj); |
|
113 | 113 | |
114 | - return $result; |
|
114 | + return $result; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -125,17 +125,17 @@ discard block |
||
125 | 125 | * @throws Exceptions\InstapagoException |
126 | 126 | */ |
127 | 127 | public function continuePayment($fields){ |
128 | - (new Validator())->release()->validate($fields); |
|
129 | - $fields = [ |
|
130 | - 'KeyID' => $this->keyId, //required |
|
131 | - 'PublicKeyId' => $this->publicKeyId, //required |
|
132 | - 'id' => $fields['id'], //required |
|
133 | - 'amount' => $fields['amount'], //required |
|
134 | - ]; |
|
128 | + (new Validator())->release()->validate($fields); |
|
129 | + $fields = [ |
|
130 | + 'KeyID' => $this->keyId, //required |
|
131 | + 'PublicKeyId' => $this->publicKeyId, //required |
|
132 | + 'id' => $fields['id'], //required |
|
133 | + 'amount' => $fields['amount'], //required |
|
134 | + ]; |
|
135 | 135 | |
136 | - $obj = $this->curlTransaccion('complete', $fields, 'POST'); |
|
137 | - $result = $this->checkResponseCode($obj); |
|
138 | - return $result; |
|
136 | + $obj = $this->curlTransaccion('complete', $fields, 'POST'); |
|
137 | + $result = $this->checkResponseCode($obj); |
|
138 | + return $result; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -148,19 +148,19 @@ discard block |
||
148 | 148 | * @throws Exceptions\InstapagoException |
149 | 149 | */ |
150 | 150 | public function query($id_pago) { |
151 | - (new Validator())->query()->validate([ |
|
152 | - 'id' => $id_pago |
|
153 | - ]); |
|
151 | + (new Validator())->query()->validate([ |
|
152 | + 'id' => $id_pago |
|
153 | + ]); |
|
154 | 154 | |
155 | - $fields = [ |
|
156 | - 'KeyID' => $this->keyId, //required |
|
157 | - 'PublicKeyId' => $this->publicKeyId, //required |
|
158 | - 'id' => $id_pago, //required |
|
159 | - ]; |
|
155 | + $fields = [ |
|
156 | + 'KeyID' => $this->keyId, //required |
|
157 | + 'PublicKeyId' => $this->publicKeyId, //required |
|
158 | + 'id' => $id_pago, //required |
|
159 | + ]; |
|
160 | 160 | |
161 | - $obj = $this->curlTransaccion('payment', $fields, 'GET'); |
|
162 | - $result = $this->checkResponseCode($obj); |
|
163 | - return $result; |
|
161 | + $obj = $this->curlTransaccion('payment', $fields, 'GET'); |
|
162 | + $result = $this->checkResponseCode($obj); |
|
163 | + return $result; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,19 +172,19 @@ discard block |
||
172 | 172 | * @throws Exceptions\InstapagoException |
173 | 173 | */ |
174 | 174 | public function cancel($id_pago) { |
175 | - (new Validator())->query()->validate([ |
|
176 | - 'id' => $id_pago |
|
177 | - ]); |
|
175 | + (new Validator())->query()->validate([ |
|
176 | + 'id' => $id_pago |
|
177 | + ]); |
|
178 | 178 | |
179 | - $fields = [ |
|
180 | - 'KeyID' => $this->keyId, //required |
|
181 | - 'PublicKeyId' => $this->publicKeyId, //required |
|
182 | - 'id' => $id_pago, //required |
|
183 | - ]; |
|
179 | + $fields = [ |
|
180 | + 'KeyID' => $this->keyId, //required |
|
181 | + 'PublicKeyId' => $this->publicKeyId, //required |
|
182 | + 'id' => $id_pago, //required |
|
183 | + ]; |
|
184 | 184 | |
185 | - $obj = $this->curlTransaccion('payment', $fields, 'DELETE'); |
|
186 | - $result = $this->checkResponseCode($obj); |
|
187 | - return $result; |
|
185 | + $obj = $this->curlTransaccion('payment', $fields, 'DELETE'); |
|
186 | + $result = $this->checkResponseCode($obj); |
|
187 | + return $result; |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -199,26 +199,26 @@ discard block |
||
199 | 199 | */ |
200 | 200 | public function curlTransaccion($url, $fields, $method) |
201 | 201 | { |
202 | - $client = new Client([ |
|
203 | - 'base_uri' => 'https://api.instapago.com/', |
|
204 | - ]); |
|
202 | + $client = new Client([ |
|
203 | + 'base_uri' => 'https://api.instapago.com/', |
|
204 | + ]); |
|
205 | 205 | |
206 | - $args = []; |
|
207 | - if (! in_array($method, ['GET', 'POST', 'DELETE'])) { |
|
208 | - throw new Exception("Not implemented yet", 1); |
|
209 | - } |
|
210 | - $key = ($method == 'GET') ? 'query' : 'form_params'; |
|
206 | + $args = []; |
|
207 | + if (! in_array($method, ['GET', 'POST', 'DELETE'])) { |
|
208 | + throw new Exception("Not implemented yet", 1); |
|
209 | + } |
|
210 | + $key = ($method == 'GET') ? 'query' : 'form_params'; |
|
211 | 211 | |
212 | - $args[$key] = $fields; |
|
212 | + $args[$key] = $fields; |
|
213 | 213 | |
214 | - try { |
|
215 | - $request = $client->request($method, $url, $args); |
|
216 | - $body = $request->getBody()->getContents(); |
|
217 | - $obj = json_decode($body, true); |
|
218 | - return $obj; |
|
219 | - } catch (\GuzzleHttp\Exception\ConnectException $e) { |
|
220 | - throw new Exceptions\TimeoutException("Cannot connect to api.instapago.com"); |
|
221 | - } |
|
214 | + try { |
|
215 | + $request = $client->request($method, $url, $args); |
|
216 | + $body = $request->getBody()->getContents(); |
|
217 | + $obj = json_decode($body, true); |
|
218 | + return $obj; |
|
219 | + } catch (\GuzzleHttp\Exception\ConnectException $e) { |
|
220 | + throw new Exceptions\TimeoutException("Cannot connect to api.instapago.com"); |
|
221 | + } |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -230,41 +230,41 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function checkResponseCode($obj) |
232 | 232 | { |
233 | - $code = $obj['code']; |
|
233 | + $code = $obj['code']; |
|
234 | 234 | |
235 | - if ($code == 400) { |
|
236 | - throw new Exceptions\InvalidInputException( |
|
237 | - 'Error al validar los datos enviados.' |
|
238 | - ); |
|
239 | - } if ($code == 401) { |
|
240 | - throw new Exceptions\AuthException( |
|
241 | - 'Error de autenticación, ha ocurrido un error' |
|
242 | - . ' con las llaves utilizadas.'); |
|
243 | - }else if ($code == 403) { |
|
244 | - throw new Exceptions\BankRejectException( |
|
245 | - 'Pago Rechazado por el banco.' |
|
246 | - ); |
|
247 | - }else if ($code == 500) { |
|
248 | - throw new Exceptions\InstapagoException( |
|
249 | - 'Ha Ocurrido un error interno dentro del servidor.' |
|
250 | - ); |
|
251 | - }else if ($code == 503) { |
|
252 | - throw new Exceptions\InstapagoException( |
|
253 | - 'Ha Ocurrido un error al procesar los parámetros de entrada.' |
|
254 | - . ' Revise los datos enviados y vuelva a intentarlo.' |
|
255 | - ); |
|
256 | - }else if ($code == 201) { |
|
257 | - return [ |
|
258 | - 'code' => $code, |
|
259 | - 'msg_banco' => $obj['message'], |
|
260 | - 'voucher' => html_entity_decode($obj['voucher']), |
|
261 | - 'id_pago' => $obj['id'], |
|
262 | - 'reference' => $obj['reference'], |
|
263 | - 'original_response' => $obj |
|
264 | - ]; |
|
265 | - } |
|
235 | + if ($code == 400) { |
|
236 | + throw new Exceptions\InvalidInputException( |
|
237 | + 'Error al validar los datos enviados.' |
|
238 | + ); |
|
239 | + } if ($code == 401) { |
|
240 | + throw new Exceptions\AuthException( |
|
241 | + 'Error de autenticación, ha ocurrido un error' |
|
242 | + . ' con las llaves utilizadas.'); |
|
243 | + }else if ($code == 403) { |
|
244 | + throw new Exceptions\BankRejectException( |
|
245 | + 'Pago Rechazado por el banco.' |
|
246 | + ); |
|
247 | + }else if ($code == 500) { |
|
248 | + throw new Exceptions\InstapagoException( |
|
249 | + 'Ha Ocurrido un error interno dentro del servidor.' |
|
250 | + ); |
|
251 | + }else if ($code == 503) { |
|
252 | + throw new Exceptions\InstapagoException( |
|
253 | + 'Ha Ocurrido un error al procesar los parámetros de entrada.' |
|
254 | + . ' Revise los datos enviados y vuelva a intentarlo.' |
|
255 | + ); |
|
256 | + }else if ($code == 201) { |
|
257 | + return [ |
|
258 | + 'code' => $code, |
|
259 | + 'msg_banco' => $obj['message'], |
|
260 | + 'voucher' => html_entity_decode($obj['voucher']), |
|
261 | + 'id_pago' => $obj['id'], |
|
262 | + 'reference' => $obj['reference'], |
|
263 | + 'original_response' => $obj |
|
264 | + ]; |
|
265 | + } |
|
266 | 266 | |
267 | - throw new \Exception('Not implemented yet'); |
|
267 | + throw new \Exception('Not implemented yet'); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | } |