Skip to content

Commit d5d1327

Browse files
committed
version 2.1.4
Update live exchange rates websites
1 parent 7fe65f2 commit d5d1327

7 files changed

+145
-88
lines changed

history.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
===============================================================================
2+
== Version 2.1.4 (August 2018)
3+
===============================================================================
4+
5+
- Update live exchange rates websites
6+
7+
8+
19
===============================================================================
210
== Version 2.1.3 (April 2018)
311
===============================================================================

js/_source/ajax.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @category Javascript
55
* @website https://gourl.io
66
* @api https://gourl.io/api.html
7-
* @version 2.1.3
7+
* @version 2.1.4
88
*/
99

1010
/**

js/_source/cryptobox.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @category Javascript
55
* @website https://gourl.io
66
* @api https://gourl.io/api.html
7-
* @version 2.1.3
7+
* @version 2.1.4
88
*/
99

1010
/**

js/_source/support.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @category Javascript
55
* @website https://gourl.io
66
* @api https://gourl.io/api.html
7-
* @version 2.1.3
7+
* @version 2.1.4
88
*/
99

1010
/**

lib/cryptobox.callback.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @copyright 2014-2018 Delta Consultants
1212
* @category Libraries
1313
* @website https://gourl.io
14-
* @version 2.1.3
14+
* @version 2.1.4
1515
*
1616
*
1717
* This file processes call-backs from Cryptocoin Payment Box server when new payment

lib/cryptobox.class.php

+132-83
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
* @package GoUrl PHP Bitcoin/Altcoin Payments and Crypto Captcha
1111
* @copyright 2014-2018 Delta Consultants
1212
* @category Libraries
13-
* @website https://gourl.io
13+
* @website https://gourl.io
1414
* @api https://gourl.io/bitcoin-payment-gateway-api.html
1515
* @example https://gourl.io/lib/examples/example_customize_box.php <----
1616
* @gitHub https://github.com/cryptoapi/Payment-Gateway
1717
* @license Free GPLv2
18-
* @version 2.1.3
18+
* @version 2.1.4
1919
*
2020
*
2121
* CLASS CRYPTOBOX - LIST OF METHODS:
@@ -53,7 +53,7 @@
5353
* E. function display_language_box(..) // Language selection dropdown list for cryptocoin payment box
5454
* F. function display_currency_box(..) // Multiple crypto currency selection list. You can accept payments in multiple crypto currencies (for example: bitcoin, bitcoincash, litecoin, dogecoin)
5555
* G. function get_country_name(..) // Get country name by country code or reverse
56-
* H. function convert_currency_live(..) // Fiat currency converter using XE.COM live exchange rates
56+
* H. function convert_currency_live(..) // Fiat currency converter using live exchange rates websites
5757
* I. function validate_gourlkey(..) // Validate gourl private/public/affiliate keys
5858
* J. function run_sql(..) // Run SQL queries and return result in array/object formats
5959
*
@@ -79,7 +79,7 @@
7979
elseif (!defined('ABSPATH')) exit; // Wordpress
8080

8181

82-
define("CRYPTOBOX_VERSION", "2.1.3");
82+
define("CRYPTOBOX_VERSION", "2.1.4");
8383

8484
// GoUrl supported crypto currencies
8585
define("CRYPTOBOX_COINS", json_encode(array('bitcoin', 'bitcoincash', 'litecoin', 'dash', 'dogecoin', 'speedcoin', 'reddcoin', 'potcoin', 'feathercoin', 'vertcoin', 'peercoin', 'monetaryunit', 'universalcurrency')));
@@ -1779,90 +1779,139 @@ function get_country_name($countryID, $reverse = false)
17791779

17801780

17811781
/* H. Function convert_currency_live()
1782-
*
1783-
* Currency Converter using XE.COM live exchange rates
1782+
*
1783+
* Currency Converter using live exchange rates websites
17841784
* Example - convert_currency_live("EUR", "USD", 22.37) - convert 22.37euro to usd
1785-
convert_currency_live("EUR", "BTC", 22.37) - convert 22.37euro to bitcoin
1785+
convert_currency_live("EUR", "BTC", 22.37) - convert 22.37euro to bitcoin
17861786
*/
17871787
function convert_currency_live($from_Currency, $to_Currency, $amount)
17881788
{
1789-
static $arr = array();
1789+
static $arr = array();
17901790

1791-
$from_Currency = trim(strtoupper(urlencode($from_Currency)));
1792-
$to_Currency = trim(strtoupper(urlencode($to_Currency)));
1793-
1794-
if ($from_Currency == "TRL") $from_Currency = "TRY"; // fix for Turkish Lyra
1795-
if ($from_Currency == "ZWL") $from_Currency = "ZWD"; // fix for Zimbabwe Dollar
1796-
if ($from_Currency == "RM") $from_Currency = "MYR"; // fix for Malaysian Ringgit
1797-
if ($from_Currency == "BTC") $from_Currency = "XBT"; // fix for Bitcoin
1798-
if ($to_Currency == "BTC") $to_Currency = "XBT"; // fix for Bitcoin
1799-
1800-
if ($from_Currency == "RIAL") $from_Currency = "IRR"; // fix for Iranian Rial
1801-
if ($from_Currency == "IRT") { $from_Currency = "IRR"; $amount = $amount * 10; } // fix for Iranian Toman; 1IRT = 10IRR
1802-
1803-
$key = $from_Currency."_".$to_Currency;
1804-
1805-
1806-
1807-
// from buffer
1808-
// ----------------
1809-
if (isset($arr[$key]))
1810-
{
1811-
if ($arr[$key] > 0)
1812-
{
1813-
$val = $arr[$key];
1814-
$total = $val*$amount;
1815-
if ($to_Currency=="XBT" || $total<0.01) $total = sprintf('%.5f', round($total, 5));
1816-
else $total = round($total, 2);
1817-
if ($total == 0) $total = sprintf('%.5f', 0.00001);
1818-
return $total;
1819-
}
1820-
else return -1;
1821-
}
1822-
1823-
1824-
1825-
// get data from xe.com
1826-
// ----------------
1827-
$val = 0;
1828-
$url = "https://www.xe.com/currencyconverter/convert/?Amount=1&From=".$from_Currency."&To=".$to_Currency;
1829-
1830-
$rawdata = get_url_contents( $url );
1831-
1832-
if (strpos($rawdata, "1 ".$from_Currency." = "))
1833-
{
1834-
$data = explode("uccResultAmount'>", $rawdata);
1835-
if (isset($data[1]))
1836-
{
1837-
$pos = stripos($data[1], "</span>");
1838-
if ($pos)
1839-
{
1840-
$data = substr($data[1], 0, $pos);
1841-
if (is_numeric($data) && $data > 0) $val = floatval($data);
1842-
}
1843-
}
1844-
}
1845-
1846-
1847-
1848-
// result
1849-
// ------------
1850-
if ($val > 0)
1851-
{
1852-
$arr[$key] = $val;
1853-
$total = $val*$amount;
1854-
if ($to_Currency=="XBT" || $total<0.01) $total = sprintf('%.5f', round($total, 5));
1855-
else $total = round($total, 2);
1856-
if ($total == 0) $total = sprintf('%.5f', 0.00001);
1857-
return $total;
1858-
}
1859-
else
1860-
{
1861-
$arr[$key] = -1;
1862-
return -1;
1863-
}
1791+
$from_Currency = trim(strtoupper(urlencode($from_Currency)));
1792+
$to_Currency = trim(strtoupper(urlencode($to_Currency)));
1793+
1794+
if ($from_Currency == "TRL") $from_Currency = "TRY"; // fix for Turkish Lyra
1795+
if ($from_Currency == "ZWD") $from_Currency = "ZWL"; // fix for Zimbabwe Dollar
1796+
if ($from_Currency == "RM") $from_Currency = "MYR"; // fix for Malaysian Ringgit
1797+
if ($from_Currency == "XBT") $from_Currency = "BTC"; // fix for Bitcoin
1798+
if ($to_Currency == "XBT") $to_Currency = "BTC"; // fix for Bitcoin
1799+
1800+
if ($from_Currency == "RIAL") $from_Currency = "IRR"; // fix for Iranian Rial
1801+
if ($from_Currency == "IRT") { $from_Currency = "IRR"; $amount = $amount * 10; } // fix for Iranian Toman; 1IRT = 10IRR
1802+
1803+
$key = $from_Currency."_".$to_Currency;
1804+
1805+
1806+
1807+
// a. restore saved exchange rate
1808+
// ----------------
1809+
if (!isset($arr[$key]) && session_status() === PHP_SESSION_ACTIVE && isset($_SESSION["exch_".$key]) && is_numeric($_SESSION["exch_".$key]) && $_SESSION["exch_".$key] > 0) $arr[$key] = $_SESSION["exch_".$key];
1810+
1811+
if (isset($arr[$key]))
1812+
{
1813+
if ($arr[$key] > 0)
1814+
{
1815+
$val = $arr[$key];
1816+
$total = $val*$amount;
1817+
if ($to_Currency=="BTC" || $total<0.01) $total = sprintf('%.5f', round($total, 5));
1818+
else $total = round($total, 2);
1819+
if ($total == 0) $total = sprintf('%.5f', 0.00001);
1820+
return $total;
1821+
}
1822+
else return -1;
1823+
}
1824+
1825+
1826+
$val = 0;
1827+
if ($from_Currency == $to_Currency) $val = 1;
1828+
1829+
1830+
1831+
// b. get BTC rates
1832+
// ----------------
1833+
$bitcoinUSD = 0;
1834+
if (!$val && ($from_Currency == "BTC" || $to_Currency == "BTC"))
1835+
{
1836+
$aval = array ('BTC', 'USD', 'AUD', 'BRL', 'CAD', 'CHF', 'CLP', 'CNY', 'DKK', 'EUR', 'GBP', 'HKD', 'INR', 'ISK', 'JPY', 'KRW', 'NZD', 'PLN', 'RUB', 'SEK', 'SGD', 'THB', 'TWD');
1837+
if (in_array($from_Currency, $aval) && in_array($to_Currency, $aval))
1838+
{
1839+
$data = json_decode(get_url_contents("https://blockchain.info/ticker"), true);
1840+
1841+
// rates BTC->...
1842+
$rates = array("BTC" => 1);
1843+
if ($data) foreach($data as $k => $v) $rates[$k] = ($v["15m"] > 1000) ? round($v["15m"]) : ($v["last"] > 1000 ? round($v["last"]) : 0);
1844+
// convert BTC/USD, EUR/BTC, etc.
1845+
if (isset($rates[$to_Currency]) && $rates[$to_Currency] > 0 && isset($rates[$from_Currency]) && $rates[$from_Currency] > 0) $val = $rates[$to_Currency] / $rates[$from_Currency];
1846+
if (isset($rates["USD"]) && $rates["USD"] > 0) $bitcoinUSD = $rates["USD"];
1847+
}
1848+
1849+
if (!$val && $bitcoinUSD < 1000)
1850+
{
1851+
$data = json_decode(get_url_contents("https://www.bitstamp.net/api/ticker/"), true);
1852+
if (isset($data["last"]) && isset($data["volume"]) && $data["last"] > 1000) $bitcoinUSD = round($data["last"]);
1853+
}
1854+
1855+
if ($from_Currency == "BTC" && $to_Currency == "USD" && $bitcoinUSD > 0) $val = $bitcoinUSD;
1856+
if ($from_Currency == "USD" && $to_Currency == "BTC" && $bitcoinUSD > 0) $val = 1 / $bitcoinUSD;
1857+
}
1858+
1859+
1860+
1861+
// c. get rates from European Central Bank https://www.ecb.europa.eu
1862+
// ----------------
1863+
$aval = array ('EUR', 'USD', 'JPY', 'BGN', 'CZK', 'DKK', 'GBP', 'HUF', 'PLN', 'RON', 'SEK', 'CHF', 'ISK', 'NOK', 'HRK', 'RUB', 'TRY', 'AUD', 'BRL', 'CAD', 'CNY', 'HKD', 'IDR', 'ILS', 'INR', 'KRW', 'MXN', 'MYR', 'NZD', 'PHP', 'SGD', 'THB', 'ZAR');
1864+
if ($bitcoinUSD > 0) $aval[] = "BTC";
1865+
if (!$val && in_array($from_Currency, $aval) && in_array($to_Currency, $aval))
1866+
{
1867+
$xml = simplexml_load_string(get_url_contents("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));
1868+
$json = json_encode($xml);
1869+
$data = json_decode($json,TRUE);
1870+
1871+
if (isset($data["Cube"]["Cube"]))
1872+
{
1873+
$data = $data["Cube"]["Cube"];
1874+
$time = $data["@attributes"]["time"];
1875+
1876+
// rates EUR->...
1877+
$rates = array("EUR" => 1);
1878+
foreach($data["Cube"] as $v) $rates[$v["@attributes"]["currency"]] = floatval($v["@attributes"]["rate"]);
1879+
if ($bitcoinUSD > 0 && $rates["USD"] > 0) $rates["BTC"] = $rates["USD"] / $bitcoinUSD;
1880+
1881+
// convert USD/JPY, EUR/GBP, etc.
1882+
if ($rates[$to_Currency] > 0 && $rates[$from_Currency] > 0) $val = $rates[$to_Currency] / $rates[$from_Currency];
1883+
}
1884+
}
1885+
1886+
1887+
// d. get rates from https://free.currencyconverterapi.com/api/v6/convert?q=BTC_EUR&compact=y
1888+
// ----------------
1889+
if (!$val)
1890+
{
1891+
$data = json_decode(get_url_contents("https://free.currencyconverterapi.com/api/v6/convert?q=".$key."&compact=y"), TRUE);
1892+
if (isset($data[$key]["val"]) && $data[$key]["val"] > 0) $val = $data[$key]["val"];
1893+
}
1894+
1895+
1896+
// e. result
1897+
// ------------
1898+
if ($val > 0)
1899+
{
1900+
if (session_status() === PHP_SESSION_ACTIVE) $_SESSION["exch_".$key] = $val;
1901+
1902+
$arr[$key] = $val;
1903+
$total = $val*$amount;
1904+
if ($to_Currency=="BTC" || $total<0.01) $total = sprintf('%.5f', round($total, 5));
1905+
else $total = round($total, 2);
1906+
if ($total == 0) $total = sprintf('%.5f', 0.00001);
1907+
return $total;
1908+
}
1909+
else
1910+
{
1911+
$arr[$key] = -1;
1912+
return -1;
1913+
}
18641914
}
1865-
18661915

18671916

18681917

@@ -2225,6 +2274,6 @@ function run_sql($sql)
22252274
foreach ($cryptobox_private_keys as $v)
22262275
if (strpos($v, " ") !== false || strpos($v, "PRV") === false || strpos($v, "AA") === false || strpos($v, "77") === false) die("Invalid Private Key - ". (CRYPTOBOX_WORDPRESS ? "please setup it on your plugin settings page" : "$v in variable \$cryptobox_private_keys, file cryptobox.config.php."));
22272276

2228-
unset($v); unset($cryptobox_private_keys);
2277+
unset($v); unset($cryptobox_private_keys);
22292278
}
22302279
?>

readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
GoUrl.io Cryptocoin Payment Gateway API
33
-----------------------------------------
44

5-
Version 2.1.3
5+
Version 2.1.4
66

77
**Accept Bitcoin, Bitcoin Cash, Litecoin, Dash, Dogecoin, Speedcoin, Reddcoin, Potcoin, Feathercoin, Vertcoin, Peercoin, UniversalCurrency, MonetaryUnit Payments Online on your website**
88

0 commit comments

Comments
 (0)