public function process() { $body = Tools::file_get_contents('php://input'); $data = trim($body); $result = OpenPayU_Order::consumeNotification($data); $response = $result->getResponse(); SimplePayuLogger::addLog('notification', __FUNCTION__, print_r($result, true), $response->order->orderId, 'Incoming notification: '); if (isset($response->order->orderId)) { $payu = new PayU(); $payu->payu_order_id = $response->order->orderId; $order_payment = $payu->getOrderPaymentBySessionId($payu->payu_order_id); $id_order = (int) $order_payment['id_order']; // if order not validated yet if ($id_order == 0 && $order_payment['status'] == PayU::PAYMENT_STATUS_NEW) { $id_order = $this->createOrder($order_payment, $payu, $response); } if (!empty($id_order)) { $payu->id_order = $id_order; $payu->updateOrderData($response); } if ($this->checkIfPaymentIdIsPresent($response) && $response->order->status == PayU::ORDER_V2_COMPLETED) { $this->addPaymentIdToOrder($response, $payu, $id_order); } //the response should be status 200 header("HTTP/1.1 200 OK"); exit; } }
/** * @return JsonResponse|Response */ public function notifyAction() { $paymentController = $this->get('ant_qa.payu_bundle.controller.payment'); /** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */ $dispatcher = $this->container->get('event_dispatcher'); try { $body = file_get_contents('php://input'); $data = stripslashes(trim($body)); /** @var \stdClass $result */ $result = \OpenPayU_Order::consumeNotification($data)->getResponse(); if ($result->order->orderId) { $order = \OpenPayU_Order::retrieve($result->order->orderId); /** @var Payment $payment */ $payment = $this->getDoctrine()->getManager()->getRepository($this->container->getParameter('payu_bundle.payment_class'))->find($result->order->orderId); if ($payment) { if ($payment->getStatus() !== Payment::STATUS_COMPLETED && $payment->getStatus() !== Payment::STATUS_CANCELED) { //update payment status $payment->setStatus($result->order->status); $this->getDoctrine()->getManager()->flush(); $event = new PaymentEvent($payment); $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_STATUS_UPDATE, $event); if ($result->order->status === Payment::STATUS_CANCELED) { //payment canceled - eg. notify user? $event = new PaymentEvent($payment); $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_CANCELED, $event); } if ($result->order->status === Payment::STATUS_COMPLETED) { //process payment action - eg. add user point? $event = new PaymentEvent($payment); $dispatcher->dispatch(AntQaPaymentEvents::PAYMENT_COMPLETED, $event); } } } $responseContent = \OpenPayU::buildOrderNotifyResponse($result->order->orderId); $response = new Response(); $response->setContent($responseContent); $response->headers->add(['Content-Type' => 'application/json']); return $response; } } catch (\Exception $e) { $this->get('logger')->addError($e->getMessage()); return new JsonResponse($e->getMessage()); } return new Response('thanks for notice'); }
public function orderNotifyRequest() { $body = file_get_contents('php://input'); $data = trim($body); $result = OpenPayU_Order::consumeNotification($data); $response = $result->getResponse(); if ($response->order->orderId) { $this->_transactionId = $response->order->orderId; $extOrderIdExploded = $pieces = explode("-", $response->order->extOrderId); $orderId = $extOrderIdExploded[0]; // Mage::log(print_r($orderId, true),null, 'notification.log'); $this->setOrderByOrderId($orderId); if ($response->order->status == 'COMPLETED' && $this->_order->getState() == Mage_Sales_Model_Order::STATE_PROCESSING) { header("HTTP/1.1 200 OK"); exit; } $this->retrieveAndUpdateByOrderRetrieved($response->order); //the response should be status 200 header("HTTP/1.1 200 OK"); } exit; }
/** * Function consume message * @access public * @param string $xml * @param boolean $response Show Response Xml * @param boolean $debug * @return object $result */ public static function consumeMessage($xml, $response = TRUE, $debug = TRUE) { $xml = stripslashes(urldecode($xml)); $rq = OpenPayU::parseOpenPayUDocument($xml); $msg = $rq['OpenPayU']['OrderDomainRequest']; switch (key($msg)) { case 'OrderNotifyRequest': return OpenPayU_Order::consumeNotification($xml, $response, $debug); break; case 'ShippingCostRetrieveRequest': return OpenPayU_Order::consumeShippingCostRetrieveRequest($xml, $debug); break; default: return key($msg); break; } }
<?php /** * OpenPayU Examples * * @copyright Copyright (c) 2011-2015 PayU * @license http://opensource.org/licenses/LGPL-3.0 Open Software License (LGPL 3.0) * http://www.payu.com * http://developers.payu.com */ require_once realpath(dirname(__FILE__)) . '/../../../lib/openpayu.php'; require_once realpath(dirname(__FILE__)) . '/../../config.php'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { $body = file_get_contents('php://input'); $data = trim($body); try { if (!empty($data)) { $result = OpenPayU_Order::consumeNotification($data); } if ($result->getResponse()->order->orderId) { /* Check if OrderId exists in Merchant Service, update Order data by OrderRetrieveRequest */ $order = OpenPayU_Order::retrieve($result->getResponse()->order->orderId); if ($order->getStatus() == 'SUCCESS') { //the response should be status 200 header("HTTP/1.1 200 OK"); } } } catch (OpenPayU_Exception $e) { echo $e->getMessage(); } }
public function orderNotifyRequest() { $body = file_get_contents('php://input'); $data = trim($body); $result = OpenPayU_Order::consumeNotification($data); $response = $result->getResponse(); $orderRetrieved = $response->order; if (isset($orderRetrieved) && is_object($orderRetrieved) && $orderRetrieved->orderId) { $this->_transactionId = $orderRetrieved->orderId; $extOrderIdExploded = explode(self::DELIMITER, $orderRetrieved->extOrderId); $orderId = array_shift($extOrderIdExploded); $this->setOrderByOrderId($orderId); if (isset($orderRetrieved->payMethod->type)) { $this->_payuPayMethod = $orderRetrieved->payMethod->type; } $payUPaymentStatus = $orderRetrieved->status; $this->_updatePaymentStatus($payUPaymentStatus); //the response should be status 200 header("HTTP/1.1 200 OK"); } exit; }
public function ordernotify() { $this->loadLibConfig(); $this->load->model('payment/payu'); $body = file_get_contents('php://input'); $data = trim($body); $result = OpenPayU_Order::consumeNotification($data); $response = $result->getResponse(); if (isset($response->order->orderId)) { //$doc = htmlspecialchars_decode($this->request->post['DOCUMENT']); try { $session_id = $response->order->orderId; $order_id = $this->model_payment_payu->getOrderIdBySessionId($session_id); $retrieve = OpenPayU_Order::retrieve($session_id); $retrieve_response = $retrieve->getResponse(); if (!($retrieve->getStatus() == 'SUCCESS')) { $this->logger->write($retrieve->getError() . ' [response: ' . serialize($retrieve->getResponse()) . ']'); } else { $this->updatecustomerdata($order_id, $retrieve_response->orders[0]->buyer); $orderStatus = $retrieve_response->orders[0]->status; $paymentStatus = $retrieve_response->orders[0]->status; $newstatus = $this->getpaymentstatusid($paymentStatus, $orderStatus); $this->updatestatus($order_id, $newstatus); header("HTTP/1.1 200 OK"); } } catch (Exception $e) { $this->logger->write($e->getMessage()); return null; } } }
/** * @param string $data * @return \OpenPayU_Result * @throws \OpenPayU_Exception */ public function orderConsumeNotification($data) { return \OpenPayU_Order::consumeNotification($data); }
function notify() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { $this->load->model('Ordermodel'); $this->config->load('payu', true); OpenPayU_Configuration::setEnvironment('secure'); OpenPayU_Configuration::setMerchantPosId($this->config->item('PosId', 'payu')); OpenPayU_Configuration::setSignatureKey($this->config->item('SignatureKey', 'payu')); $body = file_get_contents('php://input'); $data = trim($body); try { if (!empty($data)) { $result = OpenPayU_Order::consumeNotification($data); } if ($result->getResponse()->order->orderId) { /* Check if OrderId exists in Merchant Service, update Order data by OrderRetrieveRequest */ $payment = $result->getResponse()->order->orderId; $order = OpenPayU_Order::retrieve($payment); if ($order->getStatus() == 'SUCCESS') { $orders = $order->getResponse()->orders; $now = new DateTime(); $y = $now->format("Y"); $m = $now->format("m"); if (!is_dir(BASEPATH . "../invoices")) { mkdir(BASEPATH . "../invoices"); } if (!is_dir(BASEPATH . "../invoices/{$y}")) { mkdir(BASEPATH . "../invoices/{$y}"); } if (!is_dir(BASEPATH . "../invoices/{$y}/{$m}")) { mkdir(BASEPATH . "../invoices/{$y}/{$m}"); } $dir = BASEPATH . "../invoices/{$y}/{$m}"; foreach ($orders as $order) { $order = $this->Ordermodel->activate($order->orderId, $order->status); $invoice = $this->Ordermodel->make_invoice($order->data->id, $order->user->id); $order->data->invoice = $invoice; $order->data->date = $now->format("Y-m-d"); if (!is_file("{$dir}/{$invoice}.pdf")) { $msg = $this->load->view('pdf/invoice', array('order' => $order), true); require_once BASEPATH . "../html2pdf/html2pdf.class.php"; $html2pdf = new HTML2PDF('P', 'A4', 'en', true, 'UTF-8'); $html2pdf->setDefaultFont("dejavusans"); $html2pdf->pdf->SetDisplayMode('fullpage'); $html2pdf->WriteHTML($msg); $html2pdf->Output("{$dir}/{$invoice}.pdf", 'F'); $this->Ordermodel->update_invoice($invoice, "/invoices/{$y}/{$m}/{$invoice}.pdf"); } } header("HTTP/1.1 200 OK"); } } } catch (OpenPayU_Exception $e) { echo $e->getMessage(); } } }