Update catalog/controller/payment/hutko.php
This commit is contained in:
@@ -24,24 +24,20 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
if (!$order_info) {
|
if (!$order_info) {
|
||||||
$json['error'] = 'Order missing';
|
$json['error'] = 'Order missing';
|
||||||
} else {
|
} else {
|
||||||
// 1. Generate unique Ref for THIS attempt
|
$hutko_ref = $order_info['order_id'] . '#' . time();
|
||||||
$timestamp = time();
|
|
||||||
$hutko_ref = $order_info['order_id'] . '#' . $timestamp;
|
|
||||||
|
|
||||||
|
// Call the shared logic method
|
||||||
$request_data = $this->buildRequest($order_info, $hutko_ref);
|
$request_data = $this->buildRequest($order_info, $hutko_ref);
|
||||||
|
|
||||||
if (!$request_data) {
|
if (!$request_data) {
|
||||||
$json['error'] = $this->language->get('error_payment_data_build');
|
$json['error'] = $this->language->get('error_payment_data_build');
|
||||||
} else {
|
} else {
|
||||||
$this->load->model('extension/hutko/payment/hutko');
|
$this->load->model('extension/hutko/payment/hutko');
|
||||||
|
|
||||||
// 2. Call API
|
|
||||||
$response = $this->api($this->checkout_url, $request_data);
|
$response = $this->api($this->checkout_url, $request_data);
|
||||||
|
|
||||||
if (($response['response']['response_status'] ?? '') === 'success' && !empty($response['response']['checkout_url'])) {
|
if (($response['response']['response_status'] ?? '') === 'success' && !empty($response['response']['checkout_url'])) {
|
||||||
$url = $response['response']['checkout_url'];
|
$url = $response['response']['checkout_url'];
|
||||||
|
|
||||||
// 3. Log to INTERNAL DB (Not Customer History)
|
|
||||||
$this->model_extension_hutko_payment_hutko->logTransaction(
|
$this->model_extension_hutko_payment_hutko->logTransaction(
|
||||||
$order_info['order_id'],
|
$order_info['order_id'],
|
||||||
$hutko_ref,
|
$hutko_ref,
|
||||||
@@ -50,14 +46,12 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
$request_data['amount'] / 100,
|
$request_data['amount'] / 100,
|
||||||
$request_data['currency'],
|
$request_data['currency'],
|
||||||
[
|
[
|
||||||
'request_data' => $request_data, // Store sent data (except signature if needed)
|
'request_data' => $request_data,
|
||||||
'checkout_url' => $url,
|
'checkout_url' => $url,
|
||||||
'user_agent' => $this->request->server['HTTP_USER_AGENT'] ?? ''
|
'user_agent' => $this->request->server['HTTP_USER_AGENT'] ?? ''
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
// 4. Update Order Status to "Pending" (or configured status) if not already
|
|
||||||
// Only add history if it's a fresh order, don't spam.
|
|
||||||
if ($order_info['order_status_id'] == 0) {
|
if ($order_info['order_status_id'] == 0) {
|
||||||
$this->model_checkout_order->addHistory($order_info['order_id'], $this->config->get('payment_hutko_new_order_status_id'), $this->language->get('text_initiated_payment'), false);
|
$this->model_checkout_order->addHistory($order_info['order_id'], $this->config->get('payment_hutko_new_order_status_id'), $this->language->get('text_initiated_payment'), false);
|
||||||
}
|
}
|
||||||
@@ -66,8 +60,6 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
} else {
|
} else {
|
||||||
$err = $response['response']['error_message'] ?? $this->language->get('error_api_communication');
|
$err = $response['response']['error_message'] ?? $this->language->get('error_api_communication');
|
||||||
$json['error'] = $err;
|
$json['error'] = $err;
|
||||||
|
|
||||||
// Log Failure
|
|
||||||
$this->model_extension_hutko_payment_hutko->logTransaction(
|
$this->model_extension_hutko_payment_hutko->logTransaction(
|
||||||
$order_info['order_id'],
|
$order_info['order_id'],
|
||||||
$hutko_ref,
|
$hutko_ref,
|
||||||
@@ -165,8 +157,21 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function validate($data) {
|
||||||
|
$sig = $data['signature'] ?? '';
|
||||||
|
unset($data['signature'], $data['response_signature_string']);
|
||||||
|
return hash_equals($this->sign($data), $sig);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// =========================================================================
|
||||||
|
// SHARED LOGIC START
|
||||||
|
// MAINTENANCE WARNING: Keep synchronized with Admin Controller
|
||||||
|
// =========================================================================
|
||||||
|
|
||||||
private function buildRequest($order, $hutko_ref) {
|
private function buildRequest($order, $hutko_ref) {
|
||||||
// Logic same as before, but using passed $hutko_ref
|
|
||||||
$products_data = $this->getProducts($order['order_id'], $order);
|
$products_data = $this->getProducts($order['order_id'], $order);
|
||||||
|
|
||||||
$total_products_sum = 0;
|
$total_products_sum = 0;
|
||||||
@@ -196,6 +201,10 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
if ($amount_val < 0.01) $amount_val = 0.01;
|
if ($amount_val < 0.01) $amount_val = 0.01;
|
||||||
$total_cents = (int)round($amount_val * 100);
|
$total_cents = (int)round($amount_val * 100);
|
||||||
|
|
||||||
|
// Catalog side URLs are simple
|
||||||
|
$response_url = $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true);
|
||||||
|
$callback_url = $this->url->link('extension/hutko/payment/hutko.callback', '', true);
|
||||||
|
|
||||||
$reservation_data = [
|
$reservation_data = [
|
||||||
"cms_name" => "OpenCart",
|
"cms_name" => "OpenCart",
|
||||||
"cms_version" => VERSION,
|
"cms_version" => VERSION,
|
||||||
@@ -214,8 +223,8 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
'amount' => $total_cents,
|
'amount' => $total_cents,
|
||||||
'currency' => $order['currency_code'],
|
'currency' => $order['currency_code'],
|
||||||
'order_desc' => 'Order #' . $order['order_id'],
|
'order_desc' => 'Order #' . $order['order_id'],
|
||||||
'response_url' => $this->url->link('checkout/success', 'language=' . $this->config->get('config_language'), true),
|
'response_url' => $response_url,
|
||||||
'server_callback_url' => $this->url->link('extension/hutko/payment/hutko.callback', '', true),
|
'server_callback_url' => $callback_url,
|
||||||
'sender_email' => $order['email'],
|
'sender_email' => $order['email'],
|
||||||
'reservation_data' => base64_encode(json_encode($reservation_data))
|
'reservation_data' => base64_encode(json_encode($reservation_data))
|
||||||
];
|
];
|
||||||
@@ -224,8 +233,6 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions (getProducts, sign, validate, api, logOC) remain the same...
|
|
||||||
// Just ensure logOC uses file log for debug, not DB log.
|
|
||||||
private function getProducts(int $order_id, array $order_info): array {
|
private function getProducts(int $order_id, array $order_info): array {
|
||||||
$products_data = [];
|
$products_data = [];
|
||||||
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE `order_id` = '" . (int)$order_id . "'");
|
||||||
@@ -269,12 +276,6 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
foreach($arr as $v) $str .= '|' . $v;
|
foreach($arr as $v) $str .= '|' . $v;
|
||||||
return sha1($str);
|
return sha1($str);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validate($data) {
|
|
||||||
$sig = $data['signature'] ?? '';
|
|
||||||
unset($data['signature'], $data['response_signature_string']);
|
|
||||||
return hash_equals($this->sign($data), $sig);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function api($url, $data) {
|
private function api($url, $data) {
|
||||||
if ($this->config->get('payment_hutko_save_logs')) $this->logOC('Req: ' . json_encode($data));
|
if ($this->config->get('payment_hutko_save_logs')) $this->logOC('Req: ' . json_encode($data));
|
||||||
@@ -302,4 +303,7 @@ class Hutko extends \Opencart\System\Engine\Controller {
|
|||||||
private function logOC($msg) {
|
private function logOC($msg) {
|
||||||
$this->log->write("Hutko Payment: " . $msg);
|
$this->log->write("Hutko Payment: " . $msg);
|
||||||
}
|
}
|
||||||
|
// =========================================================================
|
||||||
|
// SHARED LOGIC END
|
||||||
|
// =========================================================================
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user