PHP code example of nexo-do / aura-ecf-sdk

1. Go to this page and download the library: Download nexo-do/aura-ecf-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/ */

    

nexo-do / aura-ecf-sdk example snippets



Aura\Ecf\Client;

$aura = new Client('aura_test_...'); // o aura_live_... para producción
// Default (Cloud): https://aura.nexo.com.do/api/v1
// new Client('aura_...', ['baseUrl' => 'http://localhost:3001/v1']); // self-hosted

// 1) Emitir un e-CF (202 — se procesa async)
$result = $aura->vouchers->issue([
    'clientId'    => '00000000-0000-0000-0000-000000000000',
    'typeId'      => '31',
    'counterpart' => ['rnc' => '131234567', 'legalName' => 'Cliente Demo SRL'],
    'paymentType' => 1,
    'items'       => [
        ['description' => 'Servicio', 'quantity' => 1, 'unitPrice' => 10000, 'itbisRate' => 18],
    ],
], idempotencyKey: bin2hex(random_bytes(16))); // evita doble consumo de NCF en reintentos

echo "{$result['id']} {$result['ncf']} {$result['status']}\n";

// 2) Consultar el estado final (o usa webhooks)
$voucher = $aura->vouchers->retrieve($result['id']);
echo "{$voucher['status']} {$voucher['qrUrl']} {$voucher['securityCode']}\n";

use Aura\Ecf\AuraException;

try {
    $aura->vouchers->issue($params);
} catch (AuraException $e) {
    error_log("{$e->type} {$e->getMessage()} {$e->requestId}"); // p.ej. VALIDATION ...
    if ($e->isRetryable()) {
        // reintentar
    }
}

use Aura\Ecf\Webhook;

$rawBody = file_get_contents('php://input'); // cuerpo CRUDO — no json_decode antes
$headers = getallheaders();

if (!Webhook::isValid($rawBody, $headers, $_ENV['AURA_WEBHOOK_SECRET'])) {
    http_response_code(401);
    exit;
}

$event = json_decode($rawBody, true);
// $event['type']: 'voucher.accepted' | 'voucher.rejected' | ...
http_response_code(200);

$aura = new Client();                                   // anónimo
$aura->auth->login('[email protected]', 'secret', 'acme-corp');
$aura->setMode('live');                                 // header X-Aura-Mode (opcional)

$aura->projects->list();
$aura->billing->usage();
$aura->auth->logout();

$ri = $aura->printing->pdf($voucherId);
file_put_contents('factura.pdf', $ri['content']);