diff --git a/catalog/model/payment/btcpay.php b/catalog/model/payment/btcpay.php index 7edb7f7..6f7da91 100644 --- a/catalog/model/payment/btcpay.php +++ b/catalog/model/payment/btcpay.php @@ -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; @@ -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; @@ -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') ]; }