42 lines
1.9 KiB
PHP
42 lines
1.9 KiB
PHP
<?php
|
|
namespace Opencart\Admin\Model\Extension\Hutko\Payment;
|
|
|
|
class Hutko extends \Opencart\System\Engine\Model {
|
|
public function install(): void {
|
|
// Drop old table if exists (Clean start for new architecture if needed)
|
|
// $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "hutko_order`");
|
|
|
|
// Create new Transaction Table
|
|
$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`),
|
|
KEY `idx_hutko_ref` (`hutko_ref`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
|
");
|
|
}
|
|
|
|
public function uninstall(): void {
|
|
// Optional: $this->db->query("DROP TABLE IF EXISTS `" . DB_PREFIX . "hutko_transaction`");
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
// Helper for history (OC4 compatibility)
|
|
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 . "'");
|
|
}
|
|
} |