PHP code example of brunoinds / sunat-dolar
1. Go to this page and download the library: Download brunoinds/sunat-dolar library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
brunoinds / sunat-dolar example snippets
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
use Brunoinds\SunatDolar\Enums\Currency;
Currency::USD; // 'USD'
Currency::PEN; // 'PEN'