コード例 #1
0
$intBalance = $row["balance"];
$intBalance = number_format($intBalance, 8);
//balance of BTC
//get bitcoin rate
if ($strCryptoCode == "btc") {
    $intRate_BTC_USD = funct_Billing_GetRate("btc");
    //get usd value of BTC - coindesk, gox, bitstamp
    $intCrypto2Fiat_rate = $intRate_BTC_USD;
    $total_fiat_balance = (double) ($intBalance * $intRate_BTC_USD);
    //    $intBalance_Fiat = money_format('%i', $total_fiat_balance);
    $intBalance_Fiat = $total_fiat_balance;
}
//convert to other fiat if not dollars
if ($strFiatCode != "usd") {
    //get fiat rate
    $intBalance_Fiat2USD = funct_Billing_UpdateRate_Fiat($strFiatCode);
    //echo "fiat $strFiatCode - $intBalance_Fiat2USD <br>";
    //get other crypto rate
    //$intCrypto2Fiat_rate = $intRate_BTC_USD ;
    $intCrypto2Fiat_rate = $intBalance_Fiat2USD * $intRate_BTC_USD;
    //no rate found so stick to dollars
    if (!$intBalance_Fiat2USD) {
        //set crypto back to usd
        $strFiatCode = "usd";
    }
}
//get fiat info
$query = "SELECT * FROM " . TBL_CURRENCY . " WHERE currency_code='" . $strFiatCode . "'";
//echo "SQL STMNT = " . $query .  "<br>";
$rs = mysqli_query($DB_LINK, $query) or die(mysqli_error());
$row = mysqli_fetch_array($rs);
コード例 #2
0
//echo "satoshi= ".$value_in_satoshi." <br> ";
//we need to make sure this function works. a backup may be needed! Gox, blockchain, coinbase, bitpay ?
$intRate = funct_Billing_UpdateRate("btc", RATE_HUD_EXCHANGE);
//bitstamp.. lower the rate the bigger the spread
//get value of BTC to convert to fiat
$intBTC_Convert2Fiat = $crypto_amt * (1 / $intFiatConversionPercent);
//calculate final BTC to add to BTC balance
$intBTC_Add2Balance = $crypto_amt - $intBTC_Convert2Fiat;
//calculate final FIAT to add to balance
$intTotalUSD = $intRate * $intBTC_Convert2Fiat;
//echo "userid: $intUserID";
//IF THEY have specified a different currency then we need to convert BTC to that currency
if ($intCurrencyID != 144) {
    //if fiat currency is NOT USD then we need to get the exchange rate and adjust the amount of fiat they earned
    //get fiat rate, fiat code and
    $intFiatRate = funct_Billing_UpdateRate_Fiat($strCurrencyCode);
    //convert to value of btc.. we store all this into the orders table  //ex. 0.7 for usd-eur
    $intTotalFiat = $intFiatRate * $intTotalUSD;
} else {
    $intFiatRate = 1;
    $strCurrencyCode = "USD";
    $intTotalFiat = $intTotalUSD;
    //defualt fiat is usd
}
//echo "BTC= ".$crypto_amt." <br> - USD= ".$intTotalUSD." \n <br>";
$strDebugSqlTxt = $strDebugSqlTxt . "BTC= " . $crypto_amt . " - USD= " . $intTotalUSD . " \n <br>";
//##########################################
//echo $strDebugSqlTxt ;
//add a new transaction record
//btc recieved (amt_btc), btc2 add to btc balance, btc 2 convert to fiat, btc2usd (rate), btc recieved worth in usd (amt_usd), worth in fiat (fiat_earned), btc2 (fiat_rate)
if ($intUserID) {