Update: 2026-05-04 02:29:13
This commit is contained in:
72
app/core/JoFotara.php
Normal file
72
app/core/JoFotara.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
/**
|
||||
* JoFotara (Jordan E-Invoicing) Integration Core
|
||||
* Handles UBL 2.1 XML Generation, Cryptography, and API Communication
|
||||
*/
|
||||
class JoFotara
|
||||
{
|
||||
private string $clientId;
|
||||
private string $secretKey;
|
||||
private string $environment;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
// Load credentials from DB or Environment
|
||||
$this->clientId = env('JOFOTARA_CLIENT_ID', '');
|
||||
$this->secretKey = env('JOFOTARA_SECRET', '');
|
||||
$this->environment = env('JOFOTARA_ENV', 'sandbox'); // sandbox or production
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. Generate UBL 2.1 XML for an invoice
|
||||
*/
|
||||
public function generateXML(array $invoiceData): string
|
||||
{
|
||||
// To be implemented: Full XML DOM Document generation based on UBL 2.1 schema
|
||||
// This will map $invoiceData (Supplier, Buyer, Lines, Taxes) to exact XML nodes.
|
||||
return "<Invoice><dummy>This will be full UBL 2.1 XML</dummy></Invoice>";
|
||||
}
|
||||
|
||||
/**
|
||||
* 2. Generate Base64 TLV QR Code (required by Jordan Tax Authority)
|
||||
* Tag 1: Seller Name
|
||||
* Tag 2: Tax Number
|
||||
* Tag 3: Timestamp
|
||||
* Tag 4: Invoice Total
|
||||
* Tag 5: VAT Total
|
||||
*/
|
||||
public function generateQRCode(array $invoiceData): string
|
||||
{
|
||||
$sellerName = $invoiceData['supplier_name'] ?? '';
|
||||
$taxNumber = $invoiceData['supplier_tin'] ?? '';
|
||||
$timestamp = date('Y-m-d\TH:i:s\Z', strtotime($invoiceData['invoice_date'] ?? 'now'));
|
||||
$total = number_format($invoiceData['grand_total'] ?? 0, 3, '.', '');
|
||||
$vat = number_format($invoiceData['tax_amount'] ?? 0, 3, '.', '');
|
||||
|
||||
$tlv = $this->toTLV(1, $sellerName) .
|
||||
$this->toTLV(2, $taxNumber) .
|
||||
$this->toTLV(3, $timestamp) .
|
||||
$this->toTLV(4, $total) .
|
||||
$this->toTLV(5, $vat);
|
||||
|
||||
return base64_encode($tlv);
|
||||
}
|
||||
|
||||
private function toTLV(int $tag, string $value): string
|
||||
{
|
||||
return chr($tag) . chr(strlen($value)) . $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 3. Submit Invoice to JoFotara API
|
||||
*/
|
||||
public function submitInvoice(string $xmlContent): array
|
||||
{
|
||||
// To be implemented: cURL request to JoFotara Core API
|
||||
// Requires ECDSA signing of the XML before submission
|
||||
return ['success' => true, 'uuid' => 'dummy-jofotara-id'];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user