Skip to content

Instantly share code, notes, and snippets.

View brankoajzele's full-sized avatar

Branko Ajzele brankoajzele

View GitHub Profile
<?php
$UriId = uniqid();
$ns = 'tns';
$writer = new XMLWriter();
$writer->openMemory();
//$writer->startDocument('1.0', 'UTF-8');
<?php
function UUIDv4() {
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
mt_rand(0, 0xffff),
mt_rand(0, 0x0fff) | 0x4000,
mt_rand(0, 0x3fff) | 0x8000,
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
<?php
$oib = '11111111111';
$dt = new DateTime('now');
$datumVrijemeIzdavanjaRacuna = $dt->format('d.m.Y H:i:s'); /* use invoice created_at datetime here */
$brojcanaOznakaRacuna = '23'; /* 23/MAGE5/1 */
$oznakaPoslovnogProstora = 'MAGE5'; /* 23/MAGE5/1 */
$oznakaNaplatnogUredaja = '1'; /* 23/MAGE5/1 */
$ukupniIznosRacuna = '182.50';
<?php
$certificateCAcer = '/path/to/cert/democacert.cer';
$certificateCAcerContent = file_get_contents($certificateCAcer);
/* Convert .cer to .pem, cURL uses .pem */
$certificateCApemContent = '-----BEGIN CERTIFICATE-----'.PHP_EOL
.chunk_split(base64_encode($certificateCAcerContent), 64, PHP_EOL)
.'-----END CERTIFICATE-----'.PHP_EOL;
<?php
$certificate = null;
$certificatePass = 'MyCertPassHere';
$pfxCertificate = '/path/to/cert/fiskal-demo-aplikativni.pfx';
openssl_pkcs12_read(file_get_contents($pfxCertificate), $certificate, $certificatePass);
$publicCertificate = $certificate['cert'];
$privateKey = $certificate['pkey'];
@brankoajzele
brankoajzele / fiskalizacija.php
Last active December 1, 2022 17:26
Kompletan primjer fiskalizacije (Croatian fiscalization act/law).
<?php
/**
* @author Branko Ajzele <ajzele@gmail.com, http://foggyline.net>
*/
$XMLRequestType = 'RacunZahtjev'; /* RacunZahtjev OR PoslovniProstorZahtjev */
@brankoajzele
brankoajzele / getRandomString.php
Created January 22, 2013 07:40
Function that returns random string. Can be used for generating passwords.
<?php
/**
* Function taken from Magento eCommerce platform from /app/code/core/Mage/Core/Helper/Data.php file.
*
* @param $len
* @param null $chars
* @return string
*/
function getRandomString($len, $chars = null)
@brankoajzele
brankoajzele / cerToPem.php
Created January 21, 2013 13:13
Converting .cer to .pem via pure PHP, (no system, backticks, shell_exec, exec, etc.) to get the same result as with "openssl x509 -inform der -in cert.cer -out cert.pem". Note, I am not expert on certificates, etc. This specific certificate conversion simply worked for me.
<?php
$certificateCAcer = '/certificate.cer';
$certificateCAcerContent = file_get_contents($certificateCAcer);
/* Convert .cer to .pem, cURL uses .pem */
$certificateCApemContent = '-----BEGIN CERTIFICATE-----'.PHP_EOL
.chunk_split(base64_encode($certificateCAcerContent), 64, PHP_EOL)
.'-----END CERTIFICATE-----'.PHP_EOL;
@brankoajzele
brankoajzele / loto.php
Created January 19, 2013 08:14
Loto (random) number generator.
#!/usr/bin/php
<?php
/**
* Loto (random) number generator.
*
* Script accepts 3 params.
* First two are to determine the type of loto, for example 7 of 39, or 6 of 45.
* Third parameter is the number of combinations.
*
* By default it 7 of 39 and one combination.
@brankoajzele
brankoajzele / gist:4473443
Created January 7, 2013 08:52
Fiskalizacija - digitalni potpis
<?php
public function digitallySignXml($XMLContent, $ReferenceNodeName, $store)
{
$cert = Mage::getModel('inchoo_fiskalizacija/cert');
//$cert->load(Mage::app()->getWebsite()->getId(), 'website_id');
$cert->load(Mage::getModel('core/store')->load($store)->getWebsiteId(), 'website_id');
$doc = new DOMDocument();
$doc->loadXML($XMLContent);