Thank you for getting back to me. Actually, the website, as it is, is working just the way it should. I am designing new functionality on localhost then uploading each script to see it works as expected. I did clear the cache but had other files working just fine before and after doing so. I’m really looking for a method to debug or find out if there is specifically something that is incompatible with Infinityfree. I did run into another strange issue with a password with the characters ##1 at the end. When I changed it to 001 it worked fine, though it worked in localhost all along. This file is using the passwords and .env variables which are working with the other files. This is the code with which I am currently having a the 500 ERROR problem.
include ('loadenv.php');
// BEGIN getCurrency() returns list of currencies from NowPayments.io API
// Currencies are compatible with those in Store Settings listing
function getCurrency() {
$url = "https://api.nowpayments.io/v1/currencies";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'x-api-key: '.$_ENV['NOWPAYMENTS_API_KEY']
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
$output = json_decode($resp, true);
$currencies = $output['currencies'];
return $currencies;
}
// END getCurrency() for list of currencies from NowPayments.io API
// BEGIN getminPayment() inut Customer Currency/Store Currency pair
// returns minumum payment array with minimum amount in Customer Currency first
// and same amount in fiat currency second determined by NowPayments.io API
// Run this against all currencies in the store's Outcome Wallet.
function getminPayment($pcurrencyFrom, $pcurrencyTo) {
$url = 'https://api.nowpayments.io/v1/min-amount?currency_from='.$pcurrencyFrom.'¤cy_to='.$pcurrencyTo.'&fiat_equivalent=usd';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'x-api-key: '.$_ENV['NOWPAYMENTS_API_KEY']
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
// var_dump($resp);
$output = json_decode($resp, true);
// echo "<br>var_dump of output is <br>";
// var_dump($output);
$mincryptoAmount = $output['min_amount'];
$fiat_equivalent = $output['fiat_equivalent'];
$minimums = array($mincryptoAmount,$fiat_equivalent);
return $minimums;
}
// END getminPayment() returns minumum payment reaquired from NowPayments.io API
// BEGIN getestPrice() returns estimated price in the Customer Currency
// as calculated by the NowPayments.io API
function getestPrice($pcurrencyTo,$pamount) {
$url = "https://api.nowpayments.io/v1/estimate?amount=".$pamount."¤cy_from=usd¤cy_to=".$pcurrencyTo;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
'x-api-key: '.$_ENV['NOWPAYMENTS_API_KEY']
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
$result = json_decode($resp, true);
// var_dump($result);
$mincryptoPayment = $result['estimated_amount'];
return $mincryptoPayment;
}
// END getestPrice() returns estimated price in the Customer Currency
// as calculated by the NowPayments.io API
// BEGIN getcurrencyData() to retreive up-to-date store currencies, addresses, and discounts
// Build an array of data for ticker, address, discount
function getcurrencyData() {
//Connct to websiteData MySQL database
include ('db.php');
// SQL Query
$sql = "SELECT ticker, wallet_address, discount FROM cryptocurrency;";
// Create a prepared statement
$stmt = mysqli_stmt_init($db);
// Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "MySQL query failed.";
} else {
// Bind parameters to placeholders
// Run parameters inside database
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
}
// Initialize return data array
$curData = array('ticker', 'wallet_address', 'discount');
while ($row = mysqli_fetch_assoc($result)) {
// echo "<br>var_dump of row is<br>";
// var_dump($row);
$curData[0] = $row['ticker'];
// echo "<br>data zero is ".$data[0];
$curData[1] = $row['wallet_address'];
// echo "<br>data one is ".$data[1];
$curData[2] = $row['discount'];
// echo "<br>data two is ".$data[2];
}
$db->close();
return $curData;
}
// END getcurrencyData() Return: multi-dimensional array of currency data.
// BEGIN getStoreCurrency() to retreive up-to-date store currencies, addresses, and discounts
// Build an array of data for ticker, address, discount
function getStoreCurrency() {
//Connct to websiteData MySQL database
include ('db.php');
// SQL Query
$query = "SELECT ticker, wallet_address, discount FROM cryptocurrency;";
$result = $db->query($query);
while($row = $result->fetch_array())
{
$rows[] = $row;
}
/* free result set */
$result->close();
/* close connection */
$db->close();
// echo "var_dump of Rows is<br>";
// var_dump($rows);
$tableLength = count($rows);
// echo "The table has ".$tableLength." entries.<br>";
$curData = array();
foreach($rows as $item) {
$row['ticker'] = $item['ticker'];
$row{'trade_for'} = $item['trade_for'];
$row['wallet_address'] = $item['wallet_address'];
$row['discount'] = $item['discount'];
array_push($curData, $row);
}
$db->close();
return $curData;
}
// END getStoreCurrency() Return: multi-dimensional array of currency data.
// BEGIN minPaymentEstPcicet() compare minimum payment with estimated price
function minPaymenEstPrice($pcurrencyFrom, $ptrade_for, $pamount) {
$estPrice = getestPrice($$ptrade_for, $pamount);
$minPayment = getminPayment($pcurrencyFrom,$ptrade_for);
if ($estPrice > $minPayment) {
$compare = true;
}
return $compare;
}
// END minPaymentEstPcicet() compare minimum payment with estimated price
// Call to database for $storeCurrencyData to contain ticker, address, and discount info for each currency
// Initialize $storeCurrencies to contain list of CURRENCY TICKERS ONLY for pair comparison
$storeCurrencyData = getStoreCurrency();
$storeCurrencies = array();
foreach($storeCurrencyData as $entry) {
array_push($storeCurrencies, $entry['ticker']);
}
// echo "<br>var_dump of storeCurrencies is<br>";
// var_dump($storeCurrencies);
// echo "<br><br>";
// After $storeCurrencies list is pulled from the database check viability of all pairs
// Display only pairs where a sale is possible
?>
<!DOCTYPE html>
<html>
<head>
<title>Choose and Compare Currencies</title>
</head>
<body>
<div id="dropdown">
<h1>Select Payment Currency</h1>
<p>Form using most recent data from NowPayments for Available Store Currencies</p>
<form action="selectandPay.php" method="POST">
<select name="ticker">
<option selected="selected">Select Currency</option>
<?php
// Iterating through the NowPayments currency list
foreach($storeCurrencies as $ticker){
echo "<option value='$ticker'>$ticker</option>";
}
?>
</select>
<input type="submit" name="submit" >
</form>
</div>
</body>
</html>
<?php
// Initialize Customer choice
$custChoice = '';
// Initialize wallet_address
$wallet_address = '';
// Initialize trade_for currency
$trade_for = '';
// initialize trade_for wallet_address
$trade_wallet = '';
// Initialize discount
$discount = 0.0;
// Check if form is submitted successfully
// Obtain ticker for customer's first choice
if(isset($_POST["submit"]))
{
// Check if any option is selected
if(isset($_POST['ticker']))
{
$custChoice = $_POST['ticker'];
}
else
echo "Select an option first !!";
}
// After customer chooses currency, look up discount and store's wallet_address
foreach($storeCurrencyData as $entry) {
if ($entry['ticker'] == $custChoice) {
$wallet_address = $entry['wallet_address'];
$discount = $entry['discount'];
$trade_for = $entry['trade_for'];
if ($trade_for !== $custChoice) {
// Obtain the $trade_for address
foreach($storeCurrencyData as $index) {
if ($index['ticker'] == $trade_for) {
$wallet_address = $index['wallet_address'];
}
}
}
}
}
// Obtain amount from order data
$amount = 3.25;
// Adjust amount by discount
$amount = $amount * (1 - $discount);
// Make comparison for viable sale
$gonogo = minPaymenEstPrice($custChoice, $trade_for, $amount);
if (!gonogo) {
echo "<br>Estimated Price is less than Minimum Payment -- choose another currency.";
} else
echo "<br>Estimated Price is greater than minimum payment -- proceed with transaction.";
echo "<br>The customer's currency is ".$custChoice;
echo "<br>The store's wallet address is ".$wallet_address;
$percentage = 100 * $discount;
echo "<br>The store's discount is ".$percentage."%";
echo "<br>The price in ".$custChoice." is ";
// The bookPrice will need to be determined from the Order Data
?>
type or paste code here