1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Response; |
6
|
|
|
|
7
|
|
|
class SendResponse extends AbstractResponse |
8
|
|
|
{ |
9
|
|
|
private const RECIPIENT_ID = 'recipient_id'; |
10
|
|
|
private const MESSAGE_ID = 'message_id'; |
11
|
|
|
private const ATTACHMENT_ID = 'attachment_id'; |
12
|
|
|
|
13
|
|
|
private const ERROR = 'error'; |
14
|
|
|
private const ERROR_MESSAGE = 'message'; |
15
|
|
|
private const ERROR_TYPE = 'type'; |
16
|
|
|
private const ERROR_CODE = 'code'; |
17
|
|
|
private const ERROR_SUBCODE = 'error_subcode'; |
18
|
|
|
private const ERROR_FBTRACE_ID = 'fbtrace_id'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string|null |
22
|
|
|
*/ |
23
|
|
|
protected $recipientId; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string|null |
27
|
|
|
*/ |
28
|
|
|
protected $messageId; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string|null |
32
|
|
|
*/ |
33
|
|
|
protected $attachmentId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string|null |
37
|
|
|
*/ |
38
|
|
|
protected $errorMessage; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string|null |
42
|
|
|
*/ |
43
|
|
|
protected $errorType; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var int|null |
47
|
|
|
*/ |
48
|
|
|
protected $errorCode; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int|null |
52
|
|
|
*/ |
53
|
|
|
protected $errorSubcode; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string|null |
57
|
|
|
*/ |
58
|
|
|
protected $errorFbtraceId; |
59
|
|
|
|
60
|
10 |
|
protected function parseResponse(array $response): void |
61
|
|
|
{ |
62
|
10 |
|
if (!$this->hasError($response)) { |
63
|
9 |
|
$this->recipientId = $response[self::RECIPIENT_ID] ?? null; |
64
|
9 |
|
$this->messageId = $response[self::MESSAGE_ID] ?? null; |
65
|
9 |
|
$this->attachmentId = $response[self::ATTACHMENT_ID] ?? null; |
66
|
|
|
} |
67
|
10 |
|
} |
68
|
|
|
|
69
|
10 |
|
private function hasError(array $response): bool |
70
|
|
|
{ |
71
|
10 |
|
if (isset($response[self::ERROR])) { |
72
|
1 |
|
$this->errorMessage = $response[self::ERROR][self::ERROR_MESSAGE] ?? null; |
73
|
1 |
|
$this->errorType = $response[self::ERROR][self::ERROR_TYPE] ?? null; |
74
|
1 |
|
$this->errorCode = $response[self::ERROR][self::ERROR_CODE] ?? null; |
75
|
1 |
|
$this->errorSubcode = $response[self::ERROR][self::ERROR_SUBCODE] ?? null; |
76
|
1 |
|
$this->errorFbtraceId = $response[self::ERROR][self::ERROR_FBTRACE_ID] ?? null; |
77
|
|
|
|
78
|
1 |
|
return true; |
79
|
|
|
} |
80
|
|
|
|
81
|
9 |
|
return false; |
82
|
|
|
} |
83
|
|
|
|
84
|
9 |
|
public function getRecipientId(): ?string |
85
|
|
|
{ |
86
|
9 |
|
return $this->recipientId; |
87
|
|
|
} |
88
|
|
|
|
89
|
8 |
|
public function getMessageId(): ?string |
90
|
|
|
{ |
91
|
8 |
|
return $this->messageId; |
92
|
|
|
} |
93
|
|
|
|
94
|
4 |
|
public function getAttachmentId(): ?string |
95
|
|
|
{ |
96
|
4 |
|
return $this->attachmentId; |
97
|
|
|
} |
98
|
|
|
|
99
|
3 |
|
public function getErrorMessage(): ?string |
100
|
|
|
{ |
101
|
3 |
|
return $this->errorMessage; |
102
|
|
|
} |
103
|
|
|
|
104
|
3 |
|
public function getErrorType(): ?string |
105
|
|
|
{ |
106
|
3 |
|
return $this->errorType; |
107
|
|
|
} |
108
|
|
|
|
109
|
3 |
|
public function getErrorCode(): ?int |
110
|
|
|
{ |
111
|
3 |
|
return $this->errorCode; |
112
|
|
|
} |
113
|
|
|
|
114
|
3 |
|
public function getErrorSubcode(): ?int |
115
|
|
|
{ |
116
|
3 |
|
return $this->errorSubcode; |
117
|
|
|
} |
118
|
|
|
|
119
|
3 |
|
public function getErrorFbtraceId(): ?string |
120
|
|
|
{ |
121
|
3 |
|
return $this->errorFbtraceId; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|