Skip to content

Commit

Permalink
payment success
Browse files Browse the repository at this point in the history
  • Loading branch information
btcgear committed May 14, 2013
1 parent 762017b commit 29fa09d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
24 changes: 15 additions & 9 deletions upload/catalog/controller/payment/bitcoin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ protected function index() {

$this->data['bitcoin_total'] = round($this->currency->convert($order['total'], $current_default_currency, "BTC"),4);

$this->db->query("UPDATE `" . DB_PREFIX . "order` SET bitcoin_total = '" . $this->data['bitcoin_total'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");


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').'/');
Expand All @@ -71,6 +74,7 @@ protected function index() {
$this->data['error'] = false;

$this->data['bitcoin_send_address'] = $bitcoin->getaccountaddress($this->config->get('bitcoin_prefix').'_'.$order_id);
$this->db->query("UPDATE `" . DB_PREFIX . "order` SET bitcoin_address = '" . $this->data['bitcoin_send_address'] . "', date_modified = NOW() WHERE order_id = '" . (int)$order_id . "'");

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/bitcoin.tpl')) {
$this->template = $this->config->get('config_template') . '/template/payment/bitcoin.tpl';
Expand All @@ -87,7 +91,7 @@ public function confirm_sent() {
$order_id = $this->session->data['order_id'];
$order = $this->model_checkout_order->getOrder($order_id);
$current_default_currency = $this->config->get('config_currency');
$bitcoin_total = round($this->currency->convert($order['total'], $current_default_currency, "BTC"),4);
$bitcoin_total = $order['bitcoin_total'];
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').'/');

Expand All @@ -99,17 +103,19 @@ public function confirm_sent() {

try {
$received_amount = $bitcoin->getreceivedbyaccount($this->config->get('bitcoin_prefix').'_'.$order_id,0);
if(round((float)$received_amount,4) >= round((float)$bitcoin_total,4)) {
$order = $this->model_checkout_order->getOrder($order_id);
$this->model_checkout_order->confirm($order_id, $this->config->get('bitcoin_order_status_id'));
echo true;
}
else {
echo false;
}
} catch (Exception $e) {
$this->data['error'] = true;
echo false;
}
if(round((float)$received_amount,4) >= round((float)$bitcoin_total,4)) {
$order = $this->model_checkout_order->getOrder($order_id);
$this->model_checkout_order->confirm($order_id, $this->config->get('bitcoin_order_status_id'));
echo true;
}
else {
echo false;
}

}

public function checkUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ $('#button-pay').on('click', function() {
type: 'GET',
url: 'index.php?route=payment/bitcoin/confirm_sent',
timeout: 5000,
error: function() {
document.getElementById("cboxLoadedContent").innerHTML = document.getElementById("cboxLoadedContent").innerHTML + '<div class="warning"><?php echo $error_confirm; ?></div>';
},
success: function(received) {
if(received) {
location.href = 'index.php?route=checkout/success';
Expand Down
16 changes: 16 additions & 0 deletions upload/vqmod/xml/opencart-bitcoin-module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<modification>
<id>Makes the modifications necessary to conveniently use Bitcion module</id>
<version>1.0</version>
<vqmver>2.3.2</vqmver>
<author>jga</author>

<file name="catalog/model/checkout/order.php">
<operation>
<search position="after"><![CDATA[
'currency_value' => $order_query->row['currency_value'],]]></search>
<add><![CDATA[
'bitcoin_total' => $order_query->row['bitcoin_total'],
'bitcoin_address' => $order_query->row['bitcoin_address'],]]></add>
</operation>
</file>
</modification>

0 comments on commit 29fa09d

Please sign in to comment.