From 7f66ade47e81a54badf6aca7c952e7f07d2e8d48 Mon Sep 17 00:00:00 2001 From: John Atkinson Date: Tue, 7 May 2013 20:24:09 -0700 Subject: [PATCH] improved exchange rate calculation Exchange rates are now calculated using EITHER the Mt.Gox 24-hour average OR the Mt.Gox last trade value... whichever is better for the merchant. --- upload/catalog/controller/payment/bitcoin.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/upload/catalog/controller/payment/bitcoin.php b/upload/catalog/controller/payment/bitcoin.php index 9e01113..f20ee76 100644 --- a/upload/catalog/controller/payment/bitcoin.php +++ b/upload/catalog/controller/payment/bitcoin.php @@ -179,9 +179,16 @@ public function runUpdate() { $btcdata = $dec; $currency = "BTC"; - $value = $btcdata['return']['avg']['value']; - - if ((float)$value) { + $avg_value = $btcdata['return']['avg']['value']; + $last_value = $btcdata['return']['last']['value']; + + if ((float)$avg_value && (float)$last_value) { + if($avg_value < $last_value) { + $value = $avg_value; + } + else { + $value = $last_value; + } $value = 1/$value; $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (float)$value . "', date_modified = '" . $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($currency) . "'"); }