Skip to content

Commit

Permalink
Merge pull request #11 from ndeet/fix-compatibility
Browse files Browse the repository at this point in the history
Fix compat to OC 4.0.2.0+ due to breaking change upstream.
  • Loading branch information
ndeet authored Sep 6, 2023
2 parents 4222968 + 5d7a2d4 commit 9677c82
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions catalog/model/payment/btcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ class Btcpay extends \Opencart\System\Engine\Model
public function addOrder(array $data): bool
{
return $this->db->query(
"INSERT INTO `" . DB_PREFIX . "btcpay_order` SET `order_id` = '" . (int)$data['order_id'] . "', `token` = '" . $this->db->escape(
$data['token']
) . "', `invoice_id` = '" . $this->db->escape(
$data['invoice_id']
) . "'"
"INSERT INTO `" . DB_PREFIX . "btcpay_order` SET `order_id` = '" . (int)$data['order_id'] . "', `token` = '" . $this->db->escape(
$data['token']
) . "', `invoice_id` = '" . $this->db->escape(
$data['invoice_id']
) . "'"
);
}

public function getOrder(int $order_id): array
{
$query = $this->db->query(
"SELECT * FROM `" . DB_PREFIX . "btcpay_order` WHERE `order_id` = '" . $order_id . "' ORDER BY btcpay_order_id DESC LIMIT 1"
"SELECT * FROM `" . DB_PREFIX . "btcpay_order` WHERE `order_id` = '" . $order_id . "' ORDER BY btcpay_order_id DESC LIMIT 1"
);

return $query->row;
Expand All @@ -28,21 +28,28 @@ public function getOrder(int $order_id): array
public function getOrderByInvoiceId(string $invoice_id): array
{
$query = $this->db->query(
"SELECT * FROM `" . DB_PREFIX . "btcpay_order` WHERE `invoice_id` = '" . $invoice_id . "' LIMIT 1"
"SELECT * FROM `" . DB_PREFIX . "btcpay_order` WHERE `invoice_id` = '" . $invoice_id . "' LIMIT 1"
);

return $query->row;
}

public function getMethod(array $address): array
public function getMethods(array $address = []): array
{
$this->load->language('extension/btcpay/payment/btcpay');

$query = $this->db->query(
"SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get(
'payment_btcpay_geo_zone_id'
) . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')"
);
$qStr = "SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get(
'payment_btcpay_geo_zone_id'
) . "'";

if (isset($address['country_id'])) {
$qStr .= " AND `country_id` = '" . (int)$address['country_id'] ."'";
}
if (isset($address['zone_id'])) {
$qStr .= " AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')";
}

$query = $this->db->query($qStr);

if (!$this->config->get('payment_btcpay_geo_zone_id')) {
$status = true;
Expand All @@ -55,10 +62,16 @@ public function getMethod(array $address): array
$method_data = [];

if ($status) {
$option_data['btcpay'] = [
'code' => 'btcpay.btcpay',
'name' => $this->language->get('text_title')
];

$method_data = [
'code' => 'btcpay',
'title' => $this->language->get('text_title'),
'sort_order' => $this->config->get('payment_btcpay_sort_order'),
'code' => 'btcpay',
'name' => $this->language->get('text_title'),
'option' => $option_data,
'sort_order' => $this->config->get('payment_btcpay_sort_order')
];
}

Expand Down

0 comments on commit 9677c82

Please sign in to comment.