This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from duffelhq/api-orders
API: Orders
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Duffel\Api; | ||
|
||
class Orders extends AbstractApi { | ||
public function all() { | ||
return $this->get('/air/orders'); | ||
} | ||
|
||
public function show(string $id) { | ||
return $this->get('/air/orders/'.self::encodePath($id)); | ||
} | ||
|
||
public function create(array $params) { | ||
return $this->post('/air/orders', \array_filter($params, function ($value) { | ||
return null !== $value && (!\is_string($value) || '' !== $value); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Duffel\Tests\Api; | ||
|
||
use Duffel\Api\Orders; | ||
use Duffel\Client; | ||
use Http\Client\Common\HttpMethodsClientInterface; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TestOrders extends TestCase { | ||
private $mock; | ||
private $stub; | ||
|
||
public function setUp(): void { | ||
$this->mock = $this->createMock(HttpMethodsClientInterface::class); | ||
$this->stub = $this->createStub(Client::class); | ||
$this->stub->method('getHttpClient') | ||
->willReturn($this->mock); | ||
} | ||
|
||
public function testAllCallsGetWithExpectedUri(): void { | ||
$this->mock->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('/air/orders')); | ||
|
||
$actual = new Orders($this->stub); | ||
$actual->all(); | ||
} | ||
|
||
public function testShowWithIdCallsGetWithExpectedUri(): void { | ||
$this->mock->expects($this->once()) | ||
->method('get') | ||
->with($this->equalTo('/air/orders/some-id')); | ||
|
||
$actual = new Orders($this->stub); | ||
$actual->show('some-id'); | ||
} | ||
|
||
public function testCreateWithOfferAndPassengersAndPaymentsCallsGetWithExpectedUri(): void { | ||
$this->mock->expects($this->once()) | ||
->method('post') | ||
->with( | ||
$this->equalTo('/air/orders'), | ||
$this->equalTo(['Content-Type' => 'application/json']), | ||
$this->equalTo('{"data":{"selected_offers":"off_00009htyDGjIfajdNBZRlw","payments":[{"type":"balance","amount":"30.20","currency":"GBP"}],"passengers":[{"id":"pas_00009hj8USM7Ncg31cBCLL","title":"ms","gender":"f","given_name":"Amelia","family_name":"Earhart","born_on":"1987-07-24","phone_number":"+442080160509","email":"amelia@duffel.dev"}]}}') | ||
); | ||
|
||
$actual = new Orders($this->stub); | ||
$actual->create( | ||
[ | ||
'selected_offers' => 'off_00009htyDGjIfajdNBZRlw', | ||
'payments' => [ | ||
[ | ||
'type' => 'balance', | ||
'amount' => '30.20', | ||
'currency' => 'GBP' | ||
] | ||
], | ||
'passengers' => [ | ||
[ | ||
'id' => 'pas_00009hj8USM7Ncg31cBCLL', | ||
'title' => 'ms', | ||
'gender' => 'f', | ||
'given_name' => 'Amelia', | ||
'family_name' => 'Earhart', | ||
'born_on' => '1987-07-24', | ||
'phone_number' => '+442080160509', | ||
'email' => 'amelia@duffel.dev', | ||
] | ||
] | ||
] | ||
); | ||
} | ||
|
||
public function testCreateWithOfferAndServicesAndPassengersAndPaymentsCallsGetWithExpectedUri(): void { | ||
$this->mock->expects($this->once()) | ||
->method('post') | ||
->with( | ||
$this->equalTo('/air/orders'), | ||
$this->equalTo(['Content-Type' => 'application/json']), | ||
$this->equalTo('{"data":{"selected_offers":"off_00009htyDGjIfajdNBZRlw","services":[{"id":"ase_00009hj8USM7Ncg31cB123","quantity":1}],"payments":[{"type":"balance","amount":"30.20","currency":"GBP"}],"passengers":[{"id":"pas_00009hj8USM7Ncg31cBCLL","title":"ms","gender":"f","given_name":"Amelia","family_name":"Earhart","born_on":"1987-07-24","phone_number":"+442080160509","email":"amelia@duffel.dev"}]}}') | ||
); | ||
|
||
$actual = new Orders($this->stub); | ||
$actual->create( | ||
[ | ||
'selected_offers' => 'off_00009htyDGjIfajdNBZRlw', | ||
'services' => [ | ||
[ | ||
'id' => 'ase_00009hj8USM7Ncg31cB123', | ||
"quantity" => 1, | ||
] | ||
], | ||
'payments' => [ | ||
[ | ||
'type' => 'balance', | ||
'amount' => '30.20', | ||
'currency' => 'GBP' | ||
] | ||
], | ||
'passengers' => [ | ||
[ | ||
'id' => 'pas_00009hj8USM7Ncg31cBCLL', | ||
'title' => 'ms', | ||
'gender' => 'f', | ||
'given_name' => 'Amelia', | ||
'family_name' => 'Earhart', | ||
'born_on' => '1987-07-24', | ||
'phone_number' => '+442080160509', | ||
'email' => 'amelia@duffel.dev', | ||
] | ||
] | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters