Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nticaric committed Oct 18, 2023
1 parent 78b241e commit 19c8dce
Show file tree
Hide file tree
Showing 22 changed files with 172 additions and 417 deletions.
11 changes: 11 additions & 0 deletions src/Fiskalizacija.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use DOMElement;
use Exception;
use Nticaric\Fiskalizacija\SoapClient;
use Nticaric\Fiskalizacija\XMLSerializer;

class Fiskalizacija
{
Expand Down Expand Up @@ -200,4 +201,14 @@ public function parseResponse($response, $code = 4)

}

public function signAndSend($request)
{
$serializer = new XMLSerializer($request);
$xml = $serializer->toXml();

$soapMessage = $this->signXML($xml);

return $this->sendSoap($soapMessage);
}

}
32 changes: 32 additions & 0 deletions src/Generators/EchoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php namespace Nticaric\Fiskalizacija\Generators;

/**
* Class representing EchoRequest
*
* Poruka echo metodi.
*/
class EchoRequest
{
/**
* Poruka
*
* @var string $message
*/
private $message = null;

public function __construct($message)
{
$this->setMessage($message);
}

public function getMessage()
{
return $this->message;
}

public function setMessage(string $message)
{
$this->message = $message;
return $this;
}
}
6 changes: 5 additions & 1 deletion src/Generators/NapojnicaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class NapojnicaType
*/
private $nacinPlacanjaNapojnice = null;

public function __construct($iznosNapojnice, $nacinPlacanjaNapojnice)
{
$this->iznosNapojnice = number_format($iznosNapojnice, 2, '.', '');
$this->nacinPlacanjaNapojnice = $nacinPlacanjaNapojnice;
}
/**
* Gets as iznosNapojnice
*
Expand Down Expand Up @@ -64,4 +69,3 @@ public function setNacinPlacanjaNapojnice($nacinPlacanjaNapojnice)
return $this;
}
}

6 changes: 5 additions & 1 deletion src/Generators/NapojnicaZahtjev/NapojnicaZahtjevAType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class NapojnicaZahtjevAType
*/
private $signature = null;

public function __construct()
{
$this->setId(uniqid());
}

/**
* Gets as id
*
Expand Down Expand Up @@ -121,4 +126,3 @@ public function setSignature(?\Nticaric\Fiskalizacija\Generators\Xmldsig\Signatu
return $this;
}
}

19 changes: 19 additions & 0 deletions src/Generators/RacunNapojnicaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,4 +907,23 @@ public function setNapojnica(\Nticaric\Fiskalizacija\Generators\NapojnicaType $n
$this->napojnica = $napojnica;
return $this;
}

public function generirajZastKod($pkey, $oib, $dt, $bor, $opp, $onu, $uir)
{
$medjurezultat = "";
$medjurezultat .= $oib; // 1. OIB
$medjurezultat .= $dt; // 2. Datum i vrijeme izdavanja računa zapisan kao tekst u formatu 'dd.mm.gggg hh:mm:ss'
$medjurezultat .= $bor; // 3. Brojcana oznaka racuna
$medjurezultat .= $opp; // 4. Oznaka poslovnog prostora
$medjurezultat .= $onu; // 5. Oznaka naplatnog uređaja
$medjurezultat .= $uir; // 6. Ukupni iznos računa

$zastKodSignature = null;

if (!openssl_sign($medjurezultat, $zastKodSignature, $pkey, OPENSSL_ALGO_SHA1)) {
throw new \Exception('Error creating security code');
}

return $this->zastKod = md5($zastKodSignature);
}
}
12 changes: 12 additions & 0 deletions src/Metadata/Generators.EchoRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Nticaric\Fiskalizacija\Generators\EchoRequest:
xml_root_name: EchoRequest
xml_root_namespace: 'http://www.apis-it.hr/fin/2012/types/f73'
properties:
message:
expose: true
access_type: public_method
xml_value: true # This will treat the property as the XML value
accessor:
getter: getMessage
setter: setMessage
type: string
14 changes: 0 additions & 14 deletions tests/Bill/BillNumberTest.php

This file was deleted.

77 changes: 0 additions & 77 deletions tests/Bill/BillRequestTest.php

This file was deleted.

71 changes: 0 additions & 71 deletions tests/Bill/BillTest.php

This file was deleted.

14 changes: 0 additions & 14 deletions tests/Bill/RefundTest.php

This file was deleted.

14 changes: 0 additions & 14 deletions tests/Bill/TaxRateTest.php

This file was deleted.

7 changes: 5 additions & 2 deletions tests/EchoRequestTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

use Nticaric\Fiskalizacija\EchoRequest;
use Nticaric\Fiskalizacija\Generators\EchoRequest;
use Nticaric\Fiskalizacija\SoapClient;
use Nticaric\Fiskalizacija\XMLSerializer;
use PHPUnit\Framework\TestCase;

class EchoRequestTest extends TestCase
Expand All @@ -11,7 +12,9 @@ public function testMakeEchoRequest()
$message = "proizvoljan tekst";

$echoRequest = new EchoRequest($message);
$xml = $echoRequest->toXML();

$serializer = new XMLSerializer($echoRequest);
$xml = $serializer->toXml();

$soapClient = new SoapClient("https://cistest.apis-it.hr:8449/FiskalizacijaServiceTest");
$xmlEnvelope = $soapClient->addEnvelope($xml);
Expand Down
Loading

0 comments on commit 19c8dce

Please sign in to comment.