1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Browser information |
4
|
|
|
* |
5
|
|
|
* @author Pronamic <[email protected]> |
6
|
|
|
* @copyright 2005-2020 Pronamic |
7
|
|
|
* @license GPL-3.0-or-later |
8
|
|
|
* @package Pronamic\WordPress\Pay\Gateways\Adyen |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Pronamic\WordPress\Pay\Gateways\Adyen; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Browser information |
15
|
|
|
* |
16
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v51/payments__reqParam_browserInfo |
17
|
|
|
* @link https://docs.adyen.com/development-resources/building-adyen-solutions |
18
|
|
|
* |
19
|
|
|
* @author Reüel van der Steege |
20
|
|
|
* @version 1.1.1 |
21
|
|
|
* @since 1.1.1 |
22
|
|
|
*/ |
23
|
|
|
class BrowserInformation implements \JsonSerializable { |
24
|
|
|
/** |
25
|
|
|
* The accept header value of the shopper's browser. |
26
|
|
|
* |
27
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v51/payments__reqParam_browserInfo-acceptHeader |
28
|
|
|
* @var string|null |
29
|
|
|
*/ |
30
|
|
|
private $accept_header; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The color depth of the shopper's browser in bits per pixel. This should be obtained by using the browser's |
34
|
|
|
* screen.colorDepth property. Accepted values: 1, 4, 8, 15, 16, 24, 32 or 48 bit color depth. |
35
|
|
|
* |
36
|
|
|
* @link |
37
|
|
|
* @var int|null |
38
|
|
|
*/ |
39
|
|
|
private $color_depth; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Boolean value indicating if the shopper's browser is able to execute Java. |
43
|
|
|
* |
44
|
|
|
* @link |
45
|
|
|
* @var bool|null |
46
|
|
|
*/ |
47
|
|
|
private $java_enabled; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Boolean value indicating if the shopper's browser is able to execute JavaScript. |
51
|
|
|
* A default 'true' value is assumed if the field is not present. |
52
|
|
|
* |
53
|
|
|
* @link |
54
|
|
|
* @var bool|null |
55
|
|
|
*/ |
56
|
|
|
private $javascript_enabled; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The navigator.language value of the shopper's browser (as defined in IETF BCP 47). |
60
|
|
|
* |
61
|
|
|
* @link |
62
|
|
|
* @var string|null |
63
|
|
|
*/ |
64
|
|
|
private $language; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The total height of the shopper's device screen in pixels. |
68
|
|
|
* |
69
|
|
|
* @link |
70
|
|
|
* @var int|null |
71
|
|
|
*/ |
72
|
|
|
private $screen_height; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* The total width of the shopper's device screen in pixels. |
76
|
|
|
* |
77
|
|
|
* @link |
78
|
|
|
* @var int|null |
79
|
|
|
*/ |
80
|
|
|
private $screen_width; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Time difference between UTC time and the shopper's browser local time, in minutes. |
84
|
|
|
* |
85
|
|
|
* @link |
86
|
|
|
* @var int|null |
87
|
|
|
*/ |
88
|
|
|
private $timezone_offset; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* The user agent value of the shopper's browser. |
92
|
|
|
* |
93
|
|
|
* @link |
94
|
|
|
* @var string|null |
95
|
|
|
*/ |
96
|
|
|
private $user_agent; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get accept header. |
100
|
|
|
* |
101
|
|
|
* @return string|null |
102
|
|
|
*/ |
103
|
|
|
public function get_accept_header() { |
104
|
|
|
return $this->accept_header; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Set accept header. |
109
|
|
|
* |
110
|
|
|
* @param string|null $accept_header Accept header. |
111
|
|
|
* @return void |
112
|
|
|
*/ |
113
|
|
|
public function set_accept_header( $accept_header ) { |
114
|
|
|
$this->accept_header = $accept_header; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get color depth. |
119
|
|
|
* |
120
|
|
|
* @return int|null |
121
|
|
|
*/ |
122
|
|
|
public function get_color_depth() { |
123
|
|
|
return $this->color_depth; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Set color depth. |
128
|
|
|
* |
129
|
|
|
* @param int|null $color_depth Color depth. |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function set_color_depth( $color_depth ) { |
133
|
|
|
$this->color_depth = $color_depth; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get java enabled. |
138
|
|
|
* |
139
|
|
|
* @return bool|null |
140
|
|
|
*/ |
141
|
|
|
public function get_java_enabled() { |
142
|
|
|
return $this->java_enabled; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Set java enabled. |
147
|
|
|
* |
148
|
|
|
* @param bool|null $java_enabled Java enabled. |
149
|
|
|
* @return void |
150
|
|
|
*/ |
151
|
|
|
public function set_java_enabled( $java_enabled ) { |
152
|
|
|
$this->java_enabled = $java_enabled; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Get javascript enabled. |
157
|
|
|
* |
158
|
|
|
* @return bool|null |
159
|
|
|
*/ |
160
|
|
|
public function get_javascript_enabled() { |
161
|
|
|
return $this->javascript_enabled; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Set javascript enabled. |
166
|
|
|
* |
167
|
|
|
* @param bool|null $javascript_enabled Javascript enabled. |
168
|
|
|
* @return void |
169
|
|
|
*/ |
170
|
|
|
public function set_javascript_enabled( $javascript_enabled ) { |
171
|
|
|
$this->javascript_enabled = $javascript_enabled; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Get language. |
176
|
|
|
* |
177
|
|
|
* @return string|null |
178
|
|
|
*/ |
179
|
|
|
public function get_language() { |
180
|
|
|
return $this->language; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Set language. |
185
|
|
|
* |
186
|
|
|
* @param string|null $language Language. |
187
|
|
|
* @return void |
188
|
|
|
*/ |
189
|
|
|
public function set_language( $language ) { |
190
|
|
|
$this->language = $language; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Get screen height. |
195
|
|
|
* |
196
|
|
|
* @return int|null |
197
|
|
|
*/ |
198
|
|
|
public function get_screen_height() { |
199
|
|
|
return $this->screen_height; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Set screen height. |
204
|
|
|
* |
205
|
|
|
* @param int|null $screen_height Screen height. |
206
|
|
|
* @return void |
207
|
|
|
*/ |
208
|
|
|
public function set_screen_height( $screen_height ) { |
209
|
|
|
$this->screen_height = $screen_height; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Get screen width. |
214
|
|
|
* |
215
|
|
|
* @return int|null |
216
|
|
|
*/ |
217
|
|
|
public function get_screen_width() { |
218
|
|
|
return $this->screen_width; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Set screen width. |
223
|
|
|
* |
224
|
|
|
* @param int|null $screen_width Screen width. |
225
|
|
|
* @return void |
226
|
|
|
*/ |
227
|
|
|
public function set_screen_width( $screen_width ) { |
228
|
|
|
$this->screen_width = $screen_width; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Get timezone offset. |
233
|
|
|
* |
234
|
|
|
* @return int|null |
235
|
|
|
*/ |
236
|
|
|
public function get_timezone_offset() { |
237
|
|
|
return $this->timezone_offset; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Set timezone offset. |
242
|
|
|
* |
243
|
|
|
* @param int|null $timezone_offset Timezone offset. |
244
|
|
|
* @return void |
245
|
|
|
*/ |
246
|
|
|
public function set_timezone_offset( $timezone_offset ) { |
247
|
|
|
$this->timezone_offset = $timezone_offset; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get user agent. |
252
|
|
|
* |
253
|
|
|
* @return string|null |
254
|
|
|
*/ |
255
|
|
|
public function get_user_agent() { |
256
|
|
|
return $this->user_agent; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Set user agent. |
261
|
|
|
* |
262
|
|
|
* @param string|null $user_agent User agent. |
263
|
|
|
* @return void |
264
|
|
|
*/ |
265
|
|
|
public function set_user_agent( $user_agent ) { |
266
|
|
|
$this->user_agent = $user_agent; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Create browser information from object. |
271
|
|
|
* |
272
|
|
|
* @param object $object Object. |
273
|
|
|
* @return BrowserInformation |
274
|
|
|
*/ |
275
|
|
|
public static function from_object( $object ) { |
276
|
|
|
$browser_information = new self(); |
277
|
|
|
|
278
|
|
|
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object. |
279
|
|
|
|
280
|
|
|
if ( isset( $object->acceptHeader ) ) { |
281
|
|
|
$browser_information->set_accept_header( $object->acceptHeader ); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
if ( isset( $object->colorDepth ) ) { |
285
|
|
|
$browser_information->set_color_depth( $object->colorDepth ); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
if ( isset( $object->javaEnabled ) ) { |
289
|
|
|
$browser_information->set_java_enabled( $object->javaEnabled ); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
if ( isset( $object->javaScriptEnabled ) ) { |
293
|
|
|
$browser_information->set_javascript_enabled( $object->javaScriptEnabled ); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
if ( isset( $object->language ) ) { |
297
|
|
|
$browser_information->set_language( $object->language ); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
if ( isset( $object->screenHeight ) ) { |
301
|
|
|
$browser_information->set_screen_height( $object->screenHeight ); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
if ( isset( $object->screenWidth ) ) { |
305
|
|
|
$browser_information->set_screen_width( $object->screenWidth ); |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
if ( isset( $object->timeZoneOffset ) ) { |
309
|
|
|
$browser_information->set_timezone_offset( $object->timeZoneOffset ); |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
if ( isset( $object->userAgent ) ) { |
313
|
|
|
$browser_information->set_user_agent( $object->userAgent ); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object. |
317
|
|
|
|
318
|
|
|
return $browser_information; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Get JSON. |
323
|
|
|
* |
324
|
|
|
* @return object |
325
|
|
|
*/ |
326
|
|
|
public function get_json() { |
327
|
|
|
$properties = Util::filter_null( |
328
|
|
|
array( |
329
|
|
|
'acceptHeader' => $this->get_accept_header(), |
330
|
|
|
'colorDepth' => $this->get_color_depth(), |
331
|
|
|
'javaEnabled' => $this->get_java_enabled(), |
332
|
|
|
'javaScriptEnabled' => $this->get_javascript_enabled(), |
333
|
|
|
'language' => $this->get_language(), |
334
|
|
|
'screenHeight' => $this->get_screen_height(), |
335
|
|
|
'screenWidth' => $this->get_screen_width(), |
336
|
|
|
'timeZoneOffset' => $this->get_timezone_offset(), |
337
|
|
|
'userAgent' => $this->get_user_agent(), |
338
|
|
|
) |
339
|
|
|
); |
340
|
|
|
|
341
|
|
|
$object = (object) $properties; |
342
|
|
|
|
343
|
|
|
return $object; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* JSON serialize. |
348
|
|
|
* |
349
|
|
|
* @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php |
350
|
|
|
* @return object |
351
|
|
|
*/ |
352
|
|
|
public function jsonSerialize() { |
353
|
|
|
return $this->get_json(); |
354
|
|
|
} |
355
|
|
|
} |
356
|
|
|
|