load->language('extension/hutko/payment/hutko'); $this->document->setTitle($this->language->get('heading_title')); $data['breadcrumbs'] = []; $data['breadcrumbs'][] = [ 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']) ]; $data['breadcrumbs'][] = [ 'text' => $this->language->get('text_extension'), 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment') ]; $data['breadcrumbs'][] = [ 'text' => $this->language->get('heading_title'), 'href' => $this->url->link('extension/hutko/payment/hutko', 'user_token=' . $this->session->data['user_token']) ]; // Save action $data['save'] = $this->url->link('extension/hutko/payment/hutko.save', 'user_token=' . $this->session->data['user_token']); $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment'); // Configuration Fields $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) { $data[$field] = $this->config->get($field); } // Defaults 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'; $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(); $data['log_content'] = $this->displayLastDayLog(); $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/hutko/payment/hutko', $data)); } public function save(): void { $this->load->language('extension/hutko/payment/hutko'); $json = []; if (!$this->user->hasPermission('modify', 'extension/hutko/payment/hutko')) { $json['error']['warning'] = $this->language->get('error_permission'); } // Validation if (empty($this->request->post['payment_hutko_merchant_id']) || !is_numeric($this->request->post['payment_hutko_merchant_id'])) { $json['error']['payment_hutko_merchant_id'] = $this->language->get('error_merchant_id_numeric'); } $key = $this->request->post['payment_hutko_secret_key'] ?? ''; if (empty($key) || ($key != 'test' && (strlen($key) < 10 || is_numeric($key)))) { $json['error']['payment_hutko_secret_key'] = $this->language->get('error_secret_key_invalid'); } if (!$json) { $this->load->model('setting/setting'); $this->model_setting_setting->editSetting('payment_hutko', $this->request->post); $json['success'] = $this->language->get('text_success'); } $this->response->addHeader('Content-Type: application/json'); $this->response->setOutput(json_encode($json)); } public function install(): void { $this->load->model('extension/hutko/payment/hutko'); $this->model_extension_hutko_payment_hutko->install(); // OC4 Event Registration $this->load->model('setting/event'); $event_code = 'hutko_order_info'; $event_trigger = 'admin/view/sale/order_info/after'; $event_action = 'extension/hutko/payment/hutko.order_info'; // OC 4.0.2.0 introduced the array signature for addEvent if (version_compare(VERSION, '4.0.2.0', '>=')) { $this->model_setting_event->addEvent([ 'code' => $event_code, 'description' => 'Hutko Payment Info Panel', 'trigger' => $event_trigger, 'action' => $event_action, 'status' => 1, 'sort_order' => 0 ]); } else { // Legacy argument style for 4.0.0.0 - 4.0.1.x $this->model_setting_event->addEvent($event_code, $event_trigger, $event_action, 1, 0); } } public function uninstall(): void { $this->load->model('extension/hutko/payment/hutko'); $this->model_extension_hutko_payment_hutko->uninstall(); $this->load->model('setting/event'); $this->model_setting_event->deleteEventByCode('hutko_order_info'); } // Event Handler for Admin Order View public function order_info(string &$route, array &$args, string &$output): void { if (!isset($args['order_id'])) return; $this->load->model('sale/order'); $order_info = $this->model_sale_order->getOrder((int)$args['order_id']); // FIX: Check if payment_code exists and matches either 'hutko' or 'hutko.hutko' if ($order_info && isset($order_info['payment_code']) && ($order_info['payment_code'] == 'hutko' || $order_info['payment_code'] == 'hutko.hutko')) { $this->load->language('extension/hutko/payment/hutko'); $this->load->model('extension/hutko/payment/hutko'); $hutko_order = $this->model_extension_hutko_payment_hutko->getHutkoOrder((int)$args['order_id']); $data['hutko_transaction_ref'] = $hutko_order['hutko_transaction_ref'] ?? ''; $data['order_id'] = (int)$args['order_id']; $data['user_token'] = $this->session->data['user_token']; // URLs for AJAX actions $data['refund_url'] = $this->url->link('extension/hutko/payment/hutko.refund', 'user_token=' . $this->session->data['user_token']); $data['status_url'] = $this->url->link('extension/hutko/payment/hutko.status', 'user_token=' . $this->session->data['user_token']); // Language Data $data['text_payment_information'] = $this->language->get('text_payment_information'); $data['text_hutko_transaction_ref_label'] = $this->language->get('text_hutko_transaction_ref_label'); $data['hutko_transaction_ref_display'] = $data['hutko_transaction_ref'] ?: $this->language->get('text_not_available'); $data['text_not_available'] = $this->language->get('text_not_available'); $data['text_hutko_refund_title'] = $this->language->get('text_hutko_refund_title'); $data['entry_refund_amount'] = $this->language->get('entry_refund_amount'); $data['entry_refund_comment'] = $this->language->get('entry_refund_comment'); $data['button_hutko_refund'] = $this->language->get('button_hutko_refund'); $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); $data['text_hutko_status_title'] = $this->language->get('text_hutko_status_title'); $data['button_hutko_status_check'] = $this->language->get('button_hutko_status_check'); $content = $this->load->view('extension/hutko/payment/hutko_order', $data); // Inject content before the History tab/card $pos = strpos($output, '