Giter VIP home page Giter VIP logo

laravel-currency's People

Contributors

amrshawky avatar parth391 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-currency's Issues

The output returns 0

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.

Methods return "Null"

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?

average of different money types

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

Documenting some errors I ran into for others

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.

  1. First you cannot directly use Currency. So,

$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?

  1. If you are testing the package on localhost you may run into an issue where nothing is returned. In digging into the code, since the package uses Guzzle, not having a valid cert will result in this error:

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.

Package returns null

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.

Gateway timeout on live server

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.

Converted amount is being rounded up.

I used this package for a project and noticed that the converted amount is being rounded up.

image

image

`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,

Class "AmrShawky\LaravelCurrency\Facade\Currency" not found"

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 :(

Always returns null

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

Caching of currency conversion rates

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

Now API key is needed in exchangerate.host

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!

Returning null on convert

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

Any amount other than 1 returns NULL since this morning

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

I tried converting from USD to ETH but got a weird error

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`

Suggestions for docs

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.