PHP code example of mishonorarios / mishonorarios-php

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

    

mishonorarios / mishonorarios-php example snippets


use MisHonorarios\Client;

$mishonorarios = new Client('https://tu-dominio/api/v1', 'mishonorarios_tu_token');

// Estado del emisor y del plan
$me = $mishonorarios->me();
echo $me['plan']['disponibles']; // cupo restante

// Emitir una boleta (receptor nacional)
$boleta = $mishonorarios->boletas()->emit([
    'receptor' => [
        'rut' => '12.345.678-5',
        'nombre' => 'Cliente SpA',
        'direccion' => 'Av. Siempre Viva 123',
        'region_code' => '13',
        'comuna_code' => '13101',
    ],
    'detalle' => [
        ['descripcion' => 'Asesoría contable abril', 'monto' => 120000],
    ],
]);
echo $boleta['folio'];

// Descargar el PDF (las boletas se identifican por su folio del SII)
file_put_contents('boleta.pdf', $mishonorarios->boletas()->pdf($boleta['folio']));

// Listar boletas
$lista = $mishonorarios->boletas()->list(['per_page' => 50, 'status' => 'issued']);

// Anular (por folio)
$mishonorarios->boletas()->cancel($boleta['folio'], causa: 3);

// Clientes
$mishonorarios->clientes()->create(['rut' => '11.111.111-1', 'nombre' => 'Otro Cliente']);

$mishonorarios->boletas()->emit([
    'receptor' => ['extranjero' => true, 'nombre' => 'Acme Inc. (USA)', 'direccion' => 'Miami, USA'],
    'detalle' => [['descripcion' => 'Desarrollo de software', 'monto' => 500000]],
]);

$mishonorarios->boletas()->emit([
    'receptor' => ['sin_receptor' => true, 'nombre' => 'Consumidor final'],
    'detalle' => [['descripcion' => 'Servicio', 'monto' => 30000]],
]);

use MisHonorarios\Exceptions\{AuthException, ValidationException, SiiException, RateLimitException};

try {
    $mishonorarios->boletas()->emit($payload);
} catch (ValidationException $e) {
    print_r($e->errors());        // errores por campo (422)
} catch (SiiException $e) {
    if ($e->recoverable) { /* la boleta pudo emitirse: sincroniza */ }
} catch (RateLimitException $e) {
    // espera y reintenta (429)
} catch (AuthException $e) {
    // token inválido o sin permisos (401/403)
}
bash
composer