1. Go to this page and download the library: Download flavytech/laravel-etims 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/ */
flavytech / laravel-etims example snippets
use Flavytech\Etims\Facades\Etims;
use Flavytech\Etims\DTOs\InvoiceDTO;
use Flavytech\Etims\DTOs\InvoiceLineDTO;
$invoice = InvoiceDTO::make([
'invcNo' => 'INV-2024-001',
'tpin' => config('etims.credentials.pin'),
'custTpin' => 'P000000000B', // buyer's KRA PIN
'custNm' => 'Acme Ltd',
'totAmt' => 11600.00,
'vatAmt' => 1600.00,
'taxblAmt' => 10000.00,
'salesDt' => now()->toDateString(),
'cfmDt' => now()->toDateString(),
'rcptTyCd' => 'S', // S = Sale
'pmtTyCd' => '01',
'itemList' => [
InvoiceLineDTO::make([
'itemSeq' => 1,
'itemCd' => 'ITEM-001',
'itemNm' => 'Widget Pro',
'qty' => 2,
'prc' => 5000.00,
'taxblAmt' => 10000.00,
'taxAmt' => 1600.00,
'totAmt' => 11600.00,
'taxTyCd' => 'A', // A = Standard 16% VAT
]),
],
]);
$response = Etims::submitInvoice($invoice);
if ($response->isSuccessful()) {
// Print the KRA receipt number and QR code
$receiptNumber = $response->receiptNumber;
$qrCode = $response->qrCode;
}
// Fire and forget — returns immediately
Etims::queueInvoice($invoice);
// Your application continues while KRA processes in the background.
// Listen to events to know the outcome:
protected $listen = [
\Flavytech\Etims\Events\InvoiceSubmitted::class => [
\App\Listeners\GenerateKraReceipt::class, // generate receipt PDF
\App\Listeners\UpdateOrderStatus::class, // mark order as fiscalized
],
\Flavytech\Etims\Events\InvoiceFailed::class => [
\App\Listeners\AlertOperationsTeam::class, // notify via Slack/email
\App\Listeners\FlagOrderForReview::class, // mark in your system
],
\Flavytech\Etims\Events\InvoiceQueued::class => [
\App\Listeners\ShowPendingStatus::class, // update POS UI immediately
],
];
$result = Etims::validatePin('P000000000B');
if ($result->isValid()) {
echo "Buyer: {$result->taxpayerName}";
} else {
// PIN not found in KRA registry
return back()->withError('Invalid buyer PIN. Please verify and try again.');
}
$status = Etims::getInvoiceStatus('INV-2024-001');
if ($status->isSuccessful()) {
echo "Receipt: {$status->receiptNumber}";
} elseif ($status->isPending()) {
echo "KRA is still processing this invoice.";
}
// Get all permanently failed invoices for review
$failedInvoices = Etims::failedInvoices();
foreach ($failedInvoices as $invoice) {
echo "{$invoice->invoice_number}: {$invoice->failure_reason}";
}
// Re-queue a failed invoice after fixing the issue
Etims::retryFailedInvoice($invoice->id);