Files
hutko_v4/catalog/model/payment/hutko.php

86 lines
2.9 KiB
PHP

<?php
namespace Opencart\Catalog\Model\Extension\Hutko\Payment;
class Hutko extends \Opencart\System\Engine\Model {
public function getMethods(array $address = []): array {
$method_data = $this->getMethod($address);
if ($method_data) {
return $method_data;
}
return [];
}
public function getMethod(array $address = []): array {
$this->load->language('extension/hutko/payment/hutko');
$status = true;
// 1. Currency Check
$allowed_currencies = ['UAH', 'USD', 'EUR', 'GBP', 'CZK', 'PLN'];
if (!in_array(strtoupper($this->session->data['currency']), $allowed_currencies)) {
$status = false;
}
// 2. Geo Zone Check
if ($this->config->get('payment_hutko_geo_zone_id')) {
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('payment_hutko_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if (!$query->num_rows) {
$status = false;
}
}
// 3. Total Check
if ($this->config->get('payment_hutko_total') > 0 && $this->config->get('payment_hutko_total') > $this->cart->getTotal()) {
$status = false;
}
$method_data = [];
if ($status && $this->config->get('payment_hutko_status')) {
$option_data['hutko'] = [
'code' => 'hutko.hutko',
'name' => $this->language->get('text_title')
];
$method_data = [
'code' => 'hutko',
'name' => $this->language->get('text_title'),
'option' => $option_data,
'sort_order' => (int)$this->config->get('payment_hutko_sort_order')
];
}
return $method_data;
}
/**
* Log a transaction event to the database
*
* @param int $order_id
* @param string $hutko_ref (The unique ID sent to Hutko, e.g. 101#12345678)
* @param string $type (payment, callback, refund)
* @param string $status (created, success, failed)
* @param float $amount
* @param string $currency
* @param array $payload_data (Will be json encoded)
*/
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()
");
}
public function getOrderLastSuccessTransaction($order_id) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "hutko_transaction` WHERE `order_id` = '" . (int)$order_id . "' AND `status` = 'success' AND `type` = 'callback' ORDER BY `date_added` DESC LIMIT 1");
return $query->row;
}
}