|
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 null|string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $recipientId; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var null|string |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $messageId; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var null|string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $attachmentId; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var null|string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $errorMessage; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var null|string |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $errorType; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var null|int |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $errorCode; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var null|int |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $errorSubcode; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @var null|string |
|
57
|
|
|
*/ |
|
58
|
|
|
protected $errorFbtraceId; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param array $response |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function parseResponse(array $response): void |
|
64
|
|
|
{ |
|
65
|
9 |
|
if (!$this->hasError($response)) { |
|
66
|
|
|
$this->setRecipientId($response); |
|
67
|
9 |
|
$this->setMessageId($response); |
|
68
|
9 |
|
$this->setAttachmentId($response); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
9 |
|
* @param array $response |
|
74
|
|
|
* |
|
75
|
9 |
|
* @return bool |
|
76
|
8 |
|
*/ |
|
77
|
8 |
|
private function hasError(array $response): bool |
|
78
|
8 |
|
{ |
|
79
|
|
|
if (isset($response[self::ERROR])) { |
|
80
|
9 |
|
$this->setErrorMessage($response[self::ERROR]); |
|
81
|
|
|
$this->setErrorType($response[self::ERROR]); |
|
82
|
|
|
$this->setErrorCode($response[self::ERROR]); |
|
83
|
|
|
$this->setErrorSubcode($response[self::ERROR]); |
|
84
|
|
|
$this->setErrorFbtraceId($response[self::ERROR]); |
|
85
|
|
|
|
|
86
|
|
|
return true; |
|
87
|
9 |
|
} |
|
88
|
|
|
|
|
89
|
9 |
|
return false; |
|
90
|
1 |
|
} |
|
91
|
1 |
|
|
|
92
|
1 |
|
/** |
|
93
|
1 |
|
* @return null|string |
|
94
|
1 |
|
*/ |
|
95
|
|
|
public function getRecipientId(): ?string |
|
96
|
1 |
|
{ |
|
97
|
|
|
return $this->recipientId; |
|
98
|
|
|
} |
|
99
|
8 |
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param array $response |
|
102
|
|
|
*/ |
|
103
|
|
|
private function setRecipientId(array $response): void |
|
104
|
|
|
{ |
|
105
|
7 |
|
if (isset($response[self::RECIPIENT_ID])) { |
|
106
|
|
|
$this->recipientId = $response[self::RECIPIENT_ID]; |
|
107
|
7 |
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @return null|string |
|
112
|
|
|
*/ |
|
113
|
8 |
|
public function getMessageId(): ?string |
|
114
|
|
|
{ |
|
115
|
8 |
|
return $this->messageId; |
|
116
|
7 |
|
} |
|
117
|
|
|
|
|
118
|
8 |
|
/** |
|
119
|
|
|
* @param array $response |
|
120
|
|
|
*/ |
|
121
|
|
|
private function setMessageId(array $response): void |
|
122
|
|
|
{ |
|
123
|
7 |
|
if (isset($response[self::MESSAGE_ID])) { |
|
124
|
|
|
$this->messageId = $response[self::MESSAGE_ID]; |
|
125
|
7 |
|
} |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return null|string |
|
130
|
|
|
*/ |
|
131
|
8 |
|
public function getAttachmentId(): ?string |
|
132
|
|
|
{ |
|
133
|
8 |
|
return $this->attachmentId; |
|
134
|
7 |
|
} |
|
135
|
|
|
|
|
136
|
8 |
|
/** |
|
137
|
|
|
* @param array $response |
|
138
|
|
|
*/ |
|
139
|
|
|
private function setAttachmentId(array $response): void |
|
140
|
|
|
{ |
|
141
|
4 |
|
if (isset($response[self::ATTACHMENT_ID])) { |
|
142
|
|
|
$this->attachmentId = $response[self::ATTACHMENT_ID]; |
|
143
|
4 |
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* @return null|string |
|
148
|
|
|
*/ |
|
149
|
8 |
|
public function getErrorMessage(): ?string |
|
150
|
|
|
{ |
|
151
|
8 |
|
return $this->errorMessage; |
|
152
|
2 |
|
} |
|
153
|
|
|
|
|
154
|
8 |
|
/** |
|
155
|
|
|
* @param array $error |
|
156
|
|
|
*/ |
|
157
|
|
|
private function setErrorMessage(array $error): void |
|
158
|
|
|
{ |
|
159
|
3 |
|
if (isset($error[self::ERROR_MESSAGE])) { |
|
160
|
|
|
$this->errorMessage = $error[self::ERROR_MESSAGE]; |
|
161
|
3 |
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return null|string |
|
166
|
|
|
*/ |
|
167
|
1 |
|
public function getErrorType(): ?string |
|
168
|
|
|
{ |
|
169
|
1 |
|
return $this->errorType; |
|
170
|
1 |
|
} |
|
171
|
|
|
|
|
172
|
1 |
|
/** |
|
173
|
|
|
* @param array $error |
|
174
|
|
|
*/ |
|
175
|
|
|
private function setErrorType(array $error): void |
|
176
|
|
|
{ |
|
177
|
3 |
|
if (isset($error[self::ERROR_TYPE])) { |
|
178
|
|
|
$this->errorType = $error[self::ERROR_TYPE]; |
|
179
|
3 |
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* @return null|int |
|
184
|
|
|
*/ |
|
185
|
1 |
|
public function getErrorCode(): ?int |
|
186
|
|
|
{ |
|
187
|
1 |
|
return $this->errorCode; |
|
188
|
1 |
|
} |
|
189
|
|
|
|
|
190
|
1 |
|
/** |
|
191
|
|
|
* @param array $error |
|
192
|
|
|
*/ |
|
193
|
|
|
private function setErrorCode(array $error): void |
|
194
|
|
|
{ |
|
195
|
3 |
|
if (isset($error[self::ERROR_CODE])) { |
|
196
|
|
|
$this->errorCode = $error[self::ERROR_CODE]; |
|
197
|
3 |
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @return null|int |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function getErrorSubcode(): ?int |
|
204
|
|
|
{ |
|
205
|
1 |
|
return $this->errorSubcode; |
|
206
|
1 |
|
} |
|
207
|
|
|
|
|
208
|
1 |
|
/** |
|
209
|
|
|
* @param array $error |
|
210
|
|
|
*/ |
|
211
|
|
|
private function setErrorSubcode(array $error): void |
|
212
|
|
|
{ |
|
213
|
3 |
|
if (isset($error[self::ERROR_SUBCODE])) { |
|
214
|
|
|
$this->errorSubcode = $error[self::ERROR_SUBCODE]; |
|
215
|
3 |
|
} |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* @return null|string |
|
220
|
|
|
*/ |
|
221
|
1 |
|
public function getErrorFbtraceId(): ?string |
|
222
|
|
|
{ |
|
223
|
1 |
|
return $this->errorFbtraceId; |
|
224
|
1 |
|
} |
|
225
|
|
|
|
|
226
|
1 |
|
/** |
|
227
|
|
|
* @param array $error |
|
228
|
|
|
*/ |
|
229
|
|
|
private function setErrorFbtraceId(array $error): void |
|
230
|
|
|
{ |
|
231
|
3 |
|
if (isset($error[self::ERROR_FBTRACE_ID])) { |
|
232
|
|
|
$this->errorFbtraceId = $error[self::ERROR_FBTRACE_ID]; |
|
233
|
3 |
|
} |
|
234
|
|
|
} |
|
235
|
|
|
} |
|
236
|
|
|
|