@@ -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 | } |
@@ -4,76 +4,76 @@ |
||
4 | 4 | |
5 | 5 | class OpenSSL |
6 | 6 | { |
7 | - public function __construct() {} |
|
7 | + public function __construct() {} |
|
8 | 8 | |
9 | - /** |
|
10 | - * verify signature of xml |
|
11 | - * |
|
12 | - * @param string $xml |
|
13 | - * @param string $bin_sign |
|
14 | - * @param resource $pub_key |
|
15 | - * |
|
16 | - * @return integer result of checking |
|
17 | - */ |
|
18 | - public function verify($xml, $bin_sign, $pub_key) |
|
19 | - { |
|
9 | + /** |
|
10 | + * verify signature of xml |
|
11 | + * |
|
12 | + * @param string $xml |
|
13 | + * @param string $bin_sign |
|
14 | + * @param resource $pub_key |
|
15 | + * |
|
16 | + * @return integer result of checking |
|
17 | + */ |
|
18 | + public function verify($xml, $bin_sign, $pub_key) |
|
19 | + { |
|
20 | 20 | return @openssl_verify($xml, $bin_sign, $pub_key); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * generate signature of xml |
|
25 | - * |
|
26 | - * @param string $xml |
|
27 | - * @param string $sign |
|
28 | - * @param resource $priv_key |
|
29 | - * |
|
30 | - * @return bool result of signing |
|
31 | - */ |
|
32 | - public function sign($xml, &$sign, $priv_key) |
|
33 | - { |
|
23 | + /** |
|
24 | + * generate signature of xml |
|
25 | + * |
|
26 | + * @param string $xml |
|
27 | + * @param string $sign |
|
28 | + * @param resource $priv_key |
|
29 | + * |
|
30 | + * @return bool result of signing |
|
31 | + */ |
|
32 | + public function sign($xml, &$sign, $priv_key) |
|
33 | + { |
|
34 | 34 | return @openssl_sign($xml, $sign, $priv_key); |
35 | - } |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * get public key |
|
39 | - * |
|
40 | - * @param mixed $certificate |
|
41 | - * @return resource |
|
42 | - */ |
|
43 | - public function get_pub_key($certificate) |
|
44 | - { |
|
37 | + /** |
|
38 | + * get public key |
|
39 | + * |
|
40 | + * @param mixed $certificate |
|
41 | + * @return resource |
|
42 | + */ |
|
43 | + public function get_pub_key($certificate) |
|
44 | + { |
|
45 | 45 | $pub_key = @openssl_pkey_get_public($certificate); |
46 | 46 | $this->is_key($pub_key); |
47 | 47 | |
48 | 48 | return $pub_key; |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * get private key |
|
53 | - * |
|
54 | - * @param mixed $certificate |
|
55 | - * @return resource |
|
56 | - */ |
|
57 | - public function get_priv_key($certificate) |
|
58 | - { |
|
51 | + /** |
|
52 | + * get private key |
|
53 | + * |
|
54 | + * @param mixed $certificate |
|
55 | + * @return resource |
|
56 | + */ |
|
57 | + public function get_priv_key($certificate) |
|
58 | + { |
|
59 | 59 | $priv_key = @openssl_pkey_get_private($certificate); |
60 | 60 | $this->is_key($priv_key); |
61 | 61 | |
62 | 62 | return $priv_key; |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * check key |
|
67 | - * |
|
68 | - * @param resource $key |
|
69 | - * @throws Exception\Runtime |
|
70 | - */ |
|
71 | - public function is_key($key) |
|
72 | - { |
|
65 | + /** |
|
66 | + * check key |
|
67 | + * |
|
68 | + * @param resource $key |
|
69 | + * @throws Exception\Runtime |
|
70 | + */ |
|
71 | + public function is_key($key) |
|
72 | + { |
|
73 | 73 | if ($key === FALSE) |
74 | 74 | { |
75 | - throw new Exception\Runtime('Can not extract key from certificate!', -97); |
|
75 | + throw new Exception\Runtime('Can not extract key from certificate!', -97); |
|
76 | + } |
|
76 | 77 | } |
77 | - } |
|
78 | 78 | |
79 | 79 | } |
@@ -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->sign_and_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 | $response = $this->response_check(); |
113 | 113 | break; |
114 | 114 | |
115 | - case 'Payment': |
|
115 | + case 'Payment': |
|
116 | 116 | $response = $this->response_payment(); |
117 | 117 | break; |
118 | 118 | |
119 | - case 'Confirm': |
|
119 | + case 'Confirm': |
|
120 | 120 | $response = $this->response_confirm(); |
121 | 121 | break; |
122 | 122 | |
123 | - case 'Cancel'; |
|
123 | + case 'Cancel'; |
|
124 | 124 | $response = $this->response_cancel(); |
125 | 125 | break; |
126 | 126 | |
127 | - default: |
|
127 | + default: |
|
128 | 128 | throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
129 | 129 | } |
130 | 130 | |
131 | 131 | return $response; |
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 | } |
@@ -16,42 +16,42 @@ discard block |
||
16 | 16 | |
17 | 17 | class RAW |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string raw request |
|
21 | - */ |
|
22 | - protected $raw_request; |
|
19 | + /** |
|
20 | + * @var string raw request |
|
21 | + */ |
|
22 | + protected $raw_request; |
|
23 | 23 | |
24 | - /** |
|
25 | - * RAW constructor |
|
26 | - */ |
|
27 | - public function __construct() |
|
28 | - { |
|
24 | + /** |
|
25 | + * RAW constructor |
|
26 | + */ |
|
27 | + public function __construct() |
|
28 | + { |
|
29 | 29 | $this->get_http_raw_post_data(); |
30 | 30 | $this->check_presence_request(); |
31 | - } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Get request string content |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - public function str() |
|
39 | - { |
|
33 | + /** |
|
34 | + * Get request string content |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + public function str() |
|
39 | + { |
|
40 | 40 | return strval($this->raw_request); |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get data from the body of the http request |
|
45 | - * |
|
46 | - * - with the appropriate configuration of php.ini they can be found |
|
47 | - * in the global variable $HTTP_RAW_POST_DATA |
|
48 | - * |
|
49 | - * - but it's easier just to read the data from the php://input stream, |
|
50 | - * which does not depend on the php.ini directives and allows you to read |
|
51 | - * raw data from the request body |
|
52 | - */ |
|
53 | - protected function get_http_raw_post_data() |
|
54 | - { |
|
43 | + /** |
|
44 | + * Get data from the body of the http request |
|
45 | + * |
|
46 | + * - with the appropriate configuration of php.ini they can be found |
|
47 | + * in the global variable $HTTP_RAW_POST_DATA |
|
48 | + * |
|
49 | + * - but it's easier just to read the data from the php://input stream, |
|
50 | + * which does not depend on the php.ini directives and allows you to read |
|
51 | + * raw data from the request body |
|
52 | + */ |
|
53 | + protected function get_http_raw_post_data() |
|
54 | + { |
|
55 | 55 | Log::instance()->add('request from ' . $_SERVER['REMOTE_ADDR']); |
56 | 56 | |
57 | 57 | $this->raw_request = file_get_contents('php://input'); |
@@ -59,68 +59,68 @@ discard block |
||
59 | 59 | Log::instance()->debug('request received: '); |
60 | 60 | Log::instance()->debug($this->raw_request); |
61 | 61 | Log::instance()->debug(' '); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Check if presence request |
|
66 | - * |
|
67 | - * @throws Exception\Structure |
|
68 | - */ |
|
69 | - protected function check_presence_request() |
|
70 | - { |
|
64 | + /** |
|
65 | + * Check if presence request |
|
66 | + * |
|
67 | + * @throws Exception\Structure |
|
68 | + */ |
|
69 | + protected function check_presence_request() |
|
70 | + { |
|
71 | 71 | if (empty($this->raw_request)) |
72 | 72 | { |
73 | - throw new Exception\Structure('An empty xml request', -50); |
|
73 | + throw new Exception\Structure('An empty xml request', -50); |
|
74 | + } |
|
74 | 75 | } |
75 | - } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Get group of nodes from XML-request |
|
79 | - * |
|
80 | - * @param string $name |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - public function get_nodes_from_request($name) |
|
84 | - { |
|
77 | + /** |
|
78 | + * Get group of nodes from XML-request |
|
79 | + * |
|
80 | + * @param string $name |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + public function get_nodes_from_request($name) |
|
84 | + { |
|
85 | 85 | libxml_use_internal_errors(true); |
86 | 86 | $doc = new \DOMDocument(); |
87 | 87 | if ( ! $doc->loadXML($this->raw_request)) |
88 | 88 | { |
89 | - foreach(libxml_get_errors() as $e){ |
|
89 | + foreach(libxml_get_errors() as $e){ |
|
90 | 90 | Log::instance()->error($e->message); |
91 | - } |
|
92 | - throw new Exception\Structure('The wrong XML is received', -51); |
|
91 | + } |
|
92 | + throw new Exception\Structure('The wrong XML is received', -51); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | return $this->getNodes($doc, $name); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Selects nodes by name |
|
100 | - * |
|
101 | - * @param \DOMDocument $dom |
|
102 | - * @param string $name |
|
103 | - * @param array $ret |
|
104 | - * |
|
105 | - * @return array nodes with the name |
|
106 | - */ |
|
107 | - protected function getNodes($dom, $name, $ret=array()) |
|
108 | - { |
|
98 | + /** |
|
99 | + * Selects nodes by name |
|
100 | + * |
|
101 | + * @param \DOMDocument $dom |
|
102 | + * @param string $name |
|
103 | + * @param array $ret |
|
104 | + * |
|
105 | + * @return array nodes with the name |
|
106 | + */ |
|
107 | + protected function getNodes($dom, $name, $ret=array()) |
|
108 | + { |
|
109 | 109 | foreach($dom->childNodes as $child) |
110 | 110 | { |
111 | - if ($child->nodeName == $name) |
|
112 | - { |
|
111 | + if ($child->nodeName == $name) |
|
112 | + { |
|
113 | 113 | array_push($ret, $child); |
114 | - } |
|
115 | - else |
|
116 | - { |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
117 | 117 | if (count($child->childNodes) > 0) |
118 | 118 | { |
119 | - $ret = $this->getNodes($child, $name, $ret); |
|
119 | + $ret = $this->getNodes($child, $name, $ret); |
|
120 | + } |
|
120 | 121 | } |
121 | - } |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | return $ret; |
125 | - } |
|
125 | + } |
|
126 | 126 | } |