How to apply conversion rates to wallet

Mizhack Aguilar Posted in Component Development 15 hours ago

I hope anyone can provide some input about adding a conversion rate for the wallet. The amount charge should be converted to different currencies.

Replies
Indonesian Arsalan Shah Replied 4 hours ago

You need to understand that we can not guess what is the error as this is your own code. Other member that was deleted then how he supposed to use the wallet if user is deleted? how he is accessing the wallet?

That is why post the full working modified code of wallet on github/gitlab so we can download install and test it and see the problem. As we don't have 7th sense to guess your code and the line where error is happening.

Indonesian Arsalan Shah Replied 4 hours ago

Share full modified code of wallet on github

us Mizhack Aguilar Replied 4 hours ago

Here's one member in eflymoney.com. This member did not have an issue when we changed the wallet code. We manually added a charged. However, the other member that we deleted has the same issue earlier as I posted here.
enter image description here

us Mizhack Aguilar Replied 5 hours ago

I deleted the component and the member and uploaded the fresh wallet and added the same code.

us Mizhack Aguilar Replied 5 hours ago

We are helping two businesses. And the issues are the same. Like I said, they are all in test mode. Here's for eflymoney.com for the admin. Unfortunately, I deleted the member issue in eflymoney and use the other website's issue because they are similar. We did not do a manual change of the balance of the member anymore. We did the same thing with the other website to see the difference. enter image description here

Indonesian Arsalan Shah Replied 5 hours ago

This shows completely different website then you showed in other screenshot. Please share actual website url.

Also do read carefully of what we need did you actually read?

https://www.opensource-socialnetwork.org/wiki/view/1101/how-to-report-a-bug-error-issue

Did you read which case you need to follow?

us Mizhack Aguilar Replied 13 hours ago

The admin area looks like this. But this is still in a test mode. We are deleting and changing stuffs. the conversion only appears when a charge is made.
Thanks again.
enter image description here

us Mizhack Aguilar Replied 13 hours ago

The sample conversion code is not what I would like to apply to the wallet.
This is the code that I want to integrate.

<?php
// Replace with your actual API key
$apiKey = 'YOURAPIKEY';

// Function to get exchange rates from CurrencyLayer API
function getExchangeRates($apiKey) {
$url = "https://api.currencylayer.com/live?access_key={$apiKey}";
$ch = curlinit($url);
curl
setopt($ch, CURLOPTRETURNTRANSFER, true);
$response = curl
exec($ch);
curlclose($ch);
return json
decode($response, true);
}

// Function to convert USD to another currency
function convertCurrency($amount, $toCurrency, $exchangeRates) {
if (arraykeyexists($toCurrency, $exchangeRates['quotes'])) {
return $amount * $exchangeRates['quotes'][$toCurrency];
} else {
return "Currency not supported.";
}
}

// Example usage
$exchangeRates = getExchangeRates($apiKey);
$amountInUSD = 100; // Amount in USD

echo "Amount in PHP: " . convertCurrency($amountInUSD, 'PHP', $exchangeRates) . "\n";
echo "Amount in MXN: " . convertCurrency($amountInUSD, 'MXN', $exchangeRates) . "\n";
echo "Amount in EUR: " . convertCurrency($amountInUSD, 'EUR', $exchangeRates) . "\n";
echo "Amount in GBP: " . convertCurrency($amountInUSD, 'GBP', $exchangeRates) . "\n";
echo "Amount in ILS: " . convertCurrency($amountInUSD, 'ILS', $exchangeRates) . "\n";
echo "Amount in SAR: " . convertCurrency($amountInUSD, 'SAR', $exchangeRates) . "\n";
echo "Amount in JPY: " . convertCurrency($amountInUSD, 'JPY', $exchangeRates) . "\n";
?>

us Mizhack Aguilar Replied 14 hours ago

Okay, I already uploaded the pic.
Here's the https://eflymoney.com/xp/. This is for the member issue.
Issue:
1. I applied a manual charge to the member for 2.00 USD.
2. After I did that, the member's wallet overview page got messed up. See the screenshot below. Only the specific member has the issue but not the entire members and the admin.
3. I added this code:
<?php
function convertCurrency($amount, $toCurrency) {
// Predefined exchange rates (these rates are hypothetical examples)
$exchangeRates = [
'PHP' => 56.50, // Philippine Peso
'MXN' => 18.90, // Mexican Peso
'EUR' => 0.90, // Euro
'GBP' => 0.76, // British Pound
'ILS' => 3.45, // Israeli Shekel
'SAR' => 3.75, // Saudi Riyal
'JPY' => 109.60 // Japanese Yen
];

// Convert the amount from USD to the target currency
if (array_key_exists($toCurrency, $exchangeRates)) {
    $convertedAmount = $amount * $exchangeRates[$toCurrency];
} else {
    return "Currency not supported.";
}

return $convertedAmount;

}

// Example usage
$amountInUSD = 100; // Amount in USD
echo "Amount in PHP: " . convertCurrency($amountInUSD, 'PHP') . "\n";
echo "Amount in MXN: " . convertCurrency($amountInUSD, 'MXN') . "\n";
echo "Amount in EUR: " . convertCurrency($amountInUSD, 'EUR') . "\n";
echo "Amount in GBP: " . convertCurrency($amountInUSD, 'GBP') . "\n";
echo "Amount in ILS: " . convertCurrency($amountInUSD, 'ILS') . "\n";
echo "Amount in SAR: " . convertCurrency($amountInUSD, 'SAR') . "\n";
echo "Amount in JPY: " . convertCurrency($amountInUSD, 'JPY') . "\n";
?>
But the code did not affect the other members and the admin.
This is just a test mode for now.enter image description here

Indonesian Arsalan Shah Replied 15 hours ago

I will repeat again what Michael said

Please provide a screenshot.
See https://www.opensource-socialnetwork.org/wiki/view/1101/how-to-report-a-bug-error-issue
and put your complete code on Github.

Also provide url of your social network where you installed wallet component not yours business website, sir