@@ -4,60 +4,60 @@ |
||
4 | 4 | |
5 | 5 | class Key |
6 | 6 | { |
7 | - public function __construct() {} |
|
8 | - |
|
9 | - /** |
|
10 | - * Get content of key file |
|
11 | - * @param string $fname |
|
12 | - * @param string $type |
|
13 | - * @return string |
|
14 | - * @throws Exception\Runtime |
|
15 | - */ |
|
16 | - public function get($fname, $type) |
|
17 | - { |
|
7 | + public function __construct() {} |
|
8 | + |
|
9 | + /** |
|
10 | + * Get content of key file |
|
11 | + * @param string $fname |
|
12 | + * @param string $type |
|
13 | + * @return string |
|
14 | + * @throws Exception\Runtime |
|
15 | + */ |
|
16 | + public function get($fname, $type) |
|
17 | + { |
|
18 | 18 | try |
19 | 19 | { |
20 | - $this->check_exists($fname); |
|
20 | + $this->check_exists($fname); |
|
21 | 21 | |
22 | - $key = $this->load($fname); |
|
22 | + $key = $this->load($fname); |
|
23 | 23 | } |
24 | 24 | catch (\Exception $e) |
25 | 25 | { |
26 | - throw new Exception\Runtime('The file with the '.$type.' key was '.$e->getMessage().'!', -98); |
|
26 | + throw new Exception\Runtime('The file with the '.$type.' key was '.$e->getMessage().'!', -98); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | return $key; |
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * Check if exist key file |
|
34 | - * |
|
35 | - * @param string $fname |
|
36 | - * @throws Exception\Runtime |
|
37 | - */ |
|
38 | - protected function check_exists($fname) |
|
39 | - { |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * Check if exist key file |
|
34 | + * |
|
35 | + * @param string $fname |
|
36 | + * @throws Exception\Runtime |
|
37 | + */ |
|
38 | + protected function check_exists($fname) |
|
39 | + { |
|
40 | 40 | if ( ! file_exists($fname)) |
41 | 41 | { |
42 | - throw new Exception\Runtime('not exists'); |
|
42 | + throw new Exception\Runtime('not exists'); |
|
43 | 43 | } |
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Load key file |
|
48 | - * |
|
49 | - * @param string $fname |
|
50 | - * @return string |
|
51 | - * @throws Exception\Runtime |
|
52 | - */ |
|
53 | - protected function load($fname) |
|
54 | - { |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Load key file |
|
48 | + * |
|
49 | + * @param string $fname |
|
50 | + * @return string |
|
51 | + * @throws Exception\Runtime |
|
52 | + */ |
|
53 | + protected function load($fname) |
|
54 | + { |
|
55 | 55 | $key = @file_get_contents($fname); |
56 | 56 | if ($key === FALSE) |
57 | 57 | { |
58 | - throw new Exception\Runtime('not read'); |
|
58 | + throw new Exception\Runtime('not read'); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | return $key; |
62 | - } |
|
62 | + } |
|
63 | 63 | } |
@@ -15,17 +15,17 @@ |
||
15 | 15 | |
16 | 16 | final class ErrorInfo extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * ErrorInfo constructor |
|
20 | - * |
|
21 | - * @param integer $code Error code |
|
22 | - * @param string $message Error message text |
|
23 | - */ |
|
24 | - public function __construct($code, $message) |
|
25 | - { |
|
26 | - parent::__construct(); |
|
18 | + /** |
|
19 | + * ErrorInfo constructor |
|
20 | + * |
|
21 | + * @param integer $code Error code |
|
22 | + * @param string $message Error message text |
|
23 | + */ |
|
24 | + public function __construct($code, $message) |
|
25 | + { |
|
26 | + parent::__construct(); |
|
27 | 27 | |
28 | - $this->setElementValue('StatusCode', $code); |
|
29 | - $this->setElementValue('StatusDetail', $message); |
|
30 | - } |
|
28 | + $this->setElementValue('StatusCode', $code); |
|
29 | + $this->setElementValue('StatusDetail', $message); |
|
30 | + } |
|
31 | 31 | } |
@@ -16,41 +16,41 @@ |
||
16 | 16 | |
17 | 17 | final class Check extends Response |
18 | 18 | { |
19 | - /** |
|
20 | - * @var \DOMElement |
|
21 | - */ |
|
22 | - protected $AccountInfo; |
|
23 | - |
|
24 | - /** |
|
25 | - * Check constructor |
|
26 | - * |
|
27 | - * @param AccountInfo $accountinfo account information set |
|
28 | - */ |
|
29 | - public function __construct(AccountInfo $accountinfo) |
|
30 | - { |
|
31 | - parent::__construct(); |
|
32 | - |
|
33 | - $this->setElementValue('StatusCode', 0); |
|
34 | - $this->setElementValue('StatusDetail', 'checked'); |
|
35 | - |
|
36 | - $this->create_AccountInfo($accountinfo); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Create AccountInfo node with child nodes |
|
41 | - * |
|
42 | - * @param AccountInfo $accountinfo account information set |
|
43 | - */ |
|
44 | - public function create_AccountInfo($accountinfo) |
|
45 | - { |
|
46 | - if (isset($this->AccountInfo)) return; |
|
47 | - |
|
48 | - $this->AccountInfo = $this->createElement('AccountInfo'); |
|
49 | - $this->Response->appendChild($this->AccountInfo); |
|
50 | - |
|
51 | - foreach($accountinfo as $parameter=>$value) |
|
52 | - { |
|
53 | - $this->AccountInfo->appendChild($this->createElement($parameter, $value)); |
|
54 | - } |
|
55 | - } |
|
19 | + /** |
|
20 | + * @var \DOMElement |
|
21 | + */ |
|
22 | + protected $AccountInfo; |
|
23 | + |
|
24 | + /** |
|
25 | + * Check constructor |
|
26 | + * |
|
27 | + * @param AccountInfo $accountinfo account information set |
|
28 | + */ |
|
29 | + public function __construct(AccountInfo $accountinfo) |
|
30 | + { |
|
31 | + parent::__construct(); |
|
32 | + |
|
33 | + $this->setElementValue('StatusCode', 0); |
|
34 | + $this->setElementValue('StatusDetail', 'checked'); |
|
35 | + |
|
36 | + $this->create_AccountInfo($accountinfo); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Create AccountInfo node with child nodes |
|
41 | + * |
|
42 | + * @param AccountInfo $accountinfo account information set |
|
43 | + */ |
|
44 | + public function create_AccountInfo($accountinfo) |
|
45 | + { |
|
46 | + if (isset($this->AccountInfo)) return; |
|
47 | + |
|
48 | + $this->AccountInfo = $this->createElement('AccountInfo'); |
|
49 | + $this->Response->appendChild($this->AccountInfo); |
|
50 | + |
|
51 | + foreach($accountinfo as $parameter=>$value) |
|
52 | + { |
|
53 | + $this->AccountInfo->appendChild($this->createElement($parameter, $value)); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | } |
@@ -15,35 +15,35 @@ |
||
15 | 15 | |
16 | 16 | final class Cancel extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var \DOMElement |
|
20 | - */ |
|
21 | - protected $CancelDate; |
|
22 | - |
|
23 | - /** |
|
24 | - * Cancel constructor |
|
25 | - * |
|
26 | - * @param string $orderdate |
|
27 | - */ |
|
28 | - public function __construct($canceldate) { |
|
29 | - parent::__construct(); |
|
30 | - |
|
31 | - $this->setElementValue('StatusCode', 0); |
|
32 | - $this->setElementValue('StatusDetail', 'checked'); |
|
33 | - |
|
34 | - $this->create_CancelDate($canceldate); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Create CancelDate node |
|
39 | - * |
|
40 | - * @param string $canceldate |
|
41 | - */ |
|
42 | - public function create_CancelDate($canceldate) |
|
43 | - { |
|
44 | - if (isset($this->CancelDate)) return; |
|
45 | - |
|
46 | - $this->CancelDate = $this->createElement('CancelDate', $canceldate); |
|
47 | - $this->Response->appendChild($this->CancelDate); |
|
48 | - } |
|
18 | + /** |
|
19 | + * @var \DOMElement |
|
20 | + */ |
|
21 | + protected $CancelDate; |
|
22 | + |
|
23 | + /** |
|
24 | + * Cancel constructor |
|
25 | + * |
|
26 | + * @param string $orderdate |
|
27 | + */ |
|
28 | + public function __construct($canceldate) { |
|
29 | + parent::__construct(); |
|
30 | + |
|
31 | + $this->setElementValue('StatusCode', 0); |
|
32 | + $this->setElementValue('StatusDetail', 'checked'); |
|
33 | + |
|
34 | + $this->create_CancelDate($canceldate); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Create CancelDate node |
|
39 | + * |
|
40 | + * @param string $canceldate |
|
41 | + */ |
|
42 | + public function create_CancelDate($canceldate) |
|
43 | + { |
|
44 | + if (isset($this->CancelDate)) return; |
|
45 | + |
|
46 | + $this->CancelDate = $this->createElement('CancelDate', $canceldate); |
|
47 | + $this->Response->appendChild($this->CancelDate); |
|
48 | + } |
|
49 | 49 | } |
@@ -15,36 +15,36 @@ |
||
15 | 15 | |
16 | 16 | final class Confirm extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var \DOMElement |
|
20 | - */ |
|
21 | - protected $OrderDate; |
|
22 | - |
|
23 | - /** |
|
24 | - * Confirm constructor |
|
25 | - * |
|
26 | - * @param string $orderdate |
|
27 | - */ |
|
28 | - public function __construct($orderdate) |
|
29 | - { |
|
30 | - parent::__construct(); |
|
31 | - |
|
32 | - $this->setElementValue('StatusCode', 0); |
|
33 | - $this->setElementValue('StatusDetail', 'checked'); |
|
34 | - |
|
35 | - $this->create_OrderDate($orderdate); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Create OrderDate node |
|
40 | - * |
|
41 | - * @param string $orderdate |
|
42 | - */ |
|
43 | - public function create_OrderDate($orderdate) |
|
44 | - { |
|
45 | - if (isset($this->OrderDate)) return; |
|
46 | - |
|
47 | - $this->OrderDate = $this->createElement('OrderDate', $orderdate); |
|
48 | - $this->Response->appendChild($this->OrderDate); |
|
49 | - } |
|
18 | + /** |
|
19 | + * @var \DOMElement |
|
20 | + */ |
|
21 | + protected $OrderDate; |
|
22 | + |
|
23 | + /** |
|
24 | + * Confirm constructor |
|
25 | + * |
|
26 | + * @param string $orderdate |
|
27 | + */ |
|
28 | + public function __construct($orderdate) |
|
29 | + { |
|
30 | + parent::__construct(); |
|
31 | + |
|
32 | + $this->setElementValue('StatusCode', 0); |
|
33 | + $this->setElementValue('StatusDetail', 'checked'); |
|
34 | + |
|
35 | + $this->create_OrderDate($orderdate); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Create OrderDate node |
|
40 | + * |
|
41 | + * @param string $orderdate |
|
42 | + */ |
|
43 | + public function create_OrderDate($orderdate) |
|
44 | + { |
|
45 | + if (isset($this->OrderDate)) return; |
|
46 | + |
|
47 | + $this->OrderDate = $this->createElement('OrderDate', $orderdate); |
|
48 | + $this->Response->appendChild($this->OrderDate); |
|
49 | + } |
|
50 | 50 | } |
@@ -15,36 +15,36 @@ |
||
15 | 15 | |
16 | 16 | final class Payment extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var \DOMElement |
|
20 | - */ |
|
21 | - protected $PaymentId; |
|
22 | - |
|
23 | - /** |
|
24 | - * Payment constructor |
|
25 | - * |
|
26 | - * @param string $paymentid |
|
27 | - */ |
|
28 | - public function __construct($paymentid) |
|
29 | - { |
|
30 | - parent::__construct(); |
|
31 | - |
|
32 | - $this->setElementValue('StatusCode', 0); |
|
33 | - $this->setElementValue('StatusDetail', 'checked'); |
|
34 | - |
|
35 | - $this->create_PaymentId($paymentid); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Create PaymentId node |
|
40 | - * |
|
41 | - * @param string $paymentid |
|
42 | - */ |
|
43 | - public function create_PaymentId($paymentid) |
|
44 | - { |
|
45 | - if (isset($this->PaymentId)) return; |
|
46 | - |
|
47 | - $this->PaymentId = $this->createElement('PaymentId', $paymentid); |
|
48 | - $this->Response->appendChild($this->PaymentId); |
|
49 | - } |
|
18 | + /** |
|
19 | + * @var \DOMElement |
|
20 | + */ |
|
21 | + protected $PaymentId; |
|
22 | + |
|
23 | + /** |
|
24 | + * Payment constructor |
|
25 | + * |
|
26 | + * @param string $paymentid |
|
27 | + */ |
|
28 | + public function __construct($paymentid) |
|
29 | + { |
|
30 | + parent::__construct(); |
|
31 | + |
|
32 | + $this->setElementValue('StatusCode', 0); |
|
33 | + $this->setElementValue('StatusDetail', 'checked'); |
|
34 | + |
|
35 | + $this->create_PaymentId($paymentid); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Create PaymentId node |
|
40 | + * |
|
41 | + * @param string $paymentid |
|
42 | + */ |
|
43 | + public function create_PaymentId($paymentid) |
|
44 | + { |
|
45 | + if (isset($this->PaymentId)) return; |
|
46 | + |
|
47 | + $this->PaymentId = $this->createElement('PaymentId', $paymentid); |
|
48 | + $this->Response->appendChild($this->PaymentId); |
|
49 | + } |
|
50 | 50 | } |
@@ -15,52 +15,52 @@ discard block |
||
15 | 15 | |
16 | 16 | final class Request |
17 | 17 | { |
18 | - /** |
|
19 | - * static method to create a specific class of request |
|
20 | - * |
|
21 | - * @return Request\General Request class of the appropriate type |
|
22 | - * @throws \EasyPay\Exception\Structure |
|
23 | - */ |
|
24 | - public static function get() |
|
25 | - { |
|
18 | + /** |
|
19 | + * static method to create a specific class of request |
|
20 | + * |
|
21 | + * @return Request\General Request class of the appropriate type |
|
22 | + * @throws \EasyPay\Exception\Structure |
|
23 | + */ |
|
24 | + public static function get() |
|
25 | + { |
|
26 | 26 | $raw = self::get_http_raw_post_data(); |
27 | 27 | |
28 | 28 | $r = new Request\General($raw); |
29 | 29 | |
30 | 30 | switch ($r->Operation()) |
31 | 31 | { |
32 | - case 'Check': |
|
32 | + case 'Check': |
|
33 | 33 | return new Request\Check($raw); |
34 | 34 | |
35 | - case 'Payment': |
|
35 | + case 'Payment': |
|
36 | 36 | return new Request\Payment($raw); |
37 | 37 | |
38 | - case 'Confirm': |
|
38 | + case 'Confirm': |
|
39 | 39 | return new Request\Confirm($raw); |
40 | 40 | |
41 | - case 'Cancel'; |
|
41 | + case 'Cancel'; |
|
42 | 42 | return new Request\Cancel($raw); |
43 | 43 | |
44 | - default: |
|
44 | + default: |
|
45 | 45 | throw new \EasyPay\Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
46 | 46 | } |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get data from the body of the http request |
|
51 | - * |
|
52 | - * - with the appropriate configuration of php.ini they can be found |
|
53 | - * in the global variable $HTTP_RAW_POST_DATA |
|
54 | - * |
|
55 | - * - but it's easier just to read the data from the php://input stream, |
|
56 | - * which does not depend on the php.ini directives and allows you to read |
|
57 | - * raw data from the request body |
|
58 | - * |
|
59 | - * @return string Http raw post data |
|
60 | - * |
|
61 | - */ |
|
62 | - private static function get_http_raw_post_data() |
|
63 | - { |
|
49 | + /** |
|
50 | + * Get data from the body of the http request |
|
51 | + * |
|
52 | + * - with the appropriate configuration of php.ini they can be found |
|
53 | + * in the global variable $HTTP_RAW_POST_DATA |
|
54 | + * |
|
55 | + * - but it's easier just to read the data from the php://input stream, |
|
56 | + * which does not depend on the php.ini directives and allows you to read |
|
57 | + * raw data from the request body |
|
58 | + * |
|
59 | + * @return string Http raw post data |
|
60 | + * |
|
61 | + */ |
|
62 | + private static function get_http_raw_post_data() |
|
63 | + { |
|
64 | 64 | Log::instance()->add('request from ' . $_SERVER['REMOTE_ADDR']); |
65 | 65 | |
66 | 66 | $raw_request = file_get_contents('php://input'); |
@@ -70,5 +70,5 @@ discard block |
||
70 | 70 | Log::instance()->debug(' '); |
71 | 71 | |
72 | 72 | return $raw_request; |
73 | - } |
|
73 | + } |
|
74 | 74 | } |
@@ -13,206 +13,206 @@ |
||
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 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Process request and generate response |
|
103 | - * |
|
104 | - * @throws Exception\Structure |
|
105 | - */ |
|
106 | - private function get_response() |
|
107 | - { |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Process request and generate response |
|
103 | + * |
|
104 | + * @throws Exception\Structure |
|
105 | + */ |
|
106 | + private function get_response() |
|
107 | + { |
|
108 | 108 | switch ($this->request->Operation()) |
109 | 109 | { |
110 | - case 'Check': |
|
110 | + case 'Check': |
|
111 | 111 | |
112 | 112 | return $this->response_check(); |
113 | 113 | |
114 | - case 'Payment': |
|
114 | + case 'Payment': |
|
115 | 115 | |
116 | 116 | return $this->response_payment(); |
117 | 117 | |
118 | - case 'Confirm': |
|
118 | + case 'Confirm': |
|
119 | 119 | |
120 | 120 | return $this->response_confirm(); |
121 | 121 | |
122 | - case 'Cancel'; |
|
122 | + case 'Cancel'; |
|
123 | 123 | |
124 | 124 | return $this->response_cancel(); |
125 | 125 | |
126 | - default: |
|
126 | + default: |
|
127 | 127 | break; |
128 | 128 | } |
129 | 129 | |
130 | 130 | throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * run check callback and generate a response |
|
135 | - * |
|
136 | - * @return Provider31\Response\Check |
|
137 | - */ |
|
138 | - private function response_check() |
|
139 | - { |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * run check callback and generate a response |
|
135 | + * |
|
136 | + * @return Provider31\Response\Check |
|
137 | + */ |
|
138 | + private function response_check() |
|
139 | + { |
|
140 | 140 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
141 | 141 | |
142 | 142 | $accountinfo = self::$cb->check( |
143 | - $this->request->Account() |
|
143 | + $this->request->Account() |
|
144 | 144 | ); |
145 | 145 | |
146 | 146 | // Sending a response |
147 | 147 | return new Provider31\Response\Check($accountinfo); |
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * run payment callback and generate a response |
|
152 | - * |
|
153 | - * @return Provider31\Response\Payment |
|
154 | - */ |
|
155 | - private function response_payment() |
|
156 | - { |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * run payment callback and generate a response |
|
152 | + * |
|
153 | + * @return Provider31\Response\Payment |
|
154 | + */ |
|
155 | + private function response_payment() |
|
156 | + { |
|
157 | 157 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
158 | 158 | |
159 | 159 | $paymentid = self::$cb->payment( |
160 | - $this->request->Account(), |
|
161 | - $this->request->OrderId(), |
|
162 | - $this->request->Amount() |
|
160 | + $this->request->Account(), |
|
161 | + $this->request->OrderId(), |
|
162 | + $this->request->Amount() |
|
163 | 163 | ); |
164 | 164 | |
165 | 165 | // Sending a response |
166 | 166 | return new Provider31\Response\Payment($paymentid); |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * run confirm callback and generate a response |
|
171 | - * |
|
172 | - * @return Provider31\Response\Confirm |
|
173 | - */ |
|
174 | - private function response_confirm() |
|
175 | - { |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * run confirm callback and generate a response |
|
171 | + * |
|
172 | + * @return Provider31\Response\Confirm |
|
173 | + */ |
|
174 | + private function response_confirm() |
|
175 | + { |
|
176 | 176 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
177 | 177 | |
178 | 178 | $orderdate = self::$cb->confirm( |
179 | - $this->request->PaymentId() |
|
179 | + $this->request->PaymentId() |
|
180 | 180 | ); |
181 | 181 | |
182 | 182 | // Sending a response |
183 | 183 | return new Provider31\Response\Confirm($orderdate); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * run cancel callback and generate a response |
|
188 | - * |
|
189 | - * @return Provider31\Response\Cancel |
|
190 | - */ |
|
191 | - private function response_cancel() |
|
192 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * run cancel callback and generate a response |
|
188 | + * |
|
189 | + * @return Provider31\Response\Cancel |
|
190 | + */ |
|
191 | + private function response_cancel() |
|
192 | + { |
|
193 | 193 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
194 | 194 | |
195 | 195 | $canceldate = self::$cb->cancel( |
196 | - $this->request->PaymentId() |
|
196 | + $this->request->PaymentId() |
|
197 | 197 | ); |
198 | 198 | |
199 | 199 | // Sending a response |
200 | 200 | return new Provider31\Response\Cancel($canceldate); |
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Generates an xml with an error message |
|
205 | - * |
|
206 | - * @param integer $code |
|
207 | - * @param string $message |
|
208 | - * |
|
209 | - * @return Provider31\Response\ErrorInfo |
|
210 | - */ |
|
211 | - private function get_error_response($code, $message) |
|
212 | - { |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Generates an xml with an error message |
|
205 | + * |
|
206 | + * @param integer $code |
|
207 | + * @param string $message |
|
208 | + * |
|
209 | + * @return Provider31\Response\ErrorInfo |
|
210 | + */ |
|
211 | + private function get_error_response($code, $message) |
|
212 | + { |
|
213 | 213 | Log::instance()->add('the request was processed with an error'); |
214 | 214 | |
215 | 215 | // Sending a response |
216 | 216 | return new Provider31\Response\ErrorInfo($code, $message); |
217 | - } |
|
217 | + } |
|
218 | 218 | } |
@@ -18,108 +18,108 @@ discard block |
||
18 | 18 | |
19 | 19 | class General |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string 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 string $raw Raw request data |
|
55 | - */ |
|
56 | - public function __construct($raw) |
|
57 | - { |
|
21 | + /** |
|
22 | + * @var string 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 string $raw Raw request data |
|
55 | + */ |
|
56 | + public function __construct($raw) |
|
57 | + { |
|
58 | 58 | $this->raw_request = strval($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 | if (empty($this->raw_request)) |
111 | 111 | { |
112 | - throw new Exception\Structure('An empty xml request', -50); |
|
112 | + throw new Exception\Structure('An empty xml request', -50); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | libxml_use_internal_errors(true); |
116 | 116 | $doc = new \DOMDocument(); |
117 | 117 | if ( ! $doc->loadXML($this->raw_request)) |
118 | 118 | { |
119 | - foreach(libxml_get_errors() as $e){ |
|
119 | + foreach(libxml_get_errors() as $e){ |
|
120 | 120 | Log::instance()->error($e->message); |
121 | - } |
|
122 | - throw new Exception\Structure('The wrong XML is received', -51); |
|
121 | + } |
|
122 | + throw new Exception\Structure('The wrong XML is received', -51); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | // process <Request> group |
@@ -127,35 +127,35 @@ discard block |
||
127 | 127 | |
128 | 128 | if (count($r) < 1) |
129 | 129 | { |
130 | - throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
130 | + throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | foreach ($r[0]->childNodes as $child) |
134 | 134 | { |
135 | - if ($child->nodeName == 'DateTime') |
|
136 | - { |
|
135 | + if ($child->nodeName == 'DateTime') |
|
136 | + { |
|
137 | 137 | $this->parse_request_node($child, 'DateTime'); |
138 | - } |
|
139 | - elseif ($child->nodeName == 'Sign') |
|
140 | - { |
|
138 | + } |
|
139 | + elseif ($child->nodeName == 'Sign') |
|
140 | + { |
|
141 | 141 | $this->parse_request_node($child, 'Sign'); |
142 | - } |
|
143 | - elseif (in_array($child->nodeName, $this->operations)) |
|
144 | - { |
|
142 | + } |
|
143 | + elseif (in_array($child->nodeName, $this->operations)) |
|
144 | + { |
|
145 | 145 | if ( ! isset($this->Operation)) |
146 | 146 | { |
147 | - $this->Operation = $child->nodeName; |
|
147 | + $this->Operation = $child->nodeName; |
|
148 | 148 | } |
149 | 149 | else |
150 | 150 | { |
151 | - throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
151 | + throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
152 | + } |
|
152 | 153 | } |
153 | - } |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | if ( ! isset($this->Operation)) |
157 | 157 | { |
158 | - throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
158 | + throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | // process <Operation> group |
@@ -163,42 +163,42 @@ discard block |
||
163 | 163 | |
164 | 164 | foreach ($r[0]->childNodes as $child) |
165 | 165 | { |
166 | - if ($child->nodeName == 'ServiceId') |
|
167 | - { |
|
166 | + if ($child->nodeName == 'ServiceId') |
|
167 | + { |
|
168 | 168 | $this->parse_request_node($child, 'ServiceId'); |
169 | - } |
|
169 | + } |
|
170 | + } |
|
170 | 171 | } |
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Parse node of request |
|
175 | - * |
|
176 | - * @param \DOMNode $n |
|
177 | - * @param string $name |
|
178 | - * |
|
179 | - * @throws Exception\Structure |
|
180 | - */ |
|
181 | - protected function parse_request_node($n, $name) |
|
182 | - { |
|
172 | + |
|
173 | + /** |
|
174 | + * Parse node of request |
|
175 | + * |
|
176 | + * @param \DOMNode $n |
|
177 | + * @param string $name |
|
178 | + * |
|
179 | + * @throws Exception\Structure |
|
180 | + */ |
|
181 | + protected function parse_request_node($n, $name) |
|
182 | + { |
|
183 | 183 | if ( ! isset($this->$name)) |
184 | 184 | { |
185 | - $this->$name = $n->nodeValue; |
|
185 | + $this->$name = $n->nodeValue; |
|
186 | 186 | } |
187 | 187 | else |
188 | 188 | { |
189 | - throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
189 | + throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
190 | 190 | } |
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * "Rough" validation of the received xml request |
|
195 | - * |
|
196 | - * @param array $options |
|
197 | - * @throws Exception\Data |
|
198 | - * @throws Exception\Structure |
|
199 | - */ |
|
200 | - public function validate_request($options) |
|
201 | - { |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * "Rough" validation of the received xml request |
|
195 | + * |
|
196 | + * @param array $options |
|
197 | + * @throws Exception\Data |
|
198 | + * @throws Exception\Structure |
|
199 | + */ |
|
200 | + public function validate_request($options) |
|
201 | + { |
|
202 | 202 | $this->validate_element('DateTime'); |
203 | 203 | $this->validate_element('Sign'); |
204 | 204 | $this->validate_element('ServiceId'); |
@@ -206,104 +206,104 @@ discard block |
||
206 | 206 | // compare received value ServiceId with option ServiceId |
207 | 207 | if (intval($options['ServiceId']) != intval($this->ServiceId)) |
208 | 208 | { |
209 | - throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
209 | + throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
210 | + } |
|
210 | 211 | } |
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Validation of xml-element |
|
215 | - * |
|
216 | - * @param string $name |
|
217 | - */ |
|
218 | - public function validate_element($name) |
|
219 | - { |
|
212 | + |
|
213 | + /** |
|
214 | + * Validation of xml-element |
|
215 | + * |
|
216 | + * @param string $name |
|
217 | + */ |
|
218 | + public function validate_element($name) |
|
219 | + { |
|
220 | 220 | if ( ! isset($this->$name)) |
221 | 221 | { |
222 | - throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
222 | + throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
223 | + } |
|
223 | 224 | } |
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Verify signature of request |
|
228 | - * |
|
229 | - * @param array $options |
|
230 | - */ |
|
231 | - public function verify_sign($options) |
|
232 | - { |
|
225 | + |
|
226 | + /** |
|
227 | + * Verify signature of request |
|
228 | + * |
|
229 | + * @param array $options |
|
230 | + */ |
|
231 | + public function verify_sign($options) |
|
232 | + { |
|
233 | 233 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
234 | 234 | { |
235 | - $this->check_verify_sign_result( |
|
235 | + $this->check_verify_sign_result( |
|
236 | 236 | $result = (new OpenSSL())->verify( |
237 | - str_replace($this->Sign, '', $this->raw_request), |
|
238 | - pack("H*", $this->Sign), |
|
239 | - (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
237 | + str_replace($this->Sign, '', $this->raw_request), |
|
238 | + pack("H*", $this->Sign), |
|
239 | + (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
240 | 240 | ) |
241 | - ); |
|
241 | + ); |
|
242 | + } |
|
242 | 243 | } |
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * load file with easysoft public key |
|
247 | - * |
|
248 | - * @param array $options |
|
249 | - * @throws Exception\Runtime |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - protected function get_pub_key($options) |
|
253 | - { |
|
244 | + |
|
245 | + /** |
|
246 | + * load file with easysoft public key |
|
247 | + * |
|
248 | + * @param array $options |
|
249 | + * @throws Exception\Runtime |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + protected function get_pub_key($options) |
|
253 | + { |
|
254 | 254 | if ( ! isset($options['EasySoftPKey'])) |
255 | 255 | { |
256 | - throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
256 | + throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | return (new Key())->get($options['EasySoftPKey'], 'public'); |
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * check result of openssl verify signature |
|
264 | - * |
|
265 | - * @param integer $result |
|
266 | - * @throws Exception\Sign |
|
267 | - */ |
|
268 | - protected function check_verify_sign_result($result) |
|
269 | - { |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * check result of openssl verify signature |
|
264 | + * |
|
265 | + * @param integer $result |
|
266 | + * @throws Exception\Sign |
|
267 | + */ |
|
268 | + protected function check_verify_sign_result($result) |
|
269 | + { |
|
270 | 270 | if ($result == -1) |
271 | 271 | { |
272 | - throw new Exception\Sign('Error verify signature of request!', -96); |
|
272 | + throw new Exception\Sign('Error verify signature of request!', -96); |
|
273 | 273 | } |
274 | 274 | elseif ($result == 0) |
275 | 275 | { |
276 | - throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
276 | + throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
277 | 277 | } |
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Selects nodes by name |
|
282 | - * |
|
283 | - * @param \DOMDocument $dom |
|
284 | - * @param string $name |
|
285 | - * @param array $ret |
|
286 | - * |
|
287 | - * @return array nodes with the name |
|
288 | - */ |
|
289 | - protected function getNodes($dom, $name, $ret=array()) |
|
290 | - { |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Selects nodes by name |
|
282 | + * |
|
283 | + * @param \DOMDocument $dom |
|
284 | + * @param string $name |
|
285 | + * @param array $ret |
|
286 | + * |
|
287 | + * @return array nodes with the name |
|
288 | + */ |
|
289 | + protected function getNodes($dom, $name, $ret=array()) |
|
290 | + { |
|
291 | 291 | foreach($dom->childNodes as $child) |
292 | 292 | { |
293 | - if ($child->nodeName == $name) |
|
294 | - { |
|
293 | + if ($child->nodeName == $name) |
|
294 | + { |
|
295 | 295 | array_push($ret, $child); |
296 | - } |
|
297 | - else |
|
298 | - { |
|
296 | + } |
|
297 | + else |
|
298 | + { |
|
299 | 299 | if (count($child->childNodes) > 0) |
300 | 300 | { |
301 | - $ret = $this->getNodes($child, $name, $ret); |
|
301 | + $ret = $this->getNodes($child, $name, $ret); |
|
302 | + } |
|
302 | 303 | } |
303 | - } |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | return $ret; |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | 309 | } |