diff --git a/README.md b/README.md index d527c97..661055e 100644 --- a/README.md +++ b/README.md @@ -27,73 +27,77 @@ Kao treći parametar konstruktora treba se postaviti `TLS` umjesto `SSL`. Ako bi 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 ``` @@ -121,21 +125,19 @@ pa onda ```php 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); ``` diff --git a/src/Fiskalizacija.php b/src/Fiskalizacija.php index f6bc809..8a8511a 100644 --- a/src/Fiskalizacija.php +++ b/src/Fiskalizacija.php @@ -211,4 +211,9 @@ public function signAndSend($request) return $this->sendSoap($soapMessage); } + public function certificateInfo() + { + return openssl_x509_parse($this->certificate['cert']); + } + } diff --git a/tests/FiskalizacijaTest.php b/tests/FiskalizacijaTest.php index 5b4cd91..4fd365f 100644 --- a/tests/FiskalizacijaTest.php +++ b/tests/FiskalizacijaTest.php @@ -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(); @@ -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']); + } + } diff --git a/tests/NapojnicaRequestTest.php b/tests/NapojnicaRequestTest.php index 38994fc..9b52733 100644 --- a/tests/NapojnicaRequestTest.php +++ b/tests/NapojnicaRequestTest.php @@ -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; @@ -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( @@ -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;