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