@@ -9,59 +9,59 @@ |
||
9 | 9 | |
10 | 10 | class Sign |
11 | 11 | { |
12 | - public function __construct() {} |
|
12 | + public function __construct() {} |
|
13 | 13 | |
14 | - /** |
|
15 | - * Verify signature of request |
|
16 | - * |
|
17 | - * @param array $options |
|
18 | - */ |
|
19 | - public function verify($request_str, $sign, $options) |
|
20 | - { |
|
14 | + /** |
|
15 | + * Verify signature of request |
|
16 | + * |
|
17 | + * @param array $options |
|
18 | + */ |
|
19 | + public function verify($request_str, $sign, $options) |
|
20 | + { |
|
21 | 21 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
22 | 22 | { |
23 | - $this->check_verify_sign_result( |
|
23 | + $this->check_verify_sign_result( |
|
24 | 24 | $result = (new OpenSSL())->verify( |
25 | - str_replace($sign, '', $request_str), |
|
26 | - pack("H*", $sign), |
|
27 | - (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
25 | + str_replace($sign, '', $request_str), |
|
26 | + pack("H*", $sign), |
|
27 | + (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
28 | 28 | ) |
29 | - ); |
|
29 | + ); |
|
30 | + } |
|
30 | 31 | } |
31 | - } |
|
32 | 32 | |
33 | - /** |
|
34 | - * load file with easysoft public key |
|
35 | - * |
|
36 | - * @param array $options |
|
37 | - * @throws Exception\Runtime |
|
38 | - * @return string |
|
39 | - */ |
|
40 | - protected function get_pub_key($options) |
|
41 | - { |
|
33 | + /** |
|
34 | + * load file with easysoft public key |
|
35 | + * |
|
36 | + * @param array $options |
|
37 | + * @throws Exception\Runtime |
|
38 | + * @return string |
|
39 | + */ |
|
40 | + protected function get_pub_key($options) |
|
41 | + { |
|
42 | 42 | if ( ! isset($options['EasySoftPKey'])) |
43 | 43 | { |
44 | - throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
44 | + throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | return (new Key())->get($options['EasySoftPKey'], 'public'); |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * check result of openssl verify signature |
|
52 | - * |
|
53 | - * @param integer $result |
|
54 | - * @throws Exception\Sign |
|
55 | - */ |
|
56 | - protected function check_verify_sign_result($result) |
|
57 | - { |
|
50 | + /** |
|
51 | + * check result of openssl verify signature |
|
52 | + * |
|
53 | + * @param integer $result |
|
54 | + * @throws Exception\Sign |
|
55 | + */ |
|
56 | + protected function check_verify_sign_result($result) |
|
57 | + { |
|
58 | 58 | if ($result == -1) |
59 | 59 | { |
60 | - throw new Exception\Sign('Error verify signature of request!', -96); |
|
60 | + throw new Exception\Sign('Error verify signature of request!', -96); |
|
61 | 61 | } |
62 | 62 | elseif ($result == 0) |
63 | 63 | { |
64 | - throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
64 | + throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
65 | + } |
|
65 | 66 | } |
66 | - } |
|
67 | 67 | } |
@@ -58,8 +58,7 @@ |
||
58 | 58 | if ($result == -1) |
59 | 59 | { |
60 | 60 | throw new Exception\Sign('Error verify signature of request!', -96); |
61 | - } |
|
62 | - elseif ($result == 0) |
|
61 | + } elseif ($result == 0) |
|
63 | 62 | { |
64 | 63 | throw new Exception\Sign('Signature of request is incorrect!', -95); |
65 | 64 | } |
@@ -17,124 +17,124 @@ discard block |
||
17 | 17 | |
18 | 18 | class General |
19 | 19 | { |
20 | - /** |
|
21 | - * @var EasyPay\Provider31\Request\RAW raw request |
|
22 | - */ |
|
23 | - protected $raw_request; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string 'DateTime' node |
|
27 | - */ |
|
28 | - protected $DateTime; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string 'Sign' node |
|
32 | - */ |
|
33 | - protected $Sign; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string 'Operation' type |
|
37 | - */ |
|
38 | - protected $Operation; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string 'ServiceId' node |
|
42 | - */ |
|
43 | - protected $ServiceId; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var array list of possible operations |
|
47 | - */ |
|
48 | - protected $operations = array('Check','Payment','Confirm','Cancel'); |
|
49 | - |
|
50 | - /** |
|
51 | - * General constructor |
|
52 | - * |
|
53 | - * @param EasyPay\Provider31\Request\RAW $raw Raw request data |
|
54 | - */ |
|
55 | - public function __construct($raw) |
|
56 | - { |
|
20 | + /** |
|
21 | + * @var EasyPay\Provider31\Request\RAW raw request |
|
22 | + */ |
|
23 | + protected $raw_request; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string 'DateTime' node |
|
27 | + */ |
|
28 | + protected $DateTime; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string 'Sign' node |
|
32 | + */ |
|
33 | + protected $Sign; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string 'Operation' type |
|
37 | + */ |
|
38 | + protected $Operation; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string 'ServiceId' node |
|
42 | + */ |
|
43 | + protected $ServiceId; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var array list of possible operations |
|
47 | + */ |
|
48 | + protected $operations = array('Check','Payment','Confirm','Cancel'); |
|
49 | + |
|
50 | + /** |
|
51 | + * General constructor |
|
52 | + * |
|
53 | + * @param EasyPay\Provider31\Request\RAW $raw Raw request data |
|
54 | + */ |
|
55 | + public function __construct($raw) |
|
56 | + { |
|
57 | 57 | $this->raw_request = $raw; |
58 | 58 | |
59 | 59 | $this->parse_request_data(); |
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Get DateTime |
|
64 | - * |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function DateTime() |
|
68 | - { |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Get DateTime |
|
64 | + * |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function DateTime() |
|
68 | + { |
|
69 | 69 | return $this->DateTime; |
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Get Sign |
|
74 | - * |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function Sign() |
|
78 | - { |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Get Sign |
|
74 | + * |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function Sign() |
|
78 | + { |
|
79 | 79 | return $this->Sign; |
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Get Operation type |
|
84 | - * |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function Operation() |
|
88 | - { |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Get Operation type |
|
84 | + * |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function Operation() |
|
88 | + { |
|
89 | 89 | return $this->Operation; |
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Get ServiceId |
|
94 | - * |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function ServiceId() |
|
98 | - { |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Get ServiceId |
|
94 | + * |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function ServiceId() |
|
98 | + { |
|
99 | 99 | return $this->ServiceId; |
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
104 | - * |
|
105 | - * @throws Exception\Structure |
|
106 | - */ |
|
107 | - protected function parse_request_data() |
|
108 | - { |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
104 | + * |
|
105 | + * @throws Exception\Structure |
|
106 | + */ |
|
107 | + protected function parse_request_data() |
|
108 | + { |
|
109 | 109 | // process <Request> group |
110 | 110 | $r = $this->raw_request->get_nodes_from_request('Request'); |
111 | 111 | |
112 | 112 | if (count($r) < 1) |
113 | 113 | { |
114 | - throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
114 | + throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | foreach ($r[0]->childNodes as $child) |
118 | 118 | { |
119 | - $this->check_and_parse_request_node($child, 'DateTime'); |
|
120 | - $this->check_and_parse_request_node($child, 'Sign'); |
|
119 | + $this->check_and_parse_request_node($child, 'DateTime'); |
|
120 | + $this->check_and_parse_request_node($child, 'Sign'); |
|
121 | 121 | |
122 | - if (in_array($child->nodeName, $this->operations)) |
|
123 | - { |
|
122 | + if (in_array($child->nodeName, $this->operations)) |
|
123 | + { |
|
124 | 124 | if ( ! isset($this->Operation)) |
125 | 125 | { |
126 | - $this->Operation = $child->nodeName; |
|
126 | + $this->Operation = $child->nodeName; |
|
127 | 127 | } |
128 | 128 | else |
129 | 129 | { |
130 | - throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
130 | + throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
131 | + } |
|
131 | 132 | } |
132 | - } |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | if ( ! isset($this->Operation)) |
136 | 136 | { |
137 | - throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
137 | + throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // process <Operation> group |
@@ -142,53 +142,53 @@ discard block |
||
142 | 142 | |
143 | 143 | foreach ($r[0]->childNodes as $child) |
144 | 144 | { |
145 | - $this->check_and_parse_request_node($child, 'ServiceId'); |
|
145 | + $this->check_and_parse_request_node($child, 'ServiceId'); |
|
146 | + } |
|
146 | 147 | } |
147 | - } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Check if present node of request and then parse it |
|
151 | - * |
|
152 | - * @param \DOMNode $n |
|
153 | - * @param string $name |
|
154 | - */ |
|
155 | - protected function check_and_parse_request_node($n, $name) |
|
156 | - { |
|
149 | + /** |
|
150 | + * Check if present node of request and then parse it |
|
151 | + * |
|
152 | + * @param \DOMNode $n |
|
153 | + * @param string $name |
|
154 | + */ |
|
155 | + protected function check_and_parse_request_node($n, $name) |
|
156 | + { |
|
157 | 157 | if ($n->nodeName == $name) |
158 | 158 | { |
159 | - $this->parse_request_node($n, $name); |
|
159 | + $this->parse_request_node($n, $name); |
|
160 | + } |
|
160 | 161 | } |
161 | - } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Parse node of request |
|
165 | - * |
|
166 | - * @param \DOMNode $n |
|
167 | - * @param string $name |
|
168 | - * |
|
169 | - * @throws Exception\Structure |
|
170 | - */ |
|
171 | - protected function parse_request_node($n, $name) |
|
172 | - { |
|
163 | + /** |
|
164 | + * Parse node of request |
|
165 | + * |
|
166 | + * @param \DOMNode $n |
|
167 | + * @param string $name |
|
168 | + * |
|
169 | + * @throws Exception\Structure |
|
170 | + */ |
|
171 | + protected function parse_request_node($n, $name) |
|
172 | + { |
|
173 | 173 | if ( ! isset($this->$name)) |
174 | 174 | { |
175 | - $this->$name = $n->nodeValue; |
|
175 | + $this->$name = $n->nodeValue; |
|
176 | 176 | } |
177 | 177 | else |
178 | 178 | { |
179 | - throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
179 | + throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
180 | + } |
|
180 | 181 | } |
181 | - } |
|
182 | 182 | |
183 | - /** |
|
184 | - * "Rough" validation of the received xml request |
|
185 | - * |
|
186 | - * @param array $options |
|
187 | - * @throws Exception\Data |
|
188 | - * @throws Exception\Structure |
|
189 | - */ |
|
190 | - public function validate_request($options) |
|
191 | - { |
|
183 | + /** |
|
184 | + * "Rough" validation of the received xml request |
|
185 | + * |
|
186 | + * @param array $options |
|
187 | + * @throws Exception\Data |
|
188 | + * @throws Exception\Structure |
|
189 | + */ |
|
190 | + public function validate_request($options) |
|
191 | + { |
|
192 | 192 | $this->validate_element('DateTime'); |
193 | 193 | $this->validate_element('Sign'); |
194 | 194 | $this->validate_element('ServiceId'); |
@@ -196,36 +196,36 @@ discard block |
||
196 | 196 | // compare received value ServiceId with option ServiceId |
197 | 197 | if (intval($options['ServiceId']) != intval($this->ServiceId)) |
198 | 198 | { |
199 | - throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
199 | + throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
200 | + } |
|
200 | 201 | } |
201 | - } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Validation of xml-element |
|
205 | - * |
|
206 | - * @param string $name |
|
207 | - */ |
|
208 | - public function validate_element($name) |
|
209 | - { |
|
203 | + /** |
|
204 | + * Validation of xml-element |
|
205 | + * |
|
206 | + * @param string $name |
|
207 | + */ |
|
208 | + public function validate_element($name) |
|
209 | + { |
|
210 | 210 | if ( ! isset($this->$name)) |
211 | 211 | { |
212 | - throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
212 | + throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
213 | + } |
|
213 | 214 | } |
214 | - } |
|
215 | 215 | |
216 | - /** |
|
217 | - * Verify signature of request |
|
218 | - * |
|
219 | - * @param array $options |
|
220 | - */ |
|
221 | - public function verify_sign($options) |
|
222 | - { |
|
216 | + /** |
|
217 | + * Verify signature of request |
|
218 | + * |
|
219 | + * @param array $options |
|
220 | + */ |
|
221 | + public function verify_sign($options) |
|
222 | + { |
|
223 | 223 | $sign = new \EasyPay\Sign(); |
224 | 224 | $sign->verify( |
225 | - $this->raw_request->str(), |
|
226 | - $this->Sign, |
|
227 | - $options |
|
225 | + $this->raw_request->str(), |
|
226 | + $this->Sign, |
|
227 | + $options |
|
228 | 228 | ); |
229 | - } |
|
229 | + } |
|
230 | 230 | |
231 | 231 | } |
@@ -124,8 +124,7 @@ discard block |
||
124 | 124 | if ( ! isset($this->Operation)) |
125 | 125 | { |
126 | 126 | $this->Operation = $child->nodeName; |
127 | - } |
|
128 | - else |
|
127 | + } else |
|
129 | 128 | { |
130 | 129 | throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
131 | 130 | } |
@@ -173,8 +172,7 @@ discard block |
||
173 | 172 | if ( ! isset($this->$name)) |
174 | 173 | { |
175 | 174 | $this->$name = $n->nodeValue; |
176 | - } |
|
177 | - else |
|
175 | + } else |
|
178 | 176 | { |
179 | 177 | throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
180 | 178 | } |