Skip to content

Commit

Permalink
Merge pull request #4 from hubgit3/master
Browse files Browse the repository at this point in the history
Support for Test Request and several fixes
  • Loading branch information
nticaric committed Jan 4, 2015
2 parents 02b2801 + 4eef9a5 commit df9d630
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 10 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,27 @@ $soapMessage = $fis->signXML($businessAreaRequest->toXML());
$res = $fis->sendSoap($soapMessage);
var_dump($res);
```

###Primjer testne poruke:

```php

<?php

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

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

$testRequest = new TestRequest($test);

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

$soapMessage = $fis->plainXML($testRequest->toXML());

$res = $fis->sendSoap($soapMessage);
var_dump($res);
```
12 changes: 7 additions & 5 deletions src/Bill/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,13 @@ public function toXML()
$writer->writeRaw($this->billNumber->toXML());

/*********** PDV *****************************/
$writer->startElementNs($ns, 'Pdv', null);
foreach ($this->listPDV as $pdv) {
$writer->writeRaw($pdv->toXML());
}
$writer->endElement();
if (!empty($this->listPDV)) {
$writer->startElementNs($ns, 'Pdv', null);
foreach ($this->listPDV as $pdv) {
$writer->writeRaw($pdv->toXML());
}
$writer->endElement();
}
/*********************************************/

/*********** PNP *****************************/
Expand Down
17 changes: 16 additions & 1 deletion src/Business/AddressData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ class AddressData

public $address;

public $otherTypeOfBusinessArea;

public function setAddress(Address $address)
{
$this->address = $address;
}

public function setOtherTypeOfBusinessArea($otherTypeOfBusinessArea)
{
$this->otherTypeOfBusinessArea = $otherTypeOfBusinessArea;
}

public function toXML()
{
$ns = 'tns';
Expand All @@ -22,7 +29,15 @@ public function toXML()
$writer->setIndent(true);
$writer->setIndentString(" ");
$writer->startElementNs($ns, 'AdresniPodatak', null);
$writer->writeRaw($this->address->toXML());

if($this->address) {
$writer->writeRaw($this->address->toXML());
}

if($this->otherTypeOfBusinessArea) {
$writer->writeElementNs($ns, 'OstaliTipoviPP', null, $this->otherTypeOfBusinessArea);
}

$writer->endElement();

return $writer->outputMemory();
Expand Down
12 changes: 9 additions & 3 deletions src/Business/BusinessArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,22 @@ public function toXML()
$writer->startElementNs($ns, 'PoslovniProstor', null);
$writer->writeElementNs($ns, 'Oib', null, $this->oib);
$writer->writeElementNs($ns, 'OznPoslProstora', null, $this->noteOfBusinessArea);
//AdresniPodatak
$writer->writeRaw($this->addressData->toXML());

if($this->addressData) {
$writer->writeRaw($this->addressData->toXML());
}

$writer->writeElementNs($ns, 'RadnoVrijeme', null, $this->workingTime);
$writer->writeElementNs($ns, 'DatumPocetkaPrimjene', null, $this->dateOfusage);

if($this->noteOfClosing != NULL) {
$writer->writeElementNs($ns, 'OznakaZatvaranja', null, $this->noteOfClosing);
}

$writer->writeElementNs($ns, 'SpecNamj', null, $this->specificPurpose);
if($this->specificPurpose != NULL) {
$writer->writeElementNs($ns, 'SpecNamj', null, $this->specificPurpose);
}

$writer->endElement();

return $writer->outputMemory();
Expand Down
21 changes: 21 additions & 0 deletions src/Fiskalizacija.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ public function signXML($XMLRequest)
return $envelope->saveXML();
}

public function plainXML($XMLRequest)
{
$XMLRequestDOMDoc = new DOMDocument();
$XMLRequestDOMDoc->loadXML($XMLRequest);

$envelope = new DOMDocument();

$envelope->loadXML('<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body></soapenv:Body>
</soapenv:Envelope>');

$envelope->encoding = 'UTF-8';
$envelope->version = '1.0';
$XMLRequestType = $XMLRequestDOMDoc->documentElement->localName;
$XMLRequestTypeNode = $XMLRequestDOMDoc->getElementsByTagName($XMLRequestType)->item(0);
$XMLRequestTypeNode = $envelope->importNode($XMLRequestTypeNode, true);

$envelope->getElementsByTagName('Body')->item(0)->appendChild($XMLRequestTypeNode);
return $envelope->saveXML();
}

public function sendSoap($payload)
{
$ch = curl_init();
Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toXML()
$writer->writeAttribute('Id', uniqid());
$writer->startElementNs($ns, 'Zaglavlje', null);
$writer->writeElementNs($ns, 'IdPoruke', null, $this->generateUUID());
$writer->writeElementNs($ns, 'DatumVrijeme', null, \Carbon\Carbon::now()->format('d.m.Y\Th:i:s'));
$writer->writeElementNs($ns, 'DatumVrijeme', null, \Carbon\Carbon::now()->format('d.m.Y\TH:i:s'));
$writer->endElement();

$writer->writeRaw($this->request->toXML());
Expand Down
31 changes: 31 additions & 0 deletions src/Test/Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php namespace Nticaric\Fiskalizacija\Test;

use XMLWriter;

class Test
{

public $message = "";

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

public function toXML()
{
$ns = 'tns';

$writer = new XMLWriter();
$writer->openMemory();

$writer->setIndent(true);
$writer->setIndentString(" ");

$writer->writeRaw($this->message);
$writer->endElement();

return $writer->outputMemory();
}

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

use Nticaric\Fiskalizacija\Request;
use XMLWriter;

class TestRequest extends Request
{
public function __construct(Test $test)
{
$this->request = $test;
$this->requestName = 'EchoRequest';
}

public function toXML()
{
$ns = 'tns';

$writer = new XMLWriter();
$writer->openMemory();

$writer->setIndent(true);
$writer->setIndentString(" ");
$writer->startElementNs($ns, $this->requestName, 'http://www.apis-it.hr/fin/2012/types/f73');
$writer->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$writer->writeAttribute('xsi:schemaLocation', 'http://www.apis-it.hr/fin/2012/types/f73 FiskalizacijaSchema.xsd');
$writer->writeRaw($this->request->toXML());
$writer->endElement();

return $writer->outputMemory();

}
}

0 comments on commit df9d630

Please sign in to comment.