1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Details 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
|
|
|
* Details information |
15
|
|
|
* |
16
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments |
17
|
|
|
* |
18
|
|
|
* @author Reüel van der Steege |
19
|
|
|
* @version 1.1.0 |
20
|
|
|
* @since 1.1.0 |
21
|
|
|
*/ |
22
|
|
|
class DetailsInformation extends ResponseObject { |
23
|
|
|
/** |
24
|
|
|
* The value to provide in the result. |
25
|
|
|
* |
26
|
|
|
* @var string|null |
27
|
|
|
*/ |
28
|
|
|
private $key; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The type of the required input. |
32
|
|
|
* |
33
|
|
|
* @var string|null |
34
|
|
|
*/ |
35
|
|
|
private $type; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get key. |
39
|
|
|
* |
40
|
|
|
* @return string|null |
41
|
|
|
*/ |
42
|
|
|
public function get_key() { |
43
|
|
|
return $this->key; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set key. |
48
|
|
|
* |
49
|
|
|
* @param string|null $key Key. |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
2 |
|
public function set_key( $key ) { |
53
|
2 |
|
$this->key = $key; |
54
|
2 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get type. |
58
|
|
|
* |
59
|
|
|
* @return string|null |
60
|
|
|
*/ |
61
|
|
|
public function get_type() { |
62
|
|
|
return $this->type; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Set type. |
67
|
|
|
* |
68
|
|
|
* @param string|null $type Type. |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
2 |
|
public function set_type( $type ) { |
72
|
2 |
|
$this->type = $type; |
73
|
2 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Create details information from object. |
77
|
|
|
* |
78
|
|
|
* @param object $object Object. |
79
|
|
|
* @return DetailsInformation |
80
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws validation exception when object does not contains the required properties. |
81
|
|
|
*/ |
82
|
2 |
|
public static function from_object( $object ) { |
83
|
2 |
|
$validator = new \JsonSchema\Validator(); |
84
|
|
|
|
85
|
2 |
|
$validator->validate( |
86
|
2 |
|
$object, |
87
|
|
|
(object) array( |
88
|
2 |
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/details.json' ), |
89
|
|
|
), |
90
|
2 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
91
|
|
|
); |
92
|
|
|
|
93
|
2 |
|
$details = new self(); |
94
|
|
|
|
95
|
2 |
|
if ( isset( $object->key ) ) { |
96
|
2 |
|
$details->set_key( $object->key ); |
97
|
|
|
} |
98
|
|
|
|
99
|
2 |
|
if ( isset( $object->type ) ) { |
100
|
2 |
|
$details->set_type( $object->type ); |
101
|
|
|
} |
102
|
|
|
|
103
|
2 |
|
return $details; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get JSON. |
108
|
|
|
* |
109
|
|
|
* @return object |
110
|
|
|
*/ |
111
|
|
|
public function get_json() { |
112
|
|
|
$properties = Util::filter_null( |
113
|
|
|
array( |
114
|
|
|
'key' => $this->get_key(), |
115
|
|
|
'type' => $this->get_type(), |
116
|
|
|
) |
117
|
|
|
); |
118
|
|
|
|
119
|
|
|
$object = (object) $properties; |
120
|
|
|
|
121
|
|
|
return $object; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|