@@ -13,199 +13,199 @@ |
||
| 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 | - // 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 | - */ |
|
| 105 | - protected function get_request() |
|
| 106 | - { |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * method to create a specific class of request |
|
| 103 | + * |
|
| 104 | + */ |
|
| 105 | + protected function get_request() |
|
| 106 | + { |
|
| 107 | 107 | $raw = new Provider31\Request\RAW(); |
| 108 | 108 | |
| 109 | 109 | $r = new Provider31\Request\General($raw); |
| 110 | 110 | $c = '\\EasyPay\\Provider31\\Request\\'.$r->Operation(); |
| 111 | 111 | |
| 112 | 112 | $this->request = new $c($raw); |
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * generate response |
|
| 117 | - * |
|
| 118 | - * @return mixed |
|
| 119 | - */ |
|
| 120 | - protected function get_response() |
|
| 121 | - { |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * generate response |
|
| 117 | + * |
|
| 118 | + * @return mixed |
|
| 119 | + */ |
|
| 120 | + protected function get_response() |
|
| 121 | + { |
|
| 122 | 122 | $m = 'response_'.$this->request->Operation(); |
| 123 | 123 | return $this->$m(); |
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * run check callback and generate a response |
|
| 128 | - * |
|
| 129 | - * @return Provider31\Response\Check |
|
| 130 | - */ |
|
| 131 | - private function response_Check() |
|
| 132 | - { |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * run check callback and generate a response |
|
| 128 | + * |
|
| 129 | + * @return Provider31\Response\Check |
|
| 130 | + */ |
|
| 131 | + private function response_Check() |
|
| 132 | + { |
|
| 133 | 133 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
| 134 | 134 | |
| 135 | 135 | $accountinfo = self::$cb->check( |
| 136 | - $this->request->Account() |
|
| 136 | + $this->request->Account() |
|
| 137 | 137 | ); |
| 138 | 138 | |
| 139 | 139 | // Sending a response |
| 140 | 140 | return new Provider31\Response\Check($accountinfo); |
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * run payment callback and generate a response |
|
| 145 | - * |
|
| 146 | - * @return Provider31\Response\Payment |
|
| 147 | - */ |
|
| 148 | - private function response_Payment() |
|
| 149 | - { |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * run payment callback and generate a response |
|
| 145 | + * |
|
| 146 | + * @return Provider31\Response\Payment |
|
| 147 | + */ |
|
| 148 | + private function response_Payment() |
|
| 149 | + { |
|
| 150 | 150 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
| 151 | 151 | |
| 152 | 152 | $paymentid = self::$cb->payment( |
| 153 | - $this->request->Account(), |
|
| 154 | - $this->request->OrderId(), |
|
| 155 | - $this->request->Amount() |
|
| 153 | + $this->request->Account(), |
|
| 154 | + $this->request->OrderId(), |
|
| 155 | + $this->request->Amount() |
|
| 156 | 156 | ); |
| 157 | 157 | |
| 158 | 158 | // Sending a response |
| 159 | 159 | return new Provider31\Response\Payment($paymentid); |
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * run confirm callback and generate a response |
|
| 164 | - * |
|
| 165 | - * @return Provider31\Response\Confirm |
|
| 166 | - */ |
|
| 167 | - private function response_Confirm() |
|
| 168 | - { |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * run confirm callback and generate a response |
|
| 164 | + * |
|
| 165 | + * @return Provider31\Response\Confirm |
|
| 166 | + */ |
|
| 167 | + private function response_Confirm() |
|
| 168 | + { |
|
| 169 | 169 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
| 170 | 170 | |
| 171 | 171 | $orderdate = self::$cb->confirm( |
| 172 | - $this->request->PaymentId() |
|
| 172 | + $this->request->PaymentId() |
|
| 173 | 173 | ); |
| 174 | 174 | |
| 175 | 175 | // Sending a response |
| 176 | 176 | return new Provider31\Response\Confirm($orderdate); |
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * run cancel callback and generate a response |
|
| 181 | - * |
|
| 182 | - * @return Provider31\Response\Cancel |
|
| 183 | - */ |
|
| 184 | - private function response_Cancel() |
|
| 185 | - { |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * run cancel callback and generate a response |
|
| 181 | + * |
|
| 182 | + * @return Provider31\Response\Cancel |
|
| 183 | + */ |
|
| 184 | + private function response_Cancel() |
|
| 185 | + { |
|
| 186 | 186 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
| 187 | 187 | |
| 188 | 188 | $canceldate = self::$cb->cancel( |
| 189 | - $this->request->PaymentId() |
|
| 189 | + $this->request->PaymentId() |
|
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | 192 | // Sending a response |
| 193 | 193 | return new Provider31\Response\Cancel($canceldate); |
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Generates an xml with an error message |
|
| 198 | - * |
|
| 199 | - * @param integer $code |
|
| 200 | - * @param string $message |
|
| 201 | - * |
|
| 202 | - * @return Provider31\Response\ErrorInfo |
|
| 203 | - */ |
|
| 204 | - private function get_error_response($code, $message) |
|
| 205 | - { |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Generates an xml with an error message |
|
| 198 | + * |
|
| 199 | + * @param integer $code |
|
| 200 | + * @param string $message |
|
| 201 | + * |
|
| 202 | + * @return Provider31\Response\ErrorInfo |
|
| 203 | + */ |
|
| 204 | + private function get_error_response($code, $message) |
|
| 205 | + { |
|
| 206 | 206 | Log::instance()->add('the request was processed with an error'); |
| 207 | 207 | |
| 208 | 208 | // Sending a response |
| 209 | 209 | return new Provider31\Response\ErrorInfo($code, $message); |
| 210 | - } |
|
| 210 | + } |
|
| 211 | 211 | } |