/** * Método para cargar un servicio y capturar el Exception en caso de error. */ private function loadServiceKhipu(Khipu $khipu, $service) { try { return $khipu->loadService($service); } catch (Exception $exp) { return $exp; } }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('SetRejectedByPayer'); $this->data = array('payment_id' => '', 'text' => ''); }
/** * Método que genera el formulario de pago en HTML * * @param string $button_type * Dimensión del boton a mostrar * * @return string * Formulario renderizado */ public function renderForm($button_type = '100x50') { $values = $this->getFormLabels(); $html = new DOMDocument(); $html->formatOutput = true; $form = $html->createElement('form'); $form->setAttribute('action', $this->getApiUrl()); $form->setAttribute('method', 'POST'); foreach ($values as $name => $value) { $input_hidden = $html->createElement('input'); $input_hidden->setAttribute('type', 'hidden'); $input_hidden->setAttribute('name', $name); $input_hidden->setAttribute('value', $value); $form->appendChild($input_hidden); } $input_hidden = $html->createElement('input'); $input_hidden->setAttribute('type', 'hidden'); $input_hidden->setAttribute('name', 'agent'); $input_hidden->setAttribute('value', $this->agent); $form->appendChild($input_hidden); $buttons = Khipu::getButtonsKhipu(); if (isset($buttons[$button_type])) { $button = $buttons[$button_type]; } else { $button = $buttons['100x50']; } $submit = $html->createElement('input'); $submit->setAttribute('type', 'image'); $submit->setAttribute('src', $button); $form->appendChild($submit); $html->appendChild($form); return $html->saveHTML(); }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('UpdatePaymentNotificationUrl'); $this->data = array('url' => '', 'api_version' => ''); }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('SetBillExpired'); $this->data = array('bill_id' => '', 'text' => ''); }
/** * Iniciamos el servicio */ public function __construct() { // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('VerifyPaymentNotification'); // Iniciamos los datos requeridos por le servicio $this->data = array('api_version' => '', 'receiver_id' => '', 'notification_id' => '', 'subject' => '', 'amount' => '', 'currency' => '', 'transaction_id' => '', 'payer_email' => '', 'custom' => '', 'notification_signature' => ''); }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('GetPaymentNotification'); $this->data = array('notification_token' => ''); }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('PaymentStatus'); $this->data = array('payment_id' => ''); }
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Iniciamos la variable apiUrl con la url del servicio. $this->apiUrl = Khipu::getUrlService('CreatePaymentURL'); // Iniciamos el arreglo $data con los valores que requiere el servicio. $this->data = array('receiver_id' => $receiver_id, 'subject' => '', 'body' => '', 'amount' => 0, 'custom' => '', 'notify_url' => '', 'return_url' => '', 'cancel_url' => '', 'bank_id' => '', 'expires_date' => '', 'transaction_id' => '', 'picture_url' => '', 'payer_email' => ''); }
/** * Iniciamos el servicio identificando al cobrador. */ function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Cargamos el objeto KhipuRecipientes para adjuntar destinatarios. $this->recipients = new KhipuRecipients(); // Iniciamos la variable apiUrl con la url del servicio. $this->apiUrl = Khipu::getUrlService('CreateEmail'); // Iniciamos el arreglo $data con los valores que requiere el servicio. $this->data = array('receiver_id' => $receiver_id, 'subject' => '', 'body' => '', 'transaction_id' => '', 'custom' => '', 'notify_url' => '', 'return_url' => '', 'cancel_url' => '', 'pay_directly' => 'true', 'send_emails' => 'true', 'expires_date' => '', 'picture_url' => ''); }
</div> <div class="field"> <label class="label-example">Bill ID</label> <input required type="textfield" name="bill_id" value="<?php print isset($_POST['bill_id']) ? $_POST['bill_id'] : ''; ?> "/> </div> <input type="submit" value="Expirar Pago"/> </form> <?php if (isset($_POST['receiver_id']) && isset($_POST['secret']) && isset($_POST['bill_id'])) { ?> <div>Respuesta: <?php $Khipu = new Khipu(); // Nos identificamos $Khipu->authenticate($_POST['receiver_id'], $_POST['secret']); // Vamos a expirar el pago $data = array('bill_id' => $_POST['bill_id'], 'text' => 'Expirando pago de ejemplo'); $expired_service = $Khipu->loadService('SetBillExpired'); $expired_service->setParameters($data); if ($expired_service->set()) { print '<div class="message success">Expiramos el cobro ' . $_POST['bill_id'] . '</div>'; } else { print '<div class="message error">No se pudo expirar el cobro ' . $_POST['bill_id']; print '<p>El mensaje de Khipu es: <em>' . $expired_service->getMessage() . '</em></p>'; print '</div>'; } ?> </div>
</div> <div class="field"> <label class="label-example">Correo</label> <input required type="email" name="email" value="<?php print isset($_POST['email']) ? $_POST['email'] : ''; ?> "/> </div> <input type="submit" value="Crear Cobro"/> </form> <?php if (isset($_POST['receiver_id']) && isset($_POST['secret']) && isset($_POST['email'])) { ?> <div>Respuesta: <?php $Khipu = new Khipu(); // Nos identificamos $Khipu->authenticate($_POST['receiver_id'], $_POST['secret']); // Cargamos el servicio para crear el boton // Luego cargamos el servicio. $khipu_service = $Khipu->loadService('CreateEmail'); // Preparamos los datos que queremos enviar $data = array('subject' => 'Título del pago', 'body' => 'Descripción del producto', 'transaction_id' => '1', 'pay_directly' => 'false', 'send_emails' => 'true', 'return_url' => '', 'expires_date' => time() + 30 * 24 * 60 * 60, 'picture_url' => ''); if ($_POST['amount'] > 0) { $amount = $_POST['amount']; } $khipu_service->setParameters($data); // Agregamos un destinatario con un monto $khipu_service->addRecipient('Example Name', $_POST['email'], $amount); // Lo enviamos $respuesta = $khipu_service->send();
/** * Iniciamos el servicio */ public function __construct($receiver_id, $secret) { parent::__construct($receiver_id, $secret); // Asignamos la url del servicio $this->apiUrl = Khipu::getUrlService('ReceiverStatus'); }
</div> <div class="field"> <label class="label-example">Payment ID</label> <input required type="textfield" name="payment_id" value="<?php print isset($_POST['payment_id']) ? $_POST['payment_id'] : ''; ?> "/> </div> <input type="submit" value="Marcar un pago como rechazado"/> </form> <?php if (isset($_POST['receiver_id']) && isset($_POST['secret']) && isset($_POST['payment_id'])) { ?> <div>Respuesta: <?php $Khipu = new Khipu(); // Nos identificamos $Khipu->authenticate($_POST['receiver_id'], $_POST['secret']); $data = array('payment_id' => $_POST['payment_id'], 'text' => 'Se rechaza por el example'); $service = $Khipu->loadService('SetRejectedByPayer'); $service->setParameters($data); if ($service->set()) { print '<div class="message success">Se marco como rechazado el pago ' . $_POST['payment_id']; print '</div>'; } else { print '<div class="message error">No se pudo marca como rechazado el pago ' . $_POST['payment_id']; print '<p>El mensaje de Khipu es: <em>' . $service->getMessage() . '</em></p>'; print '</div>'; } ?> </div>
</div> <div class="field"> <label class="label-example">Url (Opcional)</label> <input size="43" type="textfield" name="url" value="<?php print isset($_POST['url']) ? $_POST['url'] : ''; ?> "/> </div> <input type="submit" value="Actualizar"/> </form> <?php if (isset($_POST['receiver_id']) && isset($_POST['secret'])) { ?> <div>Respuesta: <?php $Khipu = new Khipu(); // Nos identificamos $Khipu->authenticate($_POST['receiver_id'], $_POST['secret']); $data = array('api_version' => $_POST['api_version'], 'url' => $_POST['url']); $service = $Khipu->loadService('UpdatePaymentNotificationUrl'); $service->setParameters($data); print $service->update(); print $service->getMessage(); ?> </div> <?php } ?> </div> </div> </div>
</div> <div class="field"> <label class="label-example">Llave</label> <input required size="43" type="textfield" name="secret" value="<?php print isset($_POST['secret']) ? $_POST['secret'] : ''; ?> "/> </div> <input type="submit" value="Consultar Estado"/> </form> <?php if (isset($_POST['receiver_id']) && isset($_POST['secret'])) { ?> <div>Respuesta: <?php $Khipu = new Khipu(); // Nos identificamos $Khipu->authenticate($_POST['receiver_id'], $_POST['secret']); $service = $Khipu->loadService('ReceiverStatus'); print $service->consult(); ?> </div> <?php } ?> </div> </div> </div> </body> </html>
public function setUp() { $khipu = new Khipu(); $khipu->authenticate(KHIPU_TEST_RECEIVER_ID, KHIPU_TEST_SECRET); $this->service = $khipu->loadService('CreateEmail'); }
function khipu_get_verified_order_id_1_3($receiver_id, $secret, $params, $agent) { $Khipu = new Khipu(); $Khipu->authenticate($receiver_id, $secret); $Khipu->setAgent($agent); $service = $Khipu->loadService('GetPaymentNotification'); $service->setDataFromPost(); $response = json_decode($service->consult()); if ($response->receiver_id != $receiver_id) { error_log("recibido " . $response->receiver_id . " en el receiver_id"); return 0; } return $response->receiver_id == $receiver_id ? $response->custom : 0; }
public static function getOrderFromNotification_1_2($methodname) { require_once "lib-khipu/src/Khipu.php"; $Khipu = new Khipu(); $_POST = array_map('stripslashes', $_POST); $Khipu->authenticate(Mage::getStoreConfig("payment/{$methodname}/receiver_id"), Mage::getStoreConfig("payment/{$methodname}/api_secret")); $Khipu->setAgent('khmage-1.5.0;;' . Mage::app()->getStore()->getHomeUrl() . ';;' . Mage::app()->getStore()->getName()); $create_page_service = $Khipu->loadService('VerifyPaymentNotification'); $create_page_service->setDataFromPost(); if ($_POST['receiver_id'] != Mage::getStoreConfig("payment/{$methodname}/receiver_id")) { return false; } $verify = $create_page_service->verify(); $verified = $verify['response'] == 'VERIFIED'; if ($verified) { $order = Mage::getModel('sales/order'); $order->loadByIncrementId($_POST['transaction_id']); return $order; } return null; }