Download the PHP package otherguy/php-currency-api without Composer

On this page you can find all versions of the php package otherguy/php-currency-api. 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 php-currency-api

💱 Wrapper for popular Currency Exchange Rate APIs

A PHP API Wrapper to offer a unified programming interface for popular Currency Rate APIs.

Version Installs PHP version Travis CI Coverage Coverage Maintainability

Dont worry about your favorite currency conversion service suddenly shutting down or switching plans on you. Switch away easily, without changing your code.

Inspiration 💅

I needed a currency conversion API for my travel website but could not find a good PHP package. The idea of the Rackbeat/php-currency-api package came closest but unfortunately it was just a stub and not implemented.

Features 🌈

Supported APIs 🌐

Service Identifier
FixerIO fixerio
CurrencyLayer currencylayer
Open Exchange Rates openexchangerates
Exchange Rates API exchangeratesapi

If you want to see more services added, feel free to open an issue!

Prerequisites 📚

Installation 🚀

Simply require the package using composer and you're good to go!

Usage 🛠

Currency Symbol Helper

The Otherguy\Currency\Symbol class provides constants for each supported currency.

Note: You are not required to use Otherguy\Currency\Symbol to specify symbols. It's simply a convenience helper and does not need to be used. You can simply pass strings like 'USD', 'EUR', ... to all methods.

Use the all() method to retrieve an array of all currency symbols:

The names() method returns an associative array with currency names instead:

To get the name of a single currency, use the name() method:

Initialize API Instance

To get a list of supported drivers, use the getDrivers() method:

Set Access Key

Most API providers require you to sign up and use your issued access key to authenticate against their API. You can specify your access key like so:

Set Configuration Options

To set further configuration options, you can use the config() method. An example is CurrencyLayer's JSON formatting option.

Set Base Currency

You can use either from() or source() to set the base currency. The methods are identical.

Note: Each driver sets its own default base currency. FixerIO uses EUR as base currency while CurrencyLayer uses USD.

Most services only allow you to change the base currency in their paid plans. The driver will throw a Otherguy\Currency\Exceptions\ApiException if your current plan does not allow changing the base currency.

Set Return Currencies

You can use either to() or symbols() to set the return currencies. The methods are identical. Pass a single currency or an array of currency symbols to either of these methods.

Note: Pass an empty array to return all currency symbols supported by this driver. This is the default if you don't call the method at all.

Latest Rates

This retrieves the most recent exchange rates and returns a ConversionResult object.

Historical Rates

To retrieve historical exchange rates, use the historical() method. Note that you need to specify a date either as a method parameter or by using the date() methods. See Fluent Interface for more information.

Convert Amount

Use the convert() method to convert amounts between currencies.

Note: Most API providers don't allow access to this method using your free account. You can still use the Historical Rates endpoints and perform calculations or conversions on the ConversionResult object.

Fluent Interface

Most methods can be used with a fluent interface, allowing you to chain method calls for more readable code:

Conversion Result

The historical() endpoints return a ConversionResult object. This object allows you to perform calculations and conversions easily.

Note: Even though free accounts of most providers do not allow you to change the base currency, you can still use the ConversionResult object to change the base currency later. This might not be as accurate as changing the base currency directly, though.

Note: To convert between two currencies, you need to request both of them in your initial get() or historical() request. You can not convert between currencies that have not been fetched!

See the following code for some examples of what you can do with the ConversionResult object.

Contributing 🚧

Pull Requests are more than welcome! I'm striving for 100% test coverage for this repository so please make sure to add tests for your code.


All versions of php-currency-api with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
ext-json Version *
guzzlehttp/guzzle Version ^7.2
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 otherguy/php-currency-api contains the following files

Loading the files please wait ....