Test Failed
Push — develop ( ee5b51...397f1c )
by Reüel
05:20
created

ActionInformation   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 263
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 55
dl 0
loc 263
rs 10
c 1
b 0
f 0
wmc 24

17 Methods

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