PHP code example of jonathan8312 / plemsi-laravel

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

    

jonathan8312 / plemsi-laravel example snippets


use Jonathan8312\Plemsi\Plemsi;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\Invoices\InvoiceData;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\DocumentCustomerData;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\DocumentItem;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\AdValoremTax;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\Payment;
use Jonathan8312\Plemsi\DataTransferObjects\Requests\DocumentLookupField;

$plemsi = app(Plemsi::class);

$response = $plemsi->invoices()->create(new InvoiceData(
    date: '2026-01-01',
    time: '10:00:00',
    prefix: 'SETT',
    number: 1,
    customer: new DocumentCustomerData(
        identificationNumber: '1067987456',
        name: 'Cliente de Ejemplo',
        typeDocumentIdentificationId: 3,
    ),
    items: [new DocumentItem(
        unitMeasureId: 70,
        lineExtensionAmount: 100000,
        freeOfChargeIndicator: false,
        description: 'Servicio de ejemplo',
        code: 'ITEM-1',
        typeItemIdentificationId: 4,
        priceAmount: 100000,
        baseQuantity: 1,
        invoicedQuantity: 1,
        taxTotals: [new AdValoremTax(taxId: 1, percent: 19, taxAmount: 19000, taxableAmount: 100000)],
    )],
    resolution: '18760000001',
    invoiceBaseTotal: 100000,
    invoiceTaxExclusiveTotal: 100000,
    invoiceTaxInclusiveTotal: 119000,
    totalToPay: 119000,
    payment: new Payment(paymentFormId: 1, paymentMethodId: 10, paymentDueDate: '2026-01-31', durationMeasure: '30'),
    allTaxTotals: [new AdValoremTax(taxId: 1, taxAmount: 19000, percent: 19, taxableAmount: 100000)],
));

$response->json();

// Later, look it up again:
$plemsi->invoices()->find(DocumentLookupField::Cude, $cude);

use Jonathan8312\Plemsi\Plemsi;

$plemsi = app(Plemsi::class);

$acme = $plemsi->withToken($acmeCompanyToken);
$acme->invoices()->all();

use Jonathan8312\Plemsi\Exceptions\PlemsiException;

try {
    $plemsi->invoices()->create($invoice);
} catch (PlemsiException $exception) {
    $exception->statusCode(); // ?int
    $exception->endpoint();   // ?string, e.g. "POST /api/billing/invoice"
    $exception->response();   // ?PlemsiResponse — raw status/body/json/headers
}

use Illuminate\Support\Facades\Http;

Http::fake(['*' => Http::response(['ok' => true], 200)]);

$plemsi = app(Plemsi::class);
// every call this SDK makes, including via withToken(), is now faked
bash
php artisan vendor:publish --tag=plemsi-config