PHP code example of apihub-cdc / vantage-client

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


/**
* Esto es parte del setUp() de las pruebas unitarias.
*/
$password = getenv('KEY_PASSWORD');
$this->signer = new KeyHandler(
    "/example/route/keypair.p12",
    "/example/route/cdc_cert.pem",
    $password
);

 protected $host = 'the_url';
 


public function setUp()
{
  $password = getenv('KEY_PASSWORD');
  $this->keypair = 'path/to/keypair.p12';
  $this->cert = 'path/to/certificate.pem';
  $this->url = 'this_url';

  $this->signer = new KeyHandler($this->keypair, $this->cert, $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($this->url);
  
  $this->apiInstance = new Instance($client, $config);
  $this->x_api_key = "your_api_key";
  $this->username = "your_username";
  $this->password = "your_password";
}



public function testGetVantageAportantes(){
    try {
        $request = new AportantesPeticion();
        $tipoContrato = new CatalogoContrato();

        $request->setFolio("0000001");
        $request->setTipoContrato($tipoContrato::TC);
        $request->setNumeroCuenta("4772133042201399");
        $request->setDiasAtraso(1);
        $result = $this->apiInstance->getVantageAportantes($this->x_api_key, $this->username, $this->password, $request);

        if($this->apiInstance->getStatusCode() == 200){
            print_r($result);
        }
    } catch (ApiException $e) {

        if($e->getCode() !== 204){
            echo 'Exception when calling ApiTest->testGetVantageAportantes: ', $e->getMessage(), PHP_EOL;
        }
    }
    $this->assertTrue($this->apiInstance->getStatusCode() == 200);        
}

public function testGetVantageNoAportantes(){
    try {
        $tipoContrato = new CatalogoContrato();
        $catalogoPago = new CatalogoFrecuenciaPago();
        $persona = new PersonaPeticion();
        $domicilio = new DomicilioPeticion();
        $catalogoEstados = new CatalogoEstados();
        $request = new NoAportantesPeticion();
        
        $domicilio->setDireccion("INSURGENTES SUR 1007");
        $domicilio->setColoniaPoblacion("INSURGENTES");
        $domicilio->setDelegacionMunicipio("BENITO JUAREZ");
        $domicilio->setCiudad("CIUDAD DE MÉXICO");
        $domicilio->setEstado($catalogoEstados::DF);
        $domicilio->setCp("11230");

        $persona->setPrimerNombre("JUAN");
        $persona->setApellidoPaterno("PRUEBA");
        $persona->setApellidoMaterno("SIETE");
        $persona->setFechaNacimiento("1980-01-07");
        $persona->setDomicilio($domicilio);

        $request->setFolio("0000002");
        $request->setTipoProducto("O");
        $request->setTipoContrato($tipoContrato::TC);
        $request->setFrecuenciaPago($catalogoPago::M);
        $request->setDiasAtraso(1);
        $request->setNumeroCuenta("123456");
        $request->setFechaApertura("1990-10-19");
        $request->setSaldoActual(15301);
        $request->setPersona($persona);

        $result = $this->apiInstance->getVantageNoAportantes($this->x_api_key, $this->username, $this->password, $request);

        if($this->apiInstance->getStatusCode() == 200){
            print_r($result);
        }
    } catch (ApiException $e) {

        if($e->getCode() !== 204){
            echo 'Exception when calling ApiTest->testGetVantageNoAportantes: ', $e->getMessage(), 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