ifcon / einvoice
Einvoice package for Laravel: model, trait, interface, service, controller, and config.
v1.0.6
2025-11-11 12:28 UTC
Requires
- php: >=7.1.3 <8.4
- illuminate/support: ^5.8|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
README
This package intended to use for products of Ifcon Technology Sdn Bhd.
A lightweight Laravel package that provides a ready-to-use e-invoice structure with:
- Service class:
Ifcon\Einvoice\Services\EInvoisServices - Model:
Ifcon\Einvoice\Models\Einvoice(polymorphic to your models viamodelmorph)Ifcon\Einvoice\Models\EinvoiceCustomer(polymorphic to your user models viamodelmorph)
- Config:
config/einvoice.php - Trait:
Ifcon\Einvoice\Traits\HasEinvoiceIfcon\Einvoice\Traits\HasEinvoiceCustomer
- Interface:
Ifcon\Einvoice\Contracts\Einvoiceable
Tested compatible across Laravel 5.8 through 12 and PHP 7.1.3 through 8.3.
Installation
- Require the package (for local dev add a path or VCS repository in your app's
composer.json). Once on Packagist:
composer require ifcon/einvoice
- Publish config and migrations (optional but recommended):
php artisan vendor:publish --provider="Ifcon\\Einvoice\\Providers\\EinvoiceServiceProvider" --tag=einvoice-config
php artisan vendor:publish --provider="Ifcon\\Einvoice\\Providers\\EinvoiceServiceProvider" --tag=einvoice-migrations
- Run migrations:
php artisan migrate
The package auto-discovers its service provider; no manual registration needed.
Configuration
config/einvoice.php provides:
enable(defaultfalse)api.urlapi.keytable_nameseinvoices(defaulteinvoices)einvoice_customers(defaulteinvoice_customers)
default_status(defaultpending)
Database Schema
Table: einvoices (configurable)
idINTmodel_typeVARCHAR (nullable) — morph typemodel_idINT (nullable) — morph idstatusVARCHAR — status stringmetaJSON (nullable)- Timestamps
Table: einvoice_customers (configurable)
idINTmodel_typeVARCHAR — morph typemodel_idINT — morph idnameVARCHARemailVARCHAR (nullable)phone_numberVARCHAR (nullable)msic_codeVARCHAR (nullable)tourism_tax_numberVARCHAR (nullable)gst_numberVARCHAR (nullable)sst_numberVARCHAR (nullable)id_typeVARCHARid_numberVARCHARtinVARCHARaddress1VARCHARaddress2VARCHAR (nullable)address3VARCHAR (nullable)cityVARCHARpostcodeVARCHAR (nullable)stateVARCHAR (nullable)state_codecountry_code- Timestamps
Usage in Your Models
Implement the relation via the trait, and optionally the interface:
use Ifcon\Einvoice\Traits\HasEinvoice;
use Ifcon\Einvoice\Contracts\Einvoiceable;
class Order extends Model implements Einvoiceable
{
use HasEinvoice;
}
Add user as einvoice customer
use Ifcon\Einvoice\Traits\HasEinvoiceCustomer;
class User extends Authenticatable
{
use HasEinvoiceCustomer;
}
Send invoice to einvoice server
use Ifcon\Einvoice\Services\EInvoisServices;
$transaction = Transaction::find(1);
$invoice = [
'submitDocument' => 1,
'invoiceNumber' => $invoiceNumber,
'invoiceDate' => now()->setTimezone('UTC')->format('Y-m-d H:i:s'),
'type' => '01',
'currencyCode' => 'MYR',
'return_url' => 'https://{return_url}',
"supplier" => config('einvoice.supplier'),
];
$invoiceLines = [];
$line = [
'classificationCode' => '022',
'description' => 'Buy Report',
'quantity' => 1,
'measurementUnit' => "XUN",
'unitPrice' => $transaction->amount,
'taxes' => [
[
'taxType' => '06',
'taxRate' => 0,
]
]
];
$invoiceLines[] = $line;
$invoice['invoiceLines'] = $invoiceLines;
$result = app(EInvoisServices::class)->send_einvoice($invoice);
if ($result['status']) {
$response = $result['data'];
$einvoice = $transaction->einvoice()->updateOrCreate([
'status' => 'sent'
])
if (is_array($response) && isset($response['status']) && $response['status'] && isset($response['redirectUrl'])) {
return redirect($response['redirectUrl']);
}
return back()->with('flash_success', 'Request E-Invoice Success.');
}
Button request for Einvoice
For QR Code display on validation url, install qrcode package
composer require simplesoftwareio/simple-qrcode
@if (config('einvoice.enable') && $topup->currency2 == 'MYR' )
@if ($topup->eInvoiceNotValidated())
<div>
<div class="d-block text-center">
<a href="{{ route('frontend.user.transactions.receipt.einvoice', $topup) }}" class="btn btn-primary text-center mt-2 mt-sm-0 mb-0">Request E-Invoice</a>
</div>
</div>
@endif
@if ($validationUrl = $topup->eInvoiceValidationLink())
<div>
<div class="d-block text-right">
E-Invoice Validation Link:<br />
{!! QrCode::size(100)->generate($validationUrl); !!}
</div>
</div>
@endif
@endif
Packagist Notes
- Ensure your repository is public and submit it to Packagist as
ifcon/einvoice. - Tag releases (e.g.,
v1.0.0). - Keep
composer.jsonnameand autoload namespaces intact.
License
MIT