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