public function retrieveOrder($document) { $result = \OpenPayU_Order::consumeMessage($document); if ($result->getMessage() == 'OrderNotifyRequest') { $result = \OpenPayU_Order::retrieve($result->getSessionId()); return $result->getResponse(); } return null; }
function payment_status($payment) { $this->config->load('payu', true); if (!$this->isLoggedIn) { redirect('/login', 'refresh'); } if (!$this->isAdmin) { redirect('/', 'refresh'); } OpenPayU_Configuration::setEnvironment('secure'); OpenPayU_Configuration::setMerchantPosId($this->config->item('PosId', 'payu')); OpenPayU_Configuration::setSignatureKey($this->config->item('SignatureKey', 'payu')); $order = OpenPayU_Order::retrieve($payment)->getResponse()->orders; /* $this->Debug( $order, true ); */ $this->show('user/panels/admin/payment_status', array('order' => $order)); }
/** * @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'); }
<title>Order Retrieve - OpenPayU v2</title> <link rel="stylesheet" href="../../layout/css/bootstrap.min.css"> <link rel="stylesheet" href="../../layout/css/style.css"> </head> </head> <body> <div class="container"> <div class="page-header"> <h1>Retrieve order's data - OpenPayU v2</h1> </div> <div id="message"></div> <div id="unregisteredCardData"> <?php if (isset($_POST['orderId'])) { try { $response = OpenPayU_Order::retrieve(stripslashes($_POST['orderId'])); $status_desc = OpenPayU_Util::statusDesc($response->getStatus()); if ($response->getStatus() == 'SUCCESS') { echo '<div class="alert alert-success">SUCCESS: ' . $status_desc; echo '</div>'; $order = $response->getResponse()->orders[0]; echo '<table class="table table-hover table-bordered">'; echo '<thead>'; echo '<tr><th colspan="2">Important data from response</th></tr>'; echo '</thead>'; echo '<tbody>'; echo '<tr><td>Order status</td><td>' . $order->status . '</td></tr>'; echo '<tr><td>Order id</td><td>' . $order->orderId . '</td></tr>'; echo '<tr><td>Redirect Uri</td><td><a href="' . $order->notifyUrl . '">' . $order->notifyUrl . '</a></td></tr>'; echo '</tbody>'; echo '</table>';
<?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 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 $id * @return \OpenPayU_Result * @throws \OpenPayU_Exception */ public function orderRetrieve($id) { return \OpenPayU_Order::retrieve($id); }
/** * */ public function updateOrderData($response_notification = null) { SimplePayuLogger::addLog('notification', __FUNCTION__, $this->l('Entrance:'), $this->payu_order_id); if (empty($this->payu_order_id)) { Logger::addLog($this->displayName . ' ' . $this->l('Can not get order information - id_session is empty'), 1); } $result = null; if ($response_notification) { $result = $response_notification; } else { $raw = OpenPayU_Order::retrieve($this->payu_order_id); $result = $raw->getResponse(); } SimplePayuLogger::addLog('order', __FUNCTION__, print_r($result, true), $this->payu_order_id, 'OrderRetrieve response object: '); $response = $result; // SimplePayuLogger::addLog('notification', __FUNCTION__, print_r($response, true), $this->payu_order_id); $payu_order = null; isset($response_notification) ? $payu_order = $response->order : ($payu_order = $response->orders[0]); if (isset($payu_order)) { if (!empty($this->id_order)) { $this->order = new Order($this->id_order); // Delivery address add if (!empty($payu_order->buyer)) { $buyer = $payu_order->buyer; if (isset($buyer->phone) && !empty($buyer->phone)) { $buyer->delivery->{'recipientPhone'} = $buyer->phone; } $new_delivery_address_id = $this->addNewAddress($buyer->delivery); if (!empty($new_delivery_address_id)) { $this->order->id_address_delivery = $new_delivery_address_id; $this->updateCustomizationAddress($new_delivery_address_id); } // Invoice address add if (isset($payu_order->buyer->invoice)) { if (isset($buyer->phone) && !empty($buyer->phone)) { $buyer->invoice->{'recipientPhone'} = $buyer->phone; } $new_invoice_address_id = $this->addNewAddress($buyer->invoice); if (!empty($new_invoice_address_id)) { $this->order->id_address_invoice = $new_invoice_address_id; } } } SimplePayuLogger::addLog('notification', __FUNCTION__, $this->l('Order exists in PayU system '), $this->payu_order_id); if ($this->getCurrentPrestaOrderState() != 2) { SimplePayuLogger::addLog('notification', __FUNCTION__, $this->l('Prestashop order statusIS NOT COMPLETED, go to status actualization'), $this->payu_order_id); if ($this->order->update()) { SimplePayuLogger::addLog('notification', __FUNCTION__, $this->l('Prestashop updated order status, go to PayU status update to: ') . $payu_order->status, $this->payu_order_id); $this->updateOrderState(isset($payu_order->status) ? $payu_order->status : null); } } } } }
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(); } } }