From 74726f8628b6f30512cd8f84ea91b92bca2ba265 Mon Sep 17 00:00:00 2001 From: John Atkinson Date: Thu, 6 Jun 2013 16:21:12 -0700 Subject: [PATCH] initial blockchain adds --- upload/admin/controller/payment/bitcoin.php | 6 ++++ .../language/english/payment/bitcoin.php | 1 + .../admin/view/template/payment/bitcoin.tpl | 12 +++++++ upload/catalog/controller/payment/bitcoin.php | 31 +++++++++++++------ 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/upload/admin/controller/payment/bitcoin.php b/upload/admin/controller/payment/bitcoin.php index 5bb302e..ab9b069 100644 --- a/upload/admin/controller/payment/bitcoin.php +++ b/upload/admin/controller/payment/bitcoin.php @@ -76,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_blockchain'] = $this->language->get('entry_blockchain'); $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'); @@ -175,6 +176,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.'_blockchain'])) { + $this->data[$this->payment_module_name.'_blockchain'] = $this->request->post[$this->payment_module_name.'_blockchain']; + } else { + $this->data[$this->payment_module_name.'_blockchain'] = $this->config->get($this->payment_module_name.'_blockchain'); + } 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 { diff --git a/upload/admin/language/english/payment/bitcoin.php b/upload/admin/language/english/payment/bitcoin.php index 6557632..81b72d9 100644 --- a/upload/admin/language/english/payment/bitcoin.php +++ b/upload/admin/language/english/payment/bitcoin.php @@ -26,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_blockchain'] = 'Is this a blockchain.info JSON-RPC server?:'; $_['entry_btc_decimal'] = 'Calculate BTC amount to this many decimal places:'; $_['entry_countdown_timer'] = 'Time to complete order:
In seconds'; $_['entry_status'] = 'Status:'; diff --git a/upload/admin/view/template/payment/bitcoin.tpl b/upload/admin/view/template/payment/bitcoin.tpl index 6dee69a..ec37520 100644 --- a/upload/admin/view/template/payment/bitcoin.tpl +++ b/upload/admin/view/template/payment/bitcoin.tpl @@ -59,6 +59,18 @@ Copyright (c) 2013 John Atkinson (jga) + + + + diff --git a/upload/catalog/controller/payment/bitcoin.php b/upload/catalog/controller/payment/bitcoin.php index 47d5d74..c1386b2 100644 --- a/upload/catalog/controller/payment/bitcoin.php +++ b/upload/catalog/controller/payment/bitcoin.php @@ -78,17 +78,31 @@ public function confirm_sent() { $bitcoin_btc_decimal = $this->config->get('bitcoin_btc_decimal'); $bitcoin_total = $order['bitcoin_total']; $bitcoin_address = $order['bitcoin_address']; - require_once('jsonRPCClient.php'); - $bitcoin = new jsonRPCClient('http://'.$this->config->get('bitcoin_rpc_username').':'.$this->config->get('bitcoin_rpc_password').'@'.$this->config->get('bitcoin_rpc_address').':'.$this->config->get('bitcoin_rpc_port').'/'); - - try { - $bitcoin_info = $bitcoin->getinfo(); - } catch (Exception $e) { - $this->data['error'] = true; + if(!$this->config->get('bitcoin_blockchain')) { + require_once('jsonRPCClient.php'); + $bitcoin = new jsonRPCClient('http://'.$this->config->get('bitcoin_rpc_username').':'.$this->config->get('bitcoin_rpc_password').'@'.$this->config->get('bitcoin_rpc_address').':'.$this->config->get('bitcoin_rpc_port').'/'); + + try { + $bitcoin_info = $bitcoin->getinfo(); + } catch (Exception $e) { + $this->data['error'] = true; + } } try { - $received_amount = $bitcoin->getreceivedbyaddress($bitcoin_address,0); + if(!$this->config->get('bitcoin_blockchain')) { + $received_amount = $bitcoin->getreceivedbyaddress($bitcoin_address,0); + } + else { + static $ch = null; + $ch = curl_init(); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Blockchain.info PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); + curl_setopt($ch, CURLOPT_URL, 'http://blockchain.info/q/getreceivedbyaddress/'.$bitcoin_address.'?confirmations=0'); + $res = curl_exec($ch); + if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch)); + $received_amount = $res / 100000000; + } 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')); @@ -101,7 +115,6 @@ public function confirm_sent() { $this->data['error'] = true; echo "0"; } - } public function checkUpdate() {