@@ -13,237 +13,237 @@ |
||
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 = $this->get_request(); |
|
64 | + // get request |
|
65 | + $this->request = $this->get_request(); |
|
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->sign_and_out(self::$options); |
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * method to create a specific class of request |
|
103 | - * |
|
104 | - * @return Request\General Request class of the appropriate type |
|
105 | - * @throws \EasyPay\Exception\Structure |
|
106 | - */ |
|
107 | - protected function get_request() |
|
108 | - { |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * method to create a specific class of request |
|
103 | + * |
|
104 | + * @return Request\General Request class of the appropriate type |
|
105 | + * @throws \EasyPay\Exception\Structure |
|
106 | + */ |
|
107 | + protected function get_request() |
|
108 | + { |
|
109 | 109 | $raw = new Provider31\Request\RAW(); |
110 | 110 | |
111 | 111 | $r = new Provider31\Request\General($raw); |
112 | 112 | |
113 | 113 | switch ($r->Operation()) |
114 | 114 | { |
115 | - case 'Check': |
|
115 | + case 'Check': |
|
116 | 116 | return new Provider31\Request\Check($raw); |
117 | 117 | |
118 | - case 'Payment': |
|
118 | + case 'Payment': |
|
119 | 119 | return new Provider31\Request\Payment($raw); |
120 | 120 | |
121 | - case 'Confirm': |
|
121 | + case 'Confirm': |
|
122 | 122 | return new Provider31\Request\Confirm($raw); |
123 | 123 | |
124 | - case 'Cancel'; |
|
124 | + case 'Cancel'; |
|
125 | 125 | return new Provider31\Request\Cancel($raw); |
126 | 126 | |
127 | - default: |
|
127 | + default: |
|
128 | 128 | throw new \EasyPay\Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
129 | 129 | } |
130 | - } |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Process request and generate response |
|
134 | - * |
|
135 | - * @throws Exception\Structure |
|
136 | - */ |
|
137 | - protected function get_response() |
|
138 | - { |
|
132 | + /** |
|
133 | + * Process request and generate response |
|
134 | + * |
|
135 | + * @throws Exception\Structure |
|
136 | + */ |
|
137 | + protected function get_response() |
|
138 | + { |
|
139 | 139 | switch ($this->request->Operation()) |
140 | 140 | { |
141 | - case 'Check': |
|
141 | + case 'Check': |
|
142 | 142 | $response = $this->response_check(); |
143 | 143 | break; |
144 | 144 | |
145 | - case 'Payment': |
|
145 | + case 'Payment': |
|
146 | 146 | $response = $this->response_payment(); |
147 | 147 | break; |
148 | 148 | |
149 | - case 'Confirm': |
|
149 | + case 'Confirm': |
|
150 | 150 | $response = $this->response_confirm(); |
151 | 151 | break; |
152 | 152 | |
153 | - case 'Cancel'; |
|
153 | + case 'Cancel'; |
|
154 | 154 | $response = $this->response_cancel(); |
155 | 155 | break; |
156 | 156 | |
157 | - default: |
|
157 | + default: |
|
158 | 158 | throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
159 | 159 | } |
160 | 160 | |
161 | 161 | return $response; |
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * run check callback and generate a response |
|
166 | - * |
|
167 | - * @return Provider31\Response\Check |
|
168 | - */ |
|
169 | - private function response_check() |
|
170 | - { |
|
162 | + } |
|
163 | + |
|
164 | + /** |
|
165 | + * run check callback and generate a response |
|
166 | + * |
|
167 | + * @return Provider31\Response\Check |
|
168 | + */ |
|
169 | + private function response_check() |
|
170 | + { |
|
171 | 171 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
172 | 172 | |
173 | 173 | $accountinfo = self::$cb->check( |
174 | - $this->request->Account() |
|
174 | + $this->request->Account() |
|
175 | 175 | ); |
176 | 176 | |
177 | 177 | // Sending a response |
178 | 178 | return new Provider31\Response\Check($accountinfo); |
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * run payment callback and generate a response |
|
183 | - * |
|
184 | - * @return Provider31\Response\Payment |
|
185 | - */ |
|
186 | - private function response_payment() |
|
187 | - { |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * run payment callback and generate a response |
|
183 | + * |
|
184 | + * @return Provider31\Response\Payment |
|
185 | + */ |
|
186 | + private function response_payment() |
|
187 | + { |
|
188 | 188 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
189 | 189 | |
190 | 190 | $paymentid = self::$cb->payment( |
191 | - $this->request->Account(), |
|
192 | - $this->request->OrderId(), |
|
193 | - $this->request->Amount() |
|
191 | + $this->request->Account(), |
|
192 | + $this->request->OrderId(), |
|
193 | + $this->request->Amount() |
|
194 | 194 | ); |
195 | 195 | |
196 | 196 | // Sending a response |
197 | 197 | return new Provider31\Response\Payment($paymentid); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * run confirm callback and generate a response |
|
202 | - * |
|
203 | - * @return Provider31\Response\Confirm |
|
204 | - */ |
|
205 | - private function response_confirm() |
|
206 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * run confirm callback and generate a response |
|
202 | + * |
|
203 | + * @return Provider31\Response\Confirm |
|
204 | + */ |
|
205 | + private function response_confirm() |
|
206 | + { |
|
207 | 207 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
208 | 208 | |
209 | 209 | $orderdate = self::$cb->confirm( |
210 | - $this->request->PaymentId() |
|
210 | + $this->request->PaymentId() |
|
211 | 211 | ); |
212 | 212 | |
213 | 213 | // Sending a response |
214 | 214 | return new Provider31\Response\Confirm($orderdate); |
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * run cancel callback and generate a response |
|
219 | - * |
|
220 | - * @return Provider31\Response\Cancel |
|
221 | - */ |
|
222 | - private function response_cancel() |
|
223 | - { |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * run cancel callback and generate a response |
|
219 | + * |
|
220 | + * @return Provider31\Response\Cancel |
|
221 | + */ |
|
222 | + private function response_cancel() |
|
223 | + { |
|
224 | 224 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
225 | 225 | |
226 | 226 | $canceldate = self::$cb->cancel( |
227 | - $this->request->PaymentId() |
|
227 | + $this->request->PaymentId() |
|
228 | 228 | ); |
229 | 229 | |
230 | 230 | // Sending a response |
231 | 231 | return new Provider31\Response\Cancel($canceldate); |
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Generates an xml with an error message |
|
236 | - * |
|
237 | - * @param integer $code |
|
238 | - * @param string $message |
|
239 | - * |
|
240 | - * @return Provider31\Response\ErrorInfo |
|
241 | - */ |
|
242 | - private function get_error_response($code, $message) |
|
243 | - { |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Generates an xml with an error message |
|
236 | + * |
|
237 | + * @param integer $code |
|
238 | + * @param string $message |
|
239 | + * |
|
240 | + * @return Provider31\Response\ErrorInfo |
|
241 | + */ |
|
242 | + private function get_error_response($code, $message) |
|
243 | + { |
|
244 | 244 | Log::instance()->add('the request was processed with an error'); |
245 | 245 | |
246 | 246 | // Sending a response |
247 | 247 | return new Provider31\Response\ErrorInfo($code, $message); |
248 | - } |
|
248 | + } |
|
249 | 249 | } |