Skip to content

Commit

Permalink
refactor and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nticaric committed Oct 18, 2023
1 parent 19c8dce commit a774874
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 92 deletions.
134 changes: 68 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,73 +27,77 @@ Kao treći parametar konstruktora treba se postaviti `TLS` umjesto `SSL`. Ako bi

<?php

use Carbon\Carbon;
use Nticaric\Fiskalizacija\Fiskalizacija;
use Nticaric\Fiskalizacija\Bill\Bill;
use Nticaric\Fiskalizacija\Bill\Refund;
use Nticaric\Fiskalizacija\Bill\BillNumber;
use Nticaric\Fiskalizacija\Bill\TaxRate;
use Nticaric\Fiskalizacija\Bill\BillRequest;

$billNumber = new BillNumber(1, "ODV1", "1");
use Nticaric\Fiskalizacija\Generators\BrojRacunaType;
use Nticaric\Fiskalizacija\Generators\PorezOstaloType;
use Nticaric\Fiskalizacija\Generators\PorezType;
use Nticaric\Fiskalizacija\Generators\RacunType;
use Nticaric\Fiskalizacija\Generators\RacunZahtjev;
use Nticaric\Fiskalizacija\Generators\ZaglavljeType;

$listPdv = array();
$listPdv[] = new TaxRate(25.1, 400.1, 20.1, null);
$listPdv[] = new TaxRate(10.1, 500.1, 15.444, null);
$billNumber = new BrojRacunaType(1, "ODV1", "1");

$listPnp = array();
$listPnp[] = new TaxRate(30.1, 100.1, 10.1, null);
$listPnp[] = new TaxRate(20.1, 200.1, 20.1, null);
$listPdv = [];
$listPdv[] = new PorezType(25.1, 400.1, 20.1, null);
$listPdv[] = new PorezType(10.1, 500.1, 15.444, null);

$listOtherTaxRate = array();
$listOtherTaxRate[] = new TaxRate(40.1, 453.3, 12.1, "Naziv1");
$listOtherTaxRate[] = new TaxRate(27.1, 445.1, 50.1, "Naziv2");
$listPnp = [];
$listPnp[] = new PorezType(30.1, 100.1, 10.1, null);
$listPnp[] = new PorezType(20.1, 200.1, 20.1, null);


$bill = new Bill();
$listOtherTaxRate = [];
$listOtherTaxRate[] = new PorezOstaloType("Naziv1", 40.1, 453.3, 12.1);
$listOtherTaxRate[] = new PorezOstaloType("Naziv2", 27.1, 445.1, 50.1);
$bill = new RacunType();

$bill->setOib("32314900695");
$bill->setHavePDV(true);
$invoiceDate = "15.07.2014T20:00:00";
$bill->setDateTime($invoiceDate);
// $bill->setNoteOfOrder("P");
$bill->setBillNumber($billNumber);
$bill->setListPDV($listPdv);
$bill->setListPNP($listPnp);
$bill->setListOtherTaxRate($listOtherTaxRate);
$bill->setTaxFreeValue(23.5);
$bill->setMarginForTaxRate(32.0);
$bill->setTaxFree(5.1);
//$bill->setRefund(refund);
$totalValue = 456.1;
$bill->setTotalValue($totalValue);
$bill->setTypeOfPlacanje("G");
$bill->setOibOperative("34562123431");

$fis = new Fiskalizacija("path/to/demo.pfx", "password", "TLS", true);

$bill->setSecurityCode(
$bill->securityCode(
$fis->getPrivateKey(),
$bill->oib,
$bill->dateTime,
$billNumber->numberNoteBill,
$billNumber->noteOfBusinessArea,
$billNumber->noteOfExcangeDevice,
$bill->totalValue
)
$bill->setOznSlijed("P");
$bill->setUSustPdv(true);
$bill->setDatVrijeme("15.07.2014T20:00:00");

$bill->setBrRac($billNumber);
$bill->setPdv($listPdv);
$bill->setPnp($listPnp);
$bill->setOstaliPor($listOtherTaxRate);
$bill->setIznosOslobPdv(23.5);
$bill->setIznosMarza(32.0);
$bill->setIznosNePodlOpor(5.1);
$bill->setIznosUkupno(456.1);
$bill->setNacinPlac("G");
$bill->setOibOper("34562123431");

$fis = new Fiskalizacija(
$_ENV['CERTIFICATE_PATH'],
$_ENV['CERTIFICATE_PASSWORD'],
"TLS",
true
);

$zastKod = $bill->generirajZastKod(
$fis->getPrivateKey(),
$bill->getOib(),
$bill->getDatVrijeme(),
$billNumber->getBrOznRac(),
$billNumber->getOznPosPr(),
$billNumber->getOznNapUr(),
$bill->getIznosUkupno()
);

$bill->setNoteOfRedelivary(false);
$bill->setZastKod($zastKod);
$bill->setNakDost(false);

$billRequest = new BillRequest($bill);
$billRequest = new RacunZahtjev();
$billRequest->setRacun($bill);

$soapMessage = $fis->signXML($billRequest->toXML());
$response = $fis->sendSoap($soapMessage);
$zaglavlje = new ZaglavljeType;

$parser = new ResponseParser($response);
$jir = $parser->getJir();
$billRequest->setZaglavlje($zaglavlje);

$qrGenerator = new QRGenerator($jir, $invoiceDate, $totalValue);
$res = $fis->signAndSend($billRequest);
$jir = $res->getJir();

$qrGenerator = new QRGenerator($jir, "15.07.2014T20:00:00", 456.1);
echo $qrGenerator->generateUrl(); // Output the URL
//echo $qrGenerator->getQrCode(); // Output the base64-encoded QR code image
```
Expand Down Expand Up @@ -121,21 +125,19 @@ pa onda
```php

<?php
use Nticaric\Fiskalizacija\SoapClient;
use Nticaric\Fiskalizacija\XMLSerializer;
use Nticaric\Fiskalizacija\Generators\EchoRequest;

use Nticaric\Fiskalizacija\Fiskalizacija;
use Nticaric\Fiskalizacija\Test\Test;
use Nticaric\Fiskalizacija\Test\TestRequest;
use Carbon\Carbon;

$test = new Test();
$test->setMessage("testna poruka");
$message = "proizvoljan tekst";

$testRequest = new TestRequest($test);
$echoRequest = new EchoRequest($message);

$fis = new Fiskalizacija("./path/to/demo.pfx", "password", "TLS", true);
$serializer = new XMLSerializer($echoRequest);
$xml = $serializer->toXml();

$soapMessage = $fis->plainXML($testRequest->toXML());
$soapClient = new SoapClient("https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest");
$xmlEnvelope = $soapClient->addEnvelope($xml);

$res = $fis->sendSoap($soapMessage);
var_dump($res);
$res = $soapClient->send($xmlEnvelope);
```
5 changes: 5 additions & 0 deletions src/Fiskalizacija.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,9 @@ public function signAndSend($request)
return $this->sendSoap($soapMessage);
}

public function certificateInfo()
{
return openssl_x509_parse($this->certificate['cert']);
}

}
29 changes: 19 additions & 10 deletions tests/FiskalizacijaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ public function getRacunZahtjev()

$fis = $this->initializeFiskalizacija();

$bill->setZastKod(
$bill->generirajZastKod(
$fis->getPrivateKey(),
$bill->getOib(),
$bill->getDatVrijeme(),
$billNumber->getBrOznRac(),
$billNumber->getOznPosPr(),
$billNumber->getOznNapUr(),
$bill->getIznosUkupno()
)
$zastKod = $bill->generirajZastKod(
$fis->getPrivateKey(),
$bill->getOib(),
$bill->getDatVrijeme(),
$billNumber->getBrOznRac(),
$billNumber->getOznPosPr(),
$billNumber->getOznNapUr(),
$bill->getIznosUkupno()
);

$bill->setZastKod($zastKod);
$bill->setNakDost(false);

$billRequest = new RacunZahtjev();
Expand All @@ -126,4 +126,13 @@ public function getRacunZahtjev()
return $billRequest;
}

public function testDumpCertificate()
{
$fis = $this->initializeFiskalizacija();

$info = $fis->certificateInfo();

$this->assertEquals("Financijska agencija", $info['issuer']['O']);
}

}
90 changes: 74 additions & 16 deletions tests/NapojnicaRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,35 @@

class NapojnicaRequestTest extends TestCase
{
private function initializeFiskalizacija(): Fiskalizacija
{
return new Fiskalizacija(
$_ENV['CERTIFICATE_PATH'],
$_ENV['CERTIFICATE_PASSWORD'],
"TLS",
true
);
}

public function testBillSNapojnicom()
{
$bill = $this->generateNapojnicaBill();
$racun = $this->generateBill();
$napojnicaRacun = $this->generateNapojnicaBill();

$napojnica = new NapojnicaType(2.00, "T");
$bill->setNapojnica($napojnica);
$napojnicaRacun->setNapojnica(new NapojnicaType(2.00, "T"));

$napojnicaZahtjev = new NapojnicaZahtjev;
$napojnicaZahtjev->setZaglavlje(new ZaglavljeType);
$napojnicaZahtjev->setRacun($bill);
$napojnicaZahtjev->setRacun($napojnicaRacun);

$fis = new Fiskalizacija(
$_ENV['CERTIFICATE_PATH'],
$_ENV['CERTIFICATE_PASSWORD'],
"TLS", true);
$racunZahtjev = new RacunZahtjev;
$racunZahtjev->setZaglavlje(new ZaglavljeType);
$racunZahtjev->setRacun($racun);

$serializer = new XMLSerializer($napojnicaZahtjev);
$xml = $serializer->toXml();
$fis = $this->initializeFiskalizacija();

$signed = $fis->signXML($xml);
$napojnicaRes = $fis->sendSoap($signed);
$racunRes = $fis->signAndSend($racunZahtjev);
$napojnicaRes = $fis->signAndSend($napojnicaZahtjev);

$sifraPoruke = $napojnicaRes->query('/soap:Envelope/soap:Body/tns:NapojnicaOdgovor/tns:PorukaOdgovora/tns:SifraPoruke')[0]->nodeValue;
$poruka = $napojnicaRes->query('/soap:Envelope/soap:Body/tns:NapojnicaOdgovor/tns:PorukaOdgovora/tns:Poruka')[0]->nodeValue;
Expand Down Expand Up @@ -109,10 +117,7 @@ public function generateNapojnicaBill()
$bill->setNacinPlac("G");
$bill->setOibOper("34562123431");

$fis = new Fiskalizacija(
$_ENV['CERTIFICATE_PATH'],
$_ENV['CERTIFICATE_PASSWORD'],
"TLS", true);
$fis = $this->initializeFiskalizacija();

$bill->setZastKod(
$bill->generirajZastKod(
Expand All @@ -125,6 +130,59 @@ public function generateNapojnicaBill()
$bill->getIznosUkupno()
)
);

$bill->setNakDost(false);

return $bill;
}

public function generateBill()
{
$billNumber = new BrojRacunaType(1, "ODV1", "1");

$listPdv = [];
$listPdv[] = new PorezType(25.1, 400.1, 20.1, null);
$listPdv[] = new PorezType(10.1, 500.1, 15.444, null);

$listPnp = [];
$listPnp[] = new PorezType(30.1, 100.1, 10.1, null);
$listPnp[] = new PorezType(20.1, 200.1, 20.1, null);

$listOtherTaxRate = [];
$listOtherTaxRate[] = new PorezOstaloType("Naziv1", 40.1, 453.3, 12.1);
$listOtherTaxRate[] = new PorezOstaloType("Naziv2", 27.1, 445.1, 50.1);
$bill = new RacunType();

$bill->setOib("32314900695");
$bill->setOznSlijed("P");
$bill->setUSustPdv(true);
$bill->setDatVrijeme(\Carbon\Carbon::yesterday()->format('d.m.Y\TH:i:s'));

$bill->setBrRac($billNumber);
$bill->setPdv($listPdv);
$bill->setPnp($listPnp);
$bill->setOstaliPor($listOtherTaxRate);
$bill->setIznosOslobPdv(23.5);
$bill->setIznosMarza(32.0);
$bill->setIznosNePodlOpor(5.1);
$bill->setIznosUkupno(456.1);
$bill->setNacinPlac("G");
$bill->setOibOper("34562123431");

$fis = $this->initializeFiskalizacija();

$bill->setZastKod(
$bill->generirajZastKod(
$fis->getPrivateKey(),
$bill->getOib(),
$bill->getDatVrijeme(),
$billNumber->getBrOznRac(),
$billNumber->getOznPosPr(),
$billNumber->getOznNapUr(),
$bill->getIznosUkupno()
)
);

$bill->setNakDost(false);

return $bill;
Expand Down

0 comments on commit a774874

Please sign in to comment.