|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Action 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
|
|
|
* Action 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 ActionInformation extends ResponseObject { |
|
23
|
|
|
/** |
|
24
|
|
|
* When the redirect URL must be accessed via POST, use this data to post to the redirect URL. |
|
25
|
|
|
* |
|
26
|
|
|
* @var object|null |
|
27
|
|
|
*/ |
|
28
|
|
|
private $data; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The web method that you must use to access the redirect URL. |
|
32
|
|
|
* |
|
33
|
|
|
* Possible values: GET, POST. |
|
34
|
|
|
* |
|
35
|
|
|
* @var string|null |
|
36
|
|
|
*/ |
|
37
|
|
|
private $method; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* When non-empty, contains a value that you must submit to the /payments/details endpoint. In some cases, required for polling. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string|null |
|
43
|
|
|
*/ |
|
44
|
|
|
private $payment_data; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Specifies the payment method. |
|
48
|
|
|
* |
|
49
|
|
|
* @var string|null |
|
50
|
|
|
*/ |
|
51
|
|
|
private $payment_method_type; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* A token to pass to the 3DS2 Component to get the fingerprint/challenge. |
|
55
|
|
|
* |
|
56
|
|
|
* @var string|null |
|
57
|
|
|
*/ |
|
58
|
|
|
private $token; |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Enum that specifies the action that needs to be taken by the client. |
|
62
|
|
|
* |
|
63
|
|
|
* @var string|null |
|
64
|
|
|
*/ |
|
65
|
|
|
private $type; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* The URL, to which you must redirect a shopper to complete a payment |
|
69
|
|
|
* |
|
70
|
|
|
* @var string|null |
|
71
|
|
|
*/ |
|
72
|
|
|
private $url; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get data. |
|
76
|
|
|
* |
|
77
|
|
|
* @return object|null |
|
78
|
|
|
*/ |
|
79
|
|
|
public function get_data() { |
|
80
|
|
|
return $this->data; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Set data. |
|
85
|
|
|
* |
|
86
|
|
|
* @param object|null $data Data. |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function set_data( $data ) { |
|
90
|
|
|
$this->data = $data; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get method. |
|
95
|
|
|
* |
|
96
|
|
|
* @return string|null |
|
97
|
|
|
*/ |
|
98
|
|
|
public function get_method() { |
|
99
|
|
|
return $this->method; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Set method. |
|
104
|
|
|
* |
|
105
|
|
|
* @param string|null $method Method. |
|
106
|
|
|
* @return void |
|
107
|
|
|
*/ |
|
108
|
1 |
|
public function set_method( $method ) { |
|
109
|
1 |
|
$this->method = $method; |
|
110
|
1 |
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get payment data. |
|
114
|
|
|
* |
|
115
|
|
|
* @return string|null |
|
116
|
|
|
*/ |
|
117
|
|
|
public function get_payment_data() { |
|
118
|
|
|
return $this->payment_data; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Set payment data. |
|
123
|
|
|
* |
|
124
|
|
|
* @param string|null $payment_data Payment data. |
|
125
|
|
|
* @return void |
|
126
|
|
|
*/ |
|
127
|
1 |
|
public function set_payment_data( $payment_data ) { |
|
128
|
1 |
|
$this->payment_data = $payment_data; |
|
129
|
1 |
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Get payment method type. |
|
133
|
|
|
* |
|
134
|
|
|
* @return string|null |
|
135
|
|
|
*/ |
|
136
|
|
|
public function get_payment_method_type() { |
|
137
|
|
|
return $this->payment_method_type; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Set payment method type. |
|
142
|
|
|
* |
|
143
|
|
|
* @param string|null $payment_method_type Payment method type. |
|
144
|
|
|
* @return void |
|
145
|
|
|
*/ |
|
146
|
1 |
|
public function set_payment_method_type( $payment_method_type ) { |
|
147
|
1 |
|
$this->payment_method_type = $payment_method_type; |
|
148
|
1 |
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* Get token. |
|
152
|
|
|
* |
|
153
|
|
|
* @return string|null |
|
154
|
|
|
*/ |
|
155
|
|
|
public function get_token() { |
|
156
|
|
|
return $this->token; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Set token. |
|
161
|
|
|
* |
|
162
|
|
|
* @param string|null $token Token. |
|
163
|
|
|
* @return void |
|
164
|
|
|
*/ |
|
165
|
|
|
public function set_token( $token ) { |
|
166
|
|
|
$this->token = $token; |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Get type. |
|
171
|
|
|
* |
|
172
|
|
|
* @return string|null |
|
173
|
|
|
*/ |
|
174
|
|
|
public function get_type() { |
|
175
|
|
|
return $this->type; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Set type. |
|
180
|
|
|
* |
|
181
|
|
|
* @param string|null $type Type. |
|
182
|
|
|
* @return void |
|
183
|
|
|
*/ |
|
184
|
1 |
|
public function set_type( $type ) { |
|
185
|
1 |
|
$this->type = $type; |
|
186
|
1 |
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Get URL. |
|
190
|
|
|
* |
|
191
|
|
|
* @return string|null |
|
192
|
|
|
*/ |
|
193
|
|
|
public function get_url() { |
|
194
|
|
|
return $this->url; |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
/** |
|
198
|
|
|
* Set URL. |
|
199
|
|
|
* |
|
200
|
|
|
* @param string|null $url URL. |
|
201
|
|
|
* @return void |
|
202
|
|
|
*/ |
|
203
|
1 |
|
public function set_url( $url ) { |
|
204
|
1 |
|
$this->url = $url; |
|
205
|
1 |
|
} |
|
206
|
|
|
|
|
207
|
|
|
/** |
|
208
|
|
|
* Create action information from object. |
|
209
|
|
|
* |
|
210
|
|
|
* @param object $object Object. |
|
211
|
|
|
* @return ActionInformation |
|
212
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws validation exception when object does not contains the required properties. |
|
213
|
|
|
*/ |
|
214
|
1 |
|
public static function from_object( $object ) { |
|
215
|
1 |
|
$validator = new \JsonSchema\Validator(); |
|
216
|
|
|
|
|
217
|
1 |
|
$validator->validate( |
|
218
|
1 |
|
$object, |
|
219
|
|
|
(object) array( |
|
220
|
1 |
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/action.json' ), |
|
221
|
|
|
), |
|
222
|
1 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
|
223
|
|
|
); |
|
224
|
|
|
|
|
225
|
1 |
|
$action = new self(); |
|
226
|
|
|
|
|
227
|
|
|
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object. |
|
228
|
|
|
|
|
229
|
1 |
|
if ( isset( $object->data ) ) { |
|
230
|
|
|
$action->set_data( $object->data ); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
1 |
|
if ( isset( $object->method ) ) { |
|
234
|
1 |
|
$action->set_method( $object->method ); |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
1 |
|
if ( isset( $object->paymentData ) ) { |
|
238
|
1 |
|
$action->set_payment_data( $object->paymentData ); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
1 |
|
if ( isset( $object->paymentMethodType ) ) { |
|
242
|
1 |
|
$action->set_payment_method_type( $object->paymentMethodType ); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
1 |
|
if ( isset( $object->token ) ) { |
|
246
|
|
|
$action->set_token( $object->token ); |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
1 |
|
if ( isset( $object->type ) ) { |
|
250
|
1 |
|
$action->set_type( $object->type ); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
1 |
|
if ( isset( $object->url ) ) { |
|
254
|
1 |
|
$action->set_url( $object->url ); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Adyen JSON object. |
|
258
|
|
|
|
|
259
|
1 |
|
return $action; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Get JSON. |
|
264
|
|
|
* |
|
265
|
|
|
* @return object |
|
266
|
|
|
*/ |
|
267
|
|
|
public function get_json() { |
|
268
|
|
|
$properties = Util::filter_null( |
|
269
|
|
|
array( |
|
270
|
|
|
'data' => $this->get_data(), |
|
271
|
|
|
'method' => $this->get_method(), |
|
272
|
|
|
'paymentData' => $this->get_payment_data(), |
|
273
|
|
|
'paymentMethodType' => $this->get_payment_method_type(), |
|
274
|
|
|
'token' => $this->get_token(), |
|
275
|
|
|
'type' => $this->get_type(), |
|
276
|
|
|
'url' => $this->get_url(), |
|
277
|
|
|
) |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
$object = (object) $properties; |
|
281
|
|
|
|
|
282
|
|
|
return $object; |
|
283
|
|
|
} |
|
284
|
|
|
} |
|
285
|
|
|
|