@@ -15,36 +15,36 @@ |
||
15 | 15 | |
16 | 16 | final class Payment extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
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 = self::createElement('PaymentId', $paymentid); |
|
48 | - $this->Response->appendChild($this->PaymentId); |
|
49 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
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 = self::createElement('PaymentId', $paymentid); |
|
48 | + $this->Response->appendChild($this->PaymentId); |
|
49 | + } |
|
50 | 50 | } |
@@ -42,7 +42,9 @@ |
||
42 | 42 | */ |
43 | 43 | public function create_PaymentId($paymentid) |
44 | 44 | { |
45 | - if (isset($this->PaymentId)) return; |
|
45 | + if (isset($this->PaymentId)) { |
|
46 | + return; |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $this->PaymentId = self::createElement('PaymentId', $paymentid); |
48 | 50 | $this->Response->appendChild($this->PaymentId); |
@@ -15,35 +15,35 @@ |
||
15 | 15 | |
16 | 16 | final class Cancel extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
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 = self::createElement('CancelDate', $canceldate); |
|
47 | - $this->Response->appendChild($this->CancelDate); |
|
48 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
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 = self::createElement('CancelDate', $canceldate); |
|
47 | + $this->Response->appendChild($this->CancelDate); |
|
48 | + } |
|
49 | 49 | } |
@@ -41,7 +41,9 @@ |
||
41 | 41 | */ |
42 | 42 | public function create_CancelDate($canceldate) |
43 | 43 | { |
44 | - if (isset($this->CancelDate)) return; |
|
44 | + if (isset($this->CancelDate)) { |
|
45 | + return; |
|
46 | + } |
|
45 | 47 | |
46 | 48 | $this->CancelDate = self::createElement('CancelDate', $canceldate); |
47 | 49 | $this->Response->appendChild($this->CancelDate); |
@@ -15,36 +15,36 @@ |
||
15 | 15 | |
16 | 16 | final class Confirm extends Response |
17 | 17 | { |
18 | - /** |
|
19 | - * @var string |
|
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 = self::createElement('OrderDate', $orderdate); |
|
48 | - $this->Response->appendChild($this->OrderDate); |
|
49 | - } |
|
18 | + /** |
|
19 | + * @var string |
|
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 = self::createElement('OrderDate', $orderdate); |
|
48 | + $this->Response->appendChild($this->OrderDate); |
|
49 | + } |
|
50 | 50 | } |
@@ -42,7 +42,9 @@ |
||
42 | 42 | */ |
43 | 43 | public function create_OrderDate($orderdate) |
44 | 44 | { |
45 | - if (isset($this->OrderDate)) return; |
|
45 | + if (isset($this->OrderDate)) { |
|
46 | + return; |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $this->OrderDate = self::createElement('OrderDate', $orderdate); |
48 | 50 | $this->Response->appendChild($this->OrderDate); |
@@ -16,41 +16,41 @@ |
||
16 | 16 | |
17 | 17 | final class Check extends Response |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string |
|
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 = self::createElement('AccountInfo'); |
|
49 | - $this->Response->appendChild($this->AccountInfo); |
|
50 | - |
|
51 | - foreach($accountinfo as $parameter=>$value) |
|
52 | - { |
|
53 | - $this->AccountInfo->appendChild(self::createElement($parameter, $value)); |
|
54 | - } |
|
55 | - } |
|
19 | + /** |
|
20 | + * @var string |
|
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 = self::createElement('AccountInfo'); |
|
49 | + $this->Response->appendChild($this->AccountInfo); |
|
50 | + |
|
51 | + foreach($accountinfo as $parameter=>$value) |
|
52 | + { |
|
53 | + $this->AccountInfo->appendChild(self::createElement($parameter, $value)); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | } |
@@ -43,7 +43,9 @@ |
||
43 | 43 | */ |
44 | 44 | public function create_AccountInfo($accountinfo) |
45 | 45 | { |
46 | - if (isset($this->AccountInfo)) return; |
|
46 | + if (isset($this->AccountInfo)) { |
|
47 | + return; |
|
48 | + } |
|
47 | 49 | |
48 | 50 | $this->AccountInfo = self::createElement('AccountInfo'); |
49 | 51 | $this->Response->appendChild($this->AccountInfo); |
@@ -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 | } |
@@ -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 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 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 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 | } |
@@ -61,7 +61,7 @@ |
||
61 | 61 | */ |
62 | 62 | private static function get_http_raw_post_data() |
63 | 63 | { |
64 | - Log::instance()->add('request from ' . $_SERVER['REMOTE_ADDR']); |
|
64 | + Log::instance()->add('request from '.$_SERVER['REMOTE_ADDR']); |
|
65 | 65 | |
66 | 66 | $raw_request = file_get_contents('php://input'); |
67 | 67 |
@@ -16,96 +16,96 @@ discard block |
||
16 | 16 | |
17 | 17 | abstract class Response extends \DomDocument |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string |
|
21 | - * |
|
22 | - */ |
|
23 | - const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string |
|
27 | - */ |
|
28 | - protected $Response; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $Sign; |
|
34 | - |
|
35 | - /** |
|
36 | - * Response constructor |
|
37 | - * |
|
38 | - */ |
|
39 | - public function __construct() |
|
40 | - { |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + * |
|
22 | + */ |
|
23 | + const TEMPLATE = '<Response><StatusCode></StatusCode><StatusDetail></StatusDetail><DateTime></DateTime></Response>'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string |
|
27 | + */ |
|
28 | + protected $Response; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $Sign; |
|
34 | + |
|
35 | + /** |
|
36 | + * Response constructor |
|
37 | + * |
|
38 | + */ |
|
39 | + public function __construct() |
|
40 | + { |
|
41 | 41 | parent::__construct('1.0', 'UTF-8'); |
42 | 42 | |
43 | 43 | self::loadXML(self::TEMPLATE); |
44 | 44 | |
45 | 45 | $this->Response = $this->firstChild; |
46 | 46 | $this->setElementValue('DateTime', date('Y-m-d\TH:i:s', time())); |
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Create new element node |
|
51 | - * |
|
52 | - * @param string $name |
|
53 | - * @param string $value (optional) |
|
54 | - */ |
|
55 | - public function createElement($name, $value=NULL) |
|
56 | - { |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Create new element node |
|
51 | + * |
|
52 | + * @param string $name |
|
53 | + * @param string $value (optional) |
|
54 | + */ |
|
55 | + public function createElement($name, $value=NULL) |
|
56 | + { |
|
57 | 57 | return parent::createElement($name, $value); |
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Create new node attribute |
|
62 | - * |
|
63 | - * @param string $name |
|
64 | - * @param string $value |
|
65 | - */ |
|
66 | - public function create_attr($name, $value) |
|
67 | - { |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Create new node attribute |
|
62 | + * |
|
63 | + * @param string $name |
|
64 | + * @param string $value |
|
65 | + */ |
|
66 | + public function create_attr($name, $value) |
|
67 | + { |
|
68 | 68 | return new DOMAttr($name, $value); |
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Set node value |
|
73 | - * |
|
74 | - * @param string $name |
|
75 | - * @param string $value |
|
76 | - */ |
|
77 | - public function setElementValue($name, $value) |
|
78 | - { |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Set node value |
|
73 | + * |
|
74 | + * @param string $name |
|
75 | + * @param string $value |
|
76 | + */ |
|
77 | + public function setElementValue($name, $value) |
|
78 | + { |
|
79 | 79 | foreach ($this->Response->childNodes as $child) |
80 | 80 | { |
81 | - if ($child->nodeName == $name) |
|
82 | - { |
|
81 | + if ($child->nodeName == $name) |
|
82 | + { |
|
83 | 83 | $child->nodeValue = $value; |
84 | - } |
|
84 | + } |
|
85 | + } |
|
85 | 86 | } |
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Dumps response into a string |
|
90 | - * |
|
91 | - * @return string XML |
|
92 | - */ |
|
93 | - public function friendly() |
|
94 | - { |
|
87 | + |
|
88 | + /** |
|
89 | + * Dumps response into a string |
|
90 | + * |
|
91 | + * @return string XML |
|
92 | + */ |
|
93 | + public function friendly() |
|
94 | + { |
|
95 | 95 | $this->encoding = 'UTF-8'; |
96 | 96 | $this->formatOutput = true; |
97 | 97 | //$this->save('/tmp/test1.xml'); |
98 | 98 | |
99 | 99 | return $this->saveXML(NULL, LIBXML_NOEMPTYTAG); |
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Send response |
|
104 | - * |
|
105 | - * @param array $options |
|
106 | - */ |
|
107 | - public function out($options) |
|
108 | - { |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Send response |
|
104 | + * |
|
105 | + * @param array $options |
|
106 | + */ |
|
107 | + public function out($options) |
|
108 | + { |
|
109 | 109 | $this->sign($options); |
110 | 110 | |
111 | 111 | Log::instance()->debug('response sends: '); |
@@ -115,62 +115,62 @@ discard block |
||
115 | 115 | header("Content-Type: text/xml; charset=utf-8"); |
116 | 116 | echo $this->friendly(); |
117 | 117 | exit; |
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Add Sign (if hasn't yet done) |
|
122 | - * |
|
123 | - * @param array $options |
|
124 | - */ |
|
125 | - protected function sign($options) |
|
126 | - { |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Add Sign (if hasn't yet done) |
|
122 | + * |
|
123 | + * @param array $options |
|
124 | + */ |
|
125 | + protected function sign($options) |
|
126 | + { |
|
127 | 127 | if (isset($this->Sign)) return; |
128 | 128 | |
129 | 129 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
130 | 130 | { |
131 | - $this->Sign = self::createElement('Sign'); |
|
132 | - $this->Response->appendChild($this->Sign); |
|
131 | + $this->Sign = self::createElement('Sign'); |
|
132 | + $this->Response->appendChild($this->Sign); |
|
133 | 133 | |
134 | - $sign = $this->generate_sign($options); |
|
134 | + $sign = $this->generate_sign($options); |
|
135 | 135 | |
136 | - $this->Sign->nodeValue = $sign; |
|
136 | + $this->Sign->nodeValue = $sign; |
|
137 | + } |
|
137 | 138 | } |
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Generate signature of response |
|
142 | - * |
|
143 | - * @param array $options |
|
144 | - * @return string |
|
145 | - */ |
|
146 | - public function generate_sign($options) |
|
147 | - { |
|
139 | + |
|
140 | + /** |
|
141 | + * Generate signature of response |
|
142 | + * |
|
143 | + * @param array $options |
|
144 | + * @return string |
|
145 | + */ |
|
146 | + public function generate_sign($options) |
|
147 | + { |
|
148 | 148 | if ( ! isset($options['ProviderPKey'])) |
149 | 149 | { |
150 | - Log::instance()->error('The parameter ProviderPKey is not set!'); |
|
151 | - return null; |
|
150 | + Log::instance()->error('The parameter ProviderPKey is not set!'); |
|
151 | + return null; |
|
152 | 152 | } |
153 | 153 | try |
154 | 154 | { |
155 | - $pkeyid = (new Key())->get($options['ProviderPKey'], 'private'); |
|
155 | + $pkeyid = (new Key())->get($options['ProviderPKey'], 'private'); |
|
156 | 156 | } |
157 | 157 | catch (\Exception $e) |
158 | 158 | { |
159 | - return null; |
|
159 | + return null; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | $pr_key = openssl_pkey_get_private($pkeyid); |
163 | 163 | if ($pr_key === FALSE) |
164 | 164 | { |
165 | - Log::instance()->error('Can not extract the private key from certificate!'); |
|
166 | - return null; |
|
165 | + Log::instance()->error('Can not extract the private key from certificate!'); |
|
166 | + return null; |
|
167 | 167 | } |
168 | 168 | if (openssl_sign($this->friendly(), $sign, $pr_key) === FALSE) |
169 | 169 | { |
170 | - Log::instance()->error('Can not generate signature!'); |
|
171 | - return null; |
|
170 | + Log::instance()->error('Can not generate signature!'); |
|
171 | + return null; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | return strtoupper(bin2hex($sign)); |
175 | - } |
|
175 | + } |
|
176 | 176 | } |
@@ -52,7 +52,7 @@ |
||
52 | 52 | * @param string $name |
53 | 53 | * @param string $value (optional) |
54 | 54 | */ |
55 | - public function createElement($name, $value=NULL) |
|
55 | + public function createElement($name, $value = NULL) |
|
56 | 56 | { |
57 | 57 | return parent::createElement($name, $value); |
58 | 58 | } |
@@ -124,7 +124,9 @@ discard block |
||
124 | 124 | */ |
125 | 125 | protected function sign($options) |
126 | 126 | { |
127 | - if (isset($this->Sign)) return; |
|
127 | + if (isset($this->Sign)) { |
|
128 | + return; |
|
129 | + } |
|
128 | 130 | |
129 | 131 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
130 | 132 | { |
@@ -153,8 +155,7 @@ discard block |
||
153 | 155 | try |
154 | 156 | { |
155 | 157 | $pkeyid = (new Key())->get($options['ProviderPKey'], 'private'); |
156 | - } |
|
157 | - catch (\Exception $e) |
|
158 | + } catch (\Exception $e) |
|
158 | 159 | { |
159 | 160 | return null; |
160 | 161 | } |
@@ -13,202 +13,202 @@ |
||
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 Callback |
|
28 | - */ |
|
29 | - protected static $cb; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Request |
|
33 | - */ |
|
34 | - private $request; |
|
35 | - |
|
36 | - /** |
|
37 | - * Provider31 constructor |
|
38 | - * |
|
39 | - * @param array $options |
|
40 | - * @param Callback $cb |
|
41 | - * @param \Debulog\LoggerInterface $log |
|
42 | - */ |
|
43 | - public function __construct(array $options, Callback $cb, \Debulog\LoggerInterface $log) |
|
44 | - { |
|
24 | + ); |
|
25 | + |
|
26 | + /** |
|
27 | + * @var Callback |
|
28 | + */ |
|
29 | + protected static $cb; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Request |
|
33 | + */ |
|
34 | + private $request; |
|
35 | + |
|
36 | + /** |
|
37 | + * Provider31 constructor |
|
38 | + * |
|
39 | + * @param array $options |
|
40 | + * @param Callback $cb |
|
41 | + * @param \Debulog\LoggerInterface $log |
|
42 | + */ |
|
43 | + public function __construct(array $options, Callback $cb, \Debulog\LoggerInterface $log) |
|
44 | + { |
|
45 | 45 | self::$options = array_merge(self::$options, $options); |
46 | 46 | self::$cb = $cb; |
47 | 47 | |
48 | 48 | Log::set($log); |
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Get and process request, echo response |
|
53 | - * |
|
54 | - */ |
|
55 | - public function process() |
|
56 | - { |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Get and process request, echo response |
|
53 | + * |
|
54 | + */ |
|
55 | + public function process() |
|
56 | + { |
|
57 | 57 | try |
58 | 58 | { |
59 | - // get request |
|
60 | - $this->request = Provider31\Request::get(); |
|
59 | + // get request |
|
60 | + $this->request = Provider31\Request::get(); |
|
61 | 61 | |
62 | - // validate request |
|
63 | - $this->request->validate_request(self::$options); |
|
64 | - Log::instance()->debug('request is valid'); |
|
62 | + // validate request |
|
63 | + $this->request->validate_request(self::$options); |
|
64 | + Log::instance()->debug('request is valid'); |
|
65 | 65 | |
66 | - // verify sign |
|
67 | - $this->request->verify_sign(self::$options); |
|
68 | - Log::instance()->debug('signature of request is correct'); |
|
66 | + // verify sign |
|
67 | + $this->request->verify_sign(self::$options); |
|
68 | + Log::instance()->debug('signature of request is correct'); |
|
69 | 69 | |
70 | - // get response |
|
71 | - $this->response = $this->get_response(); |
|
70 | + // get response |
|
71 | + $this->response = $this->get_response(); |
|
72 | 72 | |
73 | - Log::instance()->add('the request was processed successfully'); |
|
73 | + Log::instance()->add('the request was processed successfully'); |
|
74 | 74 | } |
75 | 75 | catch (Exception\Structure $e) |
76 | 76 | { |
77 | - $this->response = $this->get_error_response($e->getCode(), 'Error in request'); |
|
77 | + $this->response = $this->get_error_response($e->getCode(), 'Error in request'); |
|
78 | 78 | } |
79 | 79 | catch (Exception\Sign $e) |
80 | 80 | { |
81 | - $this->response = $this->get_error_response($e->getCode(), 'Signature error!'); |
|
81 | + $this->response = $this->get_error_response($e->getCode(), 'Signature error!'); |
|
82 | 82 | } |
83 | 83 | catch (Exception\Runtime $e) |
84 | 84 | { |
85 | - $this->response = $this->get_error_response($e->getCode(), 'Error while processing request'); |
|
85 | + $this->response = $this->get_error_response($e->getCode(), 'Error while processing request'); |
|
86 | 86 | } |
87 | 87 | catch (\Exception $e) |
88 | 88 | { |
89 | - $this->response = $this->get_error_response($e->getCode(), $e->getMessage()); |
|
89 | + $this->response = $this->get_error_response($e->getCode(), $e->getMessage()); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | // output response |
93 | 93 | $this->response->out(self::$options); |
94 | 94 | exit; |
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Process request and generate response |
|
99 | - * |
|
100 | - * @throws Exception\Structure |
|
101 | - */ |
|
102 | - private function get_response() |
|
103 | - { |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Process request and generate response |
|
99 | + * |
|
100 | + * @throws Exception\Structure |
|
101 | + */ |
|
102 | + private function get_response() |
|
103 | + { |
|
104 | 104 | switch ($this->request->Operation()) |
105 | 105 | { |
106 | - case 'Check': |
|
106 | + case 'Check': |
|
107 | 107 | |
108 | 108 | return $this->response_check(); |
109 | 109 | |
110 | - case 'Payment': |
|
110 | + case 'Payment': |
|
111 | 111 | |
112 | 112 | return $this->response_payment(); |
113 | 113 | |
114 | - case 'Confirm': |
|
114 | + case 'Confirm': |
|
115 | 115 | |
116 | 116 | return $this->response_confirm(); |
117 | 117 | |
118 | - case 'Cancel'; |
|
118 | + case 'Cancel'; |
|
119 | 119 | |
120 | 120 | return $this->response_cancel(); |
121 | 121 | |
122 | - default: |
|
122 | + default: |
|
123 | 123 | break; |
124 | 124 | } |
125 | 125 | |
126 | 126 | throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * run check callback and generate a response |
|
131 | - * |
|
132 | - * @return Provider31\Response\Check |
|
133 | - */ |
|
134 | - private function response_check() |
|
135 | - { |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * run check callback and generate a response |
|
131 | + * |
|
132 | + * @return Provider31\Response\Check |
|
133 | + */ |
|
134 | + private function response_check() |
|
135 | + { |
|
136 | 136 | Log::instance()->add(sprintf('Check("%s")', $this->request->Account())); |
137 | 137 | |
138 | 138 | $accountinfo = self::$cb->check( |
139 | - $this->request->Account() |
|
139 | + $this->request->Account() |
|
140 | 140 | ); |
141 | 141 | |
142 | 142 | // Sending a response |
143 | 143 | return new Provider31\Response\Check($accountinfo); |
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * run payment callback and generate a response |
|
148 | - * |
|
149 | - * @return Provider31\Response\Payment |
|
150 | - */ |
|
151 | - private function response_payment() |
|
152 | - { |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * run payment callback and generate a response |
|
148 | + * |
|
149 | + * @return Provider31\Response\Payment |
|
150 | + */ |
|
151 | + private function response_payment() |
|
152 | + { |
|
153 | 153 | Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount())); |
154 | 154 | |
155 | 155 | $paymentid = self::$cb->payment( |
156 | - $this->request->Account(), |
|
157 | - $this->request->OrderId(), |
|
158 | - $this->request->Amount() |
|
156 | + $this->request->Account(), |
|
157 | + $this->request->OrderId(), |
|
158 | + $this->request->Amount() |
|
159 | 159 | ); |
160 | 160 | |
161 | 161 | // Sending a response |
162 | 162 | return new Provider31\Response\Payment($paymentid); |
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * run confirm callback and generate a response |
|
167 | - * |
|
168 | - * @return Provider31\Response\Confirm |
|
169 | - */ |
|
170 | - private function response_confirm() |
|
171 | - { |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * run confirm callback and generate a response |
|
167 | + * |
|
168 | + * @return Provider31\Response\Confirm |
|
169 | + */ |
|
170 | + private function response_confirm() |
|
171 | + { |
|
172 | 172 | Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId())); |
173 | 173 | |
174 | 174 | $orderdate = self::$cb->confirm( |
175 | - $this->request->PaymentId() |
|
175 | + $this->request->PaymentId() |
|
176 | 176 | ); |
177 | 177 | |
178 | 178 | // Sending a response |
179 | 179 | return new Provider31\Response\Confirm($orderdate); |
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * run cancel callback and generate a response |
|
184 | - * |
|
185 | - * @return Provider31\Response\Cancel |
|
186 | - */ |
|
187 | - private function response_cancel() |
|
188 | - { |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * run cancel callback and generate a response |
|
184 | + * |
|
185 | + * @return Provider31\Response\Cancel |
|
186 | + */ |
|
187 | + private function response_cancel() |
|
188 | + { |
|
189 | 189 | Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId())); |
190 | 190 | |
191 | 191 | $canceldate = self::$cb->cancel( |
192 | - $this->request->PaymentId() |
|
192 | + $this->request->PaymentId() |
|
193 | 193 | ); |
194 | 194 | |
195 | 195 | // Sending a response |
196 | 196 | return new Provider31\Response\Cancel($canceldate); |
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Generates an xml with an error message |
|
201 | - * |
|
202 | - * @param integer $code |
|
203 | - * @param string $message |
|
204 | - * |
|
205 | - * @return Provider31\Response\ErrorInfo |
|
206 | - */ |
|
207 | - private function get_error_response($code, $message) |
|
208 | - { |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Generates an xml with an error message |
|
201 | + * |
|
202 | + * @param integer $code |
|
203 | + * @param string $message |
|
204 | + * |
|
205 | + * @return Provider31\Response\ErrorInfo |
|
206 | + */ |
|
207 | + private function get_error_response($code, $message) |
|
208 | + { |
|
209 | 209 | Log::instance()->add('the request was processed with an error'); |
210 | 210 | |
211 | 211 | // Sending a response |
212 | 212 | return new Provider31\Response\ErrorInfo($code, $message); |
213 | - } |
|
213 | + } |
|
214 | 214 | } |
@@ -71,20 +71,16 @@ |
||
71 | 71 | $this->response = $this->get_response(); |
72 | 72 | |
73 | 73 | Log::instance()->add('the request was processed successfully'); |
74 | - } |
|
75 | - catch (Exception\Structure $e) |
|
74 | + } catch (Exception\Structure $e) |
|
76 | 75 | { |
77 | 76 | $this->response = $this->get_error_response($e->getCode(), 'Error in request'); |
78 | - } |
|
79 | - catch (Exception\Sign $e) |
|
77 | + } catch (Exception\Sign $e) |
|
80 | 78 | { |
81 | 79 | $this->response = $this->get_error_response($e->getCode(), 'Signature error!'); |
82 | - } |
|
83 | - catch (Exception\Runtime $e) |
|
80 | + } catch (Exception\Runtime $e) |
|
84 | 81 | { |
85 | 82 | $this->response = $this->get_error_response($e->getCode(), 'Error while processing request'); |
86 | - } |
|
87 | - catch (\Exception $e) |
|
83 | + } catch (\Exception $e) |
|
88 | 84 | { |
89 | 85 | $this->response = $this->get_error_response($e->getCode(), $e->getMessage()); |
90 | 86 | } |