From 2a46afd8f9fde8b8e42b9b8bb77eeba3cc6209c3 Mon Sep 17 00:00:00 2001 From: John Atkinson Date: Wed, 22 May 2013 20:24:50 -0700 Subject: [PATCH] added variable decimal places also switched back to getreceivedbyaddress to confirm sent bitcoins --- upload/admin/controller/payment/bitcoin.php | 13 ++++ .../language/english/payment/bitcoin.php | 8 +++ .../admin/view/template/payment/bitcoin.tpl | 62 +++++++++++++++++++ upload/catalog/controller/payment/bitcoin.php | 14 +++-- 4 files changed, 91 insertions(+), 6 deletions(-) diff --git a/upload/admin/controller/payment/bitcoin.php b/upload/admin/controller/payment/bitcoin.php index ca5c6c6..5bb302e 100644 --- a/upload/admin/controller/payment/bitcoin.php +++ b/upload/admin/controller/payment/bitcoin.php @@ -61,6 +61,13 @@ public function index() { $this->data['text_disabled'] = $this->language->get('text_disabled'); $this->data['text_yes'] = $this->language->get('text_yes'); $this->data['text_no'] = $this->language->get('text_no'); + $this->data['text_8'] = $this->language->get('text_8'); + $this->data['text_7'] = $this->language->get('text_7'); + $this->data['text_6'] = $this->language->get('text_6'); + $this->data['text_5'] = $this->language->get('text_5'); + $this->data['text_4'] = $this->language->get('text_4'); + $this->data['text_3'] = $this->language->get('text_3'); + $this->data['text_2'] = $this->language->get('text_2'); $this->data['entry_username'] = $this->language->get('entry_username'); $this->data['entry_address'] = $this->language->get('entry_address'); @@ -69,6 +76,7 @@ public function index() { $this->data['entry_prefix'] = $this->language->get('entry_prefix'); $this->data['entry_order_status'] = $this->language->get('entry_order_status'); $this->data['entry_show_btc'] = $this->language->get('entry_show_btc'); + $this->data['entry_btc_decimal'] = $this->language->get('entry_btc_decimal'); $this->data['entry_countdown_timer'] = $this->language->get('entry_countdown_timer'); $this->data['entry_status'] = $this->language->get('entry_status'); $this->data['entry_sort_order'] = $this->language->get('entry_sort_order'); @@ -167,6 +175,11 @@ public function index() { } else { $this->data[$this->payment_module_name.'_show_btc'] = $this->config->get($this->payment_module_name.'_show_btc'); } + if (isset($this->request->post[$this->payment_module_name.'_btc_decimal'])) { + $this->data[$this->payment_module_name.'_btc_decimal'] = $this->request->post[$this->payment_module_name.'_btc_decimal']; + } else { + $this->data[$this->payment_module_name.'_btc_decimal'] = $this->config->get($this->payment_module_name.'_btc_decimal'); + } if (isset($this->request->post[$this->payment_module_name.'_countdown_timer'])) { $this->data[$this->payment_module_name.'_countdown_timer'] = $this->request->post[$this->payment_module_name.'_countdown_timer']; } else { diff --git a/upload/admin/language/english/payment/bitcoin.php b/upload/admin/language/english/payment/bitcoin.php index 4034aa3..6557632 100644 --- a/upload/admin/language/english/payment/bitcoin.php +++ b/upload/admin/language/english/payment/bitcoin.php @@ -10,6 +10,13 @@ $_['text_bitcoin'] = 'Bitcoin'; $_['text_yes'] = 'Yes'; $_['text_no'] = 'No'; +$_['text_8'] = '8'; +$_['text_7'] = '7'; +$_['text_6'] = '6'; +$_['text_5'] = '5'; +$_['text_4'] = '4'; +$_['text_3'] = '3'; +$_['text_2'] = '2'; // Entry $_['entry_username'] = 'Bitcoin RPC Username:'; @@ -19,6 +26,7 @@ $_['entry_prefix'] = 'The prefix for the address labels:
The account will be in the form [prefix]_[order_id]'; $_['entry_order_status'] = 'Status of a new order:'; $_['entry_show_btc'] = 'Show BTC as a store currency:'; +$_['entry_btc_decimal'] = 'Calculate BTC amount to this many decimal places:'; $_['entry_countdown_timer'] = 'Time to complete order:
In seconds'; $_['entry_status'] = 'Status:'; $_['entry_sort_order'] = 'Sort Order:'; diff --git a/upload/admin/view/template/payment/bitcoin.tpl b/upload/admin/view/template/payment/bitcoin.tpl index 7a07d03..6dee69a 100644 --- a/upload/admin/view/template/payment/bitcoin.tpl +++ b/upload/admin/view/template/payment/bitcoin.tpl @@ -71,6 +71,68 @@ Copyright (c) 2013 John Atkinson (jga) + + + + * diff --git a/upload/catalog/controller/payment/bitcoin.php b/upload/catalog/controller/payment/bitcoin.php index 65113aa..47d5d74 100644 --- a/upload/catalog/controller/payment/bitcoin.php +++ b/upload/catalog/controller/payment/bitcoin.php @@ -23,6 +23,7 @@ protected function index() { $this->data['error_confirm'] = $this->language->get('error_confirm'); $this->data['error_incomplete_pay'] = $this->language->get('error_incomplete_pay'); $this->data['bitcoin_countdown_timer'] = $this->config->get('bitcoin_countdown_timer'); + $bitcoin_btc_decimal = $this->config->get('bitcoin_btc_decimal'); $this->checkUpdate(); @@ -32,8 +33,8 @@ protected function index() { $current_default_currency = $this->config->get('config_currency'); - $this->data['bitcoin_total'] = round($this->currency->convert($order['total'], $current_default_currency, "BTC"),4); - + $this->data['bitcoin_total'] = sprintf("%.".$bitcoin_btc_decimal."f", round($this->currency->convert($order['total'], $current_default_currency, "BTC"),$bitcoin_btc_decimal)); + $this->db->query("UPDATE `" . DB_PREFIX . "order` SET bitcoin_total = '" . $this->data['bitcoin_total'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'"); @@ -73,7 +74,8 @@ public function confirm_sent() { $this->load->model('checkout/order'); $order_id = $this->session->data['order_id']; $order = $this->model_checkout_order->getOrder($order_id); - $current_default_currency = $this->config->get('config_currency'); + $current_default_currency = $this->config->get('config_currency'); + $bitcoin_btc_decimal = $this->config->get('bitcoin_btc_decimal'); $bitcoin_total = $order['bitcoin_total']; $bitcoin_address = $order['bitcoin_address']; require_once('jsonRPCClient.php'); @@ -86,8 +88,8 @@ public function confirm_sent() { } try { - $received_amount = $bitcoin->getbalance($bitcoin_address,0); - if(round((float)$received_amount,4) >= round((float)$bitcoin_total,4)) { + $received_amount = $bitcoin->getreceivedbyaddress($bitcoin_address,0); + if(round((float)$received_amount,$bitcoin_btc_decimal) >= round((float)$bitcoin_total,$bitcoin_btc_decimal)) { $order = $this->model_checkout_order->getOrder($order_id); $this->model_checkout_order->confirm($order_id, $this->config->get('bitcoin_order_status_id')); echo "1"; @@ -108,7 +110,7 @@ public function checkUpdate() { $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code = 'BTC'"); if(!$query->row) { - $this->db->query("INSERT INTO " . DB_PREFIX . "currency (title, code, symbol_right, decimal_place, status) VALUES ('Bitcoin', 'BTC', ' BTC', '4', ".$this->config->get('bitcoin_show_btc').")"); + $this->db->query("INSERT INTO " . DB_PREFIX . "currency (title, code, symbol_right, decimal_place, status) VALUES ('Bitcoin', 'BTC', ' BTC', ".$this->config->get('bitcoin_btc_decimal').", ".$this->config->get('bitcoin_show_btc').")"); $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code = 'BTC'"); }