@@ -17,194 +17,194 @@ |
||
17 | 17 | |
18 | 18 | abstract class Response extends \DomDocument |
19 | 19 | { |
20 | - /** |
|
21 | - * @var string |
|
22 | - * |
|
23 | - */ |
|
24 | - const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var \DOMNode |
|
28 | - */ |
|
29 | - protected $Response; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var \DOMElement |
|
33 | - */ |
|
34 | - protected $Sign; |
|
35 | - |
|
36 | - /** |
|
37 | - * Response constructor |
|
38 | - * |
|
39 | - */ |
|
40 | - public function __construct() |
|
41 | - { |
|
20 | + /** |
|
21 | + * @var string |
|
22 | + * |
|
23 | + */ |
|
24 | + const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var \DOMNode |
|
28 | + */ |
|
29 | + protected $Response; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var \DOMElement |
|
33 | + */ |
|
34 | + protected $Sign; |
|
35 | + |
|
36 | + /** |
|
37 | + * Response constructor |
|
38 | + * |
|
39 | + */ |
|
40 | + public function __construct() |
|
41 | + { |
|
42 | 42 | parent::__construct('1.0', 'UTF-8'); |
43 | 43 | |
44 | 44 | $this->loadXML(self::TEMPLATE); |
45 | 45 | |
46 | 46 | $this->Response = $this->firstChild; |
47 | 47 | $this->set_DateTime(); |
48 | - } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Set DateTime element value by current time |
|
52 | - */ |
|
53 | - public function set_DateTime() |
|
54 | - { |
|
50 | + /** |
|
51 | + * Set DateTime element value by current time |
|
52 | + */ |
|
53 | + public function set_DateTime() |
|
54 | + { |
|
55 | 55 | $this->setElementValue('DateTime', date('Y-m-d\TH:i:s', time())); |
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Create new element node |
|
60 | - * |
|
61 | - * @param string $name |
|
62 | - * @param string $value (optional) |
|
63 | - */ |
|
64 | - public function createElement($name, $value=NULL) |
|
65 | - { |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Create new element node |
|
60 | + * |
|
61 | + * @param string $name |
|
62 | + * @param string $value (optional) |
|
63 | + */ |
|
64 | + public function createElement($name, $value=NULL) |
|
65 | + { |
|
66 | 66 | return parent::createElement($name, $value); |
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Set node value |
|
71 | - * |
|
72 | - * @param string $name |
|
73 | - * @param string $value |
|
74 | - */ |
|
75 | - public function setElementValue($name, $value) |
|
76 | - { |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Set node value |
|
71 | + * |
|
72 | + * @param string $name |
|
73 | + * @param string $value |
|
74 | + */ |
|
75 | + public function setElementValue($name, $value) |
|
76 | + { |
|
77 | 77 | foreach ($this->Response->childNodes as $child) |
78 | 78 | { |
79 | - if ($child->nodeName == $name) |
|
80 | - { |
|
79 | + if ($child->nodeName == $name) |
|
80 | + { |
|
81 | 81 | $child->nodeValue = $value; |
82 | - } |
|
82 | + } |
|
83 | + } |
|
83 | 84 | } |
84 | - } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Dumps response into a string |
|
88 | - * |
|
89 | - * @return string XML |
|
90 | - */ |
|
91 | - public function friendly() |
|
92 | - { |
|
86 | + /** |
|
87 | + * Dumps response into a string |
|
88 | + * |
|
89 | + * @return string XML |
|
90 | + */ |
|
91 | + public function friendly() |
|
92 | + { |
|
93 | 93 | $this->encoding = 'UTF-8'; |
94 | 94 | $this->formatOutput = true; |
95 | 95 | |
96 | 96 | return $this->saveXML(NULL, LIBXML_NOEMPTYTAG); |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Sign and send response |
|
101 | - * |
|
102 | - * @param array $options |
|
103 | - */ |
|
104 | - public function sign_and_out($options) |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Sign and send response |
|
101 | + * |
|
102 | + * @param array $options |
|
103 | + */ |
|
104 | + public function sign_and_out($options) |
|
105 | + { |
|
106 | 106 | $this->sign($options); |
107 | 107 | $this->out_header(); |
108 | 108 | $this->out_body($this->friendly()); |
109 | - } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Send header |
|
113 | - */ |
|
114 | - protected function out_header() |
|
115 | - { |
|
111 | + /** |
|
112 | + * Send header |
|
113 | + */ |
|
114 | + protected function out_header() |
|
115 | + { |
|
116 | 116 | ob_clean(); |
117 | 117 | header("Content-Type: text/xml; charset=utf-8"); |
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Send body |
|
122 | - * |
|
123 | - * @param string $body |
|
124 | - */ |
|
125 | - protected function out_body($body) |
|
126 | - { |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Send body |
|
122 | + * |
|
123 | + * @param string $body |
|
124 | + */ |
|
125 | + protected function out_body($body) |
|
126 | + { |
|
127 | 127 | Log::instance()->debug('response sends: '); |
128 | 128 | Log::instance()->debug($body); |
129 | 129 | |
130 | 130 | echo $body; |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Add Sign (if hasn't yet done) |
|
135 | - * |
|
136 | - * @param array $options |
|
137 | - */ |
|
138 | - protected function sign($options) |
|
139 | - { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Add Sign (if hasn't yet done) |
|
135 | + * |
|
136 | + * @param array $options |
|
137 | + */ |
|
138 | + protected function sign($options) |
|
139 | + { |
|
140 | 140 | if (isset($this->Sign)) return; |
141 | 141 | |
142 | 142 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
143 | 143 | { |
144 | - $this->Sign = $this->createElement('Sign'); |
|
145 | - $this->Response->appendChild($this->Sign); |
|
144 | + $this->Sign = $this->createElement('Sign'); |
|
145 | + $this->Response->appendChild($this->Sign); |
|
146 | 146 | |
147 | - $sign = $this->generate_sign($options); |
|
147 | + $sign = $this->generate_sign($options); |
|
148 | 148 | |
149 | - $this->Sign->nodeValue = $sign; |
|
149 | + $this->Sign->nodeValue = $sign; |
|
150 | + } |
|
150 | 151 | } |
151 | - } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Generate signature of response |
|
155 | - * |
|
156 | - * @param array $options |
|
157 | - * @return string |
|
158 | - */ |
|
159 | - public function generate_sign($options) |
|
160 | - { |
|
153 | + /** |
|
154 | + * Generate signature of response |
|
155 | + * |
|
156 | + * @param array $options |
|
157 | + * @return string |
|
158 | + */ |
|
159 | + public function generate_sign($options) |
|
160 | + { |
|
161 | 161 | try |
162 | 162 | { |
163 | - $sign = ''; |
|
164 | - $this->check_sign_result( |
|
163 | + $sign = ''; |
|
164 | + $this->check_sign_result( |
|
165 | 165 | $result = (new OpenSSL())->sign( |
166 | - $this->friendly(), |
|
167 | - $sign, |
|
168 | - (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
166 | + $this->friendly(), |
|
167 | + $sign, |
|
168 | + (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
169 | 169 | ) |
170 | - ); |
|
170 | + ); |
|
171 | 171 | |
172 | - return strtoupper(bin2hex($sign)); |
|
172 | + return strtoupper(bin2hex($sign)); |
|
173 | 173 | } |
174 | 174 | catch (\Exception $e) |
175 | 175 | { |
176 | - return null; |
|
176 | + return null; |
|
177 | + } |
|
177 | 178 | } |
178 | - } |
|
179 | 179 | |
180 | - /** |
|
181 | - * load file with provider private key |
|
182 | - * |
|
183 | - * @param array $options |
|
184 | - * @throws Exception\Runtime |
|
185 | - * @return string |
|
186 | - */ |
|
187 | - protected function get_priv_key($options) |
|
188 | - { |
|
180 | + /** |
|
181 | + * load file with provider private key |
|
182 | + * |
|
183 | + * @param array $options |
|
184 | + * @throws Exception\Runtime |
|
185 | + * @return string |
|
186 | + */ |
|
187 | + protected function get_priv_key($options) |
|
188 | + { |
|
189 | 189 | if ( ! isset($options['ProviderPKey'])) |
190 | 190 | { |
191 | - throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
191 | + throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | return (new Key())->get($options['ProviderPKey'], 'private'); |
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * check result of openssl sign |
|
199 | - * |
|
200 | - * @param bool $result |
|
201 | - * @throws Exception\Sign |
|
202 | - */ |
|
203 | - protected function check_sign_result($result) |
|
204 | - { |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * check result of openssl sign |
|
199 | + * |
|
200 | + * @param bool $result |
|
201 | + * @throws Exception\Sign |
|
202 | + */ |
|
203 | + protected function check_sign_result($result) |
|
204 | + { |
|
205 | 205 | if ($result === FALSE) |
206 | 206 | { |
207 | - throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
207 | + throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
208 | + } |
|
208 | 209 | } |
209 | - } |
|
210 | 210 | } |
@@ -13,207 +13,207 @@ |
||
13 | 13 | |
14 | 14 | class Provider31 |
15 | 15 | { |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - protected static $options = array( |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + protected static $options = array( |
|
20 | 20 | 'ServiceId' => 0, |
21 | 21 | 'UseSign' => false, |
22 | 22 | 'EasySoftPKey' => '', |
23 | 23 | 'ProviderPKey' => '', |
24 | - ); |
|
25 | - |
|
26 | - /** |
|
27 | - * @var \EasyPay\Callback |
|
28 | - */ |
|
29 | - protected static $cb; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var mixed |
|
33 | - */ |
|
34 | - private $request; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Provider31\Response |
|
38 | - */ |
|
39 | - private $response; |
|
40 | - |
|
41 | - /** |
|
42 | - * Provider31 constructor |
|
43 | - * |
|
44 | - * @param array $options |
|
45 | - * @param Callback $cb |
|
46 | - * @param \Debulog\LoggerInterface $log |
|
47 | - */ |
|
48 | - public function __construct(array $options, \EasyPay\Callback $cb, \Debulog\LoggerInterface $log) |
|
49 | - { |
|
24 | + ); |
|
25 | + |
|
26 | + /** |
|
27 | + * @var \EasyPay\Callback |
|
28 | + */ |
|
29 | + protected static $cb; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var mixed |
|
33 | + */ |
|
34 | + private $request; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Provider31\Response |
|
38 | + */ |
|
39 | + private $response; |
|
40 | + |
|
41 | + /** |
|
42 | + * Provider31 constructor |
|
43 | + * |
|
44 | + * @param array $options |
|
45 | + * @param Callback $cb |
|
46 | + * @param \Debulog\LoggerInterface $log |
|
47 | + */ |
|
48 | + public function __construct(array $options, \EasyPay\Callback $cb, \Debulog\LoggerInterface $log) |
|
49 | + { |
|
50 | 50 | self::$options = array_merge(self::$options, $options); |
51 | 51 | self::$cb = $cb; |
52 | 52 | |
53 | 53 | Log::set($log); |
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Get and process request, echo response |
|
58 | - * |
|
59 | - */ |
|
60 | - public function process() |
|
61 | - { |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Get and process request, echo response |
|
58 | + * |
|
59 | + */ |
|
60 | + public function process() |
|
61 | + { |
|
62 | 62 | try |
63 | 63 | { |
64 | - // get request |
|
65 | - $this->request = Provider31\Request::get(); |
|
64 | + // get request |
|
65 | + $this->request = Provider31\Request::get(); |
|
66 | 66 | |
67 | - // validate request |
|
68 | - $this->request->validate_request(self::$options); |
|
69 | - Log::instance()->debug('request is valid'); |
|
67 | + // validate request |
|
68 | + $this->request->validate_request(self::$options); |
|
69 | + Log::instance()->debug('request is valid'); |
|
70 | 70 | |
71 | - // verify sign |
|
72 | - $this->request->verify_sign(self::$options); |
|
73 | - Log::instance()->debug('signature of request is correct'); |
|
71 | + // verify sign |
|
72 | + $this->request->verify_sign(self::$options); |
|
73 | + Log::instance()->debug('signature of request is correct'); |
|
74 | 74 | |
75 | - // get response |
|
76 | - $this->response = $this->get_response(); |
|
75 | + // get response |
|
76 | + $this->response = $this->get_response(); |
|
77 | 77 | |
78 | - Log::instance()->add('the request was processed successfully'); |
|
78 | + Log::instance()->add('the request was processed successfully'); |
|
79 | 79 | } |
80 | 80 | catch (Exception\Structure $e) |
81 | 81 | { |
82 | - $this->response = $this->get_error_response($e->getCode(), 'Error in request'); |
|
82 | + $this->response = $this->get_error_response($e->getCode(), 'Error in request'); |
|
83 | 83 | } |
84 | 84 | catch (Exception\Sign $e) |
85 | 85 | { |
86 | - $this->response = $this->get_error_response($e->getCode(), 'Signature error!'); |
|
86 | + $this->response = $this->get_error_response($e->getCode(), 'Signature error!'); |
|
87 | 87 | } |
88 | 88 | catch (Exception\Runtime $e) |
89 | 89 | { |
90 | - $this->response = $this->get_error_response($e->getCode(), 'Error while processing request'); |
|
90 | + $this->response = $this->get_error_response($e->getCode(), 'Error while processing request'); |
|
91 | 91 | } |
92 | 92 | catch (\Exception $e) |
93 | 93 | { |
94 | - $this->response = $this->get_error_response($e->getCode(), $e->getMessage()); |
|
94 | + $this->response = $this->get_error_response($e->getCode(), $e->getMessage()); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // output response |
98 | 98 | $this->response->out(self::$options); |
99 | 99 | exit; |
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Process request and generate response |
|
104 | - * |
|
105 | - * @throws Exception\Structure |
|
106 | - */ |
|
107 | - private function get_response() |
|
108 | - { |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Process request and generate response |
|
104 | + * |
|
105 | + * @throws Exception\Structure |
|
106 | + */ |
|
107 | + private function get_response() |
|
108 | + { |
|
109 | 109 | switch ($this->request->Operation()) |
110 | 110 | { |
111 | - case 'Check': |
|
111 | + case 'Check': |
|
112 | 112 | |
113 | 113 | return $this->response_check(); |
114 | 114 | |
115 | - case 'Payment': |
|
115 | + case 'Payment': |
|
116 | 116 | |
117 | 117 | return $this->response_payment(); |
118 | 118 | |
119 | - case 'Confirm': |
|
119 | + case 'Confirm': |
|
120 | 120 | |
121 | 121 | return $this->response_confirm(); |
122 | 122 | |
123 | - case 'Cancel'; |
|
123 | + case 'Cancel'; |
|
124 | 124 | |
125 | 125 | return $this->response_cancel(); |
126 | 126 | |
127 | - default: |
|
127 | + default: |
|
128 | 128 | break; |
129 | 129 | } |
130 | 130 | |
131 | 131 | throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * run check callback and generate a response |
|
136 | - * |
|
137 | - * @return Provider31\Response\Check |
|
138 | - */ |
|
139 | - private function response_check() |
|
140 | - { |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * run check callback and generate a response |
|
136 | + * |
|
137 | + * @return Provider31\Response\Check |
|
138 | + */ |
|
139 | + private function response_check() |
|
140 | + { |
|
141 | 141 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
142 | 142 | |
143 | 143 | $accountinfo = self::$cb->check( |
144 | - $this->request->Account() |
|
144 | + $this->request->Account() |
|
145 | 145 | ); |
146 | 146 | |
147 | 147 | // Sending a response |
148 | 148 | return new Provider31\Response\Check($accountinfo); |
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * run payment callback and generate a response |
|
153 | - * |
|
154 | - * @return Provider31\Response\Payment |
|
155 | - */ |
|
156 | - private function response_payment() |
|
157 | - { |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * run payment callback and generate a response |
|
153 | + * |
|
154 | + * @return Provider31\Response\Payment |
|
155 | + */ |
|
156 | + private function response_payment() |
|
157 | + { |
|
158 | 158 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
159 | 159 | |
160 | 160 | $paymentid = self::$cb->payment( |
161 | - $this->request->Account(), |
|
162 | - $this->request->OrderId(), |
|
163 | - $this->request->Amount() |
|
161 | + $this->request->Account(), |
|
162 | + $this->request->OrderId(), |
|
163 | + $this->request->Amount() |
|
164 | 164 | ); |
165 | 165 | |
166 | 166 | // Sending a response |
167 | 167 | return new Provider31\Response\Payment($paymentid); |
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * run confirm callback and generate a response |
|
172 | - * |
|
173 | - * @return Provider31\Response\Confirm |
|
174 | - */ |
|
175 | - private function response_confirm() |
|
176 | - { |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * run confirm callback and generate a response |
|
172 | + * |
|
173 | + * @return Provider31\Response\Confirm |
|
174 | + */ |
|
175 | + private function response_confirm() |
|
176 | + { |
|
177 | 177 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
178 | 178 | |
179 | 179 | $orderdate = self::$cb->confirm( |
180 | - $this->request->PaymentId() |
|
180 | + $this->request->PaymentId() |
|
181 | 181 | ); |
182 | 182 | |
183 | 183 | // Sending a response |
184 | 184 | return new Provider31\Response\Confirm($orderdate); |
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * run cancel callback and generate a response |
|
189 | - * |
|
190 | - * @return Provider31\Response\Cancel |
|
191 | - */ |
|
192 | - private function response_cancel() |
|
193 | - { |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * run cancel callback and generate a response |
|
189 | + * |
|
190 | + * @return Provider31\Response\Cancel |
|
191 | + */ |
|
192 | + private function response_cancel() |
|
193 | + { |
|
194 | 194 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
195 | 195 | |
196 | 196 | $canceldate = self::$cb->cancel( |
197 | - $this->request->PaymentId() |
|
197 | + $this->request->PaymentId() |
|
198 | 198 | ); |
199 | 199 | |
200 | 200 | // Sending a response |
201 | 201 | return new Provider31\Response\Cancel($canceldate); |
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Generates an xml with an error message |
|
206 | - * |
|
207 | - * @param integer $code |
|
208 | - * @param string $message |
|
209 | - * |
|
210 | - * @return Provider31\Response\ErrorInfo |
|
211 | - */ |
|
212 | - private function get_error_response($code, $message) |
|
213 | - { |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Generates an xml with an error message |
|
206 | + * |
|
207 | + * @param integer $code |
|
208 | + * @param string $message |
|
209 | + * |
|
210 | + * @return Provider31\Response\ErrorInfo |
|
211 | + */ |
|
212 | + private function get_error_response($code, $message) |
|
213 | + { |
|
214 | 214 | Log::instance()->add('the request was processed with an error'); |
215 | 215 | |
216 | 216 | // Sending a response |
217 | 217 | return new Provider31\Response\ErrorInfo($code, $message); |
218 | - } |
|
218 | + } |
|
219 | 219 | } |