-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathFiskalResponseXML.php
61 lines (47 loc) · 1.36 KB
/
FiskalResponseXML.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class FiskalResponseXML
{
private $allowedTypes;
/**
* @param string $xml
*/
public function __construct($xml) {
$this->doc = new DOMDocument();
$this->doc->loadXML($xml);
$this->allowedTypes = array(
'RacunOdgovor', 'PoslovniProstorOdgovor'
);
}
public function getJIR() {
if ($jir = $this->doc->getElementsByTagName('Jir')->item(0)) {
return $jir->nodeValue;
}
return false;
}
public function getType() {
foreach ($this->allowedTypes as $type) {
if ($this->doc->getElementsByTagName($type)->item(0)) {
return $type;
}
}
return false;
}
/**
* @return bool|string Textual description of error, or FALSE if there are no errors
*/
public function getErrorMessage() {
if ($e1 = $this->doc->getElementsByTagName('faultstring')->item(0)) {
return 'CODE0: ' . $e1->nodeValue;
}
if (!$this->doc->getElementsByTagName('Signature')) {
return 'CODE1: Signature not found in response';
}
if ($e2 = $this->doc->getElementsByTagName('PorukaGreske')->item(0)) {
return 'CODE2: ' . $e2->nodeValue;
}
return false;
}
public function saveXML(){
return $this->doc->saveXML();
}
}