How to apply conversion rates to wallet

Mizhack Aguilar Posted in Component Development 1 year 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.

This topic has been closed!

[Topic is Close]

Replies
us Mizhack Aguilar Replied 1 year 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 1 year 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 = 'YOUR_API_KEY';

// Function to get exchange rates from CurrencyLayer API
function getExchangeRates($apiKey) {
$url = "https://api.currencylayer.com/live?access_key={$apiKey}";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
return json_decode($response, true);
}

// Function to convert USD to another currency
function convertCurrency($amount, $toCurrency, $exchangeRates) {
if (array_key_exists($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 1 year 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 1 year 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

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions