@@ -16,134 +16,134 @@ |
||
16 | 16 | |
17 | 17 | abstract class Response extends \DomDocument |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string |
|
21 | - * |
|
22 | - */ |
|
23 | - const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var \DOMNode |
|
27 | - */ |
|
28 | - protected $Response; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var \DOMElement |
|
32 | - */ |
|
33 | - protected $Sign; |
|
34 | - |
|
35 | - /** |
|
36 | - * Response constructor |
|
37 | - * |
|
38 | - */ |
|
39 | - public function __construct() |
|
40 | - { |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + * |
|
22 | + */ |
|
23 | + const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var \DOMNode |
|
27 | + */ |
|
28 | + protected $Response; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var \DOMElement |
|
32 | + */ |
|
33 | + protected $Sign; |
|
34 | + |
|
35 | + /** |
|
36 | + * Response constructor |
|
37 | + * |
|
38 | + */ |
|
39 | + public function __construct() |
|
40 | + { |
|
41 | 41 | parent::__construct('1.0', 'UTF-8'); |
42 | 42 | |
43 | 43 | $this->loadXML(self::TEMPLATE); |
44 | 44 | |
45 | 45 | $this->Response = $this->firstChild; |
46 | 46 | $this->set_DateTime(); |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Set DateTime element value by current time |
|
51 | - */ |
|
52 | - public function set_DateTime() |
|
53 | - { |
|
49 | + /** |
|
50 | + * Set DateTime element value by current time |
|
51 | + */ |
|
52 | + public function set_DateTime() |
|
53 | + { |
|
54 | 54 | $this->setElementValue('DateTime', date('Y-m-d\TH:i:s', time())); |
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Create new element node |
|
59 | - * |
|
60 | - * @param string $name |
|
61 | - * @param string $value (optional) |
|
62 | - */ |
|
63 | - public function createElement($name, $value=NULL) |
|
64 | - { |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Create new element node |
|
59 | + * |
|
60 | + * @param string $name |
|
61 | + * @param string $value (optional) |
|
62 | + */ |
|
63 | + public function createElement($name, $value=NULL) |
|
64 | + { |
|
65 | 65 | return parent::createElement($name, $value); |
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Set node value |
|
70 | - * |
|
71 | - * @param string $name |
|
72 | - * @param string $value |
|
73 | - */ |
|
74 | - public function setElementValue($name, $value) |
|
75 | - { |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Set node value |
|
70 | + * |
|
71 | + * @param string $name |
|
72 | + * @param string $value |
|
73 | + */ |
|
74 | + public function setElementValue($name, $value) |
|
75 | + { |
|
76 | 76 | foreach ($this->Response->childNodes as $child) |
77 | 77 | { |
78 | - if ($child->nodeName == $name) |
|
79 | - { |
|
78 | + if ($child->nodeName == $name) |
|
79 | + { |
|
80 | 80 | $child->nodeValue = $value; |
81 | - } |
|
81 | + } |
|
82 | 82 | } |
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Dumps response into a string |
|
87 | - * |
|
88 | - * @return string XML |
|
89 | - */ |
|
90 | - public function friendly() |
|
91 | - { |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Dumps response into a string |
|
87 | + * |
|
88 | + * @return string XML |
|
89 | + */ |
|
90 | + public function friendly() |
|
91 | + { |
|
92 | 92 | $this->encoding = 'UTF-8'; |
93 | 93 | $this->formatOutput = true; |
94 | 94 | |
95 | 95 | return $this->saveXML(NULL, LIBXML_NOEMPTYTAG); |
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Sign and send response |
|
100 | - * |
|
101 | - * @param array $options |
|
102 | - */ |
|
103 | - public function sign_and_out($options) |
|
104 | - { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Sign and send response |
|
100 | + * |
|
101 | + * @param array $options |
|
102 | + */ |
|
103 | + public function sign_and_out($options) |
|
104 | + { |
|
105 | 105 | $this->sign($options); |
106 | 106 | $this->out_header(); |
107 | 107 | $this->out_body($this->friendly()); |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * Send header |
|
112 | - */ |
|
113 | - protected function out_header() |
|
114 | - { |
|
110 | + /** |
|
111 | + * Send header |
|
112 | + */ |
|
113 | + protected function out_header() |
|
114 | + { |
|
115 | 115 | ob_clean(); |
116 | 116 | @header("Content-Type: text/xml; charset=utf-8"); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Send body |
|
121 | - * |
|
122 | - * @param string $body |
|
123 | - */ |
|
124 | - protected function out_body($body) |
|
125 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Send body |
|
121 | + * |
|
122 | + * @param string $body |
|
123 | + */ |
|
124 | + protected function out_body($body) |
|
125 | + { |
|
126 | 126 | Log::instance()->debug('response sends: '); |
127 | 127 | Log::instance()->debug($body); |
128 | 128 | |
129 | 129 | echo $body; |
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Add Sign (if hasn't yet done) |
|
134 | - * |
|
135 | - * @param array $options |
|
136 | - */ |
|
137 | - protected function sign($options) |
|
138 | - { |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Add Sign (if hasn't yet done) |
|
134 | + * |
|
135 | + * @param array $options |
|
136 | + */ |
|
137 | + protected function sign($options) |
|
138 | + { |
|
139 | 139 | if (isset($this->Sign)) return; |
140 | 140 | |
141 | 141 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
142 | 142 | { |
143 | - $this->Sign = $this->createElement('Sign'); |
|
144 | - $this->Response->appendChild($this->Sign); |
|
143 | + $this->Sign = $this->createElement('Sign'); |
|
144 | + $this->Response->appendChild($this->Sign); |
|
145 | 145 | |
146 | - $this->Sign->nodeValue = (new Sign())->generate($this->friendly(), $options); |
|
146 | + $this->Sign->nodeValue = (new Sign())->generate($this->friendly(), $options); |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | } |
@@ -136,7 +136,9 @@ |
||
136 | 136 | */ |
137 | 137 | protected function sign($options) |
138 | 138 | { |
139 | - if (isset($this->Sign)) return; |
|
139 | + if (isset($this->Sign)) { |
|
140 | + return; |
|
141 | + } |
|
140 | 142 | |
141 | 143 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
142 | 144 | { |
@@ -18,124 +18,124 @@ 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 | - * |
|
106 | - * @throws Exception\Structure |
|
107 | - */ |
|
108 | - protected function parse_request_data() |
|
109 | - { |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
105 | + * |
|
106 | + * @throws Exception\Structure |
|
107 | + */ |
|
108 | + protected function parse_request_data() |
|
109 | + { |
|
110 | 110 | // process <Request> group |
111 | 111 | $r = $this->raw_request->get_nodes_from_request('Request'); |
112 | 112 | |
113 | 113 | if (count($r) < 1) |
114 | 114 | { |
115 | - throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
115 | + throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | foreach ($r[0]->childNodes as $child) |
119 | 119 | { |
120 | - $this->check_and_parse_request_node($child, 'DateTime'); |
|
121 | - $this->check_and_parse_request_node($child, 'Sign'); |
|
120 | + $this->check_and_parse_request_node($child, 'DateTime'); |
|
121 | + $this->check_and_parse_request_node($child, 'Sign'); |
|
122 | 122 | |
123 | - if (in_array($child->nodeName, $this->operations)) |
|
124 | - { |
|
123 | + if (in_array($child->nodeName, $this->operations)) |
|
124 | + { |
|
125 | 125 | if ( ! isset($this->Operation)) |
126 | 126 | { |
127 | - $this->Operation = $child->nodeName; |
|
127 | + $this->Operation = $child->nodeName; |
|
128 | 128 | } |
129 | 129 | else |
130 | 130 | { |
131 | - throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
131 | + throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
132 | + } |
|
132 | 133 | } |
133 | - } |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | if ( ! isset($this->Operation)) |
137 | 137 | { |
138 | - throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
138 | + throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | // process <Operation> group |
@@ -143,53 +143,53 @@ discard block |
||
143 | 143 | |
144 | 144 | foreach ($r[0]->childNodes as $child) |
145 | 145 | { |
146 | - $this->check_and_parse_request_node($child, 'ServiceId'); |
|
146 | + $this->check_and_parse_request_node($child, 'ServiceId'); |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Check if present node of request and then parse it |
|
152 | - * |
|
153 | - * @param \DOMNode $n |
|
154 | - * @param string $name |
|
155 | - */ |
|
156 | - protected function check_and_parse_request_node($n, $name) |
|
157 | - { |
|
150 | + /** |
|
151 | + * Check if present node of request and then parse it |
|
152 | + * |
|
153 | + * @param \DOMNode $n |
|
154 | + * @param string $name |
|
155 | + */ |
|
156 | + protected function check_and_parse_request_node($n, $name) |
|
157 | + { |
|
158 | 158 | if ($n->nodeName == $name) |
159 | 159 | { |
160 | - $this->parse_request_node($n, $name); |
|
160 | + $this->parse_request_node($n, $name); |
|
161 | + } |
|
161 | 162 | } |
162 | - } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Parse node of request |
|
166 | - * |
|
167 | - * @param \DOMNode $n |
|
168 | - * @param string $name |
|
169 | - * |
|
170 | - * @throws Exception\Structure |
|
171 | - */ |
|
172 | - protected function parse_request_node($n, $name) |
|
173 | - { |
|
164 | + /** |
|
165 | + * Parse node of request |
|
166 | + * |
|
167 | + * @param \DOMNode $n |
|
168 | + * @param string $name |
|
169 | + * |
|
170 | + * @throws Exception\Structure |
|
171 | + */ |
|
172 | + protected function parse_request_node($n, $name) |
|
173 | + { |
|
174 | 174 | if ( ! isset($this->$name)) |
175 | 175 | { |
176 | - $this->$name = $n->nodeValue; |
|
176 | + $this->$name = $n->nodeValue; |
|
177 | 177 | } |
178 | 178 | else |
179 | 179 | { |
180 | - throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
180 | + throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
181 | + } |
|
181 | 182 | } |
182 | - } |
|
183 | 183 | |
184 | - /** |
|
185 | - * "Rough" validation of the received xml request |
|
186 | - * |
|
187 | - * @param array $options |
|
188 | - * @throws Exception\Data |
|
189 | - * @throws Exception\Structure |
|
190 | - */ |
|
191 | - public function validate_request($options) |
|
192 | - { |
|
184 | + /** |
|
185 | + * "Rough" validation of the received xml request |
|
186 | + * |
|
187 | + * @param array $options |
|
188 | + * @throws Exception\Data |
|
189 | + * @throws Exception\Structure |
|
190 | + */ |
|
191 | + public function validate_request($options) |
|
192 | + { |
|
193 | 193 | $this->validate_element('DateTime'); |
194 | 194 | $this->validate_element('Sign'); |
195 | 195 | $this->validate_element('ServiceId'); |
@@ -197,36 +197,36 @@ discard block |
||
197 | 197 | // compare received value ServiceId with option ServiceId |
198 | 198 | if (intval($options['ServiceId']) != intval($this->ServiceId)) |
199 | 199 | { |
200 | - throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
200 | + throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
201 | + } |
|
201 | 202 | } |
202 | - } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Validation of xml-element |
|
206 | - * |
|
207 | - * @param string $name |
|
208 | - */ |
|
209 | - public function validate_element($name) |
|
210 | - { |
|
204 | + /** |
|
205 | + * Validation of xml-element |
|
206 | + * |
|
207 | + * @param string $name |
|
208 | + */ |
|
209 | + public function validate_element($name) |
|
210 | + { |
|
211 | 211 | if ( ! isset($this->$name)) |
212 | 212 | { |
213 | - throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
213 | + throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
214 | + } |
|
214 | 215 | } |
215 | - } |
|
216 | 216 | |
217 | - /** |
|
218 | - * Verify signature of request |
|
219 | - * |
|
220 | - * @param array $options |
|
221 | - */ |
|
222 | - public function verify_sign($options) |
|
223 | - { |
|
217 | + /** |
|
218 | + * Verify signature of request |
|
219 | + * |
|
220 | + * @param array $options |
|
221 | + */ |
|
222 | + public function verify_sign($options) |
|
223 | + { |
|
224 | 224 | $sign = new Sign(); |
225 | 225 | $sign->verify( |
226 | - $this->raw_request->str(), |
|
227 | - $this->Sign, |
|
228 | - $options |
|
226 | + $this->raw_request->str(), |
|
227 | + $this->Sign, |
|
228 | + $options |
|
229 | 229 | ); |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | 232 | } |
@@ -9,120 +9,120 @@ |
||
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 string $request_str |
|
18 | - * @param string $sign |
|
19 | - * @param array $options |
|
20 | - */ |
|
21 | - public function verify($request_str, $sign, $options) |
|
22 | - { |
|
14 | + /** |
|
15 | + * Verify signature of request |
|
16 | + * |
|
17 | + * @param string $request_str |
|
18 | + * @param string $sign |
|
19 | + * @param array $options |
|
20 | + */ |
|
21 | + public function verify($request_str, $sign, $options) |
|
22 | + { |
|
23 | 23 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
24 | 24 | { |
25 | - $this->check_verify_sign_result( |
|
25 | + $this->check_verify_sign_result( |
|
26 | 26 | $result = (new OpenSSL())->verify( |
27 | - str_replace($sign, '', $request_str), |
|
28 | - pack("H*", $sign), |
|
29 | - (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
27 | + str_replace($sign, '', $request_str), |
|
28 | + pack("H*", $sign), |
|
29 | + (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
30 | 30 | ) |
31 | - ); |
|
31 | + ); |
|
32 | + } |
|
32 | 33 | } |
33 | - } |
|
34 | 34 | |
35 | - /** |
|
36 | - * load file with easysoft public key |
|
37 | - * |
|
38 | - * @param array $options |
|
39 | - * @throws Exception\Runtime |
|
40 | - * @return string |
|
41 | - */ |
|
42 | - protected function get_pub_key($options) |
|
43 | - { |
|
35 | + /** |
|
36 | + * load file with easysoft public key |
|
37 | + * |
|
38 | + * @param array $options |
|
39 | + * @throws Exception\Runtime |
|
40 | + * @return string |
|
41 | + */ |
|
42 | + protected function get_pub_key($options) |
|
43 | + { |
|
44 | 44 | if ( ! isset($options['EasySoftPKey'])) |
45 | 45 | { |
46 | - throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
46 | + throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | return (new Key())->get($options['EasySoftPKey'], 'public'); |
50 | - } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * check result of openssl verify signature |
|
54 | - * |
|
55 | - * @param integer $result |
|
56 | - * @throws Exception\Sign |
|
57 | - */ |
|
58 | - protected function check_verify_sign_result($result) |
|
59 | - { |
|
52 | + /** |
|
53 | + * check result of openssl verify signature |
|
54 | + * |
|
55 | + * @param integer $result |
|
56 | + * @throws Exception\Sign |
|
57 | + */ |
|
58 | + protected function check_verify_sign_result($result) |
|
59 | + { |
|
60 | 60 | if ($result == -1) |
61 | 61 | { |
62 | - throw new Exception\Sign('Error verify signature of request!', -96); |
|
62 | + throw new Exception\Sign('Error verify signature of request!', -96); |
|
63 | 63 | } |
64 | 64 | elseif ($result == 0) |
65 | 65 | { |
66 | - throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
66 | + throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
67 | + } |
|
67 | 68 | } |
68 | - } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Generate signature of response |
|
72 | - * |
|
73 | - * @param string $request_str |
|
74 | - * @param array $options |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function generate($request_str, $options) |
|
78 | - { |
|
70 | + /** |
|
71 | + * Generate signature of response |
|
72 | + * |
|
73 | + * @param string $request_str |
|
74 | + * @param array $options |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function generate($request_str, $options) |
|
78 | + { |
|
79 | 79 | try |
80 | 80 | { |
81 | - $sign = ''; |
|
82 | - $this->check_generate_sign_result( |
|
81 | + $sign = ''; |
|
82 | + $this->check_generate_sign_result( |
|
83 | 83 | $result = (new OpenSSL())->sign( |
84 | - $request_str, |
|
85 | - $sign, |
|
86 | - (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
84 | + $request_str, |
|
85 | + $sign, |
|
86 | + (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
87 | 87 | ) |
88 | - ); |
|
88 | + ); |
|
89 | 89 | |
90 | - return strtoupper(bin2hex($sign)); |
|
90 | + return strtoupper(bin2hex($sign)); |
|
91 | 91 | } |
92 | 92 | catch (\Exception $e) |
93 | 93 | { |
94 | - return null; |
|
94 | + return null; |
|
95 | + } |
|
95 | 96 | } |
96 | - } |
|
97 | 97 | |
98 | - /** |
|
99 | - * load file with provider private key |
|
100 | - * |
|
101 | - * @param array $options |
|
102 | - * @throws Exception\Runtime |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - protected function get_priv_key($options) |
|
106 | - { |
|
98 | + /** |
|
99 | + * load file with provider private key |
|
100 | + * |
|
101 | + * @param array $options |
|
102 | + * @throws Exception\Runtime |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + protected function get_priv_key($options) |
|
106 | + { |
|
107 | 107 | if ( ! isset($options['ProviderPKey'])) |
108 | 108 | { |
109 | - throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
109 | + throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | return (new Key())->get($options['ProviderPKey'], 'private'); |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * check result of openssl sign |
|
117 | - * |
|
118 | - * @param bool $result |
|
119 | - * @throws Exception\Sign |
|
120 | - */ |
|
121 | - protected function check_generate_sign_result($result) |
|
122 | - { |
|
115 | + /** |
|
116 | + * check result of openssl sign |
|
117 | + * |
|
118 | + * @param bool $result |
|
119 | + * @throws Exception\Sign |
|
120 | + */ |
|
121 | + protected function check_generate_sign_result($result) |
|
122 | + { |
|
123 | 123 | if ($result === FALSE) |
124 | 124 | { |
125 | - throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
125 | + throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
126 | + } |
|
126 | 127 | } |
127 | - } |
|
128 | 128 | } |
@@ -60,8 +60,7 @@ discard block |
||
60 | 60 | if ($result == -1) |
61 | 61 | { |
62 | 62 | throw new Exception\Sign('Error verify signature of request!', -96); |
63 | - } |
|
64 | - elseif ($result == 0) |
|
63 | + } elseif ($result == 0) |
|
65 | 64 | { |
66 | 65 | throw new Exception\Sign('Signature of request is incorrect!', -95); |
67 | 66 | } |
@@ -88,8 +87,7 @@ discard block |
||
88 | 87 | ); |
89 | 88 | |
90 | 89 | return strtoupper(bin2hex($sign)); |
91 | - } |
|
92 | - catch (\Exception $e) |
|
90 | + } catch (\Exception $e) |
|
93 | 91 | { |
94 | 92 | return null; |
95 | 93 | } |