ifcon/einvoice

Einvoice package for Laravel: model, trait, interface, service, controller, and config.

Installs: 17

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/ifcon/einvoice

v1.0.6 2025-11-11 12:28 UTC

This package is auto-updated.

Last update: 2025-11-11 04:34:05 UTC


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 via model morph)
    • Ifcon\Einvoice\Models\EinvoiceCustomer (polymorphic to your user models via model morph)
  • Config: config/einvoice.php
  • Trait:
    • Ifcon\Einvoice\Traits\HasEinvoice
    • Ifcon\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

  1. 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
  1. 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
  1. Run migrations:
php artisan migrate

The package auto-discovers its service provider; no manual registration needed.

Configuration

config/einvoice.php provides:

  • enable (default false)
  • api.url
  • api.key
  • table_names
    • einvoices (default einvoices)
    • einvoice_customers (default einvoice_customers)
  • default_status (default pending)

Database Schema

Table: einvoices (configurable)

  • id INT
  • model_type VARCHAR (nullable) — morph type
  • model_id INT (nullable) — morph id
  • status VARCHAR — status string
  • meta JSON (nullable)
  • Timestamps

Table: einvoice_customers (configurable)

  • id INT
  • model_type VARCHAR — morph type
  • model_id INT — morph id
  • name VARCHAR
  • email VARCHAR (nullable)
  • phone_number VARCHAR (nullable)
  • msic_code VARCHAR (nullable)
  • tourism_tax_number VARCHAR (nullable)
  • gst_number VARCHAR (nullable)
  • sst_number VARCHAR (nullable)
  • id_type VARCHAR
  • id_number VARCHAR
  • tin VARCHAR
  • address1 VARCHAR
  • address2 VARCHAR (nullable)
  • address3 VARCHAR (nullable)
  • city VARCHAR
  • postcode VARCHAR (nullable)
  • state VARCHAR (nullable)
  • state_code
  • country_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.json name and autoload namespaces intact.

License

MIT