/** * @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); } }
//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 $sql = "INSERT INTO log(texto) VALUES('Pago de Servicio ID: $$idCobro')";