PHP code example of estratos / sie-banxico

1. Go to this page and download the library: Download estratos/sie-banxico 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/ */

    

estratos / sie-banxico example snippets




namespace App\Controller;

use App\Service\RequestService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Estratos\SieBanxico\SieBanxico;

class BanxicoController extends AbstractController
{


///// helper route to return exchange rate
#[Route('/banxico/tipo', name: 'app_banxico_api_tipo')]
public function getBanxicoRate(): Response
{
    $token = '4271d3f522930eb7ff3d316c4896d0ad5287298ad54363c37107e78cc0ee4c75';
    $res = $this->getExchange($token);


return $this->json($res);
}


public function  getExchange($token) {

  $service = new SieBanxico($token);

  $service->ClientInit();

  $tipo_de_cambio = $service->getExchangeRate();

  return $tipo_de_cambio;
}


}