|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * (c) Emilio Davis <[email protected]> |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +require_once 'KhipuService.php'; |
| 11 | + |
| 12 | +/** |
| 13 | + * Servicio GetPaymentNotification extiende de KhipuService |
| 14 | + * |
| 15 | + * Este servicio consulta una notificacion de pago |
| 16 | + */ |
| 17 | +class KhipuServiceGetPaymentNotification extends KhipuService { |
| 18 | + /** |
| 19 | + * Iniciamos el servicio |
| 20 | + */ |
| 21 | + public function __construct($receiver_id, $secret) { |
| 22 | + parent::__construct($receiver_id, $secret); |
| 23 | + // Asignamos la url del servicio |
| 24 | + $this->apiUrl = Khipu::getUrlService('GetPaymentNotification'); |
| 25 | + $this->data = array( |
| 26 | + 'notification_token' => '', |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Método que consulta por la notificacion de pago |
| 32 | + */ |
| 33 | + public function consult() { |
| 34 | + $string_data = $this->dataToString(); |
| 35 | + |
| 36 | + $data_to_send = array( |
| 37 | + 'hash' => $this->doHash($string_data), |
| 38 | + 'receiver_id' => $this->receiver_id, |
| 39 | + 'notification_token' => $this->data['notification_token'], |
| 40 | + ); |
| 41 | + $data_to_send['agent'] = $this->agent; |
| 42 | + $ch = curl_init(); |
| 43 | + curl_setopt($ch, CURLOPT_URL, $this->apiUrl); |
| 44 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 45 | + curl_setopt($ch, CURLOPT_POST, TRUE); |
| 46 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_to_send); |
| 47 | + $output = curl_exec($ch); |
| 48 | + $info = curl_getinfo($ch); |
| 49 | + curl_close($ch); |
| 50 | + |
| 51 | + return $output; |
| 52 | + } |
| 53 | + |
| 54 | + protected function dataToString() { |
| 55 | + $string = ''; |
| 56 | + $string .= 'receiver_id=' . $this->receiver_id; |
| 57 | + $string .= '¬ification_token=' . $this->data['notification_token']; |
| 58 | + return trim($string); |
| 59 | + } |
| 60 | +} |
0 commit comments