52 lines
2.3 KiB
PHP
52 lines
2.3 KiB
PHP
<?php
|
|
namespace Opencart\Admin\Model\Extension\Hutko\Payment;
|
|
|
|
class Hutko extends \Opencart\System\Engine\Model {
|
|
public function install(): void {
|
|
// $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "hutko_order`");
|
|
$this->db->query("
|
|
CREATE TABLE IF NOT EXISTS `" . DB_PREFIX . "hutko_transaction` (
|
|
`hutko_transaction_id` INT(11) NOT NULL AUTO_INCREMENT,
|
|
`order_id` INT(11) NOT NULL,
|
|
`hutko_ref` VARCHAR(64) NOT NULL,
|
|
`type` VARCHAR(32) NOT NULL,
|
|
`status` VARCHAR(32) NOT NULL,
|
|
`amount` DECIMAL(15,4) NOT NULL DEFAULT '0.0000',
|
|
`currency` VARCHAR(10) NOT NULL,
|
|
`payload` MEDIUMTEXT,
|
|
`date_added` DATETIME NOT NULL,
|
|
PRIMARY KEY (`hutko_transaction_id`),
|
|
KEY `idx_order_id` (`order_id`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
");
|
|
}
|
|
|
|
public function uninstall(): void {
|
|
// Optional drop
|
|
}
|
|
|
|
public function getTransactions(int $order_id): array {
|
|
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "hutko_transaction` WHERE `order_id` = '" . (int)$order_id . "' ORDER BY `date_added` DESC");
|
|
return $query->rows;
|
|
}
|
|
|
|
public function addOrderHistory(int $order_id, int $order_status_id, string $comment = '', bool $notify = false): void {
|
|
$this->db->query("INSERT INTO `" . DB_PREFIX . "order_history` SET `order_id` = '" . (int)$order_id . "', `order_status_id` = '" . (int)$order_status_id . "', `notify` = '" . (int)$notify . "', `comment` = '" . $this->db->escape($comment) . "', `date_added` = NOW()");
|
|
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET `order_status_id` = '" . (int)$order_status_id . "', `date_modified` = NOW() WHERE `order_id` = '" . (int)$order_id . "'");
|
|
}
|
|
|
|
// MIRRORED FROM CATALOG MODEL for logging admin actions
|
|
public function logTransaction($order_id, $hutko_ref, $type, $status, $amount, $currency, $payload_data = []) {
|
|
$json = json_encode($payload_data, JSON_UNESCAPED_UNICODE);
|
|
$this->db->query("INSERT INTO `" . DB_PREFIX . "hutko_transaction` SET
|
|
`order_id` = '" . (int)$order_id . "',
|
|
`hutko_ref` = '" . $this->db->escape($hutko_ref) . "',
|
|
`type` = '" . $this->db->escape($type) . "',
|
|
`status` = '" . $this->db->escape($status) . "',
|
|
`amount` = '" . (float)$amount . "',
|
|
`currency` = '" . $this->db->escape($currency) . "',
|
|
`payload` = '" . $this->db->escape($json) . "',
|
|
`date_added` = NOW()
|
|
");
|
|
}
|
|
} |