Skip to content

Commit e55549d

Browse files
committed
Merge pull request Tifon-#2 from edavism/master
Se agrega el 'agente' a cada llamada de la api
2 parents 34d2e19 + a2e795b commit e55549d

13 files changed

+37
-6
lines changed

src/Khipu.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public function authenticate($receiver_id, $secret) {
5757
$this->secret = $secret;
5858
}
5959

60+
protected $agent = 'lib-php-1.3';
61+
62+
public function setAgent($agent) {
63+
$this->agent = 'lib-php-1.3 - '.$agent;
64+
return $this;
65+
}
66+
6067
/**
6168
* Carga el servicio y retorna el objeto, en caso de no existir el servicio,
6269
* se invoca un excepcion.
@@ -77,14 +84,17 @@ public function loadService($service_name) {
7784
if ($services_name[$service_name]) {
7885
// Es requerido identificarse para usar estos servicios.
7986
if ($this->receiver_id && $this->secret) {
80-
return new $class($this->receiver_id, $this->secret);
87+
$service = new $class($this->receiver_id, $this->secret);
88+
} else {
89+
// Invocamos un Exception
90+
throw new Exception("Is necessary to authenticate to use the service \"$service_name\"");
8191
}
82-
// Invocamos un Exception
83-
throw new Exception("Is necessary to authenticate to use the service \"$service_name\"");
8492
}
8593
else {
86-
return new $class();
94+
$service = new $class();
8795
}
96+
$service->setAgent($this->agent);
97+
return $service;
8898
}
8999
// Si no existe el servicio se invoca un Exception
90100
throw new Exception("The service \"$service_name\" does not exist");

src/KhipuService/KhipuRecipients.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,4 @@ public function cleanRecipients() {
5656
public function getRecipients() {
5757
return $this->recipients;
5858
}
59-
}
59+
}

src/KhipuService/KhipuService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public function __construct($receiver_id, $secret) {
5656
$this->secret = $secret;
5757
}
5858

59+
protected $agent;
60+
public function setAgent($agent) {
61+
$this->agent = $agent;
62+
return $this;
63+
}
64+
5965
/**
6066
* Genera el Hash que requiere Khipu.
6167
*

src/KhipuService/KhipuServiceCreateEmail.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public function send() {
106106
foreach ($this->data as $name => $value) {
107107
$data_to_send[$name] = $value;
108108
}
109+
$data_to_send['agent'] = $this->agent;
110+
109111
// Iniciamos CURL
110112
$ch = curl_init();
111113
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServiceCreatePaymentPage.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public function renderForm($button_type = '100x50') {
6565
$input_hidden->setAttribute('value', $value);
6666
$form->appendChild($input_hidden);
6767
}
68+
$input_hidden = $html->createElement('input');
69+
$input_hidden->setAttribute('type', 'hidden');
70+
$input_hidden->setAttribute('name', 'agent');
71+
$input_hidden->setAttribute('value', $this->agent);
72+
$form->appendChild($input_hidden);
6873

6974
$buttons = Khipu::getButtonsKhipu();
7075
if (isset($buttons[$button_type])) {

src/KhipuService/KhipuServiceCreatePaymentURL.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function createUrl() {
5454
foreach ($this->data as $name => $value) {
5555
$data_to_send[$name] = $value;
5656
}
57+
$data_to_send['agent'] = $this->agent;
58+
5759
// Iniciamos CURL
5860
$ch = curl_init();
5961
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServicePaymentStatus.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function consult() {
3838
'receiver_id' => $this->receiver_id,
3939
'payment_id' => $this->data['payment_id'],
4040
);
41+
$data_to_send['agent'] = $this->agent;
4142

4243
$ch = curl_init();
4344
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServiceReceiverBanks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function consult() {
3434
'hash' => $this->doHash($string_data),
3535
'receiver_id' => $this->receiver_id,
3636
);
37-
37+
$data_to_send['agent'] = $this->agent;
3838
$ch = curl_init();
3939
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);
4040
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

src/KhipuService/KhipuServiceReceiverStatus.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public function consult() {
3636
'hash' => $this->doHash($string_data),
3737
'receiver_id' => $this->receiver_id,
3838
);
39+
$data_to_send['agent'] = $this->agent;
3940

4041
$ch = curl_init();
4142
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServiceSetBillExpired.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function set() {
4242
'bill_id' => $this->data['bill_id'],
4343
'text' => $this->data['text'],
4444
);
45+
$data_to_send['agent'] = $this->agent;
4546
$ch = curl_init();
4647
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);
4748
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

src/KhipuService/KhipuServiceSetPaidByReceiver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function set() {
4040
'receiver_id' => $this->receiver_id,
4141
'payment_id' => $this->data['payment_id'],
4242
);
43+
$data_to_send['agent'] = $this->agent;
4344

4445
$ch = curl_init();
4546
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServiceSetRejectedByPayer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function set() {
4242
'payment_id' => $this->data['payment_id'],
4343
'text' => $this->data['text'],
4444
);
45+
$data_to_send['agent'] = $this->agent;
4546

4647
$ch = curl_init();
4748
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

src/KhipuService/KhipuServiceUpdatePaymentNotificationUrl.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function update() {
4141
'url' => $this->data['url'],
4242
'api_version' => $this->data['api_version'],
4343
);
44+
$data_to_send['agent'] = $this->agent;
4445

4546
$ch = curl_init();
4647
curl_setopt($ch, CURLOPT_URL, $this->apiUrl);

0 commit comments

Comments
 (0)