PHP code example of apihub-cdc / telcos-client-php

1. Go to this page and download the library: Download apihub-cdc/telcos-client-php 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/ */

    

apihub-cdc / telcos-client-php example snippets


$password = getenv('KEY_PASSWORD');
$this->signer = new \lae\Client\Interceptor\KeyHandler(
    "/example/route/keypair.p12",
    "/example/route/cdc_cert.pem",
    $password
);

public function setUp()
{
    $password = getenv('KEY_PASSWORD');
    $this->signer = new KeyHandler(null, null, $password);

    $events = new MiddlewareEvents($this->signer);
    $handler = handlerStack::create();
    $handler->push($events->add_signature_header('x-signature'));   
    $handler->push($events->verify_signature_header('x-signature'));
    $client = new Client(['handler' => $handler]);

    $config = new Configuration();
    $config->setHost('the_url');
    
    $this->apiInstance = new Instance($client, $config);
    $this->x_api_key = "your_api_key";
    $this->username = "your_username";
    $this->password = "your_password";

}  

    
public function testGetReporte()
{
    $domicilio = new \Telcos\MX\Client\Model\DomicilioPeticion();
    $CatalogoEstados = new \Telcos\MX\Client\Model\CatalogoEstados();
    $CatalogoTipoDomicilio = new \Telcos\MX\Client\Model\CatalogoTipoDomicilio();
    $requestTipoAsent = new \Telcos\MX\Client\Model\CatalogoTipoAsentamiento();

    $domicilio->setEstado($CatalogoEstados::CDMX);
    $domicilio->setTipoDomicilio($CatalogoTipoDomicilio::C);
    $domicilio->setTipoAsentamiento($requestTipoAsent::_1);

    $persona = new \Telcos\MX\Client\Model\PersonaPeticion();
    $CatalogoResidencia = new \Telcos\MX\Client\Model\CatalogoResidencia();
    $requestEdoCivil = new \Telcos\MX\Client\Model\CatalogoEstadoCivil();
    $requestSexo = new \Telcos\MX\Client\Model\CatalogoSexo();
    
    $persona->setPrimerNombre("NOMBRE");
    $persona->setSegundoNombre(null);
    $persona->setApellidoPaterno("PATERNO");
    $persona->setApellidoMaterno("MATERNO");
    $persona->setApellidoAdicional(null);
    $persona->setFechaNacimiento("1980-01-04");
    $persona->setResidencia($CatalogoResidencia::_1);
    $persona->setEstadoCivil($requestEdoCivil::S);
    $persona->setSexo($requestSexo::M);
    $persona->setDomicilio($domicilio);       

    $peticion = new \Telcos\MX\Client\Model\Peticion(); 

    $peticion->setFolioOtorgante("1234");
    $peticion->setPersona($persona);

    try {
        $result = $this->apiInstance->getReporte($this->x_api_key, $this->username, $this->password, $peticion);
        if($this->apiInstance->getStatusCode() == 200){
            print_r($result);
        }
    } catch (ApiException $e) {
        echo ' code. Exception when calling ApiTest->testGetReporte: ', $e->getResponseBody(), PHP_EOL;
    }
    $this->assertTrue($this->apiInstance->getStatusCode() == 200);        
}

sh
#ejemplo con php en versión 7.3 para otra versión colocar php{version}-curl
apt-get install php7.3-curl
apt-get install php7.3-mbstring
sh
export KEY_PASSWORD=your_password
sh
export PRIVATE_KEY_FILE=pri_key.pem
export CERTIFICATE_FILE=certificate.pem
export SUBJECT=/C=MX/ST=MX/L=MX/O=CDC/CN=CDC
export PKCS12_FILE=keypair.p12
export ALIAS=circulo_de_credito