/** * @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); } }
<?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();
$resultado = $con->query($sql); mysqli_close($con); $con = include $_SERVER['DOCUMENT_ROOT']."/admin/crearConexion.php"; //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}'";