定制 unirate-api/laravel-money 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

unirate-api/laravel-money

最新稳定版本:v0.1.0

Composer 安装命令:

composer require unirate-api/laravel-money

包简介

UniRate exchange-rate bridge for akaunting/laravel-money — automatic rate fetching, caching, and conversion.

README 文档

README

Exchange-rate bridge for akaunting/laravel-money — automatic rate fetching, caching, and conversion powered by UniRate API.

CI

Installation

composer require unirate-api/laravel-money

The service provider and facade are auto-discovered. Publish the config if you need to customise:

php artisan vendor:publish --tag=unirate-config

Set your API key in .env:

UNIRATE_API_KEY=your-key-here

Get a free API key at unirateapi.com.

Usage

Facade

use UniRate\LaravelMoney\Facades\UniRate;

// Get a single rate
$rate = UniRate::getRate('USD', 'EUR');  // 0.92

// Get all rates for a base currency
$rates = UniRate::getRates('USD');  // ['EUR' => 0.92, 'GBP' => 0.79, ...]

// Convert a raw amount
$eur = UniRate::convertAmount(100.0, 'USD', 'EUR');  // 92.0

// Convert a Money instance
use Akaunting\Money\Money;
use Akaunting\Money\Currency;

$price = new Money(1000, new Currency('USD'));
$converted = UniRate::convert($price, 'EUR');
// → Money(920, Currency('EUR'))

// List supported currencies
$currencies = UniRate::currencies();  // ['USD', 'EUR', 'GBP', ...]

Money macro

A convertVia macro is registered on Akaunting\Money\Money:

$price = new Money(2500, new Currency('USD'));
$gbp = $price->convertVia('GBP');
// → Money(1975, Currency('GBP'))

Artisan command

# Fetch and display current rates
php artisan unirate:rates

# Specify a base currency
php artisan unirate:rates --base=EUR

# Flush cache before fetching
php artisan unirate:rates --flush

Dependency injection

use UniRate\LaravelMoney\UniRateExchange;

class PricingController extends Controller
{
    public function show(UniRateExchange $exchange)
    {
        $rate = $exchange->getRate('USD', 'EUR');
        // ...
    }
}

Configuration

Key Env Default Description
api_key UNIRATE_API_KEY Your UniRate API key
base_url UNIRATE_API_BASE_URL https://api.unirateapi.com API base URL
base_currency UNIRATE_BASE_CURRENCY USD Default base currency
cache.store UNIRATE_CACHE_STORE null (default) Laravel cache store name
cache.ttl UNIRATE_CACHE_TTL 3600 Cache TTL in seconds (0 = disabled)
cache.prefix unirate Cache key prefix
timeout UNIRATE_TIMEOUT 10 HTTP timeout in seconds

Requirements

Other UniRate clients

UniRate ships official client libraries and framework integrations across the ecosystem. The repos below are all maintained under the UniRate-API org.

Get a free API key at unirateapi.com.

License

MIT — see LICENSE.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固