Skip to content

Commit 051c4c7

Browse files
committed
CurrencyFX
1 parent 874a50d commit 051c4c7

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

README.md

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
# PHP Currency FX
1+
# PHP Currency FX Library
22

3-
A PHP Library handles Currency FX (rates & conversions) with ease. Available for Laravel too.
3+
[![codecov](https://codecov.io/gh/shipsaas/currency-fx/branch/main/graph/badge.svg?token=S1RA9XKU94)](https://codecov.io/gh/shipsaas/currency-fx)
4+
[![Unit Test (PHP 8.1, 8.2)](https://github.com/shipsaas/currency-fx/actions/workflows/unit.yml/badge.svg)](https://github.com/shipsaas/currency-fx/actions/workflows/unit.yml)
5+
[![Integration Test](https://github.com/shipsaas/currency-fx/actions/workflows/integration.yml/badge.svg)](https://github.com/shipsaas/currency-fx/actions/workflows/integration.yml)
6+
[![E2E Test](https://github.com/shipsaas/currency-fx/actions/workflows/e2e.yml/badge.svg)](https://github.com/shipsaas/currency-fx/actions/workflows/e2e.yml)
7+
8+
A PHP Library handles Currency FX (rates & conversions) with ease. Battery-included 🔋🔋🔋.
9+
10+
Available for Laravel too.
411

512
Tired of implementing these and integrate with 3rd services? Let's CurrencyFX help you to do that. Covered by Unit Testing & battle-tested!
613

@@ -16,14 +23,22 @@ Tired of implementing these and integrate with 3rd services? Let's CurrencyFX he
1623

1724
## Dependencies
1825
- Guzzle for API Requests
26+
- [NeverThrow](https://github.com/shipsaas/never-throw) for straightforward OK/Error response.
1927

2028
## Usage
2129

2230
Simply initialize the class with the required params. And it is ready to use in no time.
2331

2432
```php
2533
$service = new CurrencyCloudService($host, $loginId, $apiKey);
26-
$rate = $service->getRates('USD', 'SGD'); // 1.4xxx (float)
34+
$rateResponse = $service->getRates('USD', 'SGD');
35+
36+
if (!$rateResponse->isOk()) {
37+
// failed to get the rate from third party service
38+
// do something here
39+
}
40+
41+
$rate = $rateResponse->getOkResult()->rate; // float (1.4xxx)
2742
```
2843

2944
## Laravel Integration
@@ -49,20 +64,28 @@ We already defined some ENVs key for you to add 😜.
4964
### Usage
5065

5166
```php
67+
use CurrencyFX\Services\CurrencyLayerService;
68+
use CurrencyFX\Services\ExchangerRatesApiIoService;
69+
5270
// global access
53-
app(\CurrencyFX\Services\CurrencyLayerService::class)->getRates('USD', 'EUR');
71+
app(CurrencyLayerService::class)->getRates('USD', 'EUR');
5472

5573
// DI
5674
class TransferService
5775
{
5876
public function __construct(
59-
private \CurrencyFX\Services\ExchangerRatesApiIoService $rateService
77+
private ExchangerRatesApiIoService $rateService
6078
) {
6179
}
6280

6381
public function transfer(): TransferResult
6482
{
65-
$rates = $this->rateService->getRates('EUR', 'GBP');
83+
$rateRes = $this->rateService->getRates('EUR', 'GBP');
84+
if ($rateRes->isError()) {
85+
return TransferResult::error(...);
86+
}
87+
88+
$rate = $rateRes->getOkResult()->rate;
6689
}
6790
}
6891
```

0 commit comments

Comments
 (0)