load->language('extension/payment/hutko'); $this->document->setTitle($this->language->get('heading_title')); $this->load->model('setting/setting'); if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { $this->model_setting_setting->editSetting('payment_hutko', $this->request->post); $this->session->data['success'] = $this->language->get('text_success'); $this->response->redirect($this->url->link('extension/payment/hutko', 'user_token=' . $this->session->data['user_token'], true)); } $data['heading_title'] = $this->language->get('heading_title'); // Populate $data with language strings and current settings $fields = [ 'payment_hutko_merchant_id', 'payment_hutko_secret_key', 'payment_hutko_shipping_include', 'payment_hutko_shipping_product_name', 'payment_hutko_shipping_product_code', 'payment_hutko_new_order_status_id', 'payment_hutko_success_status_id', 'payment_hutko_declined_status_id', 'payment_hutko_expired_status_id', 'payment_hutko_refunded_status_id', 'payment_hutko_include_discount_to_total', 'payment_hutko_status', 'payment_hutko_sort_order', 'payment_hutko_geo_zone_id', 'payment_hutko_total', 'payment_hutko_save_logs' ]; foreach ($fields as $field) { if (isset($this->request->post[$field])) { $data[$field] = $this->request->post[$field]; } else { $data[$field] = $this->config->get($field); } } // Default values for new installs if (is_null($data['payment_hutko_shipping_product_name'])) { $data['payment_hutko_shipping_product_name'] = 'Package material'; } if (is_null($data['payment_hutko_shipping_product_code'])) { $data['payment_hutko_shipping_product_code'] = '0_0_1'; } if (is_null($data['payment_hutko_total'])) { $data['payment_hutko_total'] = '0.01'; } // Error messages $errors = ['warning', 'merchant_id', 'secret_key']; foreach ($errors as $err_key) { if (isset($this->error[$err_key])) { $data['error_' . $err_key] = $this->error[$err_key]; } else { $data['error_' . $err_key] = ''; } } $data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array('text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)); $data['breadcrumbs'][] = array('text' => $this->language->get('text_extension'), 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); $data['breadcrumbs'][] = array('text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/payment/hutko', 'user_token=' . $this->session->data['user_token'], true)); $data['action'] = $this->url->link('extension/payment/hutko', 'user_token=' . $this->session->data['user_token'], true); $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); $this->load->model('localisation/order_status'); $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); $this->load->model('localisation/geo_zone'); $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); // Logs (simplified) $data['log_content'] = $this->displayLastDayLog(); $data['user_token'] = $this->session->data['user_token']; // Ensure it's passed to the view $data['header'] = $this->load->controller('common/header'); $data['column_left'] = $this->load->controller('common/column_left'); $data['footer'] = $this->load->controller('common/footer'); $this->response->setOutput($this->load->view('extension/payment/hutko', $data)); } protected function validate() { if (!$this->user->hasPermission('modify', 'extension/payment/hutko')) { $this->error['warning'] = $this->language->get('error_permission'); } $merchantId = $this->request->post['payment_hutko_merchant_id']; $secretKey = $this->request->post['payment_hutko_secret_key']; if (empty($merchantId)) { $this->error['merchant_id'] = $this->language->get('error_merchant_id_required'); } elseif (!is_numeric($merchantId)) { $this->error['merchant_id'] = $this->language->get('error_merchant_id_numeric'); } if (empty($secretKey)) { $this->error['secret_key'] = $this->language->get('error_secret_key_required'); } elseif ($secretKey != 'test' && (strlen($secretKey) < 10 || is_numeric($secretKey))) { $this->error['secret_key'] = $this->language->get('error_secret_key_invalid'); } return !$this->error; } public function install() { $this->load->model('extension/payment/hutko'); // Load our custom model $this->model_extension_payment_hutko->install(); // Call install method from our model $this->load->model('setting/setting'); $defaults = array( 'payment_hutko_status' => 0, 'payment_hutko_sort_order' => 1, 'payment_hutko_total' => '0.01', 'payment_hutko_new_order_status_id' => $this->config->get('config_order_status_id'), // Default pending 'payment_hutko_success_status_id' => 2, // Processing 'payment_hutko_declined_status_id' => 10, // Failed 'payment_hutko_expired_status_id' => 14, // Expired 'payment_hutko_refunded_status_id' => 11, // Refunded 'payment_hutko_shipping_include' => 1, 'payment_hutko_shipping_product_name' => 'Shipping', 'payment_hutko_shipping_product_code' => 'SHIPPING_001', 'payment_hutko_save_logs' => 1, 'payment_hutko_include_discount_to_total' => 1, ); $this->model_setting_setting->editSetting('payment_hutko', $defaults); // Register event for displaying info on admin order page (OC 3.x+) if (defined('VERSION') && version_compare(VERSION, '3.0.0.0', '>=')) { $this->load->model('setting/event'); $this->model_setting_event->addEvent( 'hutko_admin_order_info_panel', // event_code (unique) 'admin/view/sale/order_info/after', // trigger (after main view is rendered) 'extension/payment/hutko/inject_admin_order_panel', // action (controller route) 1, // status (1 = enabled) 0 // sort_order ); } } public function uninstall() { $this->load->model('extension/payment/hutko'); // Load our custom model $this->model_extension_payment_hutko->uninstall(); // Call uninstall method from our model $this->load->model('setting/setting'); $this->model_setting_setting->deleteSetting('payment_hutko'); // Unregister event (OC 3.x+) if (defined('VERSION') && version_compare(VERSION, '3.0.0.0', '>=')) { $this->load->model('setting/event'); $this->model_setting_event->deleteEventByCode('hutko_admin_order_info_panel'); } } /** * Event handler to inject Hutko panel into the admin order view output. * Triggered by: admin/view/sale/order_info/after */ public function inject_admin_order_panel(&$route, &$data, &$output) { // Ensure order_id is available if (!isset($data['order_id'])) { // If order_id is not in $data, we cannot proceed. // This would be unusual for the sale/order/info route. $this->logOC("Hutko inject_admin_order_panel: order_id not found in \$data array."); return; } $order_id = (int)$data['order_id']; $current_payment_code = ''; // Check if payment_code is already in $data if (isset($data['payment_code'])) { $current_payment_code = $data['payment_code']; } else { // If not in $data, load the order info to get the payment_code $this->load->model('sale/order'); // Standard OpenCart order model $order_info = $this->model_sale_order->getOrder($order_id); if ($order_info && isset($order_info['payment_code'])) { $current_payment_code = $order_info['payment_code']; // Optionally, add it back to $data if other parts of your logic expect it, // though for this specific function, having $current_payment_code is enough. // $data['payment_code'] = $order_info['payment_code']; } else { $this->logOC("Hutko inject_admin_order_panel: Could not retrieve payment_code for order_id: " . $order_id); return; // Can't determine payment method } } // Now, check if this is a Hutko payment order if ($current_payment_code == 'hutko') { $this->load->language('extension/payment/hutko'); $this->load->model('extension/payment/hutko'); $hutko_order_data = $this->model_extension_payment_hutko->getHutkoOrder($order_id); $panel_data = []; if ($hutko_order_data && !empty($hutko_order_data['hutko_transaction_ref'])) { $panel_data['hutko_transaction_ref_display'] = $hutko_order_data['hutko_transaction_ref']; } else { $panel_data['hutko_transaction_ref_display'] = $this->language->get('text_not_available'); } $panel_data['hutko_refund_action_url'] = $this->url->link('extension/payment/hutko/refund', '', true); $panel_data['hutko_status_action_url'] = $this->url->link('extension/payment/hutko/status', '', true); $panel_data['order_id'] = $order_id; $panel_data['user_token_value'] = $this->session->data['user_token']; // Language strings for the panel template $panel_data['text_payment_information'] = $this->language->get('text_payment_information'); $panel_data['text_hutko_refund_title'] = $this->language->get('text_hutko_refund_title'); $panel_data['text_hutko_status_title'] = $this->language->get('text_hutko_status_title'); $panel_data['button_hutko_refund'] = $this->language->get('button_hutko_refund'); $panel_data['button_hutko_status_check'] = $this->language->get('button_hutko_status_check'); $panel_data['text_hutko_transaction_ref_label'] = $this->language->get('text_hutko_transaction_ref_label'); $panel_data['entry_refund_amount'] = $this->language->get('entry_refund_amount'); $panel_data['entry_refund_comment'] = $this->language->get('entry_refund_comment'); $panel_data['text_not_available'] = $this->language->get('text_not_available'); $panel_data['text_loading'] = $this->language->get('text_loading'); $panel_data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); $panel_data['user_token'] = $this->session->data['user_token']; $panel_data['order_id'] = $order_id; // Render the Hutko panel HTML $hutko_panel_html = $this->load->view('extension/payment/hutko_order_info_panel', $panel_data); // Try common injection points for better theme compatibility $possible_markers = [ '{{ history }}', // Default Twig variable for history '