Skip to content

Commit

Permalink
Add Service_BookPriceProduct (#457)
Browse files Browse the repository at this point in the history
  • Loading branch information
tsari-invia authored and therealartz committed Nov 3, 2024
1 parent 6c80805 commit f4145fd
Show file tree
Hide file tree
Showing 19 changed files with 451 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased
* Implemented ``Service_BookPriceProduct``
* Added Dockerfile/Makefile for easier development

## Release 2.1 (2 Nov 2024)
* New messages (NDC): Travel_OrderChange, Travel_SeatAvailability, Travel_ServiceList (https://github.com/amabnl/amadeus-ws-client/pull/484) - Artem Zakharchenko
* Fix mt_srand() argument is always 0 after #https://github.com/amabnl/amadeus-ws-client/pull/449 (https://github.com/amabnl/amadeus-ws-client/pull/482) - Artem Zakharchenko
Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,11 @@ For that it's best to rely on the Amadeus Web Services Extranet functional docum

You should also remember that the request options object is an object used by users of this library, so we should be able to maintain backwards compatibility even when changing the features implemented for a message.

An example pull request to learn from: https://github.com/amabnl/amadeus-ws-client/pull/74
An example pull request to learn from: https://github.com/amabnl/amadeus-ws-client/pull/74

## Testing your changes
If you have docker installed, simply run `make test`, that will
- build a basic docker image (`make build-docker-image`)
- download a composer.phar (`make composer-download`)
- install all dependencies (`make composer-install`)
- and finally run the tests (`make phpunit`)
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM php:8.3-apache

# Requirements
RUN apt-get update \
&& apt-get install -y libxslt1-dev libzip-dev unzip git curl

# PHP extensions
RUN docker-php-ext-install soap
RUN docker-php-ext-install xsl

# Add the application
ADD . /var/www
WORKDIR /var/www

RUN git config --system --add safe.directory /var/www

# Install composer
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/bin/composer

# Install dependencies
RUN composer i
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
image_name = amadeus-ws-client:build

SHELL = /bin/sh

build-docker-image:
docker build -t $(image_name) -f Dockerfile .

build-docker-image-once:
make verify-docker-image-exists || make build-docker-image

build-docker-image-no-cache:
docker build --no-cache -t $(image_name) -f Dockerfile .

verify-docker-image-exists:
docker image inspect $(image_name) >/dev/null 2>&1

composer-install:
docker run --rm -ti -v $(shell pwd):/var/www -w /var/www -u $(shell id -u) $(image_name) composer i

phpunit:
docker run --rm -ti -v $(shell pwd):/var/www -w /var/www -u $(shell id -u) $(image_name) ./vendor/bin/phpunit

test:
make build-docker-image-once
make composer-install
make phpunit
1 change: 1 addition & 0 deletions docs/list-of-supported-messages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ This is the list of messages that are at least partially supported at this time:
- Service_Integrated#
- Service_IntegratedCatalogue
- Service_StandaloneCatalogue
- Service_BookPriceProduct
- Service_BookPriceService
- Offer_CreateOffer
- Offer_VerifyOffer
Expand Down
26 changes: 26 additions & 0 deletions docs/samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3614,6 +3614,32 @@ Service_StandaloneCatalogue
])
);

------------------------
Service_BookPriceProduct
------------------------

Book ancillary with service reference 14 for pax with reference 2 and 3.

You'll get the service references from the ``Service_IntegratedCatalogue`` response.

.. code-block:: php
use Amadeus\Client\RequestOptions\Service\BookPriceProduct\Recommendation;
use Amadeus\Client\RequestOptions\ServiceBookPriceProductOptions;
$bookPriceProductResult = $client->serviceBookPriceProduct(
new ServiceBookPriceProductOptions([
'recommendations' => [
new Recommendation(
[
'id' => 14,
'customerRefIds' => [2, 3]
]
)
]
])
);
------------------------
Service_BookPriceService
------------------------
Expand Down
23 changes: 23 additions & 0 deletions src/Amadeus/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@

use Amadeus\Client\Base;
use Amadeus\Client\Exception;
use Amadeus\Client\InvalidMessageException;
use Amadeus\Client\Params;
use Amadeus\Client\RequestCreator\MessageVersionUnsupportedException;
use Amadeus\Client\RequestOptions;
use Amadeus\Client\RequestOptions\ServiceBookPriceProductOptions;
use Amadeus\Client\Result;
use Amadeus\Client\Session\Handler\UnsupportedOperationException;

Expand Down Expand Up @@ -1694,6 +1697,26 @@ public function serviceIntegratedCatalogue(
return $this->callMessage($msgName, $options, $messageOptions);
}

/**
* Service_BookPriceProduct
*
* @param ServiceBookPriceProductOptions $options
* @param array $messageOptions (OPTIONAL)
*
* @return Result
* @throws Exception
* @throws InvalidMessageException
* @throws MessageVersionUnsupportedException
*/
public function serviceBookPriceProduct(
RequestOptions\ServiceBookPriceProductOptions $options,
$messageOptions = []
) {
$msgName = 'Service_BookPriceProduct';

return $this->callMessage($msgName, $options, $messageOptions);
}

/**
* Service_BookPriceService
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Amadeus\Client\RequestCreator\Converter\Service;

use Amadeus\Client\RequestCreator\Converter\BaseConverter;
use Amadeus\Client\RequestOptions\ServiceBookPriceProductOptions;
use Amadeus\Client\Struct;

/**
* Service_BookPriceProduct Request converter
*
* @package Amadeus\Client\RequestCreator\Converter\Service
*/
class BookPriceProductConv extends BaseConverter
{
/**
* @param ServiceBookPriceProductOptions $requestOptions
* @param int|string $version
* @return Struct\Service\BookPriceProduct
*/
public function convert($requestOptions, $version)
{
return new Struct\Service\BookPriceProduct($requestOptions);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Amadeus\Client\RequestOptions\Service\BookPriceProduct;

use Amadeus\Client\LoadParamsFromArray;

class Recommendation extends LoadParamsFromArray
{
/**
* @var string|int
*/
public $id;

/**
* @var string[]|int[] One or more travelers to whom this service applies
*/
public $customerRefIds = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Amadeus\Client\RequestOptions;

use Amadeus\Client\RequestOptions\Service\BookPriceProduct\Recommendation;

/**
* Service_BookPriceProduct Request Options
*
* @package Amadeus\Client\RequestOptions
*/
class ServiceBookPriceProductOptions extends Base
{
/**
* @var string For all OpenTravel versioned messages, the version of the message is indicated by a decimal value.
*/
public $version = '1.0';

/**
* @var Recommendation[]
*/
public $recommendations = [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* amadeus-ws-client
*
* Copyright 2015 Amadeus Benelux NV
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @package Amadeus
* @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
*/

namespace Amadeus\Client\ResponseHandler\Service;

/**
* HandlerBookPriceService
*
* @package Amadeus\Client\ResponseHandler\Service
*/
class HandlerBookPriceProduct extends HandlerBookPriceService
{
}
29 changes: 29 additions & 0 deletions src/Amadeus/Client/Struct/Service/BookPriceProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Amadeus\Client\Struct\Service;

use Amadeus\Client\RequestOptions\ServiceBookPriceProductOptions;
use Amadeus\Client\Struct\BaseWsMessage;
use Amadeus\Client\Struct\Service\BookPriceProduct\Recommendation;

class BookPriceProduct extends BaseWsMessage
{
/**
* @var Recommendation[]
*/
public $Recommendation;

public $Version;

/**
* @param ServiceBookPriceProductOptions $options
*/
public function __construct($options)
{
$this->Version = $options->version;

foreach ($options->recommendations as $recommendation) {
$this->Recommendation[] = new Recommendation($recommendation);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Amadeus\Client\Struct\Service\BookPriceProduct;

class Recommendation
{
/**
* @var string
*/
public $RecoID;

/**
* @var string[]
*/
public $CustomerRefIds;

/**
* @param \Amadeus\Client\RequestOptions\Service\BookPriceProduct\Recommendation $recommendationOptions
*/
public function __construct($recommendationOptions)
{
$this->RecoID = $recommendationOptions->id;

if (!empty($recommendationOptions->customerRefIds)) {
$this->CustomerRefIds = $recommendationOptions->customerRefIds;
}
}
}
33 changes: 33 additions & 0 deletions tests/Amadeus/Client/RequestCreator/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
use Amadeus\Client\RequestOptions\PnrRetrieveOptions;
use Amadeus\Client\RequestOptions\Queue;
use Amadeus\Client\RequestOptions\QueueListOptions;
use Amadeus\Client\RequestOptions\Service\BookPriceProduct\Recommendation;
use Amadeus\Client\RequestOptions\ServiceBookPriceProductOptions;
use Amadeus\Client\Struct\Fare\InformativeBest#WithoutPNR13;
use Amadeus\Client\Struct\Offer\Reference;
use Amadeus\Client\Struct\Offer\Verify;
Expand Down Expand Up @@ -455,4 +457,35 @@ public function testCanTryBuildingSameMessageTwiceWillReuseBuilder()

self::assertInstanceOf(InformativeBest#WithoutPNR13::class, $result);
}

public function testCanCreateServiceBookPriceProductMessage()
{
$par = new RequestCreatorParams([
'originatorOfficeId' => 'BRUXXXXXX',
'receivedFrom' => 'some RF string',
'messagesAndVersions' => ['Service_BookPriceProduct' => ['version' => '1.0', 'wsdl' => 'aabbccdd']]
]);

$rq = new Base($par);

$message = $rq->createRequest(
'Service_BookPriceProduct',
new ServiceBookPriceProductOptions(
[
'version' => '1.1',
'recommendations' => [
new Recommendation(['id' => '14', 'customerRefIds' => [0, 1]])
]
]
)
);

$this->assertInstanceOf('Amadeus\Client\Struct\Service\BookPriceProduct', $message);
/** @var RetrieveAndDisplay $message */
$this->assertEquals('1.1', $message->Version);
$this->assertInstanceOf('Amadeus\Client\Struct\Service\BookPriceProduct\Recommendation', $message->Recommendation[0]);
$this->assertEquals('14', $message->Recommendation[0]->RecoID);
$this->assertEquals([0, 1], $message->Recommendation[0]->CustomerRefIds);
}

}
Loading

0 comments on commit f4145fd

Please # to comment.