From 64cf33ce96b656a6b3d94e95ccdfed2425b0cf42 Mon Sep 17 00:00:00 2001 From: dieter Date: Fri, 24 Feb 2017 11:42:52 +0100 Subject: [PATCH] Implemented Ticket_CreateTSMFareElement for Amadeus Ticket Changer Shopper flow (Issue #39) --- CHANGELOG.md | 3 + docs/list-of-supported-messages.rst | 2 +- docs/samples.rst | 37 ++++++++- src/Amadeus/Client.php | 16 ++++ .../Ticket/CreateTSMFareElementConv.php | 46 +++++++++++ .../TicketCreateTsmFareElOptions.php | 62 +++++++++++++++ .../Ticket/HandlerCreateTSMFareElement.php | 33 ++++++++ .../Struct/Ticket/CreateTSMFareElement.php | 62 +++++++++++++++ .../Client/Struct/Ticket/FareElementInfo.php | 47 +++++++++++ .../Ticket/CreateTSMFareElementTest.php | 79 +++++++++++++++++++ tests/Amadeus/ClientTest.php | 59 ++++++++++++++ 11 files changed, 444 insertions(+), 2 deletions(-) create mode 100644 src/Amadeus/Client/RequestCreator/Converter/Ticket/CreateTSMFareElementConv.php create mode 100644 src/Amadeus/Client/RequestOptions/TicketCreateTsmFareElOptions.php create mode 100644 src/Amadeus/Client/ResponseHandler/Ticket/HandlerCreateTSMFareElement.php create mode 100644 src/Amadeus/Client/Struct/Ticket/CreateTSMFareElement.php create mode 100644 src/Amadeus/Client/Struct/Ticket/FareElementInfo.php create mode 100644 tests/Amadeus/Client/Struct/Ticket/CreateTSMFareElementTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 167510cfb..afc477c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Release 1.3.0 (UNRELEASED) +* Implemented ``Ticket_CreateTSMFareElement`` message (https://github.com/amabnl/amadeus-ws-client/issues/39) + # Release 1.2.0 (23 February 2017) * Fixed bug with Corporate Unifare pricing in ``Fare_MasterPricerTravelBoardSearch`` and ``Fare_MasterPricerCalendar`` (https://github.com/amabnl/amadeus-ws-client/pull/41) - Michal Hernas * Added support for requesting rules for specific Fare Components after a pricing request in ``Fare_CheckRules`` (https://github.com/amabnl/amadeus-ws-client/issues/21) diff --git a/docs/list-of-supported-messages.rst b/docs/list-of-supported-messages.rst index a17a01112..f0b60030f 100644 --- a/docs/list-of-supported-messages.rst +++ b/docs/list-of-supported-messages.rst @@ -34,6 +34,7 @@ This is the list of messages that are at least partially supported at this time: - FOP_CreateFormOfPayment - Ticket_CreateTSTFromPricing - Ticket_CreateTSMFromPricing +- Ticket_CreateTSMFareElement - Ticket_DisplayTST - Ticket_DisplayTSMP - Ticket_DeleteTST @@ -77,7 +78,6 @@ These messages will be implemented at some point in the future. *Pull requests a - Ticket_ATCShopperMasterPricerTravelBoardSearch - Ticket_RepricePNRWithBookingClass - Ticket_ReissueConfirmedPricing -- Ticket_CreateTSMFareElement - Ticket_ProcessEDoc - Ticket_RetrieveListOfTSM - Ticket_AddDocNumber diff --git a/docs/samples.rst b/docs/samples.rst index bc2802b00..816f94129 100644 --- a/docs/samples.rst +++ b/docs/samples.rst @@ -1309,7 +1309,7 @@ Create a TSM from a Pricing previously made by a ``Service_IntegratedPricing`` c use Amadeus\Client\RequestOptions\Ticket\Pricing; use Amadeus\Client\RequestOptions\Ticket\PassengerReference; - $createTstResponse = $client->ticketCreateTSMFromPricing( + $createTsmResponse = $client->ticketCreateTSMFromPricing( new TicketCreateTsmFromPricingOptions([ 'pricings' => [ new Pricing([ @@ -1325,6 +1325,41 @@ Create a TSM from a Pricing previously made by a ``Service_IntegratedPricing`` c ]) ); +--------------------------- +Ticket_CreateTSMFareElement +--------------------------- + +Delete the form of payment from the TSM of tattoo 18: + +*In order to delete a fare element, enter '##### ' as info* + +.. code-block:: php + + use Amadeus\Client\RequestOptions\TicketCreateTsmFareElOptions; + + $createTsmResponse = $client->ticketCreateTSMFareElement( + new TicketCreateTsmFareElOptions([ + 'elementType' => TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => 18, + 'info' => '#####' + ]) + ); + + +Set the form of payment Check to the TSM of tattoo 18: + +.. code-block:: php + + use Amadeus\Client\RequestOptions\TicketCreateTsmFareElOptions; + + $createTsmResponse = $client->ticketCreateTSMFareElement( + new TicketCreateTsmFareElOptions([ + 'elementType' => TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => 18, + 'info' => 'CHECK/EUR304.89' + ]) + ); + ---------------- Ticket_DeleteTST ---------------- diff --git a/src/Amadeus/Client.php b/src/Amadeus/Client.php index 23be9d6fa..939227434 100644 --- a/src/Amadeus/Client.php +++ b/src/Amadeus/Client.php @@ -814,6 +814,22 @@ public function ticketCreateTSMFromPricing( return $this->callMessage($msgName, $options, $messageOptions); } + /** + * Ticket_CreateTSMFareElement + * + * @param RequestOptions\TicketCreateTsmFareElOptions $options + * @param array $messageOptions (OPTIONAL) + * @return Result + */ + public function ticketCreateTSMFareElement( + RequestOptions\TicketCreateTsmFareElOptions $options, + $messageOptions = [] + ) { + $msgName = 'Ticket_CreateTSMFareElement'; + + return $this->callMessage($msgName, $options, $messageOptions); + } + /** * Ticket_DeleteTST * diff --git a/src/Amadeus/Client/RequestCreator/Converter/Ticket/CreateTSMFareElementConv.php b/src/Amadeus/Client/RequestCreator/Converter/Ticket/CreateTSMFareElementConv.php new file mode 100644 index 000000000..521b058f0 --- /dev/null +++ b/src/Amadeus/Client/RequestCreator/Converter/Ticket/CreateTSMFareElementConv.php @@ -0,0 +1,46 @@ + + */ +class CreateTSMFareElementConv extends BaseConverter +{ + /** + * @param TicketCreateTsmFareElOptions $requestOptions + * @param int|string $version + * @return Struct\Ticket\CreateTSMFareElement + */ + public function convert($requestOptions, $version) + { + return new Struct\Ticket\CreateTSMFareElement($requestOptions); + } +} diff --git a/src/Amadeus/Client/RequestOptions/TicketCreateTsmFareElOptions.php b/src/Amadeus/Client/RequestOptions/TicketCreateTsmFareElOptions.php new file mode 100644 index 000000000..9f2c120bc --- /dev/null +++ b/src/Amadeus/Client/RequestOptions/TicketCreateTsmFareElOptions.php @@ -0,0 +1,62 @@ + + */ +class TicketCreateTsmFareElOptions extends Base +{ + const TYPE_FARE_DISCOUNT = "FD"; + const TYPE_ENDORSEMENT = "FE"; + const TYPE_COMMISSION = "FM"; + const TYPE_ORIGINAL_EXCHANGE_DOCUMENT = "FO"; + const TYPE_FORM_OF_PAYMENT = "FP"; + const TYPE_TOUR_CODE = "FT"; + const TYPE_MISCELLANEOUS_INFORMATION_1 = "FZ1"; + const TYPE_MISCELLANEOUS_INFORMATION_2 = "FZ2"; + + /** + * Type of the Fare element of the associated TSM. + * + * @var string + */ + public $elementType; + + /** + * The tattoo of the associated TSM. + * + * @var int + */ + public $tattoo; + + /** + * Unstructured fare element information + * + * @var string + */ + public $info; +} diff --git a/src/Amadeus/Client/ResponseHandler/Ticket/HandlerCreateTSMFareElement.php b/src/Amadeus/Client/ResponseHandler/Ticket/HandlerCreateTSMFareElement.php new file mode 100644 index 000000000..a66e07bf3 --- /dev/null +++ b/src/Amadeus/Client/ResponseHandler/Ticket/HandlerCreateTSMFareElement.php @@ -0,0 +1,33 @@ + + */ +class HandlerCreateTSMFareElement extends HandlerDisplayTSMFareElement +{ +} diff --git a/src/Amadeus/Client/Struct/Ticket/CreateTSMFareElement.php b/src/Amadeus/Client/Struct/Ticket/CreateTSMFareElement.php new file mode 100644 index 000000000..71a0f197d --- /dev/null +++ b/src/Amadeus/Client/Struct/Ticket/CreateTSMFareElement.php @@ -0,0 +1,62 @@ + + */ +class CreateTSMFareElement extends BaseWsMessage +{ + /** + * @var FareElementTattoo + */ + public $fareElementTattoo; + + /** + * @var FareElementInfo + */ + public $fareElementInfo; + + + /** + * Ticket_CreateTSMFareElement constructor. + * + * @param TicketCreateTsmFareElOptions $requestOptions + */ + public function __construct($requestOptions) + { + $this->fareElementTattoo = new FareElementTattoo( + $requestOptions->tattoo, + $requestOptions->elementType + ); + + $this->fareElementInfo = new FareElementInfo($requestOptions->info); + } +} diff --git a/src/Amadeus/Client/Struct/Ticket/FareElementInfo.php b/src/Amadeus/Client/Struct/Ticket/FareElementInfo.php new file mode 100644 index 000000000..47f9dd0a5 --- /dev/null +++ b/src/Amadeus/Client/Struct/Ticket/FareElementInfo.php @@ -0,0 +1,47 @@ + + */ +class FareElementInfo +{ + /** + * @var string + */ + public $text; + + /** + * FareElementInfo constructor. + * + * @param string $text + */ + public function __construct($text) + { + $this->text = $text; + } +} diff --git a/tests/Amadeus/Client/Struct/Ticket/CreateTSMFareElementTest.php b/tests/Amadeus/Client/Struct/Ticket/CreateTSMFareElementTest.php new file mode 100644 index 000000000..ddc6c579d --- /dev/null +++ b/tests/Amadeus/Client/Struct/Ticket/CreateTSMFareElementTest.php @@ -0,0 +1,79 @@ + + */ +class CreateTSMFareElementTest extends BaseTestCase +{ + /** + * 5.1 Operation: Delete the form of payment from the TSM + * + * This examples shows how to delete the form of payment Check from the TSM of tattoo 18. + * + * In order to delete a fare element, ##### needs to be put in tag. + */ + public function testCanMakeMessageDeleteFopFromTsm() + { + $opt = new TicketCreateTsmFareElOptions([ + 'elementType' => TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => 18, + 'info' => '#####', + ]); + + $msg = new CreateTSMFareElement($opt); + + $this->assertEquals(DisplayTSMFareElement\Reference::QUAL_FORM_OF_PAYMENT, $msg->fareElementTattoo->reference->qualifier); + $this->assertEquals(18, $msg->fareElementTattoo->reference->number); + $this->assertEquals('#####', $msg->fareElementInfo->text); + } + + /** + * 5.2 Operation: Set the form of payment Check to the TSM of tattoo 18 + * + * This examples shows how to set the form of payment Check to the TSM of tattoo 18. + */ + public function testCanMakeMessagePaymentCheck() + { + $opt = new TicketCreateTsmFareElOptions([ + 'elementType' => TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => 18, + 'info' => 'CHECK/EUR304.89', + ]); + + $msg = new CreateTSMFareElement($opt); + + $this->assertEquals(DisplayTSMFareElement\Reference::QUAL_FORM_OF_PAYMENT, $msg->fareElementTattoo->reference->qualifier); + $this->assertEquals(18, $msg->fareElementTattoo->reference->number); + $this->assertEquals('CHECK/EUR304.89', $msg->fareElementInfo->text); + } +} diff --git a/tests/Amadeus/ClientTest.php b/tests/Amadeus/ClientTest.php index 50d93d82c..76efc3c5a 100644 --- a/tests/Amadeus/ClientTest.php +++ b/tests/Amadeus/ClientTest.php @@ -1554,6 +1554,65 @@ public function testCanDoTicketCreateTSMFromPricing() $this->assertEquals($messageResult, $response); } + public function testCanDoTicketCreateTSMFareElement() + { + $mockSessionHandler = $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock(); + + $mockedSendResult = new Client\Session\Handler\SendResult(); + $mockedSendResult->responseXml = 'dummyTicketCreateTSMFareElementmessage'; + + $messageResult = new Client\Result($mockedSendResult); + + $expectedMessageResult = new Client\Struct\Ticket\CreateTSMFareElement( + new Client\RequestOptions\TicketCreateTsmFareElOptions([ + 'elementType' => Client\RequestOptions\TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => '18', + 'info' => '#####', + ]) + ); + + $mockSessionHandler + ->expects($this->once()) + ->method('sendMessage') + ->with('Ticket_CreateTSMFareElement', $expectedMessageResult, ['endSession' => false, 'returnXml' => true]) + ->will($this->returnValue($mockedSendResult)); + $mockSessionHandler + ->expects($this->never()) + ->method('getLastResponse'); + $mockSessionHandler + ->expects($this->once()) + ->method('getMessagesAndVersions') + ->will($this->returnValue(['Ticket_CreateTSMFareElement' => "10.1"])); + + $mockResponseHandler = $this->getMockBuilder('Amadeus\Client\ResponseHandler\ResponseHandlerInterface')->getMock(); + + $mockResponseHandler + ->expects($this->once()) + ->method('analyzeResponse') + ->with($mockedSendResult, 'Ticket_CreateTSMFareElement') + ->will($this->returnValue($messageResult)); + + $par = new Params(); + $par->sessionHandler = $mockSessionHandler; + $par->requestCreatorParams = new Params\RequestCreatorParams([ + 'receivedFrom' => 'some RF string', + 'originatorOfficeId' => 'BRUXXXXXX' + ]); + $par->responseHandler = $mockResponseHandler; + + $client = new Client($par); + + $response = $client->ticketCreateTSMFareElement( + new Client\RequestOptions\TicketCreateTsmFareElOptions([ + 'elementType' => Client\RequestOptions\TicketCreateTsmFareElOptions::TYPE_FORM_OF_PAYMENT, + 'tattoo' => '18', + 'info' => '#####', + ]) + ); + + $this->assertEquals($messageResult, $response); + } + public function testCanDoTicketDeleteTST() { $mockSessionHandler = $this->getMockBuilder('Amadeus\Client\Session\Handler\HandlerInterface')->getMock();