Bitcoin Forum
June 24, 2019, 08:26:59 PM *
News: Latest Bitcoin Core release: 0.18.0 [Torrent] (New!)
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Opencart bitcoin plugin for Coinbase prices  (Read 619 times)
pugetfield
Newbie
*
Offline Offline

Activity: 3
Merit: 0


View Profile
June 10, 2014, 06:53:44 PM
 #1

This is a dirty hack but i thought i would share. It is based on the btcgear plugin with the MtGox code swapped for Coinbase

1a. Download code from https://github.com/btcgear/Bitcoin_Exchange_Rate_OpenCart and extract somewhere.
1b. Download code from https://github.com/coinbase/coinbase-php and copy the 'lib' folder to \upload\catalog\controller\common\ in above dir.
2. Edit the file \upload\catalog\controller\common\bitcoin_update.php as follows; Replace everything after public function runUpdate() { (line 60) with;

Code:
require_once(dirname(__FILE__) . '/lib/Coinbase.php');
$default_currency_code = $this->config->get('config_currency');

// API settings
$_API_KEY = "YourCoinbaseApiKey";
$_API_SECRET = "YourCoinbaseApiSecret";

// run the query
$coinbase = Coinbase::withApiKey($_API_KEY, $_API_SECRET);
$currency = "BTC";
$value = $coinbase->getSpot();


if ((float)$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) . "'");
}

$this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = '" .  $this->db->escape(date('Y-m-d H:i:s')) . "' WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'");
$this->cache->delete('currency');
}
}
?>

3. Install code as per instructions in instructions.txt

Please let me know if you need any help or something, or can make the code better - or fork it on Git for me!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!