Example #1
0
 /**
  * @param Order $order
  */
 public function validateKhipuCallback(Order $order)
 {
     try {
         if (!$order || !$order->getIncrementId()) {
             throw new \Exception('Order #' . $_REQUEST['order_id'] . ' does not exists');
         }
         $payment = $order->getPayment();
         $notificationToken = isset($_POST['notification_token']) ? $_POST['notification_token'] : '';
         if ($notificationToken == '') {
             throw new \Exception('Invalid notification token.');
         }
         $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 {
             $paymentResponse = $payments->paymentsGet($notificationToken);
         } catch (\Khipu\ApiException $exception) {
             throw new \Exception(print_r($exception->getResponseObject(), TRUE));
         }
         if ($paymentResponse->getReceiverId() != $this->getConfigData('merchant_id')) {
             throw new \Exception('Invalid receiver id');
         }
         if ($paymentResponse->getTransactionId() != $payment->getAdditionalInformation('khipu_order_token')) {
             throw new \Exception('Invalid transaction id');
         }
         if ($paymentResponse->getStatus() != 'done') {
             throw new \Exception('Payment not done');
         }
         if ($paymentResponse->getAmount() != number_format($order->getGrandTotal(), $this->getDecimalPlaces($order->getOrderCurrencyCode()), '.', '')) {
             throw new \Exception('Amount mismatch');
         }
         if ($paymentResponse->getCurrency() != $order->getOrderCurrencyCode()) {
             throw new \Exception('Currency mismatch');
         }
         $order->setState(Order::STATE_PROCESSING, TRUE)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING))->save();
     } catch (\Exception $e) {
         exit('Error occurred: ' . $e);
     }
 }
Example #2
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);
$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();
Example #3
0
//Se agregan los datos:

$sql = "INSERT INTO log(texto) VALUES('notificación de Pago Token: $notification_token')";

$resultado = $con->query($sql);

mysqli_close($con);//*/
try {
    if ($api_version == '1.3') {
        $configuration = new Khipu\Configuration();
        $configuration->setSecret($secret);
        $configuration->setReceiverId($receiver_id);
        // $configuration->setDebug(true);
        $client = new Khipu\ApiClient($configuration);
        $payments = new Khipu\Client\PaymentsApi($client);
        $response = $payments->paymentsGet($notification_token);
        if ($response->getReceiverId() == $receiver_id) {
            if ($response->getStatus() == 'done') {
                $respuesta = json_decode($response);
                $idCobro = $respuesta->payment_id;
                //Se actualiza el pago como realizado en la BD
                //agregar los datos a la BD
                $con = (include $_SERVER['DOCUMENT_ROOT'] . "/admin/crearConexion.php");
                //Se agregan los datos:
                $sql = "UPDATE ventas SET pagado='SI' WHERE id_venta='{$idCobro}'";
                //$sql = "UPDATE cobro SET pagado='SI'";
                $resultado = $con->query($sql);
                /*
                                //Se registra el pago en el log
                
<?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();
}
Example #5
0
             $sqlDetalle = "UPDATE productos SET cantidad = cantidad - " . $_COOKIE["cantidad" . ($i + 1)] . " WHERE nombre = '" . $_COOKIE["producto" . ($i + 1)] . "'";
             $resultDetalle = mysqli_query($conDetalle, $sqlDetalle);
             mysqli_close($conDetalle);
             $TotalVenta += (int) $_COOKIE["cantidad" . ($i + 1)] * (int) $valor;
         }
     }
 }
 //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}'";
$receiverId = 56247;
$secretKey = 'b91a4947d8326319e66fa13abd6d4dd84661c587';
$correo = $_POST["correo"];
$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);
Example #7
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();
}