public function callback($status = false, $link = null) { $this->load->model('checkout/order'); $this->language->load('payment/maksuturva'); require_once dirname(__FILE__) . '/MaksuturvaGateway/MaksuturvaGatewayImplementation.php'; $order_id = MaksuturvaGatewayImplementation::getOrderId($this->request->get['pmt_id']); $order_info = $this->model_checkout_order->getOrder($order_id); $this->load->library('user'); $this->user = new User($this->registry); // check if order belongs to logged user - if not, stop callback. Also, let's ignore it if it's a guest payment. if ($this->customer->getId() != $order_info['customer_id'] && $order_info['customer_id'] != 0) { exit; } if ($status == false) { $values = array(); foreach ($this->_compulsoryReturnData as $field) { if (isset($this->request->get[$field])) { $values[$field] = $this->request->get[$field]; } else { return $this->message('EMPTY_ANSWER'); } } // now, validate the hash // instantiate the gateway with the original order $gateway = new MaksuturvaGatewayImplementation($order_info, $this, $this->config->get("maksuturva_encoding")); // calculate the hash for order $calculatedHash = $gateway->generateReturnHash($values); // test the hash if (!($calculatedHash == $values['pmt_hash'])) { return $this->message('RETURN_HASH'); } // Then we have a confirmed payment $this->model_checkout_order->confirm($order_info['order_id'], $this->config->get('maksuturva_completed')); $this->redirect($this->getLink('checkout/success', '', 'SSL')); } // Check if order is still not answered if ($order_info['order_status_id'] != $this->config->get('maksuturva_completed')) { if ($status == 'maksuturva_delayed') { $this->model_checkout_order->confirm($order_info['order_id'], $this->config->get($status)); } else { $this->model_checkout_order->update($order_info['order_id'], $this->config->get($status), $notify = false); } $this->redirect($this->getLink($link, '', 'SSL')); } else { return $this->message('ORDER_IN_PROGRESS'); } }
/** * Method which verifies all the pending payments * (delay payment) returned from maksuturva. */ public function verify() { // Load sale/order model to get orders $this->load->model('sale/order'); // Default methods from OpenCart admin template system $this->load->language('payment/maksuturva'); $this->document->setTitle($this->language->get('heading_maksuturva')); $this->data['text_verifylist'] = $this->language->get('text_verifylist'); $this->data['text_order'] = $this->language->get('text_order'); $this->data['text_message'] = $this->language->get('text_message'); $this->data['heading_title'] = $this->language->get('heading_maksuturva'); $this->data['breadcrumbs'] = array(); $this->data['breadcrumbs'][] = array('href' => $this->getLink('common/home', 'token=' . $this->session->data['token'], 'SSL'), 'text' => $this->language->get('text_home'), 'separator' => false); $this->data['breadcrumbs'][] = array('href' => $this->getLink('extension/payment', 'token=' . $this->session->data['token'], 'SSL'), 'text' => $this->language->get('text_payment'), 'separator' => ' :: '); $this->data['breadcrumbs'][] = array('href' => $this->getLink('payment/maksuturva', 'token=' . $this->session->data['token'], 'SSL'), 'text' => $this->language->get('heading_title'), 'separator' => ' :: '); $this->data['breadcrumbs'][] = array('href' => $this->getLink('payment/maksuturva/verify', 'token=' . $this->session->data['token'], 'SSL'), 'text' => $this->language->get('heading_maksuturva'), 'separator' => ' :: '); if (!$this->user->hasPermission('modify', 'sale/order')) { return; } // load orders from database, considering created and delayed ones $sort = "order_status_id"; $filter_order_status_id = $this->config->get("maksuturva_created"); $data = array('filter_order_status_id' => $filter_order_status_id, 'sort' => $sort); $created_orders = $this->model_sale_order->getOrders($data); $filter_order_status_id = $this->config->get("maksuturva_delayed"); $data = array('filter_order_status_id' => $filter_order_status_id, 'sort' => $sort); $delayed_orders = $this->model_sale_order->getOrders($data); $orders = array_merge($delayed_orders, $created_orders); require_once dirname(__FILE__) . '../../../../catalog/controller/payment/MaksuturvaGateway/MaksuturvaGatewayImplementation.php'; // check each one with Maksuturva $statuses = array(); $links = array(); foreach ($orders as $order) { // ignore non-maksuturva payments: $id = $order['order_id']; $links[$id] = $this->getLink('sale/order/info', 'order_id=' . $id . '&token=' . $this->session->data['token'], 'SSL'); $order_info = $this->model_sale_order->getOrder($id); if ($order_info["payment_method"] != "Maksuturva/eMaksut") { continue; } //$this->model_sale_order->editOrder($this->request->get['order_id'], $this->request->post); try { $gateway = new MaksuturvaGatewayImplementation($order_info, $this, $this->config->get("maksuturva_encoding")); $response = $gateway->statusQuery(); } catch (Exception $e) { // probably error about no CURL installed $statuses[$id] = $this->language->get('ERROR_QUERY'); continue; } if ($response === false) { $statuses[$id] = $this->language->get('ERROR_RESPONSE_FALSE'); continue; } switch ($response["pmtq_returncode"]) { // set as paid if not already set case MaksuturvaGatewayImplementation::STATUS_QUERY_PAID: case MaksuturvaGatewayImplementation::STATUS_QUERY_PAID_DELIVERY: case MaksuturvaGatewayImplementation::STATUS_QUERY_COMPENSATED: $statuses[$id] = $this->language->get('PAYMENT_IDENTIFIED') . ' (' . $response["pmtq_returntext"] . ')'; $data = array("notify" => true, "order_id" => $id, "order_status_id" => $this->config->get("maksuturva_completed"), "comment" => $statuses[$id], 'append' => true); $this->model_sale_order->addOrderHistory($id, $data); break; // set payment cancellation with the notice // stored in response_text // set payment cancellation with the notice // stored in response_text case MaksuturvaGatewayImplementation::STATUS_QUERY_PAYER_CANCELLED: case MaksuturvaGatewayImplementation::STATUS_QUERY_PAYER_CANCELLED_PARTIAL: case MaksuturvaGatewayImplementation::STATUS_QUERY_PAYER_CANCELLED_PARTIAL_RETURN: case MaksuturvaGatewayImplementation::STATUS_QUERY_PAYER_RECLAMATION: case MaksuturvaGatewayImplementation::STATUS_QUERY_CANCELLED: $statuses[$id] = $this->language->get('PAYMENT_CANCELLED') . ' (' . $response["pmtq_returntext"] . ')'; $data = array("notify" => true, "order_id" => $id, "order_status_id" => $this->config->get("maksuturva_cancelled"), "comment" => $statuses[$id]); $this->model_sale_order->addOrderHistory($id, $data); break; // no news for buyer and seller // no news for buyer and seller case MaksuturvaGatewayImplementation::STATUS_QUERY_NOT_FOUND: case MaksuturvaGatewayImplementation::STATUS_QUERY_FAILED: case MaksuturvaGatewayImplementation::STATUS_QUERY_WAITING: case MaksuturvaGatewayImplementation::STATUS_QUERY_UNPAID: case MaksuturvaGatewayImplementation::STATUS_QUERY_UNPAID_DELIVERY: $statuses[$id] = $this->language->get('NO_CHANGE') . ' (' . $response["pmtq_returntext"] . ')'; break; } //$statuses[$id] } $this->data['statuses'] = $statuses; $this->data['links'] = $links; $this->template = 'payment/maksuturva_query.tpl'; $this->children = array('common/header', 'common/footer'); $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression')); }