1. Go to this page and download the library: Download amephia/sri-ec 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/ */
amephia / sri-ec example snippets
use Teran\Sri\SRI;
// Inicializar en ambiente 'pruebas' o 'produccion'
$sri = new SRI('pruebas');
// Configurar tu firma digital (.p12)
$p12 = file_get_contents('ruta/a/tu/firma.p12');
$sri->setFirma($p12, 'tu_contraseña_p12');
use Teran\Sri\Strategies\ComprobanteInterface;
class MiDocumentoPersonalizado implements ComprobanteInterface {
public function getTipo(): string { return '01'; }
public function generarXml(): string { /* ... */ }
public function getXsdPath(): string { /* ... */ }
public function getDatosClave(): array { /* ... */ }
}
$resultado = $sri->procesar(new MiDocumentoPersonalizado());
// Correcto
date_default_timezone_set('America/Guayaquil');
$fecha = date('d/m/Y'); // Fecha actual en Ecuador
mermaid
sequenceDiagram
participant App as Tu App (PHP)
participant Lib as amephia/sri-ec
participant SRI_REST as SRI Online (REST)
participant SRI_SOAP as SRI Recepción (SOAP)
App->>Lib: 1. Enviar Datos (Array)
rect rgb(240, 240, 240)
Note over Lib, SRI_REST: Validación RUC
Lib->>SRI_REST: 2. Consultar RUC (Online)
alt RUC Existe
SRI_REST-->>Lib: OK
else Fallo / Timeout
Lib->>Lib: Fallback: Algoritmo Módulo 11
end
end
Lib->>Lib: 3. Generar Clave de Acceso (49 dígitos)
Lib->>Lib: 4. Generar XML
Lib->>Lib: 5. Validar XSD
Lib->>Lib: 6. Firmar XML (XAdES-BES)
Lib->>SRI_SOAP: 7. Enviar XML Firmado
SRI_SOAP-->>Lib: 8. Confirmación de Recepción
Lib->>SRI_SOAP: 9. Solicitar Autorización
SRI_SOAP-->>Lib: 10. Respuesta (AUTORIZADO/NO AUTORIZADO)
Lib-->>App: 11. Retornar Resultado