Completed
Push — master ( c1ae1c...dc77cb )
by angel
14s
created
Instapago/InstapagoGateway/InstapagoPayment.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -329,7 +329,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -39,259 +39,259 @@
 block discarded – undo
39 39
  */
40 40
 class InstapagoPayment
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
-
55
-    /**
56
-     * Crear un nuevo objeto de Instapago.
57
-     *
58
-     * @param string $keyId       llave privada
59
-     * @param string $publicKeyId llave publica
60
-     *                            Requeridas.
61
-     */
62
-    public function __construct($keyId, $publicKeyId)
63
-    {
64
-        try {
65
-            if (empty($keyId) && empty($publicKeyId)) {
66
-                throw new InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.');
67
-            }
68
-
69
-            if (empty($keyId)) {
70
-                throw new InstapagoException('El parámetro "keyId" es requerido para procesar la petición. ');
71
-            }
72
-
73
-            if (empty($publicKeyId)) {
74
-                throw new InstapagoException('El parámetro "publicKeyId" es requerido para procesar la petición.');
75
-            }
76
-
77
-            $this->publicKeyId = $publicKeyId;
78
-            $this->keyId = $keyId;
79
-        } catch (InstapagoException $e) {
80
-            echo $e->getMessage();
81
-        } // end try/catch
82
-    }
83
-
84
-    /**
85
-     * Crear un pago
86
-     * Efectúa un pago con tarjeta de crédito, una vez procesado retornar una respuesta.
87
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#crear-un-pago.
88
-     */
89
-    public function payment($amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres)
90
-    {
91
-        try {
92
-            $params = [$amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres];
93
-            $this->checkRequiredParams($params);
94
-
95
-            $this->amount = $amount;
96
-            $this->description = $description;
97
-            $this->cardHolder = $cardHolder;
98
-            $this->cardHolderId = $cardHolderId;
99
-            $this->cardNumber = $cardNumber;
100
-            $this->cvc = $cvc;
101
-            $this->expirationDate = $expirationDate;
102
-            $this->statusId = $statusId;
103
-            $this->ipAddres = $ipAddres;
104
-
105
-            $url = 'payment'; // endpoint
106
-
107
-            $fields = [
108
-                'KeyID'             => $this->keyId, //required
109
-                'PublicKeyId'       => $this->publicKeyId, //required
110
-                'amount'            => $this->amount, //required
111
-                'description'       => $this->description, //required
112
-                'cardHolder'        => $this->cardHolder, //required
113
-                'cardHolderId'      => $this->cardHolderId, //required
114
-                'cardNumber'        => $this->cardNumber, //required
115
-                'cvc'               => $this->cvc, //required
116
-                'expirationDate'    => $this->expirationDate, //required
117
-                'statusId'          => $this->statusId, //required
118
-                'IP'                => $this->ipAddres, //required
119
-            ];
120
-
121
-            $obj = $this->curlTransaccion($url, $fields, 'POST');
122
-            $result = $this->checkResponseCode($obj);
123
-
124
-            return $result;
125
-        } catch (InstapagoException $e) {
126
-            echo $e->getMessage();
127
-        } // end try/catch
128
-    }
129
-
130
-    /**
131
-     * Completar Pago
132
-     * Este método funciona para procesar un bloqueo o pre-autorización
133
-     * para así procesarla y hacer el cobro respectivo.
134
-     * Para usar este método es necesario configurar en `payment()` el parametro statusId a 1
135
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#completar-pago.
136
-     */
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 = '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, 'POST');
157
-            $result = $this->checkResponseCode($obj);
158
-
159
-            return $result;
160
-        } catch (InstapagoException $e) {
161
-            echo $e->getMessage();
162
-        } // end try/catch
163
-    }
164
-
165
-    /**
166
-     * Información o Cancelación del pago
167
-     * Consulta información sobre un pago generado anteriormente o puede cancelarlo.
168
-     * Requiere como parámetro el `id` que es el código de referencia de la transacción
169
-     * @param `$idPago` que es el código de referencia de la transacción
170
-     * @param `$method` que puede ser GET o DELETE según lo que desea hacer
171
-     *
172
-     * @return $obj array resultados de la transaccion
173
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
174
-     */
175
-    public function paymentCancelOrInfo($idPago, $method)
176
-    {
177
-        try {
178
-            $params = [$idPago];
179
-            $this->checkRequiredParams($params);
180
-
181
-            $this->idPago = $idPago;
182
-
183
-            $url = 'payment'; // endpoint
184
-
185
-            $fields = [
186
-                'KeyID'             => $this->keyId, //required
187
-                'PublicKeyId'       => $this->publicKeyId, //required
188
-                'id'                => $this->idPago, //required
189
-            ];
190
-
191
-            $obj = $this->curlTransaccion($url, $fields, $method);
192
-
193
-            $result = $this->checkResponseCode($obj);
194
-
195
-            return $result;
196
-
197
-        } catch (InstapagoException $e) {
198
-            echo $e->getMessage();
199
-        } // end try/catch
200
-    }
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
+
55
+	/**
56
+	 * Crear un nuevo objeto de Instapago.
57
+	 *
58
+	 * @param string $keyId       llave privada
59
+	 * @param string $publicKeyId llave publica
60
+	 *                            Requeridas.
61
+	 */
62
+	public function __construct($keyId, $publicKeyId)
63
+	{
64
+		try {
65
+			if (empty($keyId) && empty($publicKeyId)) {
66
+				throw new InstapagoException('Los parámetros "keyId" y "publicKeyId" son requeridos para procesar la petición.');
67
+			}
68
+
69
+			if (empty($keyId)) {
70
+				throw new InstapagoException('El parámetro "keyId" es requerido para procesar la petición. ');
71
+			}
72
+
73
+			if (empty($publicKeyId)) {
74
+				throw new InstapagoException('El parámetro "publicKeyId" es requerido para procesar la petición.');
75
+			}
76
+
77
+			$this->publicKeyId = $publicKeyId;
78
+			$this->keyId = $keyId;
79
+		} catch (InstapagoException $e) {
80
+			echo $e->getMessage();
81
+		} // end try/catch
82
+	}
83
+
84
+	/**
85
+	 * Crear un pago
86
+	 * Efectúa un pago con tarjeta de crédito, una vez procesado retornar una respuesta.
87
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#crear-un-pago.
88
+	 */
89
+	public function payment($amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres)
90
+	{
91
+		try {
92
+			$params = [$amount, $description, $cardHolder, $cardHolderId, $cardNumber, $cvc, $expirationDate, $statusId, $ipAddres];
93
+			$this->checkRequiredParams($params);
94
+
95
+			$this->amount = $amount;
96
+			$this->description = $description;
97
+			$this->cardHolder = $cardHolder;
98
+			$this->cardHolderId = $cardHolderId;
99
+			$this->cardNumber = $cardNumber;
100
+			$this->cvc = $cvc;
101
+			$this->expirationDate = $expirationDate;
102
+			$this->statusId = $statusId;
103
+			$this->ipAddres = $ipAddres;
104
+
105
+			$url = 'payment'; // endpoint
106
+
107
+			$fields = [
108
+				'KeyID'             => $this->keyId, //required
109
+				'PublicKeyId'       => $this->publicKeyId, //required
110
+				'amount'            => $this->amount, //required
111
+				'description'       => $this->description, //required
112
+				'cardHolder'        => $this->cardHolder, //required
113
+				'cardHolderId'      => $this->cardHolderId, //required
114
+				'cardNumber'        => $this->cardNumber, //required
115
+				'cvc'               => $this->cvc, //required
116
+				'expirationDate'    => $this->expirationDate, //required
117
+				'statusId'          => $this->statusId, //required
118
+				'IP'                => $this->ipAddres, //required
119
+			];
120
+
121
+			$obj = $this->curlTransaccion($url, $fields, 'POST');
122
+			$result = $this->checkResponseCode($obj);
123
+
124
+			return $result;
125
+		} catch (InstapagoException $e) {
126
+			echo $e->getMessage();
127
+		} // end try/catch
128
+	}
129
+
130
+	/**
131
+	 * Completar Pago
132
+	 * Este método funciona para procesar un bloqueo o pre-autorización
133
+	 * para así procesarla y hacer el cobro respectivo.
134
+	 * Para usar este método es necesario configurar en `payment()` el parametro statusId a 1
135
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#completar-pago.
136
+	 */
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 = '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, 'POST');
157
+			$result = $this->checkResponseCode($obj);
158
+
159
+			return $result;
160
+		} catch (InstapagoException $e) {
161
+			echo $e->getMessage();
162
+		} // end try/catch
163
+	}
164
+
165
+	/**
166
+	 * Información o Cancelación del pago
167
+	 * Consulta información sobre un pago generado anteriormente o puede cancelarlo.
168
+	 * Requiere como parámetro el `id` que es el código de referencia de la transacción
169
+	 * @param `$idPago` que es el código de referencia de la transacción
170
+	 * @param `$method` que puede ser GET o DELETE según lo que desea hacer
171
+	 *
172
+	 * @return $obj array resultados de la transaccion
173
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
174
+	 */
175
+	public function paymentCancelOrInfo($idPago, $method)
176
+	{
177
+		try {
178
+			$params = [$idPago];
179
+			$this->checkRequiredParams($params);
180
+
181
+			$this->idPago = $idPago;
182
+
183
+			$url = 'payment'; // endpoint
184
+
185
+			$fields = [
186
+				'KeyID'             => $this->keyId, //required
187
+				'PublicKeyId'       => $this->publicKeyId, //required
188
+				'id'                => $this->idPago, //required
189
+			];
190
+
191
+			$obj = $this->curlTransaccion($url, $fields, $method);
192
+
193
+			$result = $this->checkResponseCode($obj);
194
+
195
+			return $result;
196
+
197
+		} catch (InstapagoException $e) {
198
+			echo $e->getMessage();
199
+		} // end try/catch
200
+	}
201 201
 
202 202
  // paymentInfo
203 203
 
204
-    /**
205
-     * Realiza Transaccion
206
-     * Efectúa y retornar una respuesta a un metodo de pago.
207
-     *
208
-     *@param $url endpoint a consultar
209
-     *@param $fields datos para la consulta
210
-     *
211
-     *@return $obj array resultados de la transaccion
212
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
213
-     */
214
-    public function curlTransaccion($url, $fields, $method)
215
-    {
204
+	/**
205
+	 * Realiza Transaccion
206
+	 * Efectúa y retornar una respuesta a un metodo de pago.
207
+	 *
208
+	 *@param $url endpoint a consultar
209
+	 *@param $fields datos para la consulta
210
+	 *
211
+	 *@return $obj array resultados de la transaccion
212
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
213
+	 */
214
+	public function curlTransaccion($url, $fields, $method)
215
+	{
216 216
         
217 217
 
218
-        $client = new Client([
219
-             'base_uri' => 'https://api.instapago.com/',
220
-             //'debug' => true,
221
-        ]);
222
-
223
-        if ($method == 'GET') {
224
-            $request = $client->request('GET', $url, [
225
-                'query' => $fields
226
-            ]);
227
-        }
228
-        if ($method == 'POST' || $method == 'DELETE') {
229
-            $request = $client->request($method, $url, [
230
-                'form_params' => $fields
231
-            ]);
232
-        }
233
-
234
-        $body = $request->getBody()->getContents();
235
-
236
-        $obj = json_decode($body);
237
-
238
-        return $obj;
239
-    }
240
-
241
-    /**
242
-     * Verifica Codigo de Estado de transaccion
243
-     * Verifica y retornar el resultado de la transaccion.
244
-     *
245
-     *@param $obj datos de la consulta
246
-     *
247
-     *@return $result array datos de transaccion
248
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
249
-     */
250
-    public function checkResponseCode($obj)
251
-    {
252
-        $code = $obj->code;
253
-
254
-        if ($code == 400) {
255
-            throw new InstapagoException('Error al validar los datos enviados.');
256
-        }
257
-        if ($code == 401) {
258
-            throw new InstapagoException('Error de autenticación, ha ocurrido un error con las llaves utilizadas.');
259
-        }
260
-        if ($code == 403) {
261
-            throw new InstapagoException('Pago Rechazado por el banco.');
262
-        }
263
-        if ($code == 500) {
264
-            throw new InstapagoException('Ha Ocurrido un error interno dentro del servidor.');
265
-        }
266
-        if ($code == 503) {
267
-            throw new InstapagoException('Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.');
268
-        }
269
-        if ($code == 201) {
270
-            return [
271
-                'code'         => $code,
272
-                'msg_banco'    => $obj->message,
273
-                'voucher'      => html_entity_decode($obj->voucher),
274
-                'id_pago'      => $obj->id,
275
-                'reference'    => $obj->reference,
276
-            ];
277
-        }
278
-    }
279
-
280
-    /**
281
-     * Verifica parametros para realizar operación
282
-     * Verifica y retorna exception si algun parametro esta vacio.
283
-     *
284
-     *@param $params Array con parametros a verificar
285
-     *
286
-     *@return new InstapagoException
287
-     * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
288
-     */
289
-    private function checkRequiredParams(array $params)
290
-    {
291
-        foreach ($params as $param) {
292
-            if (empty($param)) {
293
-                throw new InstapagoException('Parámetros faltantes para procesar el pago. Verifique la documentación.');
294
-            }
295
-        }
296
-    }
218
+		$client = new Client([
219
+			 'base_uri' => 'https://api.instapago.com/',
220
+			 //'debug' => true,
221
+		]);
222
+
223
+		if ($method == 'GET') {
224
+			$request = $client->request('GET', $url, [
225
+				'query' => $fields
226
+			]);
227
+		}
228
+		if ($method == 'POST' || $method == 'DELETE') {
229
+			$request = $client->request($method, $url, [
230
+				'form_params' => $fields
231
+			]);
232
+		}
233
+
234
+		$body = $request->getBody()->getContents();
235
+
236
+		$obj = json_decode($body);
237
+
238
+		return $obj;
239
+	}
240
+
241
+	/**
242
+	 * Verifica Codigo de Estado de transaccion
243
+	 * Verifica y retornar el resultado de la transaccion.
244
+	 *
245
+	 *@param $obj datos de la consulta
246
+	 *
247
+	 *@return $result array datos de transaccion
248
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
249
+	 */
250
+	public function checkResponseCode($obj)
251
+	{
252
+		$code = $obj->code;
253
+
254
+		if ($code == 400) {
255
+			throw new InstapagoException('Error al validar los datos enviados.');
256
+		}
257
+		if ($code == 401) {
258
+			throw new InstapagoException('Error de autenticación, ha ocurrido un error con las llaves utilizadas.');
259
+		}
260
+		if ($code == 403) {
261
+			throw new InstapagoException('Pago Rechazado por el banco.');
262
+		}
263
+		if ($code == 500) {
264
+			throw new InstapagoException('Ha Ocurrido un error interno dentro del servidor.');
265
+		}
266
+		if ($code == 503) {
267
+			throw new InstapagoException('Ha Ocurrido un error al procesar los parámetros de entrada. Revise los datos enviados y vuelva a intentarlo.');
268
+		}
269
+		if ($code == 201) {
270
+			return [
271
+				'code'         => $code,
272
+				'msg_banco'    => $obj->message,
273
+				'voucher'      => html_entity_decode($obj->voucher),
274
+				'id_pago'      => $obj->id,
275
+				'reference'    => $obj->reference,
276
+			];
277
+		}
278
+	}
279
+
280
+	/**
281
+	 * Verifica parametros para realizar operación
282
+	 * Verifica y retorna exception si algun parametro esta vacio.
283
+	 *
284
+	 *@param $params Array con parametros a verificar
285
+	 *
286
+	 *@return new InstapagoException
287
+	 * https://github.com/abr4xas/php-instapago/blob/master/help/DOCUMENTACION.md#PENDIENTE
288
+	 */
289
+	private function checkRequiredParams(array $params)
290
+	{
291
+		foreach ($params as $param) {
292
+			if (empty($param)) {
293
+				throw new InstapagoException('Parámetros faltantes para procesar el pago. Verifique la documentación.');
294
+			}
295
+		}
296
+	}
297 297
 } // end class
Please login to merge, or discard this patch.