PHP code example of brunoinds / sunat-dolar-laravel

1. Go to this page and download the library: Download brunoinds/sunat-dolar-laravel 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-laravel example snippets


use Brunoinds\SunatDolarLaravel\Exchange;
use Brunoinds\SunatDolarLaravel\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\SunatDolarLaravel\Enums\Currency;

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