1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* amadeus-ws-client |
4
|
|
|
* |
5
|
|
|
* Copyright 2015 Amadeus Benelux NV |
6
|
|
|
* |
7
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
8
|
|
|
* you may not use this file except in compliance with the License. |
9
|
|
|
* You may obtain a copy of the License at |
10
|
|
|
* |
11
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
12
|
|
|
* |
13
|
|
|
* Unless required by applicable law or agreed to in writing, software |
14
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
15
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16
|
|
|
* See the License for the specific language governing permissions and |
17
|
|
|
* limitations under the License. |
18
|
|
|
* |
19
|
|
|
* @package Amadeus |
20
|
|
|
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0 |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Amadeus\Client\ResponseHandler; |
24
|
|
|
|
25
|
|
|
use Amadeus\Client\Exception; |
26
|
|
|
use Amadeus\Client\ResponseHandler\Air\RetrieveSeatMap; |
27
|
|
|
use Amadeus\Client\Result; |
28
|
|
|
use Amadeus\Client\Session\Handler\SendResult; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Default Response Handler |
32
|
|
|
* |
33
|
|
|
* @package Amadeus\Client\ResponseHandler |
34
|
|
|
* @author Dieter Devlieghere <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class Base implements ResponseHandlerInterface |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Default namespace prefix we'll be using for xpath queries |
40
|
|
|
* |
41
|
|
|
* Why not "m"? It's as good as any other letter. |
42
|
|
|
*/ |
43
|
|
|
const XMLNS_PREFIX = "m"; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Analyze the response from the server and throw an exception when an error has been detected. |
47
|
|
|
* |
48
|
|
|
* @param SendResult $sendResult The Send Result from the Session Handler |
49
|
|
|
* @param string $messageName The message that was called |
50
|
|
|
* |
51
|
|
|
* @throws Exception |
52
|
|
|
* @throws \RuntimeException |
53
|
|
|
* @return Result |
54
|
|
|
*/ |
55
|
|
|
public function analyzeResponse($sendResult, $messageName) |
56
|
|
|
{ |
57
|
|
|
$methodName = 'analyze' . str_replace('_', '', ucfirst($messageName)) . 'Response'; |
58
|
|
|
|
59
|
|
|
if (!empty($sendResult->exception)) { |
60
|
|
|
return $this->makeResultForException($sendResult); |
61
|
|
|
} elseif (method_exists($this, $methodName)) { |
62
|
|
|
return $this->$methodName( |
63
|
|
|
$sendResult |
64
|
|
|
); |
65
|
|
|
} else { |
66
|
|
|
return new Result($sendResult, Result::STATUS_UNKNOWN); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Analysing a Security_Authenticate |
72
|
|
|
* |
73
|
|
|
* @param SendResult $response Security_Authenticate result |
74
|
|
|
* @return Result |
75
|
|
|
*/ |
76
|
|
|
protected function analyzeSecurityAuthenticateResponse($response) |
77
|
|
|
{ |
78
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Analysing a Security_Authenticate |
83
|
|
|
* |
84
|
|
|
* @param SendResult $response Security_Authenticate result |
85
|
|
|
* @return Result |
86
|
|
|
*/ |
87
|
|
|
protected function analyzeSecuritySignOutResponse($response) |
88
|
|
|
{ |
89
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Unknown response for Command_Cryptic because you need to analyse the cryptic response yourself |
94
|
|
|
* |
95
|
|
|
* @param SendResult $response |
96
|
|
|
* @return Result |
97
|
|
|
*/ |
98
|
|
|
protected function analyzeCommandCrypticResponse($response) |
99
|
|
|
{ |
100
|
|
|
$ccResult = new Result($response, Result::STATUS_UNKNOWN); |
101
|
|
|
$ccResult->messages[] = new Result\NotOk( |
102
|
|
|
0, |
103
|
|
|
"Response handling not supported for cryptic entries" |
104
|
|
|
); |
105
|
|
|
|
106
|
|
|
return $ccResult; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
protected function analyzeAirSellFromRecommendationResponse($response) |
110
|
|
|
{ |
111
|
|
|
$analyzeResponse = new Result($response); |
112
|
|
|
|
113
|
|
|
$errMsgMap = [ |
114
|
|
|
"288" => "UNABLE TO SATISFY, NEED CONFIRMED FLIGHT STATUS", |
115
|
|
|
"390" => "UNABLE TO REFORMAT" |
116
|
|
|
]; |
117
|
|
|
|
118
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
119
|
|
|
|
120
|
|
|
$codeNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCode")->item(0); |
121
|
|
|
if ($codeNode instanceof \DOMNode) { |
122
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
123
|
|
|
|
124
|
|
|
$categoryNode = $domXpath->query("//m:errorSegment/m:errorDetails/m:errorCategory")->item(0); |
125
|
|
|
if ($categoryNode instanceof \DOMNode) { |
126
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$message = (array_key_exists($codeNode->nodeValue, $errMsgMap)) ? $errMsgMap[$codeNode->nodeValue] : 'UNKNOWN ERROR'; |
|
|
|
|
130
|
|
|
|
131
|
|
|
$analyzeResponse->messages [] = new Result\NotOk($codeNode->nodeValue, $message); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
return $analyzeResponse; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @param SendResult $response |
139
|
|
|
* @return Result |
140
|
|
|
*/ |
141
|
|
|
protected function analyzeAirFlightInfoResponse($response) |
142
|
|
|
{ |
143
|
|
|
$analyzeResponse = new Result($response); |
144
|
|
|
|
145
|
|
|
$code = null; |
146
|
|
|
$message = null; |
147
|
|
|
|
148
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
149
|
|
|
|
150
|
|
|
$categoryNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCategory'); |
151
|
|
|
if ($categoryNodes->length > 0) { |
152
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNodes->item(0)->nodeValue); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$codeNodes = $domXpath->query('//m:responseError/m:errorInfo/m:errorDetails/m:errorCode'); |
156
|
|
|
if ($codeNodes->length > 0) { |
157
|
|
|
$code = $codeNodes->item(0)->nodeValue; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
$messageNodes = $domXpath->query('//m:responseError/m:interactiveFreeText/m:freeText'); |
161
|
|
|
if ($messageNodes->length > 0) { |
162
|
|
|
$message = $this->makeMessageFromMessagesNodeList($messageNodes); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
if (!is_null($message) && !is_null($code)) { |
166
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, $message); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $analyzeResponse; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param SendResult $response |
174
|
|
|
* @return Result |
175
|
|
|
*/ |
176
|
|
|
protected function analyzeAirRetrieveSeatMapResponse($response) |
177
|
|
|
{ |
178
|
|
|
$analyzeResponse = new Result($response); |
179
|
|
|
|
180
|
|
|
$code = null; |
|
|
|
|
181
|
|
|
$message = null; |
|
|
|
|
182
|
|
|
|
183
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
184
|
|
|
|
185
|
|
|
$errorCodeNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:code'); |
186
|
|
View Code Duplication |
if ($errorCodeNode->length > 0) { |
|
|
|
|
187
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
188
|
|
|
|
189
|
|
|
$errCode = $errorCodeNode->item(0)->nodeValue; |
190
|
|
|
$level = null; |
191
|
|
|
$errDesc = null; |
|
|
|
|
192
|
|
|
|
193
|
|
|
$errorLevelNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:processingLevel'); |
194
|
|
|
if ($errorLevelNode->length > 0) { |
195
|
|
|
$level = RetrieveSeatMap::decodeProcessingLevel($errorLevelNode->item(0)->nodeValue); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
$errorDescNode = $domXpath->query('//m:errorInformation/m:errorDetails/m:description'); |
199
|
|
|
if ($errorDescNode->length > 0) { |
200
|
|
|
$errDesc = $errorDescNode->item(0)->nodeValue; |
201
|
|
|
} else { |
202
|
|
|
$errDesc = RetrieveSeatMap::findMessage($errCode); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
206
|
|
|
$errCode, |
207
|
|
|
$errDesc, |
208
|
|
|
$level |
209
|
|
|
); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
$codeNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:code'); |
213
|
|
View Code Duplication |
if ($codeNode->length > 0) { |
|
|
|
|
214
|
|
|
$analyzeResponse->status = Result::STATUS_WARN; |
215
|
|
|
|
216
|
|
|
$warnCode = $codeNode->item(0)->nodeValue; |
217
|
|
|
$level = null; |
218
|
|
|
$warnDesc = null; |
|
|
|
|
219
|
|
|
|
220
|
|
|
$levelNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:processingLevel'); |
221
|
|
|
if ($levelNode->length > 0) { |
222
|
|
|
$level = RetrieveSeatMap::decodeProcessingLevel($levelNode->item(0)->nodeValue); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
$descNode = $domXpath->query('//m:warningInformation/m:warningDetails/m:description'); |
226
|
|
|
if ($descNode->length > 0) { |
227
|
|
|
$warnDesc = $descNode->item(0)->nodeValue; |
228
|
|
|
} else { |
229
|
|
|
$warnDesc = RetrieveSeatMap::findMessage($warnCode); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
233
|
|
|
$warnCode, |
234
|
|
|
$warnDesc, |
235
|
|
|
$level |
236
|
|
|
); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
return $analyzeResponse; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* Analysing a PNR_Retrieve response |
244
|
|
|
* |
245
|
|
|
* @param SendResult $response PNR_Retrieve result |
246
|
|
|
* @return Result |
247
|
|
|
*/ |
248
|
|
|
protected function analyzePnrRetrieveResponse($response) |
249
|
|
|
{ |
250
|
|
|
return $this->analyzePnrReply($response); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param SendResult $response PNR_AddMultiElements result |
255
|
|
|
* @return Result |
256
|
|
|
*/ |
257
|
|
|
protected function analyzePnrAddMultiElementsResponse($response) |
258
|
|
|
{ |
259
|
|
|
return $this->analyzePnrReply($response); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* @param SendResult $response PNR_Cancel result |
264
|
|
|
* @return Result |
265
|
|
|
*/ |
266
|
|
|
protected function analyzePnrCancelResponse($response) |
267
|
|
|
{ |
268
|
|
|
return $this->analyzePnrReply($response); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* Analysing a PNR_Reply |
273
|
|
|
* |
274
|
|
|
* @param SendResult $response PNR_Retrieve result |
275
|
|
|
* @return Result |
276
|
|
|
*/ |
277
|
|
|
protected function analyzePnrReply($response) |
278
|
|
|
{ |
279
|
|
|
$analyzeResponse = new Result($response); |
280
|
|
|
|
281
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
282
|
|
|
|
283
|
|
|
//General Errors: |
284
|
|
|
$queryAllErrorCodes = "//m:generalErrorInfo//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
285
|
|
|
$queryAllErrorMsg = "//m:generalErrorInfo/m:errorWarningDescription/m:freeText"; |
286
|
|
|
|
287
|
|
|
$errorCodeNodeList = $domXpath->query($queryAllErrorCodes); |
288
|
|
|
|
289
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
290
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
291
|
|
|
|
292
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
293
|
|
|
$errorTextNodeList = $domXpath->query($queryAllErrorMsg); |
294
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
295
|
|
|
|
296
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general'); |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
//Segment errors: |
300
|
|
|
$querySegmentErrorCodes = "//m:originDestinationDetails//m:errorInfo/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
|
|
|
|
301
|
|
|
$querySegmentErrorMsg = "//m:originDestinationDetails//m:errorInfo/m:errorWarningDescription/m:freeText"; |
302
|
|
|
|
303
|
|
|
$errorCodeNodeList = $domXpath->query($querySegmentErrorCodes); |
304
|
|
|
|
305
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
306
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
307
|
|
|
|
308
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
309
|
|
|
$errorTextNodeList = $domXpath->query($querySegmentErrorMsg); |
310
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
311
|
|
|
|
312
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'segment'); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
//Element errors: |
316
|
|
|
$queryElementErrorCodes = "//m:dataElementsIndiv/m:elementErrorInformation/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
|
|
|
|
317
|
|
|
$queryElementErrorMsg = "//m:dataElementsIndiv//m:elementErrorInformation/m:errorWarningDescription/m:freeText"; |
318
|
|
|
|
319
|
|
|
$errorCodeNodeList = $domXpath->query($queryElementErrorCodes); |
320
|
|
|
|
321
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
322
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
323
|
|
|
|
324
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
325
|
|
|
|
326
|
|
|
$errorTextNodeList = $domXpath->query($queryElementErrorMsg); |
327
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
328
|
|
|
|
329
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'element'); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
return $analyzeResponse; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
/** |
336
|
|
|
* @param SendResult $response Pnr_RetrieveAndDisplay response |
337
|
|
|
* @return Result |
338
|
|
|
* @throws Exception |
339
|
|
|
*/ |
340
|
|
|
protected function analyzePnrRetrieveAndDisplayResponse($response) |
341
|
|
|
{ |
342
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
343
|
|
|
} |
344
|
|
|
|
345
|
|
|
/** |
346
|
|
|
* Analysing a PNR_DisplayHistoryReply |
347
|
|
|
* |
348
|
|
|
* @param SendResult $response PNR_DisplayHistoryReply result |
349
|
|
|
* @return Result |
350
|
|
|
* @throws Exception |
351
|
|
|
*/ |
352
|
|
|
protected function analyzePnrDisplayHistoryResponse($response) |
353
|
|
|
{ |
354
|
|
|
$analyzeResponse = new Result($response); |
355
|
|
|
|
356
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
357
|
|
|
|
358
|
|
|
$queryAllErrorCodes = "//m:generalErrorGroup//m:errorNumber/m:errorDetails/m:errorCode"; |
359
|
|
|
$queryAllErrorMsg = "//m:generalErrorGroup/m:genrealErrorText/m:freeText"; |
360
|
|
|
|
361
|
|
|
$errorCodeNodeList = $domXpath->query($queryAllErrorCodes); |
362
|
|
|
|
363
|
|
View Code Duplication |
if ($errorCodeNodeList->length > 0) { |
|
|
|
|
364
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
365
|
|
|
|
366
|
|
|
$code = $errorCodeNodeList->item(0)->nodeValue; |
367
|
|
|
$errorTextNodeList = $domXpath->query($queryAllErrorMsg); |
368
|
|
|
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList); |
369
|
|
|
|
370
|
|
|
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message)); |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
return $analyzeResponse; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
/** |
377
|
|
|
* @param SendResult $response Queue_RemoveItem response |
378
|
|
|
* @return Result |
379
|
|
|
* @throws Exception |
380
|
|
|
*/ |
381
|
|
|
protected function analyzeQueueRemoveItemResponse($response) |
382
|
|
|
{ |
383
|
|
|
return $this->analyzeGenericQueueResponse($response); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @param SendResult $response Queue_MoveItem response |
388
|
|
|
* @return Result |
389
|
|
|
* @throws Exception |
390
|
|
|
*/ |
391
|
|
|
protected function analyzeQueueMoveItemResponse($response) |
392
|
|
|
{ |
393
|
|
|
return $this->analyzeGenericQueueResponse($response); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
/** |
397
|
|
|
* @param SendResult $response Queue_PlacePNR response |
398
|
|
|
* @return Result |
399
|
|
|
* @throws Exception |
400
|
|
|
*/ |
401
|
|
|
protected function analyzeQueuePlacePNRResponse($response) |
402
|
|
|
{ |
403
|
|
|
return $this->analyzeGenericQueueResponse($response); |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* @param SendResult $response Queue_List result |
408
|
|
|
* @return Result |
409
|
|
|
* @throws Exception |
410
|
|
|
*/ |
411
|
|
|
protected function analyzeQueueListResponse($response) |
412
|
|
|
{ |
413
|
|
|
return $this->analyzeGenericQueueResponse($response); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
/** |
417
|
|
|
* Analyze a generic Queue response |
418
|
|
|
* |
419
|
|
|
* @param SendResult $response Queue_*Reply result |
420
|
|
|
* @return Result |
421
|
|
|
* @throws Exception |
422
|
|
|
*/ |
423
|
|
|
protected function analyzeGenericQueueResponse($response) |
424
|
|
|
{ |
425
|
|
|
$analysisResponse = new Result($response); |
426
|
|
|
|
427
|
|
|
$domDoc = $this->loadDomDocument($response->responseXml); |
428
|
|
|
|
429
|
|
|
$errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0); |
430
|
|
|
|
431
|
|
|
if (!is_null($errorCodeNode)) { |
432
|
|
|
$analysisResponse->status = Result::STATUS_WARN; |
433
|
|
|
|
434
|
|
|
$errorCode = $errorCodeNode->nodeValue; |
435
|
|
|
$errorMessage = $this->getErrorTextFromQueueErrorCode($errorCode); |
436
|
|
|
|
437
|
|
|
$analysisResponse->messages[] = new Result\NotOk($errorCode, $errorMessage); |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
return $analysisResponse; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
|
444
|
|
|
/** |
445
|
|
|
* |
446
|
|
|
* <Fare_PricePNRWithBookingClassReply xmlns="http://xml.amadeus.com/TPCBRR_13_2_1A"> |
447
|
|
|
* <applicationError> |
448
|
|
|
* <errorOrWarningCodeDetails> |
449
|
|
|
* <errorDetails> |
450
|
|
|
* <errorCode>00477</errorCode> |
451
|
|
|
* <errorCategory>EC</errorCategory> |
452
|
|
|
* <errorCodeOwner>1A</errorCodeOwner> |
453
|
|
|
* </errorDetails> |
454
|
|
|
* </errorOrWarningCodeDetails> |
455
|
|
|
* <errorWarningDescription> |
456
|
|
|
* <freeText>INVALID FORMAT</freeText> |
457
|
|
|
* </errorWarningDescription> |
458
|
|
|
* </applicationError> |
459
|
|
|
* </Fare_PricePNRWithBookingClassReply> |
460
|
|
|
* |
461
|
|
|
* @param SendResult $response Fare_PricePNRWithBookingClass result |
462
|
|
|
* @return Result |
463
|
|
|
* @throws Exception |
464
|
|
|
*/ |
465
|
|
|
protected function analyzeFarePricePNRWithBookingClassResponse($response) |
466
|
|
|
{ |
467
|
|
|
$analyzeResponse = new Result($response); |
468
|
|
|
|
469
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
470
|
|
|
|
471
|
|
|
$queryErrorCode = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode"; |
472
|
|
|
$queryErrorCategory = "//m:applicationError//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory"; |
473
|
|
|
$queryErrorMsg = "//m:applicationError/m:errorWarningDescription/m:freeText"; |
474
|
|
|
|
475
|
|
|
$errorCodeNodeList = $domXpath->query($queryErrorCode); |
476
|
|
|
|
477
|
|
|
if ($errorCodeNodeList->length > 0) { |
478
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
479
|
|
|
|
480
|
|
|
$errorCatNode = $domXpath->query($queryErrorCategory)->item(0); |
481
|
|
|
if ($errorCatNode instanceof \DOMNode) { |
482
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue); |
483
|
|
|
} |
484
|
|
|
|
485
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
486
|
|
|
$errorCodeNodeList->item(0)->nodeValue, |
487
|
|
|
$this->makeMessageFromMessagesNodeList( |
488
|
|
|
$domXpath->query($queryErrorMsg) |
489
|
|
|
) |
490
|
|
|
); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
return $analyzeResponse; |
494
|
|
|
} |
495
|
|
|
|
496
|
|
|
protected function analyzeFareMasterPricerTravelBoardSearchResponse($response) |
497
|
|
|
{ |
498
|
|
|
$analyzeResponse = new Result($response); |
499
|
|
|
|
500
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
501
|
|
|
|
502
|
|
|
$queryErrCode = "//m:applicationError//m:applicationErrorDetail/m:error"; |
503
|
|
|
$queryErrMsg = "//m:errorMessageText/m:description"; |
504
|
|
|
|
505
|
|
|
$codeNode = $domXpath->query($queryErrCode)->item(0); |
506
|
|
|
|
507
|
|
|
if ($codeNode instanceof \DOMNode) { |
508
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
509
|
|
|
|
510
|
|
|
$errMsg = ''; |
511
|
|
|
$errMsgNode = $domXpath->query($queryErrMsg)->item(0); |
512
|
|
|
if ($errMsgNode instanceof \DOMNode) { |
513
|
|
|
$errMsg = $errMsgNode->nodeValue; |
514
|
|
|
} |
515
|
|
|
|
516
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
517
|
|
|
$codeNode->nodeValue, |
518
|
|
|
$errMsg |
519
|
|
|
); |
520
|
|
|
} |
521
|
|
|
|
522
|
|
|
return $analyzeResponse; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* @param SendResult $response |
527
|
|
|
* @return Result |
528
|
|
|
*/ |
529
|
|
|
protected function analyzeFareConvertCurrencyResponse($response) |
530
|
|
|
{ |
531
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* @param SendResult $response |
536
|
|
|
* @return Result |
537
|
|
|
*/ |
538
|
|
|
protected function analyzeFareCheckRulesResponse($response) |
539
|
|
|
{ |
540
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
/** |
544
|
|
|
* @param SendResult $response |
545
|
|
|
* @return Result |
546
|
|
|
*/ |
547
|
|
|
protected function analyzeDocIssuanceIssueTicketResponse($response) |
548
|
|
|
{ |
549
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
View Code Duplication |
protected function analyzeTicketCreateTSTFromPricingResponse($response) |
|
|
|
|
553
|
|
|
{ |
554
|
|
|
$analyzeResponse = new Result($response); |
555
|
|
|
|
556
|
|
|
$domDoc = $this->loadDomDocument($response->responseXml); |
557
|
|
|
|
558
|
|
|
$errorCodeNode = $domDoc->getElementsByTagName("applicationErrorCode")->item(0); |
559
|
|
|
|
560
|
|
|
if (!is_null($errorCodeNode)) { |
561
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
562
|
|
|
|
563
|
|
|
$errorCatNode = $domDoc->getElementsByTagName("codeListQualifier")->item(0); |
564
|
|
|
if ($errorCatNode instanceof \DOMNode) { |
565
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue); |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
$errorCode = $errorCodeNode->nodeValue; |
569
|
|
|
$errorTextNodeList = $domDoc->getElementsByTagName("errorFreeText"); |
570
|
|
|
|
571
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
572
|
|
|
$errorCode, |
573
|
|
|
$this->makeMessageFromMessagesNodeList($errorTextNodeList) |
574
|
|
|
); |
575
|
|
|
} |
576
|
|
|
|
577
|
|
|
return $analyzeResponse; |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
/** |
581
|
|
|
* @param SendResult $response |
582
|
|
|
* @return Result |
583
|
|
|
*/ |
584
|
|
|
protected function analyzeOfferConfirmCarOfferResponse($response) |
585
|
|
|
{ |
586
|
|
|
return $this->analyzeGenericOfferResponse($response); |
587
|
|
|
} |
588
|
|
|
|
589
|
|
|
/** |
590
|
|
|
* @param SendResult $response |
591
|
|
|
* @return Result |
592
|
|
|
*/ |
593
|
|
|
protected function analyzeOfferConfirmHotelOfferResponse($response) |
594
|
|
|
{ |
595
|
|
|
$analyzeResponse = new Result($response); |
596
|
|
|
|
597
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
598
|
|
|
|
599
|
|
|
$codeNode = $domXpath->query("//m:errorDetails/m:errorCode")->item(0); |
600
|
|
|
if ($codeNode instanceof \DOMNode) { |
601
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
602
|
|
|
|
603
|
|
|
$categoryNode = $domXpath->query("//m:errorDetails/m:errorCategory")->item(0); |
604
|
|
|
if ($categoryNode instanceof \DOMNode) { |
605
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue); |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
$msgNode = $domXpath->query('//m:errorDescription/m:freeText')->item(0); |
609
|
|
|
|
610
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
611
|
|
|
$codeNode->nodeValue, |
612
|
|
|
trim($msgNode->nodeValue) |
613
|
|
|
); |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
return $analyzeResponse; |
617
|
|
|
} |
618
|
|
|
|
619
|
|
|
/** |
620
|
|
|
* @param SendResult $response |
621
|
|
|
* @return Result |
622
|
|
|
*/ |
623
|
|
|
protected function analyzeOfferConfirmAirOfferResponse($response) |
624
|
|
|
{ |
625
|
|
|
return $this->analyzeGenericOfferResponse($response); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* @param SendResult $response |
630
|
|
|
* @return Result |
631
|
|
|
*/ |
632
|
|
|
protected function analyzeOfferVerifyOfferResponse($response) |
633
|
|
|
{ |
634
|
|
|
return $this->analyzeGenericOfferResponse($response); |
635
|
|
|
} |
636
|
|
|
|
637
|
|
|
/** |
638
|
|
|
* @param SendResult $response |
639
|
|
|
* @return Result |
640
|
|
|
*/ |
641
|
|
|
protected function analyzeGenericOfferResponse($response) |
642
|
|
|
{ |
643
|
|
|
$analyzeResponse = new Result($response); |
644
|
|
|
|
645
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
646
|
|
|
|
647
|
|
|
$msgNode = $domXpath->query('//m:errorsDescription/m:errorWarningDescription/m:freeText')->item(0); |
648
|
|
|
|
649
|
|
|
if ($msgNode instanceof \DOMNode) { |
650
|
|
|
if (trim($msgNode->nodeValue) === "OFFER CONFIRMED SUCCESSFULLY" || trim($msgNode->nodeValue) === "OFFER VERIFIED SUCCESSFULLY" ) { |
|
|
|
|
651
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
652
|
|
|
0, |
653
|
|
|
trim($msgNode->nodeValue) |
654
|
|
|
); |
655
|
|
|
return $analyzeResponse; |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
$categoryNode = $domXpath->query('//m:errorDetails/m:errorCategory')->item(0); |
659
|
|
|
if ($categoryNode instanceof \DOMNode) { |
660
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue); |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
$codeNode = $domXpath->query('//m:errorDetails/m:errorCode')->item(0); |
664
|
|
|
|
665
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
666
|
|
|
$codeNode->nodeValue, |
667
|
|
|
trim($msgNode->nodeValue) |
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
return $analyzeResponse; |
672
|
|
|
} |
673
|
|
|
|
674
|
|
|
protected function analyzeMiniRuleGetFromPricingRecResponse($response) |
675
|
|
|
{ |
676
|
|
|
$analyzeResponse = new Result($response); |
677
|
|
|
|
678
|
|
|
$domXpath = $this->makeDomXpath($response->responseXml); |
679
|
|
|
|
680
|
|
|
$statusNode = $domXpath->query('//m:responseDetails/m:statusCode')->item(0); |
681
|
|
|
if ($statusNode instanceof \DOMNode) { |
682
|
|
|
$code = $statusNode->nodeValue; |
683
|
|
|
|
684
|
|
|
if ($code !== 'O') { |
685
|
|
|
$categoryNode = $domXpath->query('//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCategory')->item(0); |
|
|
|
|
686
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($categoryNode->nodeValue); |
687
|
|
|
|
688
|
|
|
$codeNode = $domXpath->query('//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode')->item(0); |
689
|
|
|
$msgNode = $domXpath->query('//m:errorWarningDescription/m:freeText')->item(0); |
690
|
|
|
|
691
|
|
|
if ($codeNode instanceof \DOMNode && $msgNode instanceof \DOMNode) { |
692
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
693
|
|
|
$codeNode->nodeValue, |
694
|
|
|
$msgNode->nodeValue |
695
|
|
|
); |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
} |
699
|
|
|
|
700
|
|
|
return $analyzeResponse; |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
/** |
704
|
|
|
* @param SendResult $response |
705
|
|
|
* @return Result |
706
|
|
|
*/ |
707
|
|
|
protected function analyzeInfoEncodeDecodeCityResponse($response) |
708
|
|
|
{ |
709
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
710
|
|
|
} |
711
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* @param SendResult $response |
714
|
|
|
* @return Result |
715
|
|
|
*/ |
716
|
|
|
protected function analyzePriceXplorerExtremeSearchResponse($response) |
717
|
|
|
{ |
718
|
|
|
return $this->analyzeSimpleResponseErrorCodeAndMessage($response); |
719
|
|
|
} |
720
|
|
|
|
721
|
|
|
/** |
722
|
|
|
* @param SendResult $response WebService message Send Result |
723
|
|
|
* @return Result |
724
|
|
|
* @throws Exception |
725
|
|
|
*/ |
726
|
|
View Code Duplication |
protected function analyzeSimpleResponseErrorCodeAndMessage($response) |
|
|
|
|
727
|
|
|
{ |
728
|
|
|
$analyzeResponse = new Result($response); |
729
|
|
|
|
730
|
|
|
$domDoc = $this->loadDomDocument($response->responseXml); |
731
|
|
|
|
732
|
|
|
$errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0); |
733
|
|
|
|
734
|
|
|
if (!is_null($errorCodeNode)) { |
735
|
|
|
$errorCatNode = $domDoc->getElementsByTagName("errorCategory")->item(0); |
736
|
|
|
if ($errorCatNode instanceof \DOMNode) { |
737
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue); |
738
|
|
|
} else { |
739
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
740
|
|
|
} |
741
|
|
|
|
742
|
|
|
$errorCode = $errorCodeNode->nodeValue; |
743
|
|
|
$errorTextNodeList = $domDoc->getElementsByTagName("freeText"); |
744
|
|
|
|
745
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
746
|
|
|
$errorCode, |
747
|
|
|
$this->makeMessageFromMessagesNodeList($errorTextNodeList) |
748
|
|
|
); |
749
|
|
|
} |
750
|
|
|
|
751
|
|
|
return $analyzeResponse; |
752
|
|
|
} |
753
|
|
|
|
754
|
|
|
/** |
755
|
|
|
* @param SendResult $response WebService message Send Result |
756
|
|
|
* @return Result |
757
|
|
|
* @throws Exception |
758
|
|
|
*/ |
759
|
|
View Code Duplication |
protected function analyzeSimpleResponseErrorCodeAndMessageStatusCode($response) |
|
|
|
|
760
|
|
|
{ |
761
|
|
|
$analyzeResponse = new Result($response); |
762
|
|
|
|
763
|
|
|
$domDoc = $this->loadDomDocument($response->responseXml); |
764
|
|
|
|
765
|
|
|
$errorCodeNode = $domDoc->getElementsByTagName("errorCode")->item(0); |
766
|
|
|
|
767
|
|
|
if (!is_null($errorCodeNode)) { |
768
|
|
|
$analyzeResponse->status = Result::STATUS_ERROR; |
769
|
|
|
|
770
|
|
|
$errorCatNode = $domDoc->getElementsByTagName("statusCode")->item(0); |
771
|
|
|
if ($errorCatNode instanceof \DOMNode) { |
772
|
|
|
$analyzeResponse->status = $this->makeStatusFromErrorQualifier($errorCatNode->nodeValue); |
773
|
|
|
} |
774
|
|
|
|
775
|
|
|
$errorCode = $errorCodeNode->nodeValue; |
776
|
|
|
$errorTextNodeList = $domDoc->getElementsByTagName("freeText"); |
777
|
|
|
|
778
|
|
|
$analyzeResponse->messages[] = new Result\NotOk( |
779
|
|
|
$errorCode, |
780
|
|
|
$this->makeMessageFromMessagesNodeList($errorTextNodeList) |
781
|
|
|
); |
782
|
|
|
} |
783
|
|
|
|
784
|
|
|
return $analyzeResponse; |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
/** |
788
|
|
|
* Returns the errortext from a Queue_*Reply errorcode |
789
|
|
|
* |
790
|
|
|
* This function is necessary because the core only responds |
791
|
|
|
* with errorcode but does not send an errortext. |
792
|
|
|
* |
793
|
|
|
* The errorcodes for all Queue_*Reply messages are the same. |
794
|
|
|
* |
795
|
|
|
* @link https://webservices.amadeus.com/extranet/viewArea.do?id=10 |
796
|
|
|
* @param string $errorCode |
797
|
|
|
* @return string the errortext for this errorcode. |
798
|
|
|
*/ |
799
|
|
|
protected function getErrorTextFromQueueErrorCode($errorCode) |
800
|
|
|
{ |
801
|
|
|
$recognizedErrors = [ |
802
|
|
|
'723' => "Invalid category", |
803
|
|
|
'911' => "Unable to process - system error", |
804
|
|
|
'913' => "Item/data not found or data not existing in processing host", |
805
|
|
|
'79D' => "Queue identifier has not been assigned for specified office identification", |
806
|
|
|
'91C' => "invalid record locator", |
807
|
|
|
'91F' => "Invalid queue number", |
808
|
|
|
'921' => "target not specified", |
809
|
|
|
'922' => "Targetted queue has wrong queue type", |
810
|
|
|
'926' => "Queue category empty", |
811
|
|
|
'928' => "Queue category not assigned", |
812
|
|
|
'92A' => "Queue category full", |
813
|
|
|
]; |
814
|
|
|
|
815
|
|
|
$errorMessage = (array_key_exists($errorCode, $recognizedErrors)) ? $recognizedErrors[$errorCode] : ''; |
816
|
|
|
|
817
|
|
|
if ($errorMessage === '') { |
818
|
|
|
$errorMessage = "QUEUE ERROR '" . $errorCode . "' (Error message unavailable)"; |
819
|
|
|
} |
820
|
|
|
|
821
|
|
|
return $errorMessage; |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
/** |
825
|
|
|
* @param string $response |
826
|
|
|
* @return \DOMDocument |
827
|
|
|
* @throws Exception when there's a problem loading the message |
828
|
|
|
*/ |
829
|
|
|
protected function loadDomDocument($response) |
830
|
|
|
{ |
831
|
|
|
$domDoc = new \DOMDocument('1.0', 'UTF-8'); |
832
|
|
|
|
833
|
|
|
$loadResult = $domDoc->loadXML($response); |
834
|
|
|
if ($loadResult === false) { |
835
|
|
|
throw new Exception('Could not load response message into DOMDocument'); |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
return $domDoc; |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
/** |
842
|
|
|
* @param $qualifier |
843
|
|
|
* @return string Result::STATUS_* |
844
|
|
|
*/ |
845
|
|
|
protected function makeStatusFromErrorQualifier($qualifier) |
846
|
|
|
{ |
847
|
|
|
$status = null; |
|
|
|
|
848
|
|
|
|
849
|
|
|
switch ($qualifier) { |
850
|
|
|
case 'INF': |
851
|
|
|
$status = Result::STATUS_INFO; |
852
|
|
|
break; |
853
|
|
|
case 'WEC': |
854
|
|
|
case 'WZZ': //Mutually defined warning |
855
|
|
|
case 'W': |
856
|
|
|
$status = Result::STATUS_WARN; |
857
|
|
|
break; |
858
|
|
|
case 'EC': |
859
|
|
|
case 'X': |
860
|
|
|
$status = Result::STATUS_ERROR; |
861
|
|
|
break; |
862
|
|
|
case 'O': |
863
|
|
|
$status = Result::STATUS_OK; |
864
|
|
|
break; |
865
|
|
|
case 'ZZZ': //Mutually defined |
866
|
|
|
default: |
867
|
|
|
$status = Result::STATUS_UNKNOWN; |
868
|
|
|
break; |
869
|
|
|
} |
870
|
|
|
|
871
|
|
|
return $status; |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
|
875
|
|
|
/** |
876
|
|
|
* Make a Xpath-queryable object for an XML string |
877
|
|
|
* |
878
|
|
|
* registers TNS namespace with prefix self::XMLNS_PREFIX |
879
|
|
|
* |
880
|
|
|
* @param string $response |
881
|
|
|
* @return \DOMXPath |
882
|
|
|
* @throws Exception when there's a problem loading the message |
883
|
|
|
*/ |
884
|
|
|
protected function makeDomXpath($response) |
885
|
|
|
{ |
886
|
|
|
$domDoc = $this->loadDomDocument($response); |
887
|
|
|
$domXpath = new \DOMXPath($domDoc); |
888
|
|
|
|
889
|
|
|
$domXpath->registerNamespace( |
890
|
|
|
self::XMLNS_PREFIX, |
891
|
|
|
$domDoc->documentElement->lookupNamespaceUri(null) |
892
|
|
|
); |
893
|
|
|
|
894
|
|
|
return $domXpath; |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
/** |
898
|
|
|
* Convert a DomNodeList of nodes containing a (potentially partial) error message into a string. |
899
|
|
|
* |
900
|
|
|
* @param \DOMNodeList $errorTextNodeList |
901
|
|
|
* @return string|null |
902
|
|
|
*/ |
903
|
|
|
protected function makeMessageFromMessagesNodeList($errorTextNodeList) |
904
|
|
|
{ |
905
|
|
|
return implode( |
906
|
|
|
' - ', |
907
|
|
|
array_map( |
908
|
|
|
function($item) { |
909
|
|
|
return trim($item->nodeValue); |
910
|
|
|
}, |
911
|
|
|
iterator_to_array($errorTextNodeList) |
912
|
|
|
) |
913
|
|
|
); |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* @param SendResult $sendResult |
918
|
|
|
* @return Result |
919
|
|
|
*/ |
920
|
|
|
protected function makeResultForException($sendResult) |
921
|
|
|
{ |
922
|
|
|
$result = new Result($sendResult, Result::STATUS_FATAL); |
923
|
|
|
|
924
|
|
|
$result->messages[] = $this->makeMessageFromException($sendResult->exception); |
925
|
|
|
|
926
|
|
|
return $result; |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* @param \Exception $exception |
931
|
|
|
* @return Result\NotOk |
932
|
|
|
* @throws Exception |
933
|
|
|
*/ |
934
|
|
|
protected function makeMessageFromException(\Exception $exception) |
935
|
|
|
{ |
936
|
|
|
$message = new Result\NotOk(); |
937
|
|
|
|
938
|
|
|
if ($exception instanceof \SoapFault) { |
939
|
|
|
$info = explode('|', $exception->getMessage()); |
940
|
|
|
$message->code = $info[0]; |
941
|
|
|
if (count($info) === 3) { |
942
|
|
|
$message->level = $info[1]; |
943
|
|
|
$message->text = $info[2]; |
944
|
|
|
} |
945
|
|
|
} |
946
|
|
|
|
947
|
|
|
return $message; |
948
|
|
|
} |
949
|
|
|
} |
950
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.