Git Product home page Git Product logo

laravel-swap's Introduction

Laravel Swap

Build status Total Downloads Version

Swap allows you to retrieve currency exchange rates from various services such as Fixer, Currency Data or Exchange Rates Data and optionally cache the results.

Sponsors

Fixer is a simple and lightweight API for foreign exchange rates that supports up to 170 world currencies.
Currency Data provides reliable exchange rates and currency conversions for your business up to 168 world currencies.
Exchange Rates Data provides reliable exchange rates and currency conversions for your business with over 15 data sources.

QuickStart

Installation

$ composer require php-http/curl-client nyholm/psr7 php-http/message florianv/laravel-swap

Laravel 5.7 or lesser

If you use cache, add also PSR-6 adapter and PSR-16 bridge cache dependencies :

$ composer require cache/illuminate-adapter cache/simple-cache-bridge

These dependencies are not required with Laravel 5.8 or greater which implements PSR-16.

Laravel 5.5+

If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php:

// /config/app.php
'providers' => [
    Swap\Laravel\SwapServiceProvider::class
],

If you want to use the facade to log messages, add this to your facades in app.php:

'aliases' => [
    'Swap' => Swap\Laravel\Facades\Swap::class
]

Copy the package config to your local config with the publish command:

$ php artisan vendor:publish --provider="Swap\Laravel\SwapServiceProvider"

Lumen

Configure the Service Provider and alias:

// /boostrap/app.php

// Register the facade
$app->withFacades(true, [
    Swap\Laravel\Facades\Swap::class => 'Swap'
]);

// Load the configuration
$app->configure('swap');

// Register the service provider
$app->register(Swap\Laravel\SwapServiceProvider::class);

Copy the configuration to /config/swap.php if you wish to override it.

Usage

// Get the latest EUR/USD rate
$rate = Swap::latest('EUR/USD');

// 1.129
$rate->getValue();

// 2016-08-26
$rate->getDate()->format('Y-m-d');

// Get the EUR/USD rate yesterday
$rate = Swap::historical('EUR/USD', Carbon\Carbon::yesterday());

Documentation

The complete documentation can be found here.

Services

Here is the list of the currently implemented services:

Service Base Currency Quote Currency Historical
Fixer EUR (free, no SSL), * (paid) * Yes
Currency Data USD (free), * (paid) * Yes
Exchange Rates Data USD (free), * (paid) * Yes
Abstract * * Yes
coinlayer * Crypto (Limited standard currencies) * Crypto (Limited standard currencies) Yes
Fixer EUR (free, no SSL), * (paid) * Yes
currencylayer USD (free), * (paid) * Yes
exchangeratesapi USD (free), * (paid) * Yes
European Central Bank EUR * Yes
National Bank of Georgia * GEL Yes
National Bank of the Republic of Belarus * BYN (from 01-07-2016),
BYR (01-01-2000 - 30-06-2016),
BYB (25-05-1992 - 31-12-1999)
Yes
National Bank of Romania RON, AED, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EGP, EUR, GBP, HRK, HUF, INR, JPY, KRW, MDL, MXN, NOK, NZD, PLN, RSD, RUB, SEK, TRY, UAH, USD, XAU, XDR, ZAR RON, AED, AUD, BGN, BRL, CAD, CHF, CNY, CZK, DKK, EGP, EUR, GBP, HRK, HUF, INR, JPY, KRW, MDL, MXN, NOK, NZD, PLN, RSD, RUB, SEK, TRY, UAH, USD, XAU, XDR, ZAR Yes
National Bank of Ukranie * UAH Yes
Central Bank of the Republic of Turkey * TRY Yes
Central Bank of the Republic of Uzbekistan * UZS Yes
Central Bank of the Czech Republic * CZK Yes
Central Bank of Russia * RUB Yes
Bulgarian National Bank * BGN Yes
WebserviceX * * No
1Forge * (free but limited or paid) * (free but limited or paid) No
Cryptonator * Crypto (Limited standard currencies) * Crypto (Limited standard currencies) No
CurrencyDataFeed * (free but limited or paid) * (free but limited or paid) No
Open Exchange Rates USD (free), * (paid) * Yes
Xignite * * Yes
Currency Converter API * * Yes (free but limited or paid)
xChangeApi.com * * Yes
fastFOREX.io USD (free), * (paid) * No
exchangerate.host * * Yes
Array * * Yes

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

laravel-swap's People

Contributors

alies-dev avatar arjanwestdorp avatar denlapaev avatar florianv avatar kslimani avatar mohammad6006 avatar naoray avatar simplenotezy 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  avatar

laravel-swap's Issues

Tag a release

If this project is ready for beta or production use, please tag a commit with an appropriate number so we can use composer without dev-master.

Thanks!

Problem with Exchange Fallback

Sometimes when I try to convert Bitcoin Cash to USD via Cryptonator/Open Exchangerates I receive the following exception:

Exchanger\Exception\UnsupportedCurrencyPairException: The currency pair "USD/BCH" is not supported by the service "Exchanger\Service\OpenExchangeRates".
Exchanger\Exception\Exception: Service temporarily unavailable

That's my call:
return $this->amount/Swap::latest('USD/BCH')->getValue()*1;

And I have Open Exchangerates before Cryptonator in my config.
Seems like as Open Exchangerates doesn't have Bitcoin Cash rates, it raises an error and doesn't fallback to cryptonator.

Tutorial

Could you add a complete tutorial (wiki) for use this package? I searched on google and some people ask how it work exactly. Thanks

Installation through composer fails

$ composer require florianv/laravel-swap php-http/message php-http/guzzle6-adapter
Using version ^1.3 for florianv/laravel-swap
Using version ^1.7 for php-http/message
Using version ^2.0 for php-http/guzzle6-adapter
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for florianv/laravel-swap ^1.3 -> satisfiable by florianv/laravel-swap[1.3.0].
    - florianv/swap 3.4.0 requires florianv/exchanger ^1.1 -> satisfiable by florianv/exchanger[1.1.0, 1.1.1, 1.1.2, 1.2.0, 1.2.1, 1.2.2].
    - florianv/exchanger 1.1.0 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - florianv/exchanger 1.1.1 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - florianv/exchanger 1.1.2 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - florianv/exchanger 1.2.0 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - florianv/exchanger 1.2.1 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - florianv/exchanger 1.2.2 requires php-http/httplug ^1.0 -> satisfiable by php-http/httplug[v1.0.0, v1.1.0].
    - Can only install one of: php-http/httplug[v2.0.0, v1.0.0].
    - Can only install one of: php-http/httplug[v2.0.0, v1.1.0].
    - php-http/guzzle6-adapter v2.0.0 requires php-http/httplug ^2.0 -> satisfiable by php-http/httplug[v2.0.0].
    - florianv/laravel-swap 1.3.0 requires florianv/swap ^3.4 -> satisfiable by florianv/swap[3.4.0].
    - Installation request for php-http/guzzle6-adapter ^2.0 -> satisfiable by php-http/guzzle6-adapter[v2.0.0].


Installation failed, reverting ./composer.json to its original content.

i cannot not get rates - laravel 5.1

ChainException in Chain.php line 66:
The chain resulted in 3 exception(s):
Exchanger\Exception\Exception: The current subscription plan does not support this API endpoint.
ErrorException: Undefined offset: 0
RuntimeException: Unable to parse XML data: String could not be parsed as XML

Yahoo service error

hi @florianv

i found => {"error":{"lang":"en-US","description":"No definition found for Table yahoo.finance.xchange"}}

Currency Layer not working

screen shot 2016-12-22 at 4 49 07 pm

'services' => [
//        'fixer' => true,
        'currency_layer' => [
            'access_key' => '******',
            'enterprise' => false,
        ],
    ],

compatibility issue: cache/adapter-common

geocoder related packages require "cache/array-adapter": "^1.0".
laravel-swap requires "cache/adapter-common": "^0.3"
Would it be possible to upgrade the package dependencies to resolve compatibility issues?

get historical rates

Hi Florian,

would it be possible to point laravel-swap at the latest version of swap to open up the possibility of picking historical rates?

Thanks,
Gerard

How to use this with middleware?

Hi,

I want to have dropdown in my navbar where i can select currency and all the prices in my app convert to selected currency, I know i should use middleware for this matter but i don't know how to begin. Would you mind help me to do that?

thanks.

Class 'Swap\Swap' not found in SwapServiceProvider.php:168

For some strange reason, I get the following error. I think it happened after updating from composer:

Class 'Swap\Swap' not found in SwapServiceProvider.php:168

Stacktrace:

[2016-03-28 14:14:21] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Fatal error: Class 'Swap\Swap' not found in /home/vagrant/Projects/myapp/vendor/florianv/laravel-swap/src/SwapServiceProvider.php:168
Stack trace:
#0 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(735): Florianv\LaravelSwap\SwapServiceProvider->Florianv\LaravelSwap\{closure}(Object(Illuminate\Foundation\Application), Array)
#1 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(633): Illuminate\Container\Container->build(Object(Closure), Array)
#2 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(687): Illuminate\Container\Container->make('swap', Array)
#3 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Container/Container.php(1178): Illuminate\Foundation\Application->make('swap')
#4 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(151): Illuminate\Container\Container->offsetGet('swap')
#5 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(120): Illuminate\Support\Facades\Facade::resolveFacadeInstance('swap')
#6 /home/vagrant/Projects/myapp/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(207): Illuminate\Support\Facades\Facade::getFacadeRoot()
#7 /home/vagrant/Projects/myapp/app/Currency.php(73): Illuminate\Support\Facades\Facade::__callStatic('quote', Array)

Fetch all conversions at once

I miss a way to fetch all conversions at once. Say I have many different currencies I need to convert at the same page, I'll be making many requests at once.

Wrong parameters for Exchanger\Exception\Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in vendor/florianv/exchanger/src/Service/Fixer.php:97

I update the library, configured the config/swap.php and i see this error:

Symfony\Component\Debug\Exception\FatalThrowableError: Wrong parameters for Exchanger\Exception\Exception([string $message [, long $code [, Throwable $previous = NULL]]]) in /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php:97

Stack trace:
#0 /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php(97): Exception->__construct(Array)
#1 /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php(42): Exchanger\Service\Fixer->createRate('http://data.fix...', Object(Exchanger\CurrencyPair))
#2 /var/www/project/project-files/vendor/florianv/exchanger/src/Service/HistoricalService.php(37): Exchanger\Service\Fixer->getLatestExchangeRate(Object(Exchanger\ExchangeRateQuery))
#3 /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Chain.php(56): Exchanger\Service\HistoricalService->getExchangeRate(Object(Exchanger\ExchangeRateQuery))
#4 /var/www/project/project-files/vendor/florianv/exchanger/src/Exchanger.php(55): Exchanger\Service\Chain->getExchangeRate(Object(Exchanger\ExchangeRateQuery))
#5 /var/www/project/project-files/vendor/florianv/swap/src/Swap.php(91): Exchanger\Exchanger->getExchangeRate(Object(Exchanger\ExchangeRateQuery))
#6 /var/www/project/project-files/vendor/florianv/swap/src/Swap.php(51): Swap\Swap->quote('USD/EUR', NULL, Array)
#7 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Swap\Swap->latest('USD/EUR')
#8 /var/www/project/project-files/app/Helpers/Currency.php(38): Illuminate\Support\Facades\Facade::__callStatic('latest', Array)
#9 /var/www/project/project-files/app/Helpers/Currency.php(17): currencyRate('EUR')
#10 /var/www/project/project-files/app/Repositories/CurrencyRepository.php(49): currencyConvert('100', 'EUR')
#11 /var/www/project/project-files/app/Http/Controllers/Frontend/CurrencyController.php(51): Simp\Repositories\CurrencyRepository->calculateByPrice(Object(Simp\Http\Requests\Frontend\CurrencyRequest))
#12 [internal function]: Simp\Http\Controllers\Frontend\CurrencyController->calculateByPrice(Object(Simp\Http\Requests\Frontend\CurrencyRequest))
#13 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#14 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('calculateByPric...', Array)
#15 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Simp\Http\Controllers\Frontend\CurrencyController), 'calculateByPric...')
#16 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Route.php(160): Illuminate\Routing\Route->runController()
#17 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Router.php(572): Illuminate\Routing\Route->run()
#18 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#19 /var/www/project/project-files/app/Http/Middleware/CheckUtm.php(32): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#20 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\CheckUtm->handle(Object(Illuminate\Http\Request), Object(Closure))
#21 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#22 /var/www/project/project-files/app/Http/Middleware/RecentlyViewed.php(16): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#23 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\RecentlyViewed->handle(Object(Illuminate\Http\Request), Object(Closure))
#24 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#25 /var/www/project/project-files/app/Http/Middleware/CheckReferral.php(32): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#26 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\CheckReferral->handle(Object(Illuminate\Http\Request), Object(Closure))
#27 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#28 /var/www/project/project-files/app/Http/Middleware/RestoreCartMiddleware.php(33): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#29 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\RestoreCartMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#30 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#31 /var/www/project/project-files/app/Http/Middleware/DetectCurrencySettings.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#32 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\DetectCurrencySettings->handle(Object(Illuminate\Http\Request), Object(Closure))
#33 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#34 /var/www/project/project-files/app/Http/Middleware/SetAppLanguage.php(57): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#35 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Simp\Http\Middleware\SetAppLanguage->handle(Object(Illuminate\Http\Request), Object(Closure))
#36 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#37 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#38 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#39 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#40 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#41 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#42 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#43 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#44 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#45 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#46 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#47 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#48 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#49 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#50 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#51 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#52 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#53 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Router.php(574): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#54 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Router.php(533): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#55 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Router.php(511): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#56 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#57 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http{closure}(Object(Illuminate\Http\Request))
#58 /var/www/project/project-files/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php(51): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#59 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Barryvdh\Debugbar\Middleware\Debugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#60 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#61 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#62 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#63 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#64 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#65 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#66 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#67 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#68 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#69 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#70 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#71 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#72 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline{closure}(Object(Illuminate\Http\Request))
#73 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing{closure}(Object(Illuminate\Http\Request))
#74 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#75 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#76 /var/www/project/project-files/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#77 {main}

Swap::latest() often takes very long to complete or hangs completely

I just discovered your package and gave it a spin, and must say I am really happy with its ease of use. Thanks for creating and sharing it with us!
I am only experiencing a glitch that, even though it only happens occassionally, could be quite a dealbreaker. A call to Swap::latest() can take very long to return, and sometimes doesn't appear to return at all (I waited for 5 minutes, which can be considered as hanging?). This doesn't appear to depend on reactivity of the remote service, as a browser refresh delivers the results immediately again. Have you or anyone else experienced this problem?

I don't know what happens under the hood, but does a request to one exchange rate service provider block calls to the others (so are they queried serially), or are all service providers queried in parallel and when the first one returns a result the others are aborted or disregarded? I don't even know if the asynchronous behavior of the latter is possible in PHP, but wouldn't that be the best solution?
Alternatively, it would be nice to be able to set a timeout on a exchange rate query and try again, or abort, if the timeout is exceeded.

I am using this package together with Laravel 5.4. For sake of completeness, here is my config/swap.php:

return [
    'options' => [
        'cache_ttl' => env('SWAP_CACHE_LIFE', 3600) // 1 hour
    ],
    'services' => [
        'google' => true,
        'yahoo' => true,
        'fixer' => true,
        'european_central_bank' => true,
    ],
    'cache' => 'file',
    'http_client' => null,
    'request_factory' => null,
    'cache_item_pool' => null,
];

Cannot use rate in any computation

The package handles the exchange for me nicely and when i output the result to screen or log it i get the desired result but if i try to use it in any computation i get the following error.

exception 'ErrorException' with message 'Object of class Swap\Model\Rate could not be converted to int'

I have tried to typecast the result in any form but still not working. I have tried the follwing but no result

$this->rates = \Swap::quote("{$this->store->currency}/USD");

$product->sales_price = $product->sales_price * floatval($this->rates);
$product->sales_price = $product->sales_price * floatval($this->rates->getValue());
$product->sales_price = $product->sales_price * (float)$this->rates;
$product->sales_price = $product->sales_price * (double)$this->rates;

and many others but still getting the error.

exchange query '' is not supported by the service "Exchanger\Service\Chain"

Hi,

I have a paid account with Fixer, and wanted to run queries for USD/PYG and got the following error.

Code:
$rate = Swap::historical('USD/PYG', Carbon::parse($date));

Returns:

"The exchange query "USD/PYG" is not supported by the service "Exchanger\Service\Chain"."
Exchanger\Exception\UnsupportedExchangeQueryException 
…/vendor/florianv/exchanger/src/Exchanger.php53

The same code works perfectly with EUR/USD. What am I doing wrong or is there something I should do regarding chaining. Also if I inverted this to USD/EUR it won't work.

Maximum Monthly API Request Reached.

While the API is running fine on the local development server and not in the production server.
It throws this exception :
The chain resulted in 2 exception(s): Exchanger\Exception\Exception: The maximum allowed API amount of monthly API requests has been reached. Exchanger\Exception\Exception: The currency is not supported or Google changed the response format

Cache is not working

I have a job which runs twice per hour. The exchange rate is cached for 24 hours. Still, fixer.io tells me I had 32 requests the last < 24 hours.

This is stored in the cache folder but it seems not to be used.
1564327443s:516:"a:4:{i:0;b:1;i:1;O:22:"Exchanger\ExchangeRate":4:{s:36:"Exchanger\ExchangeRatecurrencyPair";O:22:"Exchanger\CurrencyPair":2:{s:36:"Exchanger\CurrencyPairbaseCurrency";s:3:"EUR";s:37:"Exchanger\CurrencyPairquoteCurrency";s:3:"GBP";}s:29:"Exchanger\ExchangeRatevalue";d:0.900369;s:28:"Exchanger\ExchangeRatedate";O:8:"DateTime":3:{s:4:"date";s:26:"2019-07-28 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:3:"UTC";}s:32:"Exchanger\ExchangeRateprovider";s:5:"fixer";}i:2;a:0:{}i:3;i:1564412403;}";

Exchanger\Exception\UnsupportedCurrencyPairException: The currency pair "USD/EUR" is not supported by the service "Exchanger\Service\Fixer".

Everything was working fine till morning from last one month after the fixer changes its services and implementation but suddenly in production site i could see the errors, when i checked the Laravel log, i could see the following errors.

Exchanger\Exception\ChainException: The chain resulted in 1 exception(s):
Exchanger\Exception\UnsupportedCurrencyPairException: The currency pair "USD/EUR" is not supported by the service "Exchanger\Service\Fixer". in /var/www/project/project-files/vendor/florianv/exchanger/src/Service/Chain.php:66
Stack trace:
#0 /var/www/project/project-files/vendor/florianv/exchanger/src/Exchanger.php(75): Exchanger\Service\Chain->getExchangeRate(Object(Exchanger\ExchangeRateQuery))
#1 /var/www/project/project-files/vendor/florianv/swap/src/Swap.php(91): Exchanger\Exchanger->getExchangeRate(Object(Exchanger\ExchangeRateQuery))
#2 /var/www/project/project-files/vendor/florianv/swap/src/Swap.php(51): Swap\Swap->quote('USD/EUR', NULL, Array)
#3 /var/www/project/project-files/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): Swap\Swap->latest('USD/EUR')
#4 /var/www/project/project-files/app/Helpers/Currency.php(38): Illuminate\Support\Facades\Facade::__callStatic('latest', Array)
#5 /var/www/project/project-files/app/Providers/CacheServiceProvider.php(187): currencyRate('EUR')

We haven't changed our implementation it was working fine till today morning. Anyone facing the same issues.

Fallback if no internet

Could be cool with some fallbacks on local macine / machine without internet.

Currently the whole app crashes with a:

 throw new ChainProviderException($exceptions);

Swap::latest() with yahoo service problem

Hi, today i got a errors, swap doesn't work for yahoo and xignite.
Error when i tryed get latest value with yahoo service
[Exchanger\Exception\ChainException]
The chain resulted in 1 exception(s):
Exchanger\Exception\Exception: No definition found for Table yahoo.finance.
xchange

and when I tryed with xiginite
[Exchanger\Exception\ChainException]
The chain resulted in 1 exception(s):
Exchanger\Exception\Exception: Invalid base

Anybody have the same problem? Yesterday everything was great, i dont know what is wrong.

Cannot add my own service

Hi!

I want to add my own service. What i did but it doesn't work:

  1. Created App\Services\Swap\NationalBankOfBelarus and extends HistoricalService;
  2. Created App\Providers\SwapServiceProvider and added to config/app.php providers;
  3. Inside App\Providers\SwapServiceProvider::register():
        $this->app->singleton('national_bank_of_belarus', function ($app) {
            return new NationalBankOfBelarus(null, null, ['value' => 1]);
        });

        $this->app->tag('national_bank_of_belarus', ['swap.service']);
  1. Added to config/swap.php 'national_bank_of_belarus' => true

But i'm getting an error that service 'national_bank_of_belarus' doesn't exists. What i missed?

The "access_key" option must be provided to use fixer.io in project-files/vendor/florianv/exchanger/src/Service/Fixer.php:51

As the fixer.io has changed it API and access_key is required. I am usign Laravel framework. I used "florianv/laravel-swap": "^1.1", and i updated the library today and now i can see one new constant ACCESS_KEY_OPTION = 'access_key' in florianv/exchanger/src/Service/Fixer.php ;
It has these constants now:

const ACCESS_KEY_OPTION = 'access_key';
const LATEST_URL = 'http://data.fixer.io/api/latest?base=%s&access_key=%s';
const HISTORICAL_URL = 'http://data.fixer.io/api/%s?base=%s&access_key=%s';

I have config/swap.php, i tried to pass it the access_key there but it doesnt work.
'currency_layer' => [
'access_key' => '7ca208ea0d6d3323a14427bf9ed21',
// 'enterprise' => true, // Tried also with enabling this.
],

In config/services.php, i tried to pass it but still i can see the above error in laravel log. How to i pass the access_key.
'fixer' => [
'access_key' => '7ca208ea0d6d3323a14427bf9ed21'
],

How to i pass the access key, tried in many ways but its not working.

Rate in history

Some providers allows to make history query so it would be nice to be able to perform something like
quote('EUR/USD', '2011-08-08').
Actually it is a deal killer for me. I wish i could use your package.

My 2 cents

FEATURE: Integration with Lumen

First of, thank you for a great library!

Since many developers including me are using Lumen, I wanted to ask you, whether you could implement an integration between those two. It would really come in handy. I managed to integrate your library with Lumen, however I could not do so without modifying your code - which is bad in a sense that I cannot keep up with your updates anymore.

Thank you in advance.

The exchange query is not supported by the service "Exchanger\Service\Chain".

Althought getting the latest rate works perfectly I am having problems using swap::historical().

I get this error
The exchange query "EUR/USD" is not supported by the service "Exchanger\Service\Chain".
even when i use the example from the docs Swap::historical('EUR/USD', Carbon\Carbon::yesterday());

Any ideas ? Ive tried it with google and European Central bank

The currency is not supported or Google changed the response format

Hi there,

Using this package which is great. I am using the google service and get this error:

The chain resulted in 1 exception(s):
Exchanger\Exception\Exception: The currency is not supported or Google changed the response format

Using these versions:
florianv/laravel-swap ^1.1
florianv/exchanger 1.2.0

Any help would be appreciated or am i using wrong versions? Thanks.

Matthijs

Installation through composer fails

Hi ,
When I run ''composer require florianv/laravel-swap" this command in teminal

Using version ^0.4.0 for florianv/laravel-swap
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)

Your requirements could not be resolved to an installable set of packages.

Problem 1
- guzzle/guzzle v3.9.3 requires ext-curl * -> the requested PHP extension curl is missing from your system.
- guzzle/guzzle v3.9.3 requires ext-curl * -> the requested PHP extension curl is missing from your system.
- guzzle/guzzle v3.9.3 requires ext-curl * -> the requested PHP extension curl is missing from your system.
- Installation request for guzzle/guzzle == 3.9.3.0 -> satisfiable by guzzle/guzzle[v3.9.3].

To enable extensions, verify that they are enabled in those .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.ini
You can also run php --ini inside terminal to see which files are used by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

Laravel 5.8 Support

Hey @florianv,

Can you please add support for Laravel 5.8? As i update my app to 5.8, i get the following error. I suppose it's because the tagged method signature has been changed.

Thanks for this great package.

` Symfony\Component\Debug\Exception\FatalThrowableError : Argument 1 passed to Exchanger\Service\Chain::__construct() must be of the type array, object given, called in /Users/carbon/www/crm/vendor/florianv/laravel-swap/src/SwapServiceProvider.php on line 130

at /Users/carbon/www/crm/vendor/florianv/exchanger/src/Service/Chain.php:38
34| * Creates a new chain service.
35| *
36| * @param ExchangeRateService[] $services
37| */

38| public function __construct(array $services = [])
39| {
40| $this->services = $services;
41| }
42|

Exception trace:

1 Exchanger\Service\Chain::__construct(Object(Illuminate\Container\RewindableGenerator))
/Users/carbon/www/crm/vendor/florianv/laravel-swap/src/SwapServiceProvider.php:130`

Maximum function nesting level of '100' reached, aborting!

I am getting the following error:

Maximum function nesting level of '100' reached, aborting!

This is the line that seems to provoke it:

$rate = Swap::quote($currency . '/' . $convertToCurrency);

It works fine on Homestead, but when pushing to staging server, managed by DigitalOcean and Laravel forge this happens.

It seems to be too slow

I was comparing getting a value straight from Fixer.io API and from Swap, and it seems that Swap is quite slower:

// it takes about 750ms
file_get_contents('http://api.fixer.io/latest?base=USD&symbols=EUR');

// it takes about 1800ms using fixer.io
$rate = \Swap::latest('USD/EUR');

Yeah, sure, it should be slower, but 1 extra second seems too much. Is it making more than one request?

Anyway, thanks for this great library!

string or object implementing

I try to get \Swap::latest("AED/ARS")->getValue();
"The Response content must be a string or object implementing __toString(), "boolean" given."

Error when using National Bank of Romania

swap.php

    'services' => [
        'national_bank_of_romania' => true,
        //'european_central_bank' => true,
    ],

works with european cental bank, but not romanian

$rate = Swap::latest('EUR/RON');
dd($rate);
ChainException in Chain.php line 66:
in /home/vagrant/project/vendor/florianv/exchanger/src/Service/Chain.php line 66
at Chain->getExchangeRate(object(ExchangeRateQuery)) in Exchanger.php line 63
at Exchanger->getExchangeRate(object(ExchangeRateQuery)) in Swap.php line 91
at Swap->quote('EUR/RON', null, array()) in Swap.php line 51
at Swap->latest('EUR/RON') in Facade.php line 237
at Facade::__callStatic('latest', array('EUR/RON')) in web.php line 105
at RouteServiceProvider->{closure}() in Route.php line 176
at Route->runCallable() in Route.php line 147
at Route->run(object(Request)) in Router.php line 642

ChainException with Google

Hello,
I used this package for a while and it was working perfectly. But now I get an Exception when using Google to get data.
I'm using Lumen and Here is the exception I got:
rez

Any information?

Invalid Base issue while converting from AED to USD

Hi,
I was using the same package from few months.It was working fine and were displaying the result. but from today morning it starts to give the exception

I write a simplest function that converts from AED to USD and it gives this error.
The chain resulted in 2 exception(s): Exchanger\Exception\Exception: Invalid base Exchanger\Exception\Exception: The currency is not supported or Google changed the response format

latest()->getValue() is rounding the value in some cases

Hello guys, using google service in both environments I get a different response from:
\Swap::latest('USD/BRL')->getValue()
dev: "3.90777648"
prod: "3.91"

As you can see, in production server it is getting rounded to 2 decimal places even having the same config/swap.php file.

Environments:

Development:

PHP 7.2.5-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May  5 2018 04:59:13) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.5-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Production:

PHP 7.1.16-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Apr  5 2018 08:47:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.16-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies

Edit: Discovered that is not related to the plugin nor google itself. Seems that AWS (prod server) is getting the google address somewhat different... the output generated for a simple cUrl command ( curl -k -sA "Chrome" -L 'https://www.google.com/search?q=1+USD+to+BRL' -o aaa.html ) in the prod server is:
image


While the local is:
image

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.