Skip to content

Commit 8565645

Browse files
committed
actualizacion de la documentacion para mostrar la nueva forma de validar las notificaciones de pago
1 parent be8faf3 commit 8565645

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,31 @@ A continuación un ejemplo:
130130

131131
$Khipu = new Khipu();
132132
// No necesitamos identificar al cobrador para usar este servicio.
133-
$khipu_service = $Khipu->loadService('VerifyPaymentNotification');
134-
// Adjuntamos los valores del $_POST en el servicio.
135-
$khipu_service->setDataFromPost();
136-
// Hacemos una solicitud a Khipu para verificar.
137-
$response = $khipu_service->verify();
138-
if ($response['response'] == 'VERIFIED') {
139-
// Hacemos algo al respecto...
133+
134+
$api_version = $_POST['api_version'];
135+
136+
if($api_version == '1.2') {
137+
$khipu_service = $Khipu->loadService('VerifyPaymentNotification');
138+
$khipu_service->setDataFromPost();
139+
$response = $khipu_service->verify();
140+
if($response['response'] == 'VERIFIED'){
141+
//el pago esta verificado, hacemos algo al respecto
142+
}
143+
144+
} else if ($api_version == '1.3') {
145+
146+
$khipu_service = $Khipu->loadService('GetPaymentNotification');
147+
$khipu_service->setDataFromPost();
148+
$response = $khipu_service->consult();
149+
150+
//validamos que la notificacion de pago corresponda con una solicitud de pago esperada
151+
152+
153+
} else {
154+
// api de notificacion no soportada
140155
}
141156

157+
142158
```
143159

144160
### 4) Verificar Estado de una cuenta Khipu

src/KhipuService/KhipuServiceGetPaymentNotification.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ public function consult() {
5151
return $output;
5252
}
5353

54+
/**
55+
* Esta funcion es para asignar los valores recibidos por POST.
56+
*
57+
* Puede usarse en reemplazo del metodo setParameter().
58+
*/
59+
public function setDataFromPost() {
60+
// Recorremos el arreglo $data
61+
foreach ($this->data as $key => $value) {
62+
// Si existe la llave en $_POST entonces asignamos su valor
63+
// a $data
64+
if (isset($_POST[$key])) {
65+
$this->data[$key] = $_POST[$key];
66+
}
67+
}
68+
}
69+
5470
protected function dataToString() {
5571
$string = '';
5672
$string .= 'receiver_id=' . $this->receiver_id;

0 commit comments

Comments
 (0)