Git Product home page Git Product logo

laravel-currency's Introduction

laravel-currency's People

Contributors

alberto-bottarini avatar antonioribeiro avatar billmn avatar christopherokonkwo avatar damms005 avatar gkarugi avatar hardevine avatar harlekoy avatar henzel avatar hiyahin avatar imbrish avatar joe-pritchard avatar kwolniak avatar laravel-shift avatar leonigas avatar martinjac avatar mattias-persson avatar ncrazed avatar putchi avatar sudden-break avatar torann avatar umbertix avatar vaniyokk avatar veneliniliev 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

Currency::hasCurrency() return always true

I tried to use

Currency::hasCurrency('EUR')

But it seams to return always true.
Then I adopted this solution :

public function hasCurrency($currency)
    {
    return $currency == $this->getCurrencyCode();
    // return isset($this->currencies[$currency]);
    }

Couldn't install

Appreciate you written such a awesome package!
I not sure why i can't install the package. here is what i got from the composer

The requested package torann/laravel-currency could not be found in any version, there may be a typo in the package name.

Thanks

Database driver will fail to create records in strict db configruations.

Running php artisan currency:manage add USD will result in an INSERT query that attempts to insert an empty string ('') value into the integer id column which yields the following error on PostgreSQL:

invalid input syntax for integer

and probably something similar on MySQL with relevant strict modes enabled.

This is due to this default array. Since your migration sets the id column to auto increment the id should be dropped from the default array completely.

There are no commands defined in the "currency" namespace.

Hi,
I followed the installation steps but when I tried to run php artisan currency:update it throws an InvalidArgumentException with There are no commands defined in the "currency" namespace. message.

Is there something I missed?
Thanks
Laravel v.4.1.30

getCurrencies() returns all

The function getCurrencies() returns all the currencies, even when in the comment of the function says that it would return only the active one's.

Can't rollback migrations due to missing class.

After installing laravel-currency and doing all the migrations I was unable to reset my database using php artisan migrate:refresh --seed as it threw an error telling me the class didn't exist. I had to manually move the migration from /vendor/torann/migrations to my app's migrations folder.

Default Currency not working?

Hello, I used this package to display currencies for an ecomm site but the default settings I use are not working.
I made EUR the default currency in the config.php, but my currency always displays as USD. I have to use EUR as the second parameter in the function to display my currency as EUR.
I've also tried the currency:cleanup and currency:update commands with no success.
Don't know if it's a real problem, but I thought I should submit it.
Thanks.

Feature Request: Rounding

It would be great if rounding could be implemented into the Currency:format() function, including to which point it would round to (hundreds, tens, unit, 1 decimal point, etc.) and whether to always round up (ceil), always round down (floor) or round to the nearest point.

Redis Caching not working

i'm using cache driver as redis but it not seems to use cached?
my config as follows

'cache_driver' => 'redis',

Arr:exist only for >5.1

On Laravel 5.1 the method exist for the class Arr does not exist. It is has. So this library is not compatible with Laravel 5.1 for this reason. I'll set a PR for a fix.

Currency Converter

Hi!
Can you make currency converter in this package, like

$rate = currency($price, 'USD/EUR');
// $rate = ['value'=> $value, 'date' => $date]
$rate->getValue(); // 0.8768
//or
$price = 1;
$convert = currency($price, 'USD', 'EUR');
$convert = 0.8768;

if user default currency is same as in config file I use $inverse method. But if I use for each user different default currency this method can not be used.

Middleware FatalThrowableError (1.0x)

I was just playing arround with the newer dev version, and trying to get it working but I get an exception if the middleware is activated.

I'll leave you the trace here:

FatalThrowableError in Database.php line 65: Call to a member function keyBy() on array in Database.php line 65 at Database->all() in Currency.php line 212 at Currency->getCurrencies() in Currency.php line 173 at Currency->hasCurrency(null) in CurrencyMiddleware.php line 47 at CurrencyMiddleware->getUserCurrency(object(Request)) in CurrencyMiddleware.php line 26 at CurrencyMiddleware->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CurrencyMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Kernel.php line 122 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 at Kernel->handle(object(Request)) in index.php line 53

I can not use filesystem

If I use filesystem I found this error

ErrorException in Currency.php line 102:
Undefined index: EUR

I need use filesystem for best performance.

Thankssss

Missing some currencies

How can I add more currencies?

I think It's will be great to add more currencies using artisan like this :

php artisan currency:add --currencies=BDT,BHD

or/and using code :

Currency::add([
'BDT', 'BHD'
]);

And this will fetch for data from the Finance yahoo! and update currency table.

Thanks for sharing

@currency ignores default value

I defined in the configuration ('config/packages/torann/currency/config.php') 'EUR' as default. But in my view is 'USD' - why ignored it? Newest version from composer without any modifications. Only i've changed 'USD' in 'EUR'.

Regards,

Dennis

Rename db table to "currencies"

I m just thinking doing this simple thing will make it more Laravel complaint. Not a real issue though :)
Thanks for creating this nice little package BTW.

create currency command gives error.

I tried the command on the documentation:

currency()->create([
'currency_name' => 'U.S. Dollar',
'currency_code' => 'USD',
'currency_symbol' => '$',
'currency_format' => '$1,0.00',
'exchange_rate' => 1.00000000,
'active' => 1,
]);

I get the following error:

Undefined index: code

Move Currencies formats

Move the currency formats to their own file and use the package config file to enable and disable currencies.

Table doesn't exist on installing

After this:
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"

I receive this:

[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist (SQL: select * from `currencies`)

[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist 

Object of class DateTime could not be converted to string

Get the following when running Artisan:

Updating currency exchange rates from Finance Yahoo...

[ErrorException]
Object of class DateTime could not be converted to string

currency:update [-o|--openexchangerates]

After upgrading Composer and running migrate again...

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'value' at row 1 (SQL: update currency set value = 1.00 , updated_at = 2014-06-10 18:44:10 where code = USD)

Negative currency

negative US currency displays as $-3.00 where it is normally appropriate to use -$3.00 or ($3.00). Perhaps just a formatting issue.

Error when updating to Laravel 5.4

It looks this package is causing errors when php artisan optimize is executed during the upgrade progress.

php artisan optimize

[Illuminate\Contracts\Container\BindingResolutionException]
Unresolvable dependency resolving [Parameter #0 [ array $config
]] in class Torann\Currency\Drivers\Database

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'value' at row 1

Using:

  • Laravel Framework version 4.2.11
  • PHP Version => 5.6.1 (on Windows)
  • MYSQL 5.6.21 (on Windows)
  • "torann/currency": "dev-master"

Resolved by converting value to a number on line 103

// Update each rate
foreach ($lines as $line)
{
   $code = substr($line, 4, 3);
   $value = substr($line, 11, 6) * 1.00; //force conversion to number

   if ($value)
        {
            $this->app['db']->table($this->table_name)
                ->where('code', $code)
                ->update(array(
                    'value'         => $value,
                    'updated_at'    => new \DateTime('now'),
                ));
        }
}

Specify 'base' currency when updating database

When I ran the currency:update command on my local testing server, the resulting base currency was GBP (that is, the one that got a rate of 1.00000).

However, the same command on our production server resulted in USD getting a value of 1.00000.

Is there a way to ensure the downloaded values are relative to the correct 'base' currency?

Registering as singleton?

I wonder if the service should be registered as singleton.

The current $this->app->bind doesn't seem to work for me, the currency got reset to null in the service.

public function registerCurrency()
{
    $this->app->singleton('currency', function ($app) {
        $config = $app->config->get('currency', []);
        return new Currency($config, $app['cache']);
    });
}

Error in Middleware and no formatting of default currency

When I add the Middleware to Kernel.php I get the following error on all pages:

FatalThrowableError in CurrencyMiddleware.php line 29:
Call to a member function get() on null

Also, the default currency (which I have set to GBP) is not formatted. If I use Currency::format(15) the result is simply 15. If I specify the currency: Currency::format(15,'GBP') it is properly formatted as £15.00. Conversion is working.

CACHE Error

Strange error on production server... Any ideas? Cache cleanup & clear done.

capture

Call to undefined method Currency::isDeferred()

Command: php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"

Output:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Torann\Currency\Facades\Currency::isDeferred()

Came this error, while porting my 4.2 app used 0.1 version to 5.1.*@dev version of laravel.

Thanks,

Error: Artisan : : Array to string conversion

First of all, thank you for a nice package! Very useful for me.

So, I changed thousand point to NULL in DB currency table and now I get error while artisan update command: Error: Array to string conversion.

I don't need this point in returned value. Any ideas?

No currency conversion function?

I was looking for a function to help me convert between currencies, I couldn't find one in the source -- it would be great if there was a function like this built in:

public static function convert($amount, $fromCode, $toCode) {
        $from = app('currency')->getCurrency($fromCode);
        $to = app('currency')->getCurrency($toCode);

        return ($to['value'] / $from['value']) * $amount;
    }

It is not really clear at all that when using the currency function, specifying a currency code different than the config default will actually convert the amount to the specified currency relative to your default currency. I assumed currency(100, 'JPY') would give me ¥100.00, instead I get ¥10,339.00 because my default currency is USD.

Call to a member function keyBy() on array

I'm not sure if it's realted to #50 but when I call the currency($number, $from, $to) I get an exception aswell. I'll leave the trace as well.

It seems to understand that app('currency') is an array and therefore it can't access the->convert() in the helpers file.

ErrorException in Database.php line 65: Call to a member function keyBy() on array (View: /home/vagrant/clark-diamonds-app/resources/views/public/order/show.blade.php) in Database.php line 65 at CompilerEngine->handleViewException(object(FatalThrowableError), '1') in PhpEngine.php line 46 at PhpEngine->evaluatePath('/home/vagrant/clark-diamonds-app/storage/framework/views/8700e366dfdca230aaa883aa4acd5515', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'order' => object(Order), 'diamond_info' => array(object(Collection)))) in CompilerEngine.php line 58 at CompilerEngine->get('/home/vagrant/clark-diamonds-app/resources/views/public/order/show.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'order' => object(Order), 'diamond_info' => array(object(Collection)))) in View.php line 147 at View->getContents() in View.php line 118 at View->renderContents() in View.php line 83 at View->render() in Response.php line 51 at Response->setContent(object(View)) in Response.php line 202 at Response->__construct(object(View)) in Router.php line 1229 at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 112 at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114 at ControllerDispatcher->callWithinStack(object(OrdersController), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67 at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\OrdersController', 'show') in Route.php line 203 at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134 at Route->run(object(Request)) in Router.php line 708 at Router->Illuminate\Routing\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 45 at Authenticate->handle(object(Request), object(Closure)) at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Router.php line 710 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 673 at Router->dispatchToRoute(object(Request)) in Router.php line 635 at Router->dispatch(object(Request)) in Kernel.php line 236 at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Debugbar.php line 51 at Debugbar->handle(object(Request), object(Closure)) at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Kernel.php line 122 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 at Kernel->handle(object(Request)) in index.php line 53

Calling Commands from Controller do not work

In one of my controllers I want to call Artisan::call('currency:update') but it does not work. The Exception:

CommandNotFoundException in Application.php line 490:
There are no commands defined in the "currency" namespace.

However, in a different part of my application (a Seeder class), Artisan::call('currency:update') works.

So what is causing the crash in the controller?

How do I unistall this package?

I'm trying to unistall this package using composer remove torann/currency but I get this error:

[RuntimeException] >
Error Output: PHP Fatal error: Class 'Torann\Currency\CurrencyServiceProvider' not found in home/myUser/WebProjects/myProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146

How can I clean delete this package?

Space or other special characters break formatting

Function below doesn't give results that one would expect if format involves extra space, dot etc.

currency(12345.6789)

Two examples:

  1. kr 1,0.00kr 12 345,6789
  2. kr. 1,0.00kr. 12.346

Both formats are default so it looks like something doesn't work as it should ;)

"php artisan currency:update" command rise an Exception

The problem is on the the currecy table field 'value'. At the moment is a DOUBLE(15,8) but rise an error on the value 1.00 that is the default currency value, that because try to store a value that contain only 2 decimal. I resolved this changing the field into DECIMAL(17,2) that actually is more precise than DOUBLE. Of course in this way the value is rounded! what you think?

The "openexchangerates" option does not exist

Laravel 5.2
After update currency:

> php artisan currency:update
> [InvalidArgumentException]
> The "openexchangerates" option does not exist.
    public function fire()
    {
        // Get Settings
        $defaultCurrency = $this->currency->getConfig('default');

        if ($this->input->getOption('openexchangerates')) { //The "openexchangerates" option does not exist
            if (!$api = $this->currency->getConfig('api_key')) {
                $this->error('An API key is needed from OpenExchangeRates.org to continue.');

                return;
            }

            // Get rates
            $this->updateFromOpenExchangeRates($defaultCurrency, $api);
        }
        else {
            // Get rates
            $this->updateFromYahoo($defaultCurrency);
        }
    }

Composer update error

Composer.json

"minimum-stability": "dev",
"laravel/framework": "5.3.*",
"torann/currency": "^1.0",

Composer update after artisan:optimize

  [Symfony\Component\Debug\Exception\FatalThrowableError]                                                                                                                                                           
  Type error: Too few arguments to function Torann\Currency\Drivers\Database::__construct(), 1 passed in /Users/Alex/WEBHOSTS/FHMatchL5/vendor/torann/currency/src/Currency.php on line 255 and exactly 2 expected  

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.