Skip to content

Commit

Permalink
initial blockchain adds
Browse files Browse the repository at this point in the history
  • Loading branch information
btcgear committed Jun 6, 2013
1 parent 2a46afd commit 74726f8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
6 changes: 6 additions & 0 deletions upload/admin/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions upload/admin/language/english/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$_['entry_prefix'] = 'The prefix for the address labels:<br /><span class="help">The account will be in the form [prefix]_[order_id]</span>';
$_['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:<br /><span class="help">In seconds</span>';
$_['entry_status'] = 'Status:';
Expand Down
12 changes: 12 additions & 0 deletions upload/admin/view/template/payment/bitcoin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ Copyright (c) 2013 John Atkinson (jga)
<?php if ($error_prefix) { ?>
<span class="error"><?php echo $error_prefix; ?></span>
<?php } ?></td>
</tr>
<tr>
<td><?php echo $entry_blockchain; ?></td>
<td><select name="bitcoin_blockchain">
<?php if ($bitcoin_blockchain) { ?>
<option value="1" selected="selected"><?php echo $text_yes; ?></option>
<option value="0"><?php echo $text_no; ?></option>
<?php } else { ?>
<option value="1"><?php echo $text_yes; ?></option>
<option value="0" selected="selected"><?php echo $text_no; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><?php echo $entry_show_btc; ?></td>
Expand Down
31 changes: 22 additions & 9 deletions upload/catalog/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -101,7 +115,6 @@ public function confirm_sent() {
$this->data['error'] = true;
echo "0";
}

}

public function checkUpdate() {
Expand Down

0 comments on commit 74726f8

Please sign in to comment.