shipsaas/currency-fx
Composer 安装命令:
composer require shipsaas/currency-fx
包简介
A PHP Library handles Currency FX from multiple online FX services. Battery-included.
README 文档
README
A PHP Library handles Currency FX (rates & conversions) with ease. Battery-included 🔋🔋🔋.
Available for Laravel too.
Tired of implementing these and integrate with 3rd services? Let's CurrencyFX help you to do that. Covered by Unit Testing & battle-tested!
Available Services / Batteries
- https://exchangeratesapi.io/
- https://exchangerate.host/
- https://fixer.io/
- https://currencylayer.com/
- https://www.currencycloud.com/
Supports
- PHP 8.1+
Dependencies
- Guzzle for API Requests
- NeverThrow for straightforward OK/Error response.
Usage
Simply initialize the class with the required params. And it is ready to use in no time.
$service = new CurrencyCloudService($host, $loginId, $apiKey); $rateResponse = $service->getRates('USD', 'SGD'); if (!$rateResponse->isOk()) { // failed to get the rate from third party service // do something here } $rate = $rateResponse->getOkResult()->rate; // float (1.4xxx)
Laravel Integration
Requirement: Laravel 10+
Just simply install the package and lets Laravel discovery magic happens 🥰
Since we already bind the services in Laravel Container, all you have to do is update the ENVs and that's all.
Export the configuration
php artisan vendor:publish --tag=currency-fx-configs
Update ENVs
After published the config, checkout the configs/currency-fx.php.
We already defined some ENVs key for you to add 😜.
Usage
use CurrencyFX\Services\CurrencyLayerService; use CurrencyFX\Services\ExchangerRatesApiIoService; // global access app(CurrencyLayerService::class)->getRates('USD', 'EUR'); // DI class TransferService { public function __construct( private ExchangerRatesApiIoService $rateService ) { } public function transfer(): TransferResult { $rateRes = $this->rateService->getRates('EUR', 'GBP'); if ($rateRes->isError()) { return TransferResult::error(...); } $rate = $rateRes->getOkResult()->rate; } }
Tests
We love tests, always. We have 3 kind of test cases:
- Unit Tests
- Integration Tests
- E2E Tests
Check out the TEST-README.md to learn more!
Contribute to the project
- All changes must follow PSR-1 / PSR-12 coding conventions.
- Unit testing is a must, cover things as much as you can.
Feel free to add more driver and share it to the whole PHP community 😆
This library is useful?
Thank you, please give it a ⭐️⭐️⭐️ to support the project.
Don't forget to share with your friends & colleagues, so they can also build their own SaaS products as well 🚀
License
MIT LICENSE
Contributors
ShipSaas, Seth Phat & Contributors
shipsaas/currency-fx 适用场景与选型建议
shipsaas/currency-fx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 29, 最近一次更新时间为 2023 年 04 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「library」 「currency」 「PHP Library」 「fx」 「exchange rates」 「currency rates」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shipsaas/currency-fx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shipsaas/currency-fx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shipsaas/currency-fx 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fixer.io data provider for Peso
Inbox pattern process implementation for your Laravel Applications
TCMB Currenct Converter
Core library that defines common interfaces used by the rest of the intahwebz..
Immutable PHP currency converter that's data-agnostic.
Amqp classes
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-17