1. Go to this page and download the library: Download azur/sdk 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/ */
azur / sdk example snippets
$azur = new Azur\Sdk\Azur('azur_test_…');
$borrador = $azur->facturas->guardar([
'cliente' => ['id_cliente' => 123],
'productos' => [['id' => 45, 'cantidad' => 2]],
]);
$azur->facturas->enviar($borrador['id']); // al SRI
$azur = new Azur\Sdk\Azur(getenv('AZUR_CREDENCIAL'));
echo $azur->ambiente(); // "pruebas" o "produccion"
use Azur\Sdk\Azur;
$azur = new Azur(getenv('AZUR_CREDENCIAL'));
$ctx = $azur->contexto();
echo $ctx->get('empresa.nombre'), ' · ', $ctx->get('ambiente.nombre');
$plan = $azur->plan();
use Azur\Sdk\Excepciones\Validacion;
// Las búsquedas nunca eligen por usted: si `unico` es false, hay varios candidatos.
$clientes = $azur->clientes->buscar('0912345678');
$idCliente = $clientes['unico']
? $clientes['clientes'][0]['id']
: $azur->clientes->crear([
'identificacion' => '0912345678',
'nombrerazonsocial' => 'JUAN PÉREZ',
'direccion' => 'Av. 9 de Octubre, Guayaquil',
'correo' => '[email protected]',
])['id'];
try {
$f = $azur->facturas->guardar([
'cliente' => ['id_cliente' => $idCliente],
'productos' => [['id' => 45, 'cantidad' => 2, 'descuento' => 0]],
'formas_pago' => [['codigo' => '20', 'valor' => 23.00]],
]);
} catch (Validacion $e) {
print_r($e->getMotivos()); // un motivo por cada cosa que falla
}
echo $f['id'], ' ', $f['estado']; // borrador
// Los totales los calcula el servidor. Mire $f->avisos.
$r = $azur->comprobantes->listar(['tipo' => 'factura,credito', 'desde' => '2026-09-01', 'limite' => 50]);
foreach ($r['comprobantes'] as $c) {
echo $c['tipo_nombre'], ' ', $c['numero'], ' ', $c['estado'], "\n";
}
// Operar por tipo cuando el tipo llega como dato (nombre o código SRI):
$pdf = $azur->comprobantes->pdf('01', 123);
$pdf->guardar('/tmp'); // usa $pdf->nombre
// Todas las páginas, fila a fila (generador):
foreach ($azur->productos->todos(['limite' => 100]) as $p) { /* … */ }
// Mantener un ERP al día: lo que CAMBIÓ (emitido, autorizado, rechazado, anulado…)
$sync = $azur->comprobantes->sincronizar(['modificado_desde' => $ultimaVez]);
foreach ($sync as $c) {
upsert($c['recurso'], $c['id'], $c); // puede repetirse alguna fila: guarde por id
}
$ultimaVez = $sync->getReturn()['proximo_desde']; // guárdelo para la próxima vez
$w = $azur->webhooks->crear('https://mi-sitio.ec/webhooks/azur', ['comprobante.autorizado', 'comprobante.rechazado']);
$secreto = $w['secreto']; // whsec_… — SOLO se devuelve ahora: guárdelo
$azur->webhooks->listar(); $azur->webhooks->envios($w['id']); $azur->webhooks->eliminar($w['id']);
use Azur\Sdk\Webhook;
use Azur\Sdk\Excepciones\FirmaWebhookInvalida;
Route::post('/webhooks/azur', function (Illuminate\Http\Request $request) {
try {
$evento = Webhook::verificar($request->getContent(), $request->headers->all(), config('services.azur.webhook_secret'));
} catch (FirmaWebhookInvalida $e) {
abort(400);
}
ProcesarAvisoAzur::dispatch($evento); // responda rápido; procese en cola
return response()->noContent();
});
try {
$azur->facturas->enviar(123);
} catch (Validacion $e) {
print_r($e->getMotivos());
} catch (Conflicto $e) {
if ($e->getCodigo() === 'firma_caducada') { /* renovar la firma */ }
} catch (ErrorRed | ErrorServidor $e) {
// Reintente más tarde con la MISMA llave para no duplicar:
$azur->facturas->enviar(123, ['idempotency_key' => $e->getIdempotencyKey()]);
}
new Azur($credencial, [
'base_url' => 'https://azur.com.ec/plataforma/api/v2', // o solo el dominio
'timeout' => 30, // s
'timeout_conexion' => 10, // s
'reintentos' => 3,
'espera_base' => 0.5, // s
'espera_maxima' => 30, // s
'idempotencia_automatica' => true,
'cabeceras' => [], // cabeceras extra
'http_client' => $guzzle, // su GuzzleHttp\ClientInterface (proxy, logs…)
'handler' => $pila, // o solo un HandlerStack
]);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.