PHP code example of pronesoft-rd / ecf-sdk-php

1. Go to this page and download the library: Download pronesoft-rd/ecf-sdk-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/ */

    

pronesoft-rd / ecf-sdk-php example snippets



PronesoftEcfSdk\EcfClient;
use PronesoftEcfSdk\ApiException;

// 1. Configurar credenciales (ejemplo con Sandbox)
$host = 'https://api.ecf.sandbox.pronesoft.com/api/v1';
$clientId = 'SBX-TU-EMPRESA-UUID';
$clientSecret = 'tu-client-secret-aqui';
$tenantId = 'SBX-RNC-DE-LA-EMPRESA-ACTIVA'; // Opcional: ID de la empresa activa (inyecta x-tenant-id)

try {
    // 2. Inicializar el cliente único (se autentica automáticamente y establece el tenant de sesión)
    $client = new EcfClient($host, $clientId, $clientSecret, $tenantId);
    
    // 3. Consumir cualquier servicio de negocio directamente
    $documentsSentApi = $client->documentsSent();
    $logs = $documentsSentApi->getSentDocumentLogs('uuid-del-documento');
    
    print_r($logs);

} catch (ApiException $e) {
    echo "Error retornado por la API: " . $e->getResponseBody() . "\n";
} catch (\Exception $e) {
    echo "Error general: " . $e->getMessage() . "\n";
}

$sucursalClient = $client->forTenant('uuid-de-la-sucursal');
$logs = $sucursalClient->documentsSent()->getSentDocumentLogs('uuid-del-documento');