@@ -329,7 +329,7 @@ |
||
329 | 329 | /** |
330 | 330 | * Realiza Transaccion |
331 | 331 | * Efectúa y retornar una respuesta a un metodo de pago. |
332 | - *@param $url endpoint a consultar |
|
332 | + *@param string $url endpoint a consultar |
|
333 | 333 | *@param $fields datos para la consulta |
334 | 334 | *@return $obj array resultados de la transaccion |
335 | 335 | * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
@@ -35,274 +35,274 @@ |
||
35 | 35 | */ |
36 | 36 | class InstapagoPayment |
37 | 37 | { |
38 | - protected $keyId; |
|
39 | - protected $publicKeyId; |
|
40 | - public $cardHolder; |
|
41 | - public $cardHolderId; |
|
42 | - public $cardNumber; |
|
43 | - public $cvc; |
|
44 | - public $expirationDate; |
|
45 | - public $amount; |
|
46 | - public $description; |
|
47 | - public $statusId; |
|
48 | - public $ipAddres; |
|
49 | - public $idPago; |
|
50 | - public $root = 'https://api.instapago.com/'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Crear un nuevo objeto de Instapago. |
|
54 | - * |
|
55 | - * @param string $keyId llave privada |
|
56 | - * @param string $publicKeyId llave publica |
|
57 | - * Requeridas. |
|
58 | - */ |
|
59 | - public function __construct($keyId, $publicKeyId) |
|
60 | - { |
|
61 | - try { |
|
62 | - if (empty($keyId) && empty($publicKeyId)) { |
|
63 | - throw new InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.'); |
|
64 | - } |
|
65 | - |
|
66 | - if (empty($keyId)) { |
|
67 | - throw new InstapagoException('El parámetro "keyId" es requerido para procesar la petición. '); |
|
68 | - } |
|
69 | - |
|
70 | - if (empty($publicKeyId)) { |
|
71 | - throw new InstapagoException('El parámetro "publicKeyId" es requerido para procesar la petición.'); |
|
72 | - } |
|
73 | - |
|
74 | - $this->publicKeyId = $publicKeyId; |
|
75 | - $this->keyId = $keyId; |
|
76 | - } catch (InstapagoException $e) { |
|
77 | - echo $e->getMessage(); |
|
78 | - } // end try/catch |
|
79 | - } |
|
38 | + protected $keyId; |
|
39 | + protected $publicKeyId; |
|
40 | + public $cardHolder; |
|
41 | + public $cardHolderId; |
|
42 | + public $cardNumber; |
|
43 | + public $cvc; |
|
44 | + public $expirationDate; |
|
45 | + public $amount; |
|
46 | + public $description; |
|
47 | + public $statusId; |
|
48 | + public $ipAddres; |
|
49 | + public $idPago; |
|
50 | + public $root = 'https://api.instapago.com/'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Crear un nuevo objeto de Instapago. |
|
54 | + * |
|
55 | + * @param string $keyId llave privada |
|
56 | + * @param string $publicKeyId llave publica |
|
57 | + * Requeridas. |
|
58 | + */ |
|
59 | + public function __construct($keyId, $publicKeyId) |
|
60 | + { |
|
61 | + try { |
|
62 | + if (empty($keyId) && empty($publicKeyId)) { |
|
63 | + throw new InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.'); |
|
64 | + } |
|
65 | + |
|
66 | + if (empty($keyId)) { |
|
67 | + throw new InstapagoException('El parámetro "keyId" es requerido para procesar la petición. '); |
|
68 | + } |
|
69 | + |
|
70 | + if (empty($publicKeyId)) { |
|
71 | + throw new InstapagoException('El parámetro "publicKeyId" es requerido para procesar la petición.'); |
|
72 | + } |
|
73 | + |
|
74 | + $this->publicKeyId = $publicKeyId; |
|
75 | + $this->keyId = $keyId; |
|
76 | + } catch (InstapagoException $e) { |
|
77 | + echo $e->getMessage(); |
|
78 | + } // end try/catch |
|
79 | + } |
|
80 | 80 | |
81 | 81 | // end construct |
82 | 82 | |
83 | - /** |
|
84 | - * Crear un pago |
|
85 | - * Efectúa un pago con tarjeta de crédito, una vez procesado retornar una respuesta. |
|
86 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#crear-un-pago. |
|
87 | - */ |
|
88 | - public function payment($amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres) |
|
89 | - { |
|
90 | - try { |
|
91 | - $params = [$amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres]; |
|
92 | - $this->checkRequiredParams($params); |
|
93 | - |
|
94 | - $this->amount = $amount; |
|
95 | - $this->description = $description; |
|
96 | - $this->cardHolder = $cardHolder; |
|
97 | - $this->cardHolderId = $cardHolderId; |
|
98 | - $this->cardNumber = $cardNumber; |
|
99 | - $this->cvc = $cvc; |
|
100 | - $this->expirationDate = $expirationDate; |
|
101 | - $this->statusId = $statusId; |
|
102 | - $this->ipAddres = $ipAddres; |
|
103 | - |
|
104 | - $url = $this->root.'payment'; // endpoint |
|
105 | - |
|
106 | - $fields = [ |
|
107 | - 'KeyID' => $this->keyId, //required |
|
108 | - 'PublicKeyId' => $this->publicKeyId, //required |
|
109 | - 'amount' => $this->amount, //required |
|
110 | - 'description' => $this->description, //required |
|
111 | - 'cardHolder' => $this->cardHolder, //required |
|
112 | - 'cardHolderId' => $this->cardHolderId, //required |
|
113 | - 'cardNumber' => $this->cardNumber, //required |
|
114 | - 'cvc' => $this->cvc, //required |
|
115 | - 'expirationDate' => $this->expirationDate, //required |
|
116 | - 'statusId' => $this->statusId, //required |
|
117 | - 'IP' => $this->ipAddres, //required |
|
118 | - ]; |
|
119 | - |
|
120 | - $obj = $this->curlTransaccion($url, $fields); |
|
121 | - $result = $this->checkResponseCode($obj); |
|
122 | - |
|
123 | - return $result; |
|
124 | - } catch (InstapagoException $e) { |
|
125 | - echo $e->getMessage(); |
|
126 | - } // end try/catch |
|
127 | - } |
|
83 | + /** |
|
84 | + * Crear un pago |
|
85 | + * Efectúa un pago con tarjeta de crédito, una vez procesado retornar una respuesta. |
|
86 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#crear-un-pago. |
|
87 | + */ |
|
88 | + public function payment($amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres) |
|
89 | + { |
|
90 | + try { |
|
91 | + $params = [$amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres]; |
|
92 | + $this->checkRequiredParams($params); |
|
93 | + |
|
94 | + $this->amount = $amount; |
|
95 | + $this->description = $description; |
|
96 | + $this->cardHolder = $cardHolder; |
|
97 | + $this->cardHolderId = $cardHolderId; |
|
98 | + $this->cardNumber = $cardNumber; |
|
99 | + $this->cvc = $cvc; |
|
100 | + $this->expirationDate = $expirationDate; |
|
101 | + $this->statusId = $statusId; |
|
102 | + $this->ipAddres = $ipAddres; |
|
103 | + |
|
104 | + $url = $this->root.'payment'; // endpoint |
|
105 | + |
|
106 | + $fields = [ |
|
107 | + 'KeyID' => $this->keyId, //required |
|
108 | + 'PublicKeyId' => $this->publicKeyId, //required |
|
109 | + 'amount' => $this->amount, //required |
|
110 | + 'description' => $this->description, //required |
|
111 | + 'cardHolder' => $this->cardHolder, //required |
|
112 | + 'cardHolderId' => $this->cardHolderId, //required |
|
113 | + 'cardNumber' => $this->cardNumber, //required |
|
114 | + 'cvc' => $this->cvc, //required |
|
115 | + 'expirationDate' => $this->expirationDate, //required |
|
116 | + 'statusId' => $this->statusId, //required |
|
117 | + 'IP' => $this->ipAddres, //required |
|
118 | + ]; |
|
119 | + |
|
120 | + $obj = $this->curlTransaccion($url, $fields); |
|
121 | + $result = $this->checkResponseCode($obj); |
|
122 | + |
|
123 | + return $result; |
|
124 | + } catch (InstapagoException $e) { |
|
125 | + echo $e->getMessage(); |
|
126 | + } // end try/catch |
|
127 | + } |
|
128 | 128 | |
129 | 129 | // end payment |
130 | 130 | |
131 | - /** |
|
132 | - * Completar Pago |
|
133 | - * Este método funciona para procesar un bloqueo o pre-autorización |
|
134 | - * para así procesarla y hacer el cobro respectivo. |
|
135 | - * Para usar este método es necesario configurar en `payment()` el parametro statusId a 1 |
|
136 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#completar-pago. |
|
137 | - */ |
|
138 | - public function continuePayment($idPago, $amount) |
|
139 | - { |
|
140 | - try { |
|
141 | - $params = [$idPago, $amount]; |
|
142 | - $this->checkRequiredParams($params); |
|
143 | - |
|
144 | - $this->idPago = $idPago; |
|
145 | - $this->amount = $amount; |
|
146 | - |
|
147 | - $url = $this->root.'complete'; // endpoint |
|
148 | - |
|
149 | - $fields = [ |
|
150 | - 'KeyID' => $this->keyId, //required |
|
151 | - 'PublicKeyId' => $this->publicKeyId, //required |
|
152 | - 'id' => $this->idPago, //required |
|
153 | - 'amount' => $this->amount, //required |
|
154 | - ]; |
|
155 | - |
|
156 | - $obj = $this->curlTransaccion($url, $fields); |
|
157 | - $result = $this->checkResponseCode($obj); |
|
158 | - |
|
159 | - return $result; |
|
160 | - } catch (InstapagoException $e) { |
|
161 | - echo $e->getMessage(); |
|
162 | - } // end try/catch |
|
163 | - } |
|
131 | + /** |
|
132 | + * Completar Pago |
|
133 | + * Este método funciona para procesar un bloqueo o pre-autorización |
|
134 | + * para así procesarla y hacer el cobro respectivo. |
|
135 | + * Para usar este método es necesario configurar en `payment()` el parametro statusId a 1 |
|
136 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#completar-pago. |
|
137 | + */ |
|
138 | + public function continuePayment($idPago, $amount) |
|
139 | + { |
|
140 | + try { |
|
141 | + $params = [$idPago, $amount]; |
|
142 | + $this->checkRequiredParams($params); |
|
143 | + |
|
144 | + $this->idPago = $idPago; |
|
145 | + $this->amount = $amount; |
|
146 | + |
|
147 | + $url = $this->root.'complete'; // endpoint |
|
148 | + |
|
149 | + $fields = [ |
|
150 | + 'KeyID' => $this->keyId, //required |
|
151 | + 'PublicKeyId' => $this->publicKeyId, //required |
|
152 | + 'id' => $this->idPago, //required |
|
153 | + 'amount' => $this->amount, //required |
|
154 | + ]; |
|
155 | + |
|
156 | + $obj = $this->curlTransaccion($url, $fields); |
|
157 | + $result = $this->checkResponseCode($obj); |
|
158 | + |
|
159 | + return $result; |
|
160 | + } catch (InstapagoException $e) { |
|
161 | + echo $e->getMessage(); |
|
162 | + } // end try/catch |
|
163 | + } |
|
164 | 164 | |
165 | 165 | // continuePayment |
166 | 166 | |
167 | - /** |
|
168 | - * Anular Pago |
|
169 | - * Este método funciona para procesar una anulación de un pago o un bloqueo. |
|
170 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#anular-pago. |
|
171 | - */ |
|
172 | - public function cancelPayment($idPago) |
|
173 | - { |
|
174 | - try { |
|
175 | - $params = [$idPago]; |
|
176 | - |
|
177 | - $this->checkRequiredParams($params); |
|
178 | - |
|
179 | - $this->idPago = $idPago; |
|
180 | - |
|
181 | - $url = $this->root.'payment'; // endpoint |
|
182 | - |
|
183 | - $myCurl = curl_init(); |
|
184 | - curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
|
185 | - curl_setopt($myCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
186 | - curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
187 | - $server_output = curl_exec($myCurl); |
|
188 | - curl_close($myCurl); |
|
189 | - $obj = json_decode($server_output); |
|
190 | - $result = $this->checkResponseCode($obj); |
|
191 | - |
|
192 | - return $result; |
|
193 | - } catch (InstapagoException $e) { |
|
194 | - echo $e->getMessage(); |
|
195 | - } // end try/catch |
|
196 | - } |
|
167 | + /** |
|
168 | + * Anular Pago |
|
169 | + * Este método funciona para procesar una anulación de un pago o un bloqueo. |
|
170 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#anular-pago. |
|
171 | + */ |
|
172 | + public function cancelPayment($idPago) |
|
173 | + { |
|
174 | + try { |
|
175 | + $params = [$idPago]; |
|
176 | + |
|
177 | + $this->checkRequiredParams($params); |
|
178 | + |
|
179 | + $this->idPago = $idPago; |
|
180 | + |
|
181 | + $url = $this->root.'payment'; // endpoint |
|
182 | + |
|
183 | + $myCurl = curl_init(); |
|
184 | + curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
|
185 | + curl_setopt($myCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
|
186 | + curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
187 | + $server_output = curl_exec($myCurl); |
|
188 | + curl_close($myCurl); |
|
189 | + $obj = json_decode($server_output); |
|
190 | + $result = $this->checkResponseCode($obj); |
|
191 | + |
|
192 | + return $result; |
|
193 | + } catch (InstapagoException $e) { |
|
194 | + echo $e->getMessage(); |
|
195 | + } // end try/catch |
|
196 | + } |
|
197 | 197 | |
198 | 198 | // cancelPayment |
199 | 199 | |
200 | - /** |
|
201 | - * Información del Pago |
|
202 | - * Consulta información sobre un pago generado anteriormente. |
|
203 | - * Requiere como parámetro el `id` que es el código de referencia de la transacción |
|
204 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#información-del-pago. |
|
205 | - */ |
|
206 | - public function paymentInfo($idPago) |
|
207 | - { |
|
208 | - try { |
|
209 | - $params = [$idPago]; |
|
210 | - $this->checkRequiredParams($params); |
|
211 | - |
|
212 | - $this->idPago = $idPago; |
|
213 | - |
|
214 | - $url = $this->root.'payment'; // endpoint |
|
215 | - |
|
216 | - $myCurl = curl_init(); |
|
217 | - curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
218 | - curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
|
219 | - $server_output = curl_exec($myCurl); |
|
220 | - curl_close($myCurl); |
|
221 | - $obj = json_decode($server_output); |
|
222 | - $result = $this->checkResponseCode($obj); |
|
223 | - |
|
224 | - return $result; |
|
225 | - } catch (InstapagoException $e) { |
|
226 | - echo $e->getMessage(); |
|
227 | - } // end try/catch |
|
228 | - } |
|
200 | + /** |
|
201 | + * Información del Pago |
|
202 | + * Consulta información sobre un pago generado anteriormente. |
|
203 | + * Requiere como parámetro el `id` que es el código de referencia de la transacción |
|
204 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#información-del-pago. |
|
205 | + */ |
|
206 | + public function paymentInfo($idPago) |
|
207 | + { |
|
208 | + try { |
|
209 | + $params = [$idPago]; |
|
210 | + $this->checkRequiredParams($params); |
|
211 | + |
|
212 | + $this->idPago = $idPago; |
|
213 | + |
|
214 | + $url = $this->root.'payment'; // endpoint |
|
215 | + |
|
216 | + $myCurl = curl_init(); |
|
217 | + curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
218 | + curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
|
219 | + $server_output = curl_exec($myCurl); |
|
220 | + curl_close($myCurl); |
|
221 | + $obj = json_decode($server_output); |
|
222 | + $result = $this->checkResponseCode($obj); |
|
223 | + |
|
224 | + return $result; |
|
225 | + } catch (InstapagoException $e) { |
|
226 | + echo $e->getMessage(); |
|
227 | + } // end try/catch |
|
228 | + } |
|
229 | 229 | |
230 | 230 | // paymentInfo |
231 | 231 | |
232 | - /** |
|
233 | - * Realiza Transaccion |
|
234 | - * Efectúa y retornar una respuesta a un metodo de pago. |
|
235 | - * |
|
236 | - *@param $url endpoint a consultar |
|
237 | - *@param $fields datos para la consulta |
|
238 | - * |
|
239 | - *@return $obj array resultados de la transaccion |
|
240 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
241 | - */ |
|
242 | - public function curlTransaccion($url, $fields) |
|
243 | - { |
|
244 | - $myCurl = curl_init(); |
|
245 | - curl_setopt($myCurl, CURLOPT_URL, $url); |
|
246 | - curl_setopt($myCurl, CURLOPT_POST, 1); |
|
247 | - curl_setopt($myCurl, CURLOPT_POSTFIELDS, http_build_query($fields)); |
|
248 | - curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true); |
|
249 | - $server_output = curl_exec($myCurl); |
|
250 | - curl_close($myCurl); |
|
251 | - $obj = json_decode($server_output); |
|
232 | + /** |
|
233 | + * Realiza Transaccion |
|
234 | + * Efectúa y retornar una respuesta a un metodo de pago. |
|
235 | + * |
|
236 | + *@param $url endpoint a consultar |
|
237 | + *@param $fields datos para la consulta |
|
238 | + * |
|
239 | + *@return $obj array resultados de la transaccion |
|
240 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
241 | + */ |
|
242 | + public function curlTransaccion($url, $fields) |
|
243 | + { |
|
244 | + $myCurl = curl_init(); |
|
245 | + curl_setopt($myCurl, CURLOPT_URL, $url); |
|
246 | + curl_setopt($myCurl, CURLOPT_POST, 1); |
|
247 | + curl_setopt($myCurl, CURLOPT_POSTFIELDS, http_build_query($fields)); |
|
248 | + curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, true); |
|
249 | + $server_output = curl_exec($myCurl); |
|
250 | + curl_close($myCurl); |
|
251 | + $obj = json_decode($server_output); |
|
252 | 252 | |
253 | - return $obj; |
|
254 | - |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Verifica Codigo de Estado de transaccion |
|
259 | - * Verifica y retornar el resultado de la transaccion. |
|
260 | - * |
|
261 | - *@param $obj datos de la consulta |
|
262 | - * |
|
263 | - *@return $result array datos de transaccion |
|
264 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
265 | - */ |
|
266 | - public function checkResponseCode($obj) |
|
267 | - { |
|
268 | - $code = $obj->code; |
|
269 | - |
|
270 | - if ($code == 400) { |
|
271 | - throw new InstapagoException('Error al validar los datos enviados.'); |
|
272 | - } elseif ($code == 401) { |
|
273 | - throw new InstapagoException('Error de autenticación, ha ocurrido un error con las llaves utilizadas.'); |
|
274 | - } elseif ($code == 403) { |
|
275 | - throw new InstapagoException('Pago Rechazado por el banco.'); |
|
276 | - } elseif ($code == 500) { |
|
277 | - throw new InstapagoException('Ha Ocurrido un error interno dentro del servidor.'); |
|
278 | - } elseif ($code == 503) { |
|
279 | - throw new InstapagoException('Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.'); |
|
280 | - } elseif ($code == 201) { |
|
281 | - return [ |
|
282 | - 'code' => $code, |
|
283 | - 'msg_banco' => $obj->message, |
|
284 | - 'voucher' => html_entity_decode($obj->voucher), |
|
285 | - 'id_pago' => $obj->id, |
|
286 | - 'reference' => $obj->reference, |
|
287 | - ]; |
|
288 | - } |
|
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Verifica parametros para realizar operación |
|
293 | - * Verifica y retorna exception si algun parametro esta vacio. |
|
294 | - * |
|
295 | - *@param $params Array con parametros a verificar |
|
296 | - * |
|
297 | - *@return new InstapagoException |
|
298 | - * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
299 | - */ |
|
300 | - private function checkRequiredParams(array $params) |
|
301 | - { |
|
302 | - foreach ($params as $param) { |
|
303 | - if (empty($param)) { |
|
304 | - throw new InstapagoException('Parámetros faltantes para procesar el pago. Verifique la documentación.'); |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
253 | + return $obj; |
|
254 | + |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Verifica Codigo de Estado de transaccion |
|
259 | + * Verifica y retornar el resultado de la transaccion. |
|
260 | + * |
|
261 | + *@param $obj datos de la consulta |
|
262 | + * |
|
263 | + *@return $result array datos de transaccion |
|
264 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
265 | + */ |
|
266 | + public function checkResponseCode($obj) |
|
267 | + { |
|
268 | + $code = $obj->code; |
|
269 | + |
|
270 | + if ($code == 400) { |
|
271 | + throw new InstapagoException('Error al validar los datos enviados.'); |
|
272 | + } elseif ($code == 401) { |
|
273 | + throw new InstapagoException('Error de autenticación, ha ocurrido un error con las llaves utilizadas.'); |
|
274 | + } elseif ($code == 403) { |
|
275 | + throw new InstapagoException('Pago Rechazado por el banco.'); |
|
276 | + } elseif ($code == 500) { |
|
277 | + throw new InstapagoException('Ha Ocurrido un error interno dentro del servidor.'); |
|
278 | + } elseif ($code == 503) { |
|
279 | + throw new InstapagoException('Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.'); |
|
280 | + } elseif ($code == 201) { |
|
281 | + return [ |
|
282 | + 'code' => $code, |
|
283 | + 'msg_banco' => $obj->message, |
|
284 | + 'voucher' => html_entity_decode($obj->voucher), |
|
285 | + 'id_pago' => $obj->id, |
|
286 | + 'reference' => $obj->reference, |
|
287 | + ]; |
|
288 | + } |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Verifica parametros para realizar operación |
|
293 | + * Verifica y retorna exception si algun parametro esta vacio. |
|
294 | + * |
|
295 | + *@param $params Array con parametros a verificar |
|
296 | + * |
|
297 | + *@return new InstapagoException |
|
298 | + * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE |
|
299 | + */ |
|
300 | + private function checkRequiredParams(array $params) |
|
301 | + { |
|
302 | + foreach ($params as $param) { |
|
303 | + if (empty($param)) { |
|
304 | + throw new InstapagoException('Parámetros faltantes para procesar el pago. Verifique la documentación.'); |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | 308 | } // end class |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $this->statusId = $statusId; |
102 | 102 | $this->ipAddres = $ipAddres; |
103 | 103 | |
104 | - $url = $this->root.'payment'; // endpoint |
|
104 | + $url = $this->root . 'payment'; // endpoint |
|
105 | 105 | |
106 | 106 | $fields = [ |
107 | 107 | 'KeyID' => $this->keyId, //required |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | $this->idPago = $idPago; |
145 | 145 | $this->amount = $amount; |
146 | 146 | |
147 | - $url = $this->root.'complete'; // endpoint |
|
147 | + $url = $this->root . 'complete'; // endpoint |
|
148 | 148 | |
149 | 149 | $fields = [ |
150 | 150 | 'KeyID' => $this->keyId, //required |
@@ -178,12 +178,12 @@ discard block |
||
178 | 178 | |
179 | 179 | $this->idPago = $idPago; |
180 | 180 | |
181 | - $url = $this->root.'payment'; // endpoint |
|
181 | + $url = $this->root . 'payment'; // endpoint |
|
182 | 182 | |
183 | 183 | $myCurl = curl_init(); |
184 | 184 | curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
185 | 185 | curl_setopt($myCurl, CURLOPT_CUSTOMREQUEST, "DELETE"); |
186 | - curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
186 | + curl_setopt($myCurl, CURLOPT_URL, $url . '?' . 'KeyID=' . $this->keyId . '&PublicKeyId=' . $this->publicKeyId . '&id=' . $this->idPago); |
|
187 | 187 | $server_output = curl_exec($myCurl); |
188 | 188 | curl_close($myCurl); |
189 | 189 | $obj = json_decode($server_output); |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | |
212 | 212 | $this->idPago = $idPago; |
213 | 213 | |
214 | - $url = $this->root.'payment'; // endpoint |
|
214 | + $url = $this->root . 'payment'; // endpoint |
|
215 | 215 | |
216 | 216 | $myCurl = curl_init(); |
217 | - curl_setopt($myCurl, CURLOPT_URL, $url.'?'.'KeyID='.$this->keyId.'&PublicKeyId='.$this->publicKeyId.'&id='.$this->idPago); |
|
217 | + curl_setopt($myCurl, CURLOPT_URL, $url . '?' . 'KeyID=' . $this->keyId . '&PublicKeyId=' . $this->publicKeyId . '&id=' . $this->idPago); |
|
218 | 218 | curl_setopt($myCurl, CURLOPT_RETURNTRANSFER, 1); |
219 | 219 | $server_output = curl_exec($myCurl); |
220 | 220 | curl_close($myCurl); |
@@ -35,8 +35,8 @@ |
||
35 | 35 | */ |
36 | 36 | class InstapagoException extends Exception |
37 | 37 | { |
38 | - public function __construct($message = null) |
|
39 | - { |
|
40 | - parent::__construct($message); |
|
41 | - } |
|
38 | + public function __construct($message = null) |
|
39 | + { |
|
40 | + parent::__construct($message); |
|
41 | + } |
|
42 | 42 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | */ |
29 | 29 | |
30 | 30 | spl_autoload_register(function ($class) { |
31 | - $file = dirname(__DIR__).DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php'; |
|
31 | + $file = dirname(__DIR__).DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php'; |
|
32 | 32 | |
33 | - return (!is_file($file)) ?: require $file; |
|
33 | + return (!is_file($file)) ?: require $file; |
|
34 | 34 | }); |
@@ -27,8 +27,8 @@ |
||
27 | 27 | * @copyright 2016 Angel Cruz |
28 | 28 | */ |
29 | 29 | |
30 | -spl_autoload_register(function ($class) { |
|
31 | - $file = dirname(__DIR__).DIRECTORY_SEPARATOR.str_replace('\\', DIRECTORY_SEPARATOR, $class).'.php'; |
|
30 | +spl_autoload_register(function($class) { |
|
31 | + $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; |
|
32 | 32 | |
33 | - return (!is_file($file)) ?: require $file; |
|
33 | + return ( ! is_file($file)) ?: require $file; |
|
34 | 34 | }); |