Skip to content

Commit

Permalink
added variable decimal places
Browse files Browse the repository at this point in the history
also switched back to getreceivedbyaddress to confirm sent bitcoins
  • Loading branch information
btcgear committed May 23, 2013
1 parent dcd5b64 commit 2a46afd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 6 deletions.
13 changes: 13 additions & 0 deletions upload/admin/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions upload/admin/language/english/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
$_['text_bitcoin'] = '<img src="view/image/payment/bitcoin.jpg" alt="Bitcoin" title="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:';
Expand All @@ -19,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_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:';
$_['entry_sort_order'] = 'Sort Order:';
Expand Down
62 changes: 62 additions & 0 deletions upload/admin/view/template/payment/bitcoin.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,68 @@ Copyright (c) 2013 John Atkinson (jga)
<option value="0" selected="selected"><?php echo $text_no; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><?php echo $entry_btc_decimal; ?></td>
<td><select name="bitcoin_btc_decimal">
<?php if ($bitcoin_btc_decimal == 8) { ?>
<option value="8" selected="selected"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } else if ($bitcoin_btc_decimal == 7) { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7" selected="selected"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } else if ($bitcoin_btc_decimal == 6) { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6" selected="selected"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } else if ($bitcoin_btc_decimal == 5) { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5" selected="selected"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } else if ($bitcoin_btc_decimal == 3) { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3" selected="selected"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } else if ($bitcoin_btc_decimal == 2) { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2" selected="selected"><?php echo $text_5; ?></option>
<?php } else { ?>
<option value="8"><?php echo $text_8; ?></option>
<option value="7"><?php echo $text_7; ?></option>
<option value="6"><?php echo $text_6; ?></option>
<option value="5"><?php echo $text_5; ?></option>
<option value="4" selected="selected"><?php echo $text_4; ?></option>
<option value="3"><?php echo $text_3; ?></option>
<option value="2"><?php echo $text_2; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_countdown_timer; ?></td>
Expand Down
14 changes: 8 additions & 6 deletions upload/catalog/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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 . "'");


Expand Down Expand Up @@ -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');
Expand All @@ -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";
Expand All @@ -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'");
}

Expand Down

0 comments on commit 2a46afd

Please sign in to comment.