|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace OrcaServices\NovaApi\Method; |
|
4
|
|
|
|
|
5
|
|
|
use DOMDocument; |
|
6
|
|
|
use DOMElement; |
|
7
|
|
|
use Exception; |
|
8
|
|
|
use OrcaServices\NovaApi\Parameter\NovaSearchServicesParameter; |
|
9
|
|
|
use OrcaServices\NovaApi\Parser\NovaApiErrorParser; |
|
10
|
|
|
use OrcaServices\NovaApi\Parser\NovaMessageParser; |
|
11
|
|
|
use OrcaServices\NovaApi\Result\NovaSearchServicesResult; |
|
12
|
|
|
use OrcaServices\NovaApi\Result\NovaServiceResult; |
|
13
|
|
|
use OrcaServices\NovaApi\Soap\NovaApiSoapAction; |
|
14
|
|
|
use OrcaServices\NovaApi\Xml\XmlDocument; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* SOAP method. |
|
18
|
|
|
*/ |
|
19
|
|
|
final class NovaSearchServicesMethod implements NovaMethod |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var NovaApiSoapAction |
|
23
|
|
|
*/ |
|
24
|
|
|
private $novaSoapAction; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var NovaApiErrorParser |
|
28
|
|
|
*/ |
|
29
|
|
|
private $novaErrorParser; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var NovaMessageParser |
|
33
|
|
|
*/ |
|
34
|
|
|
private $novaMessageParser; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* NovaSearchPartnerMethod constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param NovaApiSoapAction $novaSoapAction The novaSoapAction |
|
40
|
|
|
* @param NovaApiErrorParser $novaErrorParser The novaErrorParser |
|
41
|
|
|
* @param NovaMessageParser $novaMessageParser The message parser |
|
42
|
|
|
*/ |
|
43
|
11 |
|
public function __construct( |
|
44
|
|
|
NovaApiSoapAction $novaSoapAction, |
|
45
|
|
|
NovaApiErrorParser $novaErrorParser, |
|
46
|
|
|
NovaMessageParser $novaMessageParser |
|
47
|
|
|
) { |
|
48
|
11 |
|
$this->novaSoapAction = $novaSoapAction; |
|
49
|
11 |
|
$this->novaErrorParser = $novaErrorParser; |
|
50
|
11 |
|
$this->novaMessageParser = $novaMessageParser; |
|
51
|
11 |
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Search NOVA services (customer) for a customer. |
|
55
|
|
|
* |
|
56
|
|
|
* https://confluence-ext.sbb.ch/display/NOVAUG/sucheLeistungen |
|
57
|
|
|
* |
|
58
|
|
|
* @param NovaSearchServicesParameter $parameter The parameters |
|
59
|
|
|
* |
|
60
|
|
|
* @return NovaSearchServicesResult the services matching the search parameter |
|
61
|
|
|
* @throws Exception if an error occurs |
|
62
|
|
|
* |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function searchServices(NovaSearchServicesParameter $parameter): NovaSearchServicesResult |
|
65
|
|
|
{ |
|
66
|
|
|
// The SOAP endpoint url |
|
67
|
1 |
|
$url = $this->novaSoapAction->getNovaSalesServiceUrl(); |
|
68
|
|
|
|
|
69
|
|
|
// The SOAP action (http header) |
|
70
|
1 |
|
$soapAction = $this->novaSoapAction->getSoapAction('geschaeftspartner', 'sucheLeistungen'); |
|
71
|
|
|
|
|
72
|
|
|
// The SOAP content (http body) |
|
73
|
1 |
|
$body = $this->createRequestBody($parameter); |
|
74
|
|
|
|
|
75
|
|
|
try { |
|
76
|
1 |
|
$xmlContent = $this->novaSoapAction->invokeSoapRequest($url, $soapAction, $body); |
|
77
|
1 |
|
$xml = XmlDocument::createFromXmlString($xmlContent); |
|
78
|
|
|
|
|
79
|
1 |
|
return $this->createResult($xml); |
|
80
|
|
|
} catch (Exception $exception) { |
|
81
|
|
|
throw $this->novaErrorParser->createGeneralException($exception); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Create SOAP body XML content. |
|
87
|
|
|
* |
|
88
|
|
|
* @param NovaSearchServicesParameter $parameter The parameters |
|
89
|
|
|
* |
|
90
|
|
|
* @return string The xml content |
|
91
|
|
|
*/ |
|
92
|
1 |
|
private function createRequestBody(NovaSearchServicesParameter $parameter): string |
|
93
|
|
|
{ |
|
94
|
1 |
|
$dom = new DOMDocument('1.0', 'utf-8'); |
|
95
|
1 |
|
$dom->formatOutput = true; |
|
96
|
|
|
|
|
97
|
1 |
|
$dom->appendChild($dom->createComment(' powered by Barakuda ')); |
|
98
|
|
|
|
|
99
|
1 |
|
$envelope = $dom->createElement('soapenv:Envelope'); |
|
100
|
1 |
|
$dom->appendChild($envelope); |
|
101
|
1 |
|
$envelope->setAttribute('xmlns:soapenv', 'http://schemas.xmlsoap.org/soap/envelope/'); |
|
102
|
|
|
|
|
103
|
1 |
|
$soapHeader = $dom->createElement('soapenv:Header'); |
|
104
|
1 |
|
$envelope->appendChild($soapHeader); |
|
105
|
|
|
|
|
106
|
1 |
|
$body = $dom->createElement('soapenv:Body'); |
|
107
|
1 |
|
$envelope->appendChild($body); |
|
108
|
|
|
|
|
109
|
1 |
|
$method = $dom->createElement('sucheLeistungen'); |
|
110
|
1 |
|
$body->appendChild($method); |
|
111
|
|
|
|
|
112
|
1 |
|
$searchQuery = $dom->createElement('leistungsSuchRequest'); |
|
113
|
1 |
|
$this->novaSoapAction->appendDomClientIdentifier($dom, $searchQuery, $parameter, ''); |
|
114
|
1 |
|
$this->novaSoapAction->appendDomCorrelationContext($dom, $searchQuery, $parameter, ''); |
|
115
|
|
|
|
|
116
|
1 |
|
$service = $dom->createElement('leistung'); |
|
117
|
1 |
|
$tkid = $dom->createElement('tkid'); |
|
118
|
1 |
|
$tkid->appendChild($dom->createTextNode($parameter->tkId)); |
|
119
|
1 |
|
$service->appendChild($tkid); |
|
120
|
1 |
|
$searchQuery->appendChild($service); |
|
121
|
1 |
|
$method->appendChild($searchQuery); |
|
122
|
|
|
|
|
123
|
1 |
|
$this->novaSoapAction->appendMethodNamespaces($method); |
|
124
|
|
|
|
|
125
|
1 |
|
return (string)$dom->saveXML(); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Create result object. |
|
130
|
|
|
* |
|
131
|
|
|
* @param XmlDocument $xml The xml document |
|
132
|
|
|
* |
|
133
|
|
|
* @return NovaSearchServicesResult The mapped result |
|
134
|
|
|
*/ |
|
135
|
1 |
|
private function createResult(XmlDocument $xml): NovaSearchServicesResult |
|
136
|
|
|
{ |
|
137
|
1 |
|
$result = new NovaSearchServicesResult(); |
|
138
|
|
|
|
|
139
|
1 |
|
$xml = $xml->withoutNamespaces(); |
|
140
|
|
|
|
|
141
|
|
|
// Find and append all messages |
|
142
|
1 |
|
foreach ($this->novaMessageParser->findNovaMessages($xml) as $message) { |
|
143
|
|
|
$result->addMessage($message); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
// Root node |
|
147
|
1 |
|
$responseNode = $xml->queryFirstNode('/Envelope/Body/sucheLeistungenResponse/leistungsSuchResponse'); |
|
148
|
1 |
|
$serviceNodes = $xml->queryNodes('leistungsSuchErgebnis/leistung', $responseNode); |
|
149
|
|
|
|
|
150
|
|
|
/** @var DOMElement $serviceNode */ |
|
151
|
1 |
|
foreach ($serviceNodes as $serviceNode) { |
|
152
|
1 |
|
$result->addService($this->createService($serviceNode, $xml)); |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
1 |
|
return $result; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Map partner node to NovaPartner object. |
|
160
|
|
|
* |
|
161
|
|
|
* @param DOMElement $serviceNode The partnerNode |
|
162
|
|
|
* @param XmlDocument $xml The xml document |
|
163
|
|
|
* |
|
164
|
|
|
* @return NovaServiceResult The new NovaService instance |
|
165
|
|
|
*/ |
|
166
|
1 |
|
private function createService(DOMElement $serviceNode, XmlDocument $xml): NovaServiceResult |
|
167
|
|
|
{ |
|
168
|
1 |
|
$service = new NovaServiceResult(); |
|
169
|
|
|
|
|
170
|
1 |
|
$service->tkId = $xml->findNodeValue('verkaufsParameter/wert/tkid', $serviceNode); |
|
171
|
1 |
|
$service->validFrom = $xml->createChronosFromXsDateTime( |
|
172
|
1 |
|
$xml->findAttributeValue('nutzungsInfo/nutzungsZeitraum/tarifierbarerZeitraum/@von', $serviceNode) |
|
|
|
|
|
|
173
|
|
|
); |
|
174
|
1 |
|
$service->validTo = $xml->createChronosFromXsDateTime( |
|
175
|
1 |
|
$xml->findAttributeValue('nutzungsInfo/nutzungsZeitraum/tarifierbarerZeitraum/@bis', $serviceNode) |
|
176
|
|
|
); |
|
177
|
|
|
|
|
178
|
1 |
|
$service->productNumber = $xml->findAttributeValue('@produktNummer', $serviceNode); |
|
179
|
|
|
|
|
180
|
1 |
|
foreach ($xml->queryNodes('geltungsBereich/zonenGeltungsBereich/zonenBuendel/zonen', $serviceNode) as $zone) { |
|
181
|
1 |
|
$service->addZone($xml->findNodeValue('code', $zone)); |
|
|
|
|
|
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
1 |
|
return $service; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|