https://github.com/MukhtarSayedSaleh/saudi-zakat-qr-generator I can include this library in opencart 2 easily since it is pure php but how can I include it in twig files, or any php library.
how could I use the following code in admin/view/template/sale/order_invoice.twig
require __DIR__ . '/vendor/autoload.php';
use MuktarSayedSaleh\ZakatTlv\Encoder;
$encoder = new Encoder();
$qr_signature = $encoder->encode(
"Sparehub",
"1234567890",
null,
10000,
150
);
var_dump($qr_signature);
Edit: I'm trying to create it as a library in system/library/ZakatTlv/Encoder.php
<?php
namespace ZakatTlv;
use DateTime;
use ZakatTlv\Tag;
class Encoder {
public function __construct($registry) {
$this->config = $registry->get('config');
$this->db = $registry->get('db');
$this->request = $registry->get('request');
$this->session = $registry->get('session');
$this->registry = $registry;
}
public function encode(
string $seller_name,
string $seller_vat_number,
string $timestamp=null,
float $total_amount,
float $vat_amount
) {
$now = new DateTime("now");
$timestamp = $timestamp ?? $now->format('Y-m-dTH:i:sP');
$components = [];
$index=0;
foreach([
$seller_name,
$seller_vat_number,
$timestamp,
$total_amount,
$vat_amount
] as $value){
$components[] = strval(
new Tag(++$index, $value)
);
}
//return $this->registry->get($components);
return base64_encode(
implode($components)
);
}
}
When I try to call it in the controller like this
$this->registry->set('ZakatTlv/Encoder', new Encoder($this->registry));
$Encoder->encode("Sparehub", "1234567890", null, 10000, 150);
I get this error Fatal error: Uncaught Error: Class 'Encoder' not found
So how could I register a library in opencart3