GithubHelp home page GithubHelp logo

quicktech-as / exchange-rate Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 10 KB

Package Laravel to currency conversion using ExchangeRate API.

License: MIT License

PHP 100.00%
laravel illuminate currency exchange-rate

exchange-rate's Introduction

Quicktech\ExchangeRate (Laravel 5 Package)

Quicktech\ExchangeRate is a succinct and flexible way to use ExchangeRate API to convert currencies in Laravel 5 applications.

Contents

Installation

  1. In order to install Laravel 5, just add the following to your composer.json. Then run composer update:
"quicktech-as/exchange-rate": "^1.0"
  1. Open your config/app.php and add the following to the providers array:
Quicktech\ExchangeRate\ExchangeRateServiceProvider::class,
  1. In the same config/app.php and add the following to the aliases array:
'ExchangeRate' => Quicktech\ExchangeRate\Facade\ExchangeRate::class,
  1. Run the command below to publish the package config file config/exchange_rate.php:
php artisan vendor:publish

Configuration

Open your .env file and setup your ExchangeRate credentials:

EXCHANGERATE_DEFAULT_CURRENCY = 'your default currency'
EXCHANGERATE_API_KEY = 'your api key'
EXCHANGERATE_API_URI = 'https://v3.exchangerate-api.com'

Usage

Get rates based on default currency

To get all rates based on your defult currency, you can use this resource:

$rates = ExchangeRate::rates();

The method above will return the following response:

[
    "AUD" => 1.32230,
    "BGN" => 1.8096,
    "BRL" => 3.11,
    "..." => 1.31135,
    "..." => 7.473, etc. etc.
]

Convert currency value

To convert currency value, you can use this resource:

$value = ExchangeRate::convert(10.00, 'USD', 'BRL');
// 31.11

License

Quicktech\ExchangeRate is free software distributed under the terms of the MIT license.

Contribution guidelines

Please report any issue you find in the issues page.
Pull requests are welcome.

exchange-rate's People

Contributors

gilbertojb avatar

Watchers

 avatar

Forkers

stefanyohansson

exchange-rate's Issues

Facades\ExchangeRate error

Hi guys,

I have found a problem while trying to test the library, i am not sure what's causing it but after run installation steps i got:

ErrorException in AliasLoader.php line 66: Class 'Quicktech\ExchangeRate\Facades\ExchangeRate' not found

    in AliasLoader.php line 66
    at HandleExceptions->handleError('2', 'Class 'Quicktech\ExchangeRate\Facades\ExchangeRate' not found', '/home/vagrant/code/xchangecoins/vendor/laravel/framework/src/Illuminate/Foundation/AliasLoader.php', '66', array('alias' => 'ExchangeRate'))
    at class_alias('Quicktech\ExchangeRate\Facades\ExchangeRate', 'ExchangeRate') in AliasLoader.php line 66
    at AliasLoader->load('ExchangeRate')
    at spl_autoload_call('ExchangeRate') in CoinOrder.php line 103
    at CoinOrder->brlPrice('6.70') in 3b24fd2e953997b8e5ac25df1a1d166ed212a3ae.php line 98
    at include('/home/vagrant/code/xchangecoins/storage/framework/views/3b24fd2e953997b8e5ac25df1a1d166ed212a3ae.php') in PhpEngine.php line 42
    at PhpEngine->evaluatePath('/home/vagrant/code/xchangecoins/storage/framework/views/3b24fd2e953997b8e5ac25df1a1d166ed212a3ae.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'page_title' => 'Checkout #2', 'order' => object(CoinOrder), 'contract' => '')) in CompilerEngine.php line 59
    at CompilerEngine->get('/home/vagrant/code/xchangecoins/resources/views/checkout_trader_order.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'page_title' => 'Checkout #2', 'order' => object(CoinOrder), 'contract' => '')) in View.php line 149
    at View->getContents() in View.php line 120
    at View->renderContents() in View.php line 85
    at View->render() in Response.php line 53
    at Response->setContent(object(View)) in Response.php line 201
    at Response->__construct(object(View)) in Router.php line 1085
    at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 94
    at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in UserActive.php line 22
    at UserActive->handle(object(Request), object(Closure))
    at call_user_func_array(array(object(UserActive), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 28
    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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 96
    at ControllerDispatcher->callWithinStack(object(TraderController), object(Route), object(Request), 'orderCheckout') in ControllerDispatcher.php line 54
    at ControllerDispatcher->dispatch(object(Route), object(Request), 'BrasilMiner\Http\Controllers\TraderController', 'orderCheckout') in Route.php line 174
    at Route->runController(object(Request)) in Route.php line 140
    at Route->run(object(Request)) in Router.php line 724
    at Router->Illuminate\Routing\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
    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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
    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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 726
    at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
    at Router->dispatchToRoute(object(Request)) in Router.php line 675
    at Router->dispatch(object(Request)) in Kernel.php line 246
    at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
    at Pipeline->Illuminate\Routing\{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 136
    at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
    at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
    at Pipeline->Illuminate\Routing\{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 132
    at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
    at Kernel->handle(object(Request)) in index.php line 53

well, i have the vendor/quick... directory, so composer did well:

[17:46] λ tree vendor/quicktech-as/
vendor/quicktech-as/
└── exchange-rate
    ├── composer.json
    ├── config
    │   └── config.php
    ├── LICENSE
    ├── phpcs.xml
    ├── phpunit.xml.dist
    ├── README.md
    ├── src
    │   ├── ExchangeRateManager.php
    │   ├── ExchangeRateServiceProvider.php
    │   └── Facade
    │       └── ExchangeRate.php
    └── tests
        └── ExchangeRateManagerTest.php

5 directories, 10 files

I have the provider and aliases in config/app.php

'providers' => [
//...
Quicktech\ExchangeRate\ExchangeRateServiceProvider::class,
],

'aliases' => [
'ExchangeRate' => Quicktech\ExchangeRate\Facades\ExchangeRate::class,
],

and i have the config/exchange_rate.php file:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Application Currency
    |--------------------------------------------------------------------------
    |
    | The application currency determines the default currency that will be
    | used by the ExchangeRate API.
    |
    */
    'default_currency' => env('EXCHANGERATE_DEFAULT_CURRENCY', 'USD'),

    /*
    |--------------------------------------------------------------------------
    | API Key for exchangerate-api.com
    |--------------------------------------------------------------------------
    |
    | Only if you have a key of ExchangeRate API.
    |
    */
    'api_key' => env('EXCHANGERATE_API_KEY', ''),
    
    /*
    |--------------------------------------------------------------------------
    | API Uri for exchangerate-api.com
    |--------------------------------------------------------------------------
    |
    | Only if you have a key of ExchangeRate API.
    |
    */
    'api_uri' => env('EXCHANGERATE_API_URI', ''),

I already executed composer dump-autoload and composer update several times expecting something different happens 😢

laravel version: 5.2 ("laravel/framework": "5.2.*",)
let me know if I am missing something

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.