@@ -13,79 +13,79 @@ discard block |
||
| 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 | - protected $request; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var Provider31\Response |
|
| 38 | - */ |
|
| 39 | - protected $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 | + protected $request; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var Provider31\Response |
|
| 38 | + */ |
|
| 39 | + protected $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->get_request(); |
|
| 64 | + // get request |
|
| 65 | + $this->get_request(); |
|
| 66 | 66 | |
| 67 | - // get response |
|
| 68 | - $this->response = $this->get_response(); |
|
| 67 | + // get response |
|
| 68 | + $this->response = $this->get_response(); |
|
| 69 | 69 | |
| 70 | - Log::instance()->add('the request was processed successfully'); |
|
| 70 | + Log::instance()->add('the request was processed successfully'); |
|
| 71 | 71 | } |
| 72 | 72 | catch (\Exception $e) |
| 73 | 73 | { |
| 74 | - $this->response = $this->get_error_response($e); |
|
| 74 | + $this->response = $this->get_error_response($e); |
|
| 75 | 75 | |
| 76 | - Log::instance()->add('the request was processed with an error'); |
|
| 76 | + Log::instance()->add('the request was processed with an error'); |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | // output response |
| 80 | 80 | $this->response->sign_and_out(self::$options); |
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * method to create a specific class of request |
|
| 85 | - * |
|
| 86 | - */ |
|
| 87 | - protected function get_request() |
|
| 88 | - { |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * method to create a specific class of request |
|
| 85 | + * |
|
| 86 | + */ |
|
| 87 | + protected function get_request() |
|
| 88 | + { |
|
| 89 | 89 | $raw = new Provider31\Request\RAW(); |
| 90 | 90 | |
| 91 | 91 | $r = new Provider31\Request\General($raw); |
@@ -100,114 +100,114 @@ discard block |
||
| 100 | 100 | // verify sign |
| 101 | 101 | $this->request->verify_sign(self::$options); |
| 102 | 102 | Log::instance()->debug('signature of request is correct'); |
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * generate response |
|
| 107 | - * |
|
| 108 | - * @return mixed |
|
| 109 | - */ |
|
| 110 | - protected function get_response() |
|
| 111 | - { |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * generate response |
|
| 107 | + * |
|
| 108 | + * @return mixed |
|
| 109 | + */ |
|
| 110 | + protected function get_response() |
|
| 111 | + { |
|
| 112 | 112 | $m = 'response_'.$this->request->Operation(); |
| 113 | 113 | return $this->$m(); |
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * run check callback and generate a response |
|
| 118 | - * |
|
| 119 | - * @return Provider31\Response\Check |
|
| 120 | - */ |
|
| 121 | - private function response_Check() |
|
| 122 | - { |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * run check callback and generate a response |
|
| 118 | + * |
|
| 119 | + * @return Provider31\Response\Check |
|
| 120 | + */ |
|
| 121 | + private function response_Check() |
|
| 122 | + { |
|
| 123 | 123 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
| 124 | 124 | |
| 125 | 125 | $accountinfo = self::$cb->check( |
| 126 | - $this->request->Account() |
|
| 126 | + $this->request->Account() |
|
| 127 | 127 | ); |
| 128 | 128 | |
| 129 | 129 | // Sending a response |
| 130 | 130 | return new Provider31\Response\Check($accountinfo); |
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * run payment callback and generate a response |
|
| 135 | - * |
|
| 136 | - * @return Provider31\Response\Payment |
|
| 137 | - */ |
|
| 138 | - private function response_Payment() |
|
| 139 | - { |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * run payment callback and generate a response |
|
| 135 | + * |
|
| 136 | + * @return Provider31\Response\Payment |
|
| 137 | + */ |
|
| 138 | + private function response_Payment() |
|
| 139 | + { |
|
| 140 | 140 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
| 141 | 141 | |
| 142 | 142 | $paymentid = self::$cb->payment( |
| 143 | - $this->request->Account(), |
|
| 144 | - $this->request->OrderId(), |
|
| 145 | - $this->request->Amount() |
|
| 143 | + $this->request->Account(), |
|
| 144 | + $this->request->OrderId(), |
|
| 145 | + $this->request->Amount() |
|
| 146 | 146 | ); |
| 147 | 147 | |
| 148 | 148 | // Sending a response |
| 149 | 149 | return new Provider31\Response\Payment($paymentid); |
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * run confirm callback and generate a response |
|
| 154 | - * |
|
| 155 | - * @return Provider31\Response\Confirm |
|
| 156 | - */ |
|
| 157 | - private function response_Confirm() |
|
| 158 | - { |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * run confirm callback and generate a response |
|
| 154 | + * |
|
| 155 | + * @return Provider31\Response\Confirm |
|
| 156 | + */ |
|
| 157 | + private function response_Confirm() |
|
| 158 | + { |
|
| 159 | 159 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
| 160 | 160 | |
| 161 | 161 | $orderdate = self::$cb->confirm( |
| 162 | - $this->request->PaymentId() |
|
| 162 | + $this->request->PaymentId() |
|
| 163 | 163 | ); |
| 164 | 164 | |
| 165 | 165 | // Sending a response |
| 166 | 166 | return new Provider31\Response\Confirm($orderdate); |
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * run cancel callback and generate a response |
|
| 171 | - * |
|
| 172 | - * @return Provider31\Response\Cancel |
|
| 173 | - */ |
|
| 174 | - private function response_Cancel() |
|
| 175 | - { |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * run cancel callback and generate a response |
|
| 171 | + * |
|
| 172 | + * @return Provider31\Response\Cancel |
|
| 173 | + */ |
|
| 174 | + private function response_Cancel() |
|
| 175 | + { |
|
| 176 | 176 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
| 177 | 177 | |
| 178 | 178 | $canceldate = self::$cb->cancel( |
| 179 | - $this->request->PaymentId() |
|
| 179 | + $this->request->PaymentId() |
|
| 180 | 180 | ); |
| 181 | 181 | |
| 182 | 182 | // Sending a response |
| 183 | 183 | return new Provider31\Response\Cancel($canceldate); |
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Generates an xml with an error message |
|
| 188 | - * |
|
| 189 | - * @param mixed $e |
|
| 190 | - * |
|
| 191 | - * @return Provider31\Response\ErrorInfo |
|
| 192 | - */ |
|
| 193 | - private function get_error_response($e) |
|
| 194 | - { |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Generates an xml with an error message |
|
| 188 | + * |
|
| 189 | + * @param mixed $e |
|
| 190 | + * |
|
| 191 | + * @return Provider31\Response\ErrorInfo |
|
| 192 | + */ |
|
| 193 | + private function get_error_response($e) |
|
| 194 | + { |
|
| 195 | 195 | $message = $e->getMessage(); |
| 196 | 196 | |
| 197 | 197 | if ($e instanceof Exception\Structure) |
| 198 | 198 | { |
| 199 | - $message = 'Error in request'; |
|
| 199 | + $message = 'Error in request'; |
|
| 200 | 200 | } |
| 201 | 201 | elseif ($e instanceof Exception\Sign) |
| 202 | 202 | { |
| 203 | - $message = 'Signature error!'; |
|
| 203 | + $message = 'Signature error!'; |
|
| 204 | 204 | } |
| 205 | 205 | elseif ($e instanceof Exception\Runtime) |
| 206 | 206 | { |
| 207 | - $message = 'Error while processing request'; |
|
| 207 | + $message = 'Error while processing request'; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // Sending a response |
| 211 | 211 | return new Provider31\Response\ErrorInfo($e->getCode(), $message); |
| 212 | - } |
|
| 212 | + } |
|
| 213 | 213 | } |