Skip to content

Commit

Permalink
Allow for-sale config to be specified when events and seasons are cre…
Browse files Browse the repository at this point in the history
…ated (#99)

Co-authored-by: Steve Chaloner <[email protected]>
  • Loading branch information
schaloner and Steve Chaloner authored Oct 16, 2023
1 parent 876a54a commit d744dce
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Events/CreateEventParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ class CreateEventParams extends EventParams
*/
public $channels;

/**
* @var \Seatsio\Events\ForSaleConfig
*/
public $forSaleConfig;

static function create(): CreateEventParams
{
return new CreateEventParams();
Expand All @@ -22,4 +27,13 @@ public function setChannels(array $channels): self
$this->channels = $channels;
return $this;
}

/**
* @param \Seatsio\Events\ForSaleConfig $forSaleConfig
*/
public function setForSaleConfig(ForSaleConfig $forSaleConfig): self
{
$this->forSaleConfig = $forSaleConfig;
return $this;
}
}
8 changes: 8 additions & 0 deletions src/Events/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function create(string $chartKey, CreateEventParams $params = null): Even
if ($params->channels !== null) {
$request->channels = $params->channels;
}

if ($params->forSaleConfig !== null) {
$request->forSaleConfig = $params->forSaleConfig;
}
}

$res = $this->client->post('/events', ['json' => $request]);
Expand Down Expand Up @@ -112,6 +116,10 @@ public function createMultiple(string $chartKey, array $createEventParams): arra
$eventToCreate->channels = $param->channels;
}

if ($param->forSaleConfig !== null) {
$eventToCreate->forSaleConfig = $param->forSaleConfig;
}

$request->events[] = $eventToCreate;
}

Expand Down
7 changes: 7 additions & 0 deletions src/Events/ForSaleConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ class ForSaleConfig
* @var string[]
*/
public $categories;

public function __construct(bool $forSale, array $objects = null, array $areaPlaces = null, array $categories = null) {
$this->forSale = $forSale;
$this->objects = $objects;
$this-> areaPlaces = $areaPlaces;
$this->categories = $categories;
}
}
15 changes: 15 additions & 0 deletions src/Seasons/SeasonCreationParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Seatsio\Seasons;

use Seatsio\Events\ForSaleConfig;
use Seatsio\Events\TableBookingConfig;

class SeasonCreationParams
Expand Down Expand Up @@ -32,6 +33,11 @@ class SeasonCreationParams
*/
public $channels;

/**
* @var \Seatsio\Events\ForSaleConfig
*/
public $forSaleConfig;

public function __construct(string $key = null)
{
$this->key = $key;
Expand Down Expand Up @@ -68,4 +74,13 @@ public function setChannels(array $channels): self
$this->channels = $channels;
return $this;
}

/**
* @param \Seatsio\Events\ForSaleConfig $forSaleConfig
*/
public function setForSaleConfig(ForSaleConfig $forSaleConfig): self
{
$this->forSaleConfig = $forSaleConfig;
return $this;
}
}
4 changes: 4 additions & 0 deletions src/Seasons/Seasons.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function create(string $chartKey, SeasonCreationParams $seasonCreationPar
if ($seasonCreationParams->channels !== null) {
$request->channels = $seasonCreationParams->channels;
}

if ($seasonCreationParams->forSaleConfig !== null) {
$request->forSaleConfig = $seasonCreationParams->forSaleConfig;
}
}

$res = $this->client->post('/seasons', ['json' => $request]);
Expand Down
10 changes: 10 additions & 0 deletions tests/Events/CreateEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,14 @@ public function testChannelsCanBePassedIn()

self::assertEquals($channels, $event->channels);
}

public function testForSaleConfigCanBePassedIn()
{
$chartKey = $this->createTestChart();
$forSaleConfig = new ForSaleConfig(true, ["A-1"], ["GA1" => 3], ["Cat1"]);

$event = $this->seatsioClient->events->create($chartKey, CreateEventParams::create()->setForSaleConfig($forSaleConfig));

self::assertEquals($forSaleConfig, $event->forSaleConfig);
}
}
15 changes: 15 additions & 0 deletions tests/Events/CreateEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,19 @@ public function test_channelsCanBePassedIn()
self::assertEquals($channels, $events[0]->channels);
}

public function test_forSaleConfigCanBePassedIn()
{
$chartKey = $this->createTestChart();
$forSaleConfig1 = new ForSaleConfig(true, ["A-1"], ["GA1" => 3], ["Cat1"]);
$forSaleConfig2 = new ForSaleConfig(true, ["A-2"], ["GA1" => 5], ["Cat1"]);
$params = [
CreateEventParams::create()->setForSaleConfig($forSaleConfig1),
CreateEventParams::create()->setForSaleConfig($forSaleConfig2)
];

$events = $this->seatsioClient->events->createMultiple($chartKey, $params);

self::assertEquals($forSaleConfig1, $events[0]->forSaleConfig);
self::assertEquals($forSaleConfig2, $events[1]->forSaleConfig);
}
}
12 changes: 12 additions & 0 deletions tests/Seasons/CreateSeasonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Seatsio\Seasons;

use Seatsio\Events\Channel;
use Seatsio\Events\ForSaleConfig;
use Seatsio\Events\TableBookingConfig;
use Seatsio\SeatsioClientTest;
use function Functional\map;
Expand Down Expand Up @@ -90,4 +91,15 @@ public function testChannelsCanBePassedIn()
self::assertNotNull($season->key);
self::assertEquals($channels, $season->channels);
}

public function testForSaleConfigCanBePassedIn()
{
$chartKey = $this->createTestChart();
$forSaleConfig = new ForSaleConfig(false, ["A-1"], ["GA1" => 3], ["Cat1"]);

$season = $this->seatsioClient->seasons->create($chartKey, (new SeasonCreationParams())->setForSaleConfig($forSaleConfig));

self::assertNotNull($season->key);
self::assertEquals($forSaleConfig, $season->forSaleConfig);
}
}

0 comments on commit d744dce

Please sign in to comment.