Ejemplo n.º 1
0
 /**
  * @param Order $order
  * @return array
  */
 public function getKhipuRequest(Order $order)
 {
     $token = substr(md5(rand()), 0, 32);
     $payment = $order->getPayment();
     $payment->setAdditionalInformation('khipu_order_token', $token);
     $payment->save();
     $description = array();
     foreach ($order->getAllItems() as $item) {
         $description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
     }
     $configuration = new \Khipu\Configuration();
     $configuration->setSecret($this->getConfigData('merchant_secret'));
     $configuration->setReceiverId($this->getConfigData('merchant_id'));
     $configuration->setPlatform('magento2-khipu', Payment::KHIPU_MAGENTO_VERSION);
     $client = new \Khipu\ApiClient($configuration);
     $payments = new \Khipu\Client\PaymentsApi($client);
     try {
         $createPaymentResponse = $payments->paymentsPost($this->storeManager->getWebsite()->getName() . ' Carro #' . $order->getIncrementId(), $order->getOrderCurrencyCode(), number_format($order->getGrandTotal(), $this->getDecimalPlaces($order->getOrderCurrencyCode()), '.', ''), $payment->getAdditionalInformation('khipu_order_token'), null, join($description, ', '), null, $this->urlBuilder->getUrl('checkout/onepage/success'), $this->urlBuilder->getUrl('checkout/onepage/failure'), null, $this->urlBuilder->getUrl('khipu/payment/callback') . '?order_id=' . $order->getIncrementId(), '1.3', null, null, null, null, null, null, null, null);
     } catch (\Khipu\ApiException $exception) {
         $error = $exception->getResponseObject();
         $msg = "Error de comunicación con khipu.\n";
         $msg .= "Código: " . $error->getStatus() . "\n";
         $msg .= "Mensaje: " . $error->getMessage() . "\n";
         if (method_exists($error, 'getErrors')) {
             $msg .= "Errores:";
             foreach ($error->getErrors() as $errorItem) {
                 $msg .= "\n" . $errorItem->getField() . ": " . $errorItem->getMessage();
             }
         }
         return array('reason' => $msg, 'status' => false);
     }
     return array('status' => true, 'payment_url' => $createPaymentResponse->getPaymentUrl());
 }
Ejemplo n.º 2
0
// Debemos conocer el $receiverId y el $secretKey de ante mano.
$receiverId = 43182;
$secretKey = '7b32f743f795ac77cd9e7b99c1ccece20d1921cb';
require __DIR__ . '/vendor/autoload.php';
$configuration = new Khipu\Configuration();
$configuration->setReceiverId($receiverId);
$configuration->setSecret($secretKey);
// $configuration->setDebug(true);
$client = new Khipu\ApiClient($configuration);
$payments = new Khipu\Client\PaymentsApi($client);
$subject = 'asdf';
try {
    $expires_date = new DateTime();
    $expires_date->setDate(2016, 4, 4);
    $response = $payments->paymentsPost('PRUEBA PAO QL', 'CLP', 5000);
    /*
    	        , 'FACT2001' // código del cobrador de la transacción, Ej. orden de cómpra o número de factura
    	        , null
    	        , 'Descripción de la compra' // Descripción
    	        , null
    	        , 'http://google.com' // URL de retorno
    	        , 'http://mi-ecomerce.com/backend/cancel' // URL de rechazo
    	        , 'http://http://arropa.org/admin/imagenes/Holaupcycling2.jpg' // Imágen a mostrar
    	        , 'http://mi-ecomerce.com/backend/notify'// URL de notificación
    	        , '1.3' // Versión de la API de notificación
    	        , $expires_date//*/
    echo 'aqui';
} catch (Exception $e) {
    echo $e->getMessage();
}
Ejemplo n.º 3
0
<?php

// Debemos conocer el $receiverId y el $secretKey de ante mano.
$receiverId = 43182;
$secretKey = '7b32f743f795ac77cd9e7b99c1ccece20d1921cb';
require __DIR__ . '/vendor/autoload.php';
$configuration = new Khipu\Configuration();
$configuration->setReceiverId($receiverId);
$configuration->setSecret($secretKey);
$configuration->setDebug(true);
// $configuration->setDebug(true);
$client = new Khipu\ApiClient($configuration);
$payments = new Khipu\Client\PaymentsApi($client);
$subject = 'PRUEBA PAGO KHIPU';
try {
    $response = $payments->paymentsPost($subject, 'CLP', 500, null, null, null, null, null, null, null, null, null, null, true, 'Estefanía Palacios Cortés', '$correo', true);
    print_r($response);
} catch (Exception $e) {
    echo $e->getMessage();
}
Ejemplo n.º 4
0
         }
     }
 }
 //Generamos una nueva venta con khipu
 require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
 $configuration = new Khipu\Configuration();
 $configuration->setReceiverId($receiverId);
 $configuration->setSecret($secretKey);
 //$configuration->setDebug(false);
 // $configuration->setDebug(true);
 $client = new Khipu\ApiClient($configuration);
 $payments = new Khipu\Client\PaymentsApi($client);
 $subject = 'Cobro por Venta de Productos - arropa.org';
 $usuario = $nombre . " " . $apellido;
 try {
     $response = $payments->paymentsPost($subject, 'CLP', $TotalVenta, "Cobro por Venta de Productos - arropa.org", null, null, null, "http://arropa.org/retornoCompra.php", null, "http://arropa.org/images/logo.png", null, null, null, true, $usuario, $correo, true);
     $respuesta = json_decode($response);
     $id_venta = $respuesta->payment_id;
     $url_pago = $respuesta->payment_url;
     //Registramos la venta en la BD y actualizamos los ID del detalle
     $con = (include $_SERVER['DOCUMENT_ROOT'] . "/admin/crearConexion.php");
     //Se obtienen los datos del producto
     $sql = "INSERT INTO ventas(url_pago, id_venta, total) VALUES('{$url_pago}', '{$id_venta}', '{$TOTAL}')";
     $result = mysqli_query($con, $sql);
     $nuevaIDVenta = mysqli_insert_id($con);
     //Se actualizan los detalles de la venta:
     $sql = "UPDATE detalle_ventas SET ventaID='{$nuevaIDVenta}' WHERE ventaID='{$idAleatorio}'";
     $result = mysqli_query($con, $sql);
     mysqli_close($con);
     //*/
     $con = (include $_SERVER['DOCUMENT_ROOT'] . "/admin/crearConexion.php");
Ejemplo n.º 5
0
$origen = $_POST["origen"];
$destino = $_POST["destino"];
$idReserva = $_POST["idReserva"];
$precio = $_POST["precio"];
$usuario = $_POST["usuario"];
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
$configuration = new Khipu\Configuration();
$configuration->setReceiverId($receiverId);
$configuration->setSecret($secretKey);
$configuration->setDebug(false);
// $configuration->setDebug(true);
$client = new Khipu\ApiClient($configuration);
$payments = new Khipu\Client\PaymentsApi($client);
$subject = 'Cobro de Servicio de Transporte';
try {
    $response = $payments->paymentsPost($subject, 'CLP', $precio, "Cobro de Servicio de Transporte", "Cobro por Servicio desde {$origen} hasta {$destino}", null, null, null, null, "http://taxislibertador.cl/logo.png", null, null, null, true, $usuario, $correo, true);
    $respuesta = json_decode($response);
    $idCobro = $respuesta->payment_id;
    $urlCobro = $respuesta->payment_url;
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    //agregar los datos a la BD
    $con = (include $_SERVER['DOCUMENT_ROOT'] . "/admin/crearConexion.php");
    //Se agregan los datos:
    $sql = "INSERT INTO cobro (usuario, correo, origen, destino, idCobro, idReserva, precio, urlCobro) VALUES('{$usuario}','{$correo}','{$origen}','{$destino}','{$idCobro}','{$idReserva}','{$precio}','{$urlCobro}')";
    $resultado = $con->query($sql);
    mysqli_close($con);
    //redireccionar a programas
    header("location:/admin/cobros");
} catch (Exception $e) {
Ejemplo n.º 6
0
<?php

// Debemos conocer el $receiverId y el $secretKey de ante mano.
//$receiver_id = include $_SERVER['DOCUMENT_ROOT']."/admin/khipu/obtenerID.php";
//$secret = include $_SERVER['DOCUMENT_ROOT']."/admin/khipu/obtenerSecret.php";
$receiverId = 43182;
$secretKey = "7b32f743f795ac77cd9e7b99c1ccece20d1921cb";
//Generamos una nueva venta con khipu
require $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';
$configuration = new Khipu\Configuration();
$configuration->setReceiverId($receiverId);
$configuration->setSecret($secretKey);
$configuration->setDebug(false);
$client = new Khipu\ApiClient($configuration);
$payments = new Khipu\Client\PaymentsApi($client);
try {
    $response = $payments->paymentsPost("Cualquier cosa", 'CLP', 1000, "Cobro por Venta de Productos - arropa.org", null, null, null, "http://arropa.org/retornoCompra.php", null, "http://arropa.org/images/logo.png", null, null, null, true, "Guillermo", "*****@*****.**", true);
    $respuesta = json_decode($response);
    $id_venta = $respuesta->payment_id;
    $url_pago = $respuesta->payment_url;
    //redireccionar al pago
    header("location:{$url_pago}");
} catch (Exception $e) {
    echo $e->getMessage();
}