Skip to content

Commit

Permalink
Support for PNR_Reply 14.1 and older General error format (fixes #51)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerMika committed Mar 21, 2017
1 parent 49bfc53 commit 4f4e529
Show file tree
Hide file tree
Showing 4 changed files with 958 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Amadeus/Client/ResponseHandler/PNR/HandlerRetrieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace Amadeus\Client\ResponseHandler\PNR;

use Amadeus\Client\Exception;
use Amadeus\Client\ResponseHandler\StandardResponseHandler;
use Amadeus\Client\Result;
use Amadeus\Client\Session\Handler\SendResult;
Expand All @@ -37,6 +36,8 @@ class HandlerRetrieve extends StandardResponseHandler
{
const Q_G_ERR = "//m:generalErrorInfo//m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
const Q_G_MSG = "//m:generalErrorInfo/m:errorWarningDescription/m:freeText";
const Q_G_OLD_ERR = "//m:generalErrorInfo//m:messageErrorInformation/m:errorDetail/m:errorCode";
const Q_G_OLD_MSG = "//m:generalErrorInfo/m:messageErrorText/m:text";
const Q_S_ERR = "//m:originDestinationDetails//m:errorInfo/m:errorOrWarningCodeDetails/m:errorDetails/m:errorCode";
const Q_S_MSG = "//m:originDestinationDetails//m:errorInfo/m:errorWarningDescription/m:freeText";
const Q_E_ERR = "//m:dataElementsIndiv/m:elementErrorInformation/m:errorOrWarningCodeDetails//m:errorCode";
Expand Down Expand Up @@ -67,6 +68,19 @@ public function analyze(SendResult $response)
$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general');
}

//General Errors - PNR_Reply v 14.1 and below:
$errorCodeNodeList = $domXpath->query(self::Q_G_OLD_ERR);

if ($errorCodeNodeList->length > 0) {
$analyzeResponse->status = Result::STATUS_ERROR;

$code = $errorCodeNodeList->item(0)->nodeValue;
$errorTextNodeList = $domXpath->query(self::Q_G_OLD_MSG);
$message = $this->makeMessageFromMessagesNodeList($errorTextNodeList);

$analyzeResponse->messages[] = new Result\NotOk($code, trim($message), 'general');
}

//Segment errors:
$errorCodeNodeList = $domXpath->query(self::Q_S_ERR);

Expand Down
16 changes: 16 additions & 0 deletions tests/Amadeus/Client/ResponseHandler/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,22 @@ public function testCanFindSimultaneousChangesErrorMessageInPnrReply()
$this->assertEquals('general', $result->messages[0]->level);
}

public function testCanHandleIssue50ErrorMessageInPnrReply()
{
$respHandler = new ResponseHandler\Base();

$sendResult = new SendResult();
$sendResult->responseXml = $this->getTestFile('pnrAddMultiElements14_1_need_received_from.txt');

$result = $respHandler->analyzeResponse($sendResult, 'PNR_AddMultiElements');

$this->assertEquals(Result::STATUS_ERROR, $result->status);
$this->assertCount(1, $result->messages);
$this->assertEquals('8111', $result->messages[0]->code);
$this->assertEquals("ERROR AT END OF TRANSACTION TIME - ERROR AT EOT TIME - NEED RECEIVED FROM", $result->messages[0]->text);
$this->assertEquals('general', $result->messages[0]->level);
}

public function testCanFindTopLevelErrorMessageInPnrReply()
{
$respHandler = new ResponseHandler\Base();
Expand Down
Loading

0 comments on commit 4f4e529

Please sign in to comment.