brunoinds/sunat-dolar

此包的最新版本(v1.0.0)没有提供许可证信息。

计算 SUNAT 秘鲁美元汇率

v1.0.0 2023-12-29 00:24 UTC

This package is auto-updated.

Last update: 2024-09-29 01:59:33 UTC


README

一个简单的基于秘鲁 SUNAT 汇率的 PHP 货币兑换库。

安装

通过 Composer 安装

composer require brunoinds/sunat-dolar

用法

Exchange 类提供在 PEN 和 USD 之间兑换的方法

use Brunoinds\SunatDolar\Exchange;
use Brunoinds\SunatDolar\Enums\Currency;

// Get current exchange rate
$result = Exchange::now()->convert(Currency::USD, 1)->to(Currency::PEN);

// Get historical exchange rate 
$date = new DateTime('2023-12-10');
$result = Exchange::on($date)
                ->convert(Currency::USD, 1)
                ->to(Currency::PEN);
echo $result // 0.27

// Get buy/sell prices
$dollarBuy = Exchange::on($date)->getDollarBuyPrice(); //3.749;
$solesSell = Exchange::on($date)->getSolesSellPrice(); //0.266

Currency 枚举提供支持货币的常量

use Brunoinds\SunatDolar\Enums\Currency;

Currency::USD; // 'USD'
Currency::PEN; // 'PEN' 

测试

单元测试位于 tests 目录中。使用以下命令运行测试

composer test

贡献

欢迎提交拉取请求!

许可证

MIT 许可证

如果您想扩展任何部分或有其他反馈,请告诉我!