1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SetBased\ClubCollect\Resource; |
5
|
|
|
|
6
|
|
|
use SetBased\ClubCollect\ClubCollectApiClient; |
7
|
|
|
use SetBased\ClubCollect\Exception\ClubCollectApiException; |
8
|
|
|
use SetBased\ClubCollect\Helper\Cast; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* An entity representing a ticket. |
12
|
|
|
*/ |
13
|
|
|
class Ticket extends BaseResource |
14
|
|
|
{ |
15
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
16
|
|
|
/** |
17
|
|
|
* @var \DateTime |
18
|
|
|
*/ |
19
|
|
|
public $date; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
public $invoiceId; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
public $message; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
public $sender; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
public $ticketId; |
40
|
|
|
|
41
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
42
|
|
|
/** |
43
|
|
|
* Object constructor. |
44
|
|
|
* |
45
|
|
|
* @param ClubCollectApiClient $client The API client. |
46
|
|
|
* @param array $response The API response. |
47
|
|
|
* @param string|null $invoiceId The Id of the current invoice for which we are manipulating tickets |
48
|
|
|
* |
49
|
|
|
* @throws ClubCollectApiException |
50
|
|
|
*/ |
51
|
|
|
public function __construct(ClubCollectApiClient $client, array $response, ?string $invoiceId) |
52
|
|
|
{ |
53
|
|
|
parent::__construct($client); |
54
|
|
|
|
55
|
|
|
try |
56
|
|
|
{ |
57
|
|
|
$this->date = Cast::toManDateTime($response['date']); |
58
|
|
|
$this->invoiceId = Cast::toOptString($response['invoice_id'] ?? null, $invoiceId); |
59
|
|
|
$this->message = Cast::toManString($response['message']); |
60
|
|
|
$this->sender = Cast::toManString($response['sender']); |
61
|
|
|
$this->ticketId = Cast::toManString($response['ticket_id']); |
62
|
|
|
} |
63
|
|
|
catch (\Throwable $exception) |
64
|
|
|
{ |
65
|
|
|
throw new ClubCollectApiException([$exception], 'Failed to create a ticket'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
//-------------------------------------------------------------------------------------------------------------------- |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
//---------------------------------------------------------------------------------------------------------------------- |
73
|
|
|
|