<?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();
/** * @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); } }