Download the PHP package worksome/exchange without Composer

On this page you can find all versions of the php package worksome/exchange. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package exchange

Exchange

Check exchange rates for any currency in Laravel

Latest Version on Packagist GitHub Tests Action Status GitHub Static Analysis Action Status Total Downloads

If your app supports multi-currency, you'll no doubt need to check exchange rates. There are many third party services to accomplish this, but why bother reinventing the wheel when we've done all the hard work for you?

Exchange provides an abstraction layer for exchange rate APIs, with a full suite of tools for caching, testing and local development.

Installation

You can install the package via composer.

To install the exchange config file, you can use our install artisan command!

Exchange is now installed!

Usage

Exchange ships with a number of useful drivers for retrieving exchange rates. The default is exchange_rate, which is a free service, but you're welcome to change that to suit you app's requirements.

The driver can be set using the EXCHANGE_DRIVER environment variable. Supported values are: null, fixer, exchange_rate and cache. Let's take a look at each of the options available.

Null

You can start using Exchange locally with the null driver. This will simply return 1.0 for every exchange rate, which is generally fine for local development.

In the example above, we are retrieving exchange rates for GBP and EUR based on USD. The rates method will return a Worksome\Exchange\Support\Rates object, which includes the base currency, retrieved rates and the time of retrieval. Retrieved rates are an array with currency codes as keys and exchange rates as values.

Fixer

Of course, the null driver isn't very useful when you want actual exchange rates. For this, you should use the fixer driver.

In your exchange.php config file, set default to fixer, or set EXCHANGE_DRIVER to fixer in your .env file. Next, you'll need an access key from https://fixer.io/dashboard. Set FIXER_ACCESS_KEY to your provided access key from Fixer.

That's it! Fixer is now configured as the default driver and running Exchange::rates() again will make a request to Fixer for up-to-date exchange rates.

ExchangeRate.host

exchangerate.host is an alternative to Fixer with an identical API spec.

In your exchange.php config file, set default to exchange_rate, or set EXCHANGE_DRIVER to exchange_rate in your .env file. Set EXCHANGE_RATE_ACCESS_KEY to your provided access key from exchangerate.host.

With that task completed, you're ready to start using exchangerate.host for retrieving up-to-date exchange rates.

Currency.GetGeoApi.com

Currency.GetGeoApi.com is an alternative option you can use with a free quota.

In your exchange.php config file, set default to currency_geo, or set EXCHANGE_DRIVER to currency_geo in your .env file. Set CURRENCY_GEO_ACCESS_KEY to your provided access key from currency.getgeoapi.com.

With that task completed, you're ready to start using Currency.GetGeoApi.com for retrieving up-to-date exchange rates.

Frankfurter.app

frankfurter.app is an open-source API for current and historical foreign exchange rates published by the European Central Bank, which can be used without an API key.

In your exchange.php config file, set default to frankfurter, or set EXCHANGE_DRIVER to frankfurter in your .env file.

With that task completed, you're ready to start using frankfurter.app for retrieving up-to-date exchange rates.

Cache

It's unlikely that you want to make a request to a third party service every time you call Exchange::rates(). To remedy this, we provide a cache decorator that can be used to store retrieved exchange rates for a specified period (24 hours by default).

In your exchange.php config file, set default to cache, or set EXCHANGE_DRIVER to cache in your .env file. You'll also want to pick a strategy under services.cache.strategy. By default, this will be fixer, but you are free to change that. The strategy is the service that will be used to perform the exchange rate lookup when nothing is found in the cache.

There is also the option to override the ttl (how many seconds rates are cached for), key for your cached rates, and the store.

Artisan

We provide an Artisan command for you to check Exchange is working correctly in your project.

In the example above, exchange rates will be retrieved and displayed in the console from a base of USD to GBP and EUR respectively. You can add as many currencies as you'd like to the command.

CleanShot 2022-02-23 at 13 10 55@2x

Testing

To help you write tests using Exchange, we provide a fake implementation via the Exchange::fake() method.

The assertRetrievedRates method will cause your test to fail if no exchange rates were ever retrieved.

Internally, Exchange prides itself on a thorough test suite written in Pest, strict static analysis, and a very high level of code coverage. You may run these tests yourself by cloning the project and running our test script:

Changelog

Please see GitHub Releases for more information on what has changed recently.

Credits

License

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


All versions of exchange with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0 || ^11.0
nunomaduro/termwind Version ^1.15 || ^2.0
spatie/laravel-package-tools Version ^1.16
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package worksome/exchange contains the following files

Loading the files please wait ....