@@ -18,221 +18,221 @@ discard block |
||
18 | 18 | |
19 | 19 | class General |
20 | 20 | { |
21 | - /** |
|
22 | - * @var EasyPay\Provider31\Request\RAW raw request |
|
23 | - */ |
|
24 | - protected $raw_request; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string 'DateTime' node |
|
28 | - */ |
|
29 | - protected $DateTime; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var string 'Sign' node |
|
33 | - */ |
|
34 | - protected $Sign; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string 'Operation' type |
|
38 | - */ |
|
39 | - protected $Operation; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var string 'ServiceId' node |
|
43 | - */ |
|
44 | - protected $ServiceId; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array list of possible operations |
|
48 | - */ |
|
49 | - protected $operations = array('Check','Payment','Confirm','Cancel'); |
|
50 | - |
|
51 | - /** |
|
52 | - * General constructor |
|
53 | - * |
|
54 | - * @param \EasyPay\Provider31\Request\RAW $raw Raw request data |
|
55 | - */ |
|
56 | - public function __construct($raw) |
|
57 | - { |
|
21 | + /** |
|
22 | + * @var EasyPay\Provider31\Request\RAW raw request |
|
23 | + */ |
|
24 | + protected $raw_request; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string 'DateTime' node |
|
28 | + */ |
|
29 | + protected $DateTime; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var string 'Sign' node |
|
33 | + */ |
|
34 | + protected $Sign; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string 'Operation' type |
|
38 | + */ |
|
39 | + protected $Operation; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var string 'ServiceId' node |
|
43 | + */ |
|
44 | + protected $ServiceId; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array list of possible operations |
|
48 | + */ |
|
49 | + protected $operations = array('Check','Payment','Confirm','Cancel'); |
|
50 | + |
|
51 | + /** |
|
52 | + * General constructor |
|
53 | + * |
|
54 | + * @param \EasyPay\Provider31\Request\RAW $raw Raw request data |
|
55 | + */ |
|
56 | + public function __construct($raw) |
|
57 | + { |
|
58 | 58 | $this->raw_request = $raw; |
59 | 59 | |
60 | 60 | $this->parse_request_data(); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Get DateTime |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function DateTime() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Get DateTime |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function DateTime() |
|
69 | + { |
|
70 | 70 | return $this->DateTime; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Get Sign |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function Sign() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Get Sign |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function Sign() |
|
79 | + { |
|
80 | 80 | return $this->Sign; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get Operation type |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function Operation() |
|
89 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get Operation type |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function Operation() |
|
89 | + { |
|
90 | 90 | return $this->Operation; |
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Get ServiceId |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function ServiceId() |
|
99 | - { |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Get ServiceId |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function ServiceId() |
|
99 | + { |
|
100 | 100 | return $this->ServiceId; |
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
105 | - * processes contents of <Request> node |
|
106 | - */ |
|
107 | - protected function parse_request_data() |
|
108 | - { |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
105 | + * processes contents of <Request> node |
|
106 | + */ |
|
107 | + protected function parse_request_data() |
|
108 | + { |
|
109 | 109 | $r = $this->check_request_count( |
110 | - $this->raw_request->get_nodes_from_request('Request') |
|
110 | + $this->raw_request->get_nodes_from_request('Request') |
|
111 | 111 | ); |
112 | 112 | |
113 | 113 | foreach ($r[0]->childNodes as $child) |
114 | 114 | { |
115 | - $this->check_and_parse_request_node($child, 'DateTime'); |
|
116 | - $this->check_and_parse_request_node($child, 'Sign'); |
|
115 | + $this->check_and_parse_request_node($child, 'DateTime'); |
|
116 | + $this->check_and_parse_request_node($child, 'Sign'); |
|
117 | 117 | |
118 | - $this->check_and_parse_operation($child); |
|
118 | + $this->check_and_parse_operation($child); |
|
119 | 119 | } |
120 | 120 | $this->parse_operation_data(); |
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Check count of <Request> nodes in xml-request |
|
125 | - * |
|
126 | - * @throws Exception\Structure |
|
127 | - */ |
|
128 | - protected function check_request_count($ar) |
|
129 | - { |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Check count of <Request> nodes in xml-request |
|
125 | + * |
|
126 | + * @throws Exception\Structure |
|
127 | + */ |
|
128 | + protected function check_request_count($ar) |
|
129 | + { |
|
130 | 130 | if (count($ar) < 1) |
131 | 131 | { |
132 | - throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
132 | + throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
133 | 133 | } |
134 | 134 | elseif (count($ar) > 1) |
135 | 135 | { |
136 | - throw new Exception\Structure('The xml-query contains several elements Request!', -52); |
|
136 | + throw new Exception\Structure('The xml-query contains several elements Request!', -52); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $ar; |
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
144 | - * processes contents of <Operation> node |
|
145 | - * |
|
146 | - * @throws Exception\Structure |
|
147 | - */ |
|
148 | - protected function parse_operation_data() |
|
149 | - { |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
144 | + * processes contents of <Operation> node |
|
145 | + * |
|
146 | + * @throws Exception\Structure |
|
147 | + */ |
|
148 | + protected function parse_operation_data() |
|
149 | + { |
|
150 | 150 | $this->check_presence_operation(); |
151 | 151 | |
152 | 152 | $r = $this->raw_request->get_nodes_from_request($this->Operation); |
153 | 153 | |
154 | 154 | foreach ($r[0]->childNodes as $child) |
155 | 155 | { |
156 | - $this->check_and_parse_request_node($child, 'ServiceId'); |
|
156 | + $this->check_and_parse_request_node($child, 'ServiceId'); |
|
157 | 157 | } |
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Check if present node of request and then parse it |
|
162 | - * |
|
163 | - * @param \DOMNode $n |
|
164 | - * @param string $name |
|
165 | - */ |
|
166 | - protected function check_and_parse_request_node($n, $name) |
|
167 | - { |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Check if present node of request and then parse it |
|
162 | + * |
|
163 | + * @param \DOMNode $n |
|
164 | + * @param string $name |
|
165 | + */ |
|
166 | + protected function check_and_parse_request_node($n, $name) |
|
167 | + { |
|
168 | 168 | if ($n->nodeName == $name) |
169 | 169 | { |
170 | - $this->parse_request_node($n, $name); |
|
170 | + $this->parse_request_node($n, $name); |
|
171 | 171 | } |
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Check if given node is Operation |
|
176 | - * |
|
177 | - * @throws Exception\Structure |
|
178 | - */ |
|
179 | - protected function check_and_parse_operation($n) |
|
180 | - { |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Check if given node is Operation |
|
176 | + * |
|
177 | + * @throws Exception\Structure |
|
178 | + */ |
|
179 | + protected function check_and_parse_operation($n) |
|
180 | + { |
|
181 | 181 | if (in_array($n->nodeName, $this->operations)) |
182 | 182 | { |
183 | - if ( ! isset($this->Operation)) |
|
184 | - { |
|
183 | + if ( ! isset($this->Operation)) |
|
184 | + { |
|
185 | 185 | $this->Operation = $n->nodeName; |
186 | - } |
|
187 | - else |
|
188 | - { |
|
186 | + } |
|
187 | + else |
|
188 | + { |
|
189 | 189 | throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
190 | - } |
|
190 | + } |
|
191 | 191 | } |
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Check if Operation present in request |
|
196 | - * |
|
197 | - * @throws Exception\Structure |
|
198 | - */ |
|
199 | - protected function check_presence_operation() |
|
200 | - { |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Check if Operation present in request |
|
196 | + * |
|
197 | + * @throws Exception\Structure |
|
198 | + */ |
|
199 | + protected function check_presence_operation() |
|
200 | + { |
|
201 | 201 | if ( ! isset($this->Operation)) |
202 | 202 | { |
203 | - throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
203 | + throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
204 | 204 | } |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Parse node of request |
|
209 | - * |
|
210 | - * @param \DOMNode $n |
|
211 | - * @param string $name |
|
212 | - * |
|
213 | - * @throws Exception\Structure |
|
214 | - */ |
|
215 | - protected function parse_request_node($n, $name) |
|
216 | - { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Parse node of request |
|
209 | + * |
|
210 | + * @param \DOMNode $n |
|
211 | + * @param string $name |
|
212 | + * |
|
213 | + * @throws Exception\Structure |
|
214 | + */ |
|
215 | + protected function parse_request_node($n, $name) |
|
216 | + { |
|
217 | 217 | if ( ! isset($this->$name)) |
218 | 218 | { |
219 | - $this->$name = $n->nodeValue; |
|
219 | + $this->$name = $n->nodeValue; |
|
220 | 220 | } |
221 | 221 | else |
222 | 222 | { |
223 | - throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
223 | + throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
224 | + } |
|
224 | 225 | } |
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * "Rough" validation of the received xml request |
|
229 | - * |
|
230 | - * @param array $options |
|
231 | - * @throws Exception\Data |
|
232 | - * @throws Exception\Structure |
|
233 | - */ |
|
234 | - public function validate_request($options) |
|
235 | - { |
|
226 | + |
|
227 | + /** |
|
228 | + * "Rough" validation of the received xml request |
|
229 | + * |
|
230 | + * @param array $options |
|
231 | + * @throws Exception\Data |
|
232 | + * @throws Exception\Structure |
|
233 | + */ |
|
234 | + public function validate_request($options) |
|
235 | + { |
|
236 | 236 | $this->validate_element('DateTime'); |
237 | 237 | $this->validate_element('Sign'); |
238 | 238 | $this->validate_element('ServiceId'); |
@@ -240,36 +240,36 @@ discard block |
||
240 | 240 | // compare received value ServiceId with option ServiceId |
241 | 241 | if (intval($options['ServiceId']) != intval($this->ServiceId)) |
242 | 242 | { |
243 | - throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
243 | + throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
244 | + } |
|
244 | 245 | } |
245 | - } |
|
246 | - |
|
247 | - /** |
|
248 | - * Validation of xml-element |
|
249 | - * |
|
250 | - * @param string $name |
|
251 | - */ |
|
252 | - public function validate_element($name) |
|
253 | - { |
|
246 | + |
|
247 | + /** |
|
248 | + * Validation of xml-element |
|
249 | + * |
|
250 | + * @param string $name |
|
251 | + */ |
|
252 | + public function validate_element($name) |
|
253 | + { |
|
254 | 254 | if ( ! isset($this->$name)) |
255 | 255 | { |
256 | - throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
256 | + throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
257 | + } |
|
257 | 258 | } |
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Verify signature of request |
|
262 | - * |
|
263 | - * @param array $options |
|
264 | - */ |
|
265 | - public function verify_sign($options) |
|
266 | - { |
|
259 | + |
|
260 | + /** |
|
261 | + * Verify signature of request |
|
262 | + * |
|
263 | + * @param array $options |
|
264 | + */ |
|
265 | + public function verify_sign($options) |
|
266 | + { |
|
267 | 267 | $sign = new Sign(); |
268 | 268 | $sign->verify( |
269 | - $this->raw_request->str(), |
|
270 | - $this->Sign, |
|
271 | - $options |
|
269 | + $this->raw_request->str(), |
|
270 | + $this->Sign, |
|
271 | + $options |
|
272 | 272 | ); |
273 | - } |
|
273 | + } |
|
274 | 274 | |
275 | 275 | } |
@@ -130,8 +130,7 @@ discard block |
||
130 | 130 | if (count($ar) < 1) |
131 | 131 | { |
132 | 132 | throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
133 | - } |
|
134 | - elseif (count($ar) > 1) |
|
133 | + } elseif (count($ar) > 1) |
|
135 | 134 | { |
136 | 135 | throw new Exception\Structure('The xml-query contains several elements Request!', -52); |
137 | 136 | } |
@@ -183,8 +182,7 @@ discard block |
||
183 | 182 | if ( ! isset($this->Operation)) |
184 | 183 | { |
185 | 184 | $this->Operation = $n->nodeName; |
186 | - } |
|
187 | - else |
|
185 | + } else |
|
188 | 186 | { |
189 | 187 | throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
190 | 188 | } |
@@ -217,8 +215,7 @@ discard block |
||
217 | 215 | if ( ! isset($this->$name)) |
218 | 216 | { |
219 | 217 | $this->$name = $n->nodeValue; |
220 | - } |
|
221 | - else |
|
218 | + } else |
|
222 | 219 | { |
223 | 220 | throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
224 | 221 | } |