amrshawky / laravel-currency Goto Github PK
View Code? Open in Web Editor NEWLaravel package for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host
License: MIT License
Laravel package for current and historical currency exchange rates & crypto exchange rates. based on the free API exchangerate.host
License: MIT License
Hello, This package was working fine for me, But now it always giving 0 when printing the results, I don't Know if the problem from my side or yours.
Hi, Thanks for compiling this package!
I'm running through a Laravel Tutorial that uses your package (https://www.youtube.com/watch?v=dHPcWbC62R4) but I'm running into a persistent issue.
I've tried to run the:
Currency::convert()
->from('USD')
->to('EUR')
->get();
Method, but it returned 'null'. I've tried a combination of other methods, such as ->amount(40) but it yields the same result.
I cloned and installed the 'master' repo that the tutorial is based on (Repo Here: https://github.com/codewithdary/laravel-currency-converter) and it yields the same problem. I've installed all the dependencies through composer but i seem to get the same result.
I see that this package uses an API, just wanted to verify that this connection is still active?
Hello. I have 2 columns named "currency" and "bid" in my bids table in database. In the Currency column I store the currency types as USD, EUR, GBP. I keep the bid amounts written in the bid column. When I show the bids for the relevant request in the blade file, I want to show the average of these bid amounts. However, since the coin types are different, it collects other offer types only in numerical logic. example: 15 euros + 9 gbp = 24 usd.
example2: $bids->average(''bid) ; //12
The example should be:
1.09x15€=16.35$
1.30x9£=11.7$
16.35+11.7/2
avg = $28.05
This isn't so much an issue but just to help others that may use this package and run into the same problems I did.
$rates = Currency::rates()->latest()->get();
will result in "Non-static method AmrShawky\Currency\Currency::rates() should not be called statically". Instead you must instantiate Currency then use it like:
$rates = (new Currency())->rates()->latest()->get();
Maybe consider modifying the readme?
GuzzleHttp\Exception\RequestException cURL error 60: SSL certificate problem: unable to get local issuer certificate
So you have two choices, go through the steps to install a valid certificate on your system (SO helps here) or modify the code to disable SSL certificate validation. You can do this as follows in the CurrencyRate.php file constructor:
$this->client = $client ?? new Client(['verify' => false ]);
Similarly you would need to do this in CurrencyConversion.php if you use that. Of course do not do this in production.
HTH others using this package.
i don't know what am doing wrong as this doesn't seem to work for me.
use AmrShawky\LaravelCurrency\Facade\Currency;
Route::get('test', function(){
dd(Currency::rates()->latest()->get());
});
i don't suppose there is any configuration file to publish because there was no provision for that.
I have re-installed the package but still nothing.
Hello,
I am using laravel-currency package in my project. On local, it working perfectly. But on a live server, it's throwing 504 Gateway Time-out error.
My live server operates on an IP address, Do I have to point it out to the domain name, Please guide me as I can't find any clue for this issue to be resolved.
I used this package for a project and noticed that the converted amount is being rounded up.
`function monetize($amount) {
// Get current location
$ip = request()->ip();
$geoData = geoip($ip);
// Get currency symbol
$dbCurrency = Currency::where('code', $geoData['currency'])->first();
// Strip "," symbol
$stripped = str_replace(',', '', number_format($amount/100, 2));
if ($amount != 0) {
$retval = CurrencyConverter::convert()
->from('PHP')
->to($geoData['currency'])
->amount($stripped)
->round(2)
->get();
} else {
$retval = number_format($amount/100, 2);
}
$retval = $dbCurrency->symbol . ' ' . $retval;
$decimal = substr($retval, strpos($retval, '.') + 1);
$cur = strtok($retval, '.');
return __(':cur<small>.:decimal</small>', ['cur' => $cur, 'decimal' => $decimal]);
}`
is there any way to prevent this from happening?
Kind regards,
I installed this package properly and I am calling the class,
use AmrShawky\LaravelCurrency\Facade\Currency;
it's returning this error
Class "AmrShawky\LaravelCurrency\Facade\Currency" not found"
I dont know if there is something i am doing wrong.
I would really appreciate a quick response :(
Currency::convert() ->from('USD') ->to($to) ->date($date) ->amount(1) ->round(2) ->get()
Hi , the code above was working correctly bu last days started returning null
, any idea ?
thank you
Hey @amrshawky, great project! This is just the easiest to use and cleanest currency library I found.
Are you planning to implement any kind of caching, so that we don't hit rate limits at exchangerate.host API?
I would like to use the default Laravel Cache driver for this, maybe allowing to pass any PSR-6 compliant cache implementation. Caching should ideally be done on both single currency conversions (by e.g. storing from-to currency rates in an array) or for whole rates data (see below).
I didn't find it easy to implement this in your library and pass some caching over to amrshawky/currency
through Laravel facade, so for the moment, I am just using this helper class in my project:
<?php
namespace App\Helpers;
use AmrShawky\LaravelCurrency\Facade\Currency;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
class CurrencyCached
{
/**
* @var array currency rates
*/
protected array $rates;
/**
* @var string cache key
*/
protected string $cacheKey = 'currency-rates';
/**
* @param int|null $cacheTtl
*/
public function __construct(int $cacheTtl = null)
{
$ttl = $cacheTtl ?? config('app.cache_ttl.currency');
$this->rates = Cache::remember($this->cacheKey, $ttl, function () {
return Currency::rates()->latest()->get();
});
}
/**
* Currency conversion.
*
* @param float $amount
* @param string $toCurrency
* @param string $fromCurrency
* @return float|int
*/
public function convert(float $amount, string $toCurrency = 'CHF', string $fromCurrency = 'EUR')
{
return $amount * $this->rates[$toCurrency] / $this->rates[$fromCurrency];
}
}
Cheers, Philip
All calls now prompt the following error:
AmrShawky\Exceptions\RequestException {
"success": false,
"error": {
"code": 101,
"type": "missing_access_key",
"info": "You have not supplied an API Access Key. [Required format: access_key=YOUR_ACCESS_KEY]"
}
}
Could it be possible to include an option to use an API key?
Thank you!
Today, every time I convert any amount it returns null
AmrShawky\LaravelCurrency\Facade\Currency::convert()->from('USD')->to('EUR')->amount(2)->get();
AmrShawky\LaravelCurrency\Facade\Currency::convert()->from('USD')->to('HNL')->amount(1)->get();
Both return null
AmrShawky\LaravelCurrency\Facade\Currency::convert()->from('USD')->to('EUR')->amount(1)->get();
returns 0.881118
AmrShawky\LaravelCurrency\Facade\Currency::convert()->from('USD')->to('EUR')->amount(2)->get();
returns NULL
This is the function below
public function showRate()
{
$currency = Currency::convert()
->from('USD')
->to('ETH')
->source('crypto')
->withoutVerifying()
->get();
return floor($currency * $this->balance);
}
error: `A non-numeric value encountered`
Initially currencies like GHS, NGN, AED were included in the rates returned but are not included now.
Thanks for this great package, works like a treat for us.
It might be worth mentioning that the amount to be converted may not be negative. We now handle this with a wrapper but it caused some strange output before we discovered this behaviour.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.