PHP code example of dazza-dev / dgt-cr-sender

1. Go to this page and download the library: Download dazza-dev/dgt-cr-sender 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/ */

    

dazza-dev / dgt-cr-sender example snippets


use DazzaDev\DgtCrSender\Sender;

// Instanciar el sender
$sender = new Sender();

// Entorno de pruebas (true para pruebas, false para producción)
$sender->setTestMode(true);

$token = $sender->auth('usuario_api', 'clave_api');

$newToken = $sender->renewToken($token['refresh_token']);

$sender->setBearerToken($token['access_token']);
$sender->setRefreshToken($token['refresh_token']);

$sender->logout($token['refresh_token']);

// Setear Emisor
$sender->setIssuer([
    'identification_type' => '02',
    'identification_number' => 'identification_del_emisor',
]);

// Setear Receptor
$sender->setReceiver([
    'identification_type' => '02',
    'identification_number' => 'identification_del_receptor',
]);

$sender->setCallbackUrl('https://tu-dominio.com/callback');

$sender->send(
    documentType: 'invoice',
    documentKey: $clave,
    date: '2025-11-18T00:00:00-06:00',
    signedXml: base64_encode($xml)
);

$documentStatus = $sender->checkStatus(
    documentKey: $clave
);

$documents = $sender->getDocuments(
    offset: 0,
    limit: 50
);

$document = $sender->getDocument(
    documentKey: $clave
);