1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Redirect 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
|
|
|
* Redirect information |
15
|
|
|
* |
16
|
|
|
* @link https://docs.adyen.com/api-explorer/#/PaymentSetupAndVerificationService/v41/payments |
17
|
|
|
* |
18
|
|
|
* @author Remco Tolsma |
19
|
|
|
* @version 1.0.0 |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
*/ |
22
|
|
|
class RedirectInformation 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
|
|
|
* The URL, to which you must redirect a shopper to complete a payment |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $url; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Construct redirect information. |
48
|
|
|
* |
49
|
|
|
* @param string $method Method. |
50
|
|
|
* @param string $url URL. |
51
|
|
|
*/ |
52
|
6 |
|
public function __construct( $method, $url ) { |
53
|
6 |
|
$this->method = $method; |
54
|
6 |
|
$this->url = $url; |
55
|
6 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get data. |
59
|
|
|
* |
60
|
|
|
* @return object|null |
61
|
|
|
*/ |
62
|
2 |
|
public function get_data() { |
63
|
2 |
|
return $this->data; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Set data. |
68
|
|
|
* |
69
|
|
|
* @param object|null $data Data. |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
2 |
|
public function set_data( $data ) { |
73
|
2 |
|
$this->data = $data; |
74
|
2 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get method. |
78
|
|
|
* |
79
|
|
|
* @return string |
80
|
|
|
*/ |
81
|
5 |
|
public function get_method() { |
82
|
5 |
|
return $this->method; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get URL. |
87
|
|
|
* |
88
|
|
|
* @return string |
89
|
|
|
*/ |
90
|
4 |
|
public function get_url() { |
91
|
4 |
|
return $this->url; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Create redirect information from object. |
96
|
|
|
* |
97
|
|
|
* @param object $object Object. |
98
|
|
|
* @return RedirectInformation |
99
|
|
|
* @throws \JsonSchema\Exception\ValidationException Throws validation exception when object does not contains the required properties. |
100
|
|
|
*/ |
101
|
4 |
|
public static function from_object( $object ) { |
102
|
4 |
|
$validator = new \JsonSchema\Validator(); |
103
|
|
|
|
104
|
4 |
|
$validator->validate( |
105
|
4 |
|
$object, |
106
|
|
|
(object) array( |
107
|
4 |
|
'$ref' => 'file://' . realpath( __DIR__ . '/../json-schemas/redirect.json' ), |
108
|
|
|
), |
109
|
4 |
|
\JsonSchema\Constraints\Constraint::CHECK_MODE_EXCEPTIONS |
110
|
|
|
); |
111
|
|
|
|
112
|
4 |
|
$redirect = new self( |
113
|
4 |
|
$object->method, |
114
|
4 |
|
$object->url |
115
|
|
|
); |
116
|
|
|
|
117
|
4 |
|
if ( isset( $object->data ) ) { |
118
|
1 |
|
$redirect->set_data( $object->data ); |
119
|
|
|
} |
120
|
|
|
|
121
|
4 |
|
return $redirect; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Get JSON. |
126
|
|
|
* |
127
|
|
|
* @return object |
128
|
|
|
*/ |
129
|
|
|
public function get_json() { |
130
|
|
|
$properties = Util::filter_null( |
131
|
|
|
array( |
132
|
|
|
'method' => $this->get_method(), |
133
|
|
|
'url' => $this->get_url(), |
134
|
|
|
) |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
$object = (object) $properties; |
138
|
|
|
|
139
|
|
|
return $object; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|