@@ -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 | } |
@@ -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 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | protected function get_http_raw_post_data() |
| 54 | 54 | { |
| 55 | - Log::instance()->add('request from ' . $_SERVER['REMOTE_ADDR']); |
|
| 55 | + Log::instance()->add('request from '.$_SERVER['REMOTE_ADDR']); |
|
| 56 | 56 | |
| 57 | 57 | $this->raw_request = file_get_contents('php://input'); |
| 58 | 58 | |
@@ -86,7 +86,7 @@ discard block |
||
| 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 | 91 | } |
| 92 | 92 | throw new Exception\Structure('The wrong XML is received', -51); |
@@ -104,9 +104,9 @@ discard block |
||
| 104 | 104 | * |
| 105 | 105 | * @return array nodes with the name |
| 106 | 106 | */ |
| 107 | - protected function getNodes($dom, $name, $ret=array()) |
|
| 107 | + protected function getNodes($dom, $name, $ret = array()) |
|
| 108 | 108 | { |
| 109 | - foreach($dom->childNodes as $child) |
|
| 109 | + foreach ($dom->childNodes as $child) |
|
| 110 | 110 | { |
| 111 | 111 | if ($child->nodeName == $name) |
| 112 | 112 | { |
@@ -111,8 +111,7 @@ |
||
| 111 | 111 | if ($child->nodeName == $name) |
| 112 | 112 | { |
| 113 | 113 | array_push($ret, $child); |
| 114 | - } |
|
| 115 | - else |
|
| 114 | + } else |
|
| 116 | 115 | { |
| 117 | 116 | if (count($child->childNodes) > 0) |
| 118 | 117 | { |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Check extends General |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string 'Account' node |
|
| 21 | - */ |
|
| 22 | - protected $Account; |
|
| 19 | + /** |
|
| 20 | + * @var string 'Account' node |
|
| 21 | + */ |
|
| 22 | + protected $Account; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Check constructor |
|
| 26 | - * |
|
| 27 | - * @param string $raw Raw request data |
|
| 28 | - */ |
|
| 29 | - public function __construct($raw) |
|
| 30 | - { |
|
| 24 | + /** |
|
| 25 | + * Check constructor |
|
| 26 | + * |
|
| 27 | + * @param string $raw Raw request data |
|
| 28 | + */ |
|
| 29 | + public function __construct($raw) |
|
| 30 | + { |
|
| 31 | 31 | parent::__construct($raw); |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get Account |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function Account() |
|
| 40 | - { |
|
| 34 | + /** |
|
| 35 | + * Get Account |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function Account() |
|
| 40 | + { |
|
| 41 | 41 | return $this->Account; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - protected function parse_request_data() |
|
| 49 | - { |
|
| 44 | + /** |
|
| 45 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + protected function parse_request_data() |
|
| 49 | + { |
|
| 50 | 50 | parent::parse_request_data(); |
| 51 | 51 | |
| 52 | 52 | $r = $this->raw_request->get_nodes_from_request('Check'); |
| 53 | 53 | |
| 54 | 54 | foreach ($r[0]->childNodes as $child) |
| 55 | 55 | { |
| 56 | - $this->check_and_parse_request_node($child, 'Account'); |
|
| 56 | + $this->check_and_parse_request_node($child, 'Account'); |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | - } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * validate Check request |
|
| 62 | - * |
|
| 63 | - * @param array $options |
|
| 64 | - * @throws Exception\Structure |
|
| 65 | - */ |
|
| 66 | - public function validate_request($options) |
|
| 67 | - { |
|
| 60 | + /** |
|
| 61 | + * validate Check request |
|
| 62 | + * |
|
| 63 | + * @param array $options |
|
| 64 | + * @throws Exception\Structure |
|
| 65 | + */ |
|
| 66 | + public function validate_request($options) |
|
| 67 | + { |
|
| 68 | 68 | parent::validate_request($options); |
| 69 | 69 | |
| 70 | 70 | $this->validate_element('Account'); |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -16,91 +16,91 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Payment extends General |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string 'Account' node |
|
| 21 | - */ |
|
| 22 | - protected $Account; |
|
| 19 | + /** |
|
| 20 | + * @var string 'Account' node |
|
| 21 | + */ |
|
| 22 | + protected $Account; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var string 'OrderId' node |
|
| 26 | - */ |
|
| 27 | - protected $OrderId; |
|
| 24 | + /** |
|
| 25 | + * @var string 'OrderId' node |
|
| 26 | + */ |
|
| 27 | + protected $OrderId; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var string 'Amount' node |
|
| 31 | - */ |
|
| 32 | - protected $Amount; |
|
| 29 | + /** |
|
| 30 | + * @var string 'Amount' node |
|
| 31 | + */ |
|
| 32 | + protected $Amount; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Payment constructor |
|
| 36 | - * |
|
| 37 | - * @param string $raw Raw request data |
|
| 38 | - */ |
|
| 39 | - public function __construct($raw) |
|
| 40 | - { |
|
| 34 | + /** |
|
| 35 | + * Payment constructor |
|
| 36 | + * |
|
| 37 | + * @param string $raw Raw request data |
|
| 38 | + */ |
|
| 39 | + public function __construct($raw) |
|
| 40 | + { |
|
| 41 | 41 | parent::__construct($raw); |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Get Account |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function Account() |
|
| 50 | - { |
|
| 44 | + /** |
|
| 45 | + * Get Account |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function Account() |
|
| 50 | + { |
|
| 51 | 51 | return $this->Account; |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Get OrderId |
|
| 56 | - * |
|
| 57 | - * @return string |
|
| 58 | - */ |
|
| 59 | - public function OrderId() |
|
| 60 | - { |
|
| 54 | + /** |
|
| 55 | + * Get OrderId |
|
| 56 | + * |
|
| 57 | + * @return string |
|
| 58 | + */ |
|
| 59 | + public function OrderId() |
|
| 60 | + { |
|
| 61 | 61 | return $this->OrderId; |
| 62 | - } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Get Amount |
|
| 66 | - * |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function Amount() |
|
| 70 | - { |
|
| 64 | + /** |
|
| 65 | + * Get Amount |
|
| 66 | + * |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function Amount() |
|
| 70 | + { |
|
| 71 | 71 | return $this->Amount; |
| 72 | - } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 76 | - * |
|
| 77 | - */ |
|
| 78 | - protected function parse_request_data() |
|
| 79 | - { |
|
| 74 | + /** |
|
| 75 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 76 | + * |
|
| 77 | + */ |
|
| 78 | + protected function parse_request_data() |
|
| 79 | + { |
|
| 80 | 80 | parent::parse_request_data(); |
| 81 | 81 | |
| 82 | 82 | $r = $this->raw_request->get_nodes_from_request('Payment'); |
| 83 | 83 | |
| 84 | 84 | foreach ($r[0]->childNodes as $child) |
| 85 | 85 | { |
| 86 | - $this->check_and_parse_request_node($child, 'Account'); |
|
| 87 | - $this->check_and_parse_request_node($child, 'OrderId'); |
|
| 88 | - $this->check_and_parse_request_node($child, 'Amount'); |
|
| 86 | + $this->check_and_parse_request_node($child, 'Account'); |
|
| 87 | + $this->check_and_parse_request_node($child, 'OrderId'); |
|
| 88 | + $this->check_and_parse_request_node($child, 'Amount'); |
|
| 89 | + } |
|
| 89 | 90 | } |
| 90 | - } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * validate Payment request |
|
| 94 | - * |
|
| 95 | - * @param array $options |
|
| 96 | - * @throws Exception\Structure |
|
| 97 | - */ |
|
| 98 | - public function validate_request($options) |
|
| 99 | - { |
|
| 92 | + /** |
|
| 93 | + * validate Payment request |
|
| 94 | + * |
|
| 95 | + * @param array $options |
|
| 96 | + * @throws Exception\Structure |
|
| 97 | + */ |
|
| 98 | + public function validate_request($options) |
|
| 99 | + { |
|
| 100 | 100 | parent::validate_request($options); |
| 101 | 101 | |
| 102 | 102 | $this->validate_element('Account'); |
| 103 | 103 | $this->validate_element('OrderId'); |
| 104 | 104 | $this->validate_element('Amount'); |
| 105 | - } |
|
| 105 | + } |
|
| 106 | 106 | } |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | /** |
| 48 | 48 | * @var array list of possible operations |
| 49 | 49 | */ |
| 50 | - protected $operations = array('Check','Payment','Confirm','Cancel'); |
|
| 50 | + protected $operations = array('Check', 'Payment', 'Confirm', 'Cancel'); |
|
| 51 | 51 | |
| 52 | 52 | /** |
| 53 | 53 | * General constructor |
@@ -124,8 +124,7 @@ discard block |
||
| 124 | 124 | if ( ! isset($this->Operation)) |
| 125 | 125 | { |
| 126 | 126 | $this->Operation = $child->nodeName; |
| 127 | - } |
|
| 128 | - else |
|
| 127 | + } else |
|
| 129 | 128 | { |
| 130 | 129 | throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
| 131 | 130 | } |
@@ -173,8 +172,7 @@ discard block |
||
| 173 | 172 | if ( ! isset($this->$name)) |
| 174 | 173 | { |
| 175 | 174 | $this->$name = $n->nodeValue; |
| 176 | - } |
|
| 177 | - else |
|
| 175 | + } else |
|
| 178 | 176 | { |
| 179 | 177 | throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
| 180 | 178 | } |
@@ -18,124 +18,124 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | class General |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var EasyPay\Provider31\Request\RAW 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 \EasyPay\Provider31\Request\RAW $raw Raw request data |
|
| 55 | - */ |
|
| 56 | - public function __construct($raw) |
|
| 57 | - { |
|
| 21 | + /** |
|
| 22 | + * @var EasyPay\Provider31\Request\RAW 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 \EasyPay\Provider31\Request\RAW $raw Raw request data |
|
| 55 | + */ |
|
| 56 | + public function __construct($raw) |
|
| 57 | + { |
|
| 58 | 58 | $this->raw_request = $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 | // process <Request> group |
| 111 | 111 | $r = $this->raw_request->get_nodes_from_request('Request'); |
| 112 | 112 | |
| 113 | 113 | if (count($r) < 1) |
| 114 | 114 | { |
| 115 | - throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
| 115 | + throw new Exception\Structure('The xml-query does not contain any element Request!', -52); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | foreach ($r[0]->childNodes as $child) |
| 119 | 119 | { |
| 120 | - $this->check_and_parse_request_node($child, 'DateTime'); |
|
| 121 | - $this->check_and_parse_request_node($child, 'Sign'); |
|
| 120 | + $this->check_and_parse_request_node($child, 'DateTime'); |
|
| 121 | + $this->check_and_parse_request_node($child, 'Sign'); |
|
| 122 | 122 | |
| 123 | - if (in_array($child->nodeName, $this->operations)) |
|
| 124 | - { |
|
| 123 | + if (in_array($child->nodeName, $this->operations)) |
|
| 124 | + { |
|
| 125 | 125 | if ( ! isset($this->Operation)) |
| 126 | 126 | { |
| 127 | - $this->Operation = $child->nodeName; |
|
| 127 | + $this->Operation = $child->nodeName; |
|
| 128 | 128 | } |
| 129 | 129 | else |
| 130 | 130 | { |
| 131 | - throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
| 131 | + throw new Exception\Structure('There is more than one Operation type element in the xml-query!', -53); |
|
| 132 | + } |
|
| 132 | 133 | } |
| 133 | - } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | if ( ! isset($this->Operation)) |
| 137 | 137 | { |
| 138 | - throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
| 138 | + throw new Exception\Structure('There is no Operation type element in the xml request!', -55); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // process <Operation> group |
@@ -143,53 +143,53 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | foreach ($r[0]->childNodes as $child) |
| 145 | 145 | { |
| 146 | - $this->check_and_parse_request_node($child, 'ServiceId'); |
|
| 146 | + $this->check_and_parse_request_node($child, 'ServiceId'); |
|
| 147 | + } |
|
| 147 | 148 | } |
| 148 | - } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Check if present node of request and then parse it |
|
| 152 | - * |
|
| 153 | - * @param \DOMNode $n |
|
| 154 | - * @param string $name |
|
| 155 | - */ |
|
| 156 | - protected function check_and_parse_request_node($n, $name) |
|
| 157 | - { |
|
| 150 | + /** |
|
| 151 | + * Check if present node of request and then parse it |
|
| 152 | + * |
|
| 153 | + * @param \DOMNode $n |
|
| 154 | + * @param string $name |
|
| 155 | + */ |
|
| 156 | + protected function check_and_parse_request_node($n, $name) |
|
| 157 | + { |
|
| 158 | 158 | if ($n->nodeName == $name) |
| 159 | 159 | { |
| 160 | - $this->parse_request_node($n, $name); |
|
| 160 | + $this->parse_request_node($n, $name); |
|
| 161 | + } |
|
| 161 | 162 | } |
| 162 | - } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Parse node of request |
|
| 166 | - * |
|
| 167 | - * @param \DOMNode $n |
|
| 168 | - * @param string $name |
|
| 169 | - * |
|
| 170 | - * @throws Exception\Structure |
|
| 171 | - */ |
|
| 172 | - protected function parse_request_node($n, $name) |
|
| 173 | - { |
|
| 164 | + /** |
|
| 165 | + * Parse node of request |
|
| 166 | + * |
|
| 167 | + * @param \DOMNode $n |
|
| 168 | + * @param string $name |
|
| 169 | + * |
|
| 170 | + * @throws Exception\Structure |
|
| 171 | + */ |
|
| 172 | + protected function parse_request_node($n, $name) |
|
| 173 | + { |
|
| 174 | 174 | if ( ! isset($this->$name)) |
| 175 | 175 | { |
| 176 | - $this->$name = $n->nodeValue; |
|
| 176 | + $this->$name = $n->nodeValue; |
|
| 177 | 177 | } |
| 178 | 178 | else |
| 179 | 179 | { |
| 180 | - throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
| 180 | + throw new Exception\Structure('There is more than one '.$name.' element in the xml-query!', -56); |
|
| 181 | + } |
|
| 181 | 182 | } |
| 182 | - } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * "Rough" validation of the received xml request |
|
| 186 | - * |
|
| 187 | - * @param array $options |
|
| 188 | - * @throws Exception\Data |
|
| 189 | - * @throws Exception\Structure |
|
| 190 | - */ |
|
| 191 | - public function validate_request($options) |
|
| 192 | - { |
|
| 184 | + /** |
|
| 185 | + * "Rough" validation of the received xml request |
|
| 186 | + * |
|
| 187 | + * @param array $options |
|
| 188 | + * @throws Exception\Data |
|
| 189 | + * @throws Exception\Structure |
|
| 190 | + */ |
|
| 191 | + public function validate_request($options) |
|
| 192 | + { |
|
| 193 | 193 | $this->validate_element('DateTime'); |
| 194 | 194 | $this->validate_element('Sign'); |
| 195 | 195 | $this->validate_element('ServiceId'); |
@@ -197,36 +197,36 @@ discard block |
||
| 197 | 197 | // compare received value ServiceId with option ServiceId |
| 198 | 198 | if (intval($options['ServiceId']) != intval($this->ServiceId)) |
| 199 | 199 | { |
| 200 | - throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
| 200 | + throw new Exception\Data('This request is not for our ServiceId!', -58); |
|
| 201 | + } |
|
| 201 | 202 | } |
| 202 | - } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * Validation of xml-element |
|
| 206 | - * |
|
| 207 | - * @param string $name |
|
| 208 | - */ |
|
| 209 | - public function validate_element($name) |
|
| 210 | - { |
|
| 204 | + /** |
|
| 205 | + * Validation of xml-element |
|
| 206 | + * |
|
| 207 | + * @param string $name |
|
| 208 | + */ |
|
| 209 | + public function validate_element($name) |
|
| 210 | + { |
|
| 211 | 211 | if ( ! isset($this->$name)) |
| 212 | 212 | { |
| 213 | - throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
| 213 | + throw new Exception\Structure('There is no '.$name.' element in the xml request!', -57); |
|
| 214 | + } |
|
| 214 | 215 | } |
| 215 | - } |
|
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Verify signature of request |
|
| 219 | - * |
|
| 220 | - * @param array $options |
|
| 221 | - */ |
|
| 222 | - public function verify_sign($options) |
|
| 223 | - { |
|
| 217 | + /** |
|
| 218 | + * Verify signature of request |
|
| 219 | + * |
|
| 220 | + * @param array $options |
|
| 221 | + */ |
|
| 222 | + public function verify_sign($options) |
|
| 223 | + { |
|
| 224 | 224 | $sign = new Sign(); |
| 225 | 225 | $sign->verify( |
| 226 | - $this->raw_request->str(), |
|
| 227 | - $this->Sign, |
|
| 228 | - $options |
|
| 226 | + $this->raw_request->str(), |
|
| 227 | + $this->Sign, |
|
| 228 | + $options |
|
| 229 | 229 | ); |
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | } |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Confirm extends General |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string 'PaymentId' node |
|
| 21 | - */ |
|
| 22 | - protected $PaymentId; |
|
| 19 | + /** |
|
| 20 | + * @var string 'PaymentId' node |
|
| 21 | + */ |
|
| 22 | + protected $PaymentId; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Check constructor |
|
| 26 | - * |
|
| 27 | - * @param string $raw Raw request data |
|
| 28 | - */ |
|
| 29 | - public function __construct($raw) |
|
| 30 | - { |
|
| 24 | + /** |
|
| 25 | + * Check constructor |
|
| 26 | + * |
|
| 27 | + * @param string $raw Raw request data |
|
| 28 | + */ |
|
| 29 | + public function __construct($raw) |
|
| 30 | + { |
|
| 31 | 31 | parent::__construct($raw); |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get PaymentId |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function PaymentId() |
|
| 40 | - { |
|
| 34 | + /** |
|
| 35 | + * Get PaymentId |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function PaymentId() |
|
| 40 | + { |
|
| 41 | 41 | return $this->PaymentId; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - protected function parse_request_data() |
|
| 49 | - { |
|
| 44 | + /** |
|
| 45 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + protected function parse_request_data() |
|
| 49 | + { |
|
| 50 | 50 | parent::parse_request_data(); |
| 51 | 51 | |
| 52 | 52 | $r = $this->raw_request->get_nodes_from_request('Confirm'); |
| 53 | 53 | |
| 54 | 54 | foreach ($r[0]->childNodes as $child) |
| 55 | 55 | { |
| 56 | - $this->check_and_parse_request_node($child, 'PaymentId'); |
|
| 56 | + $this->check_and_parse_request_node($child, 'PaymentId'); |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | - } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * validate Confirm request |
|
| 62 | - * |
|
| 63 | - * @param array $options |
|
| 64 | - * @throws Exception\Structure |
|
| 65 | - */ |
|
| 66 | - public function validate_request($options) |
|
| 67 | - { |
|
| 60 | + /** |
|
| 61 | + * validate Confirm request |
|
| 62 | + * |
|
| 63 | + * @param array $options |
|
| 64 | + * @throws Exception\Structure |
|
| 65 | + */ |
|
| 66 | + public function validate_request($options) |
|
| 67 | + { |
|
| 68 | 68 | parent::validate_request($options); |
| 69 | 69 | |
| 70 | 70 | $this->validate_element('PaymentId'); |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -16,57 +16,57 @@ |
||
| 16 | 16 | |
| 17 | 17 | class Cancel extends General |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var string 'PaymentId' node |
|
| 21 | - */ |
|
| 22 | - protected $PaymentId; |
|
| 19 | + /** |
|
| 20 | + * @var string 'PaymentId' node |
|
| 21 | + */ |
|
| 22 | + protected $PaymentId; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Check constructor |
|
| 26 | - * |
|
| 27 | - * @param string $raw Raw request data |
|
| 28 | - */ |
|
| 29 | - public function __construct($raw) |
|
| 30 | - { |
|
| 24 | + /** |
|
| 25 | + * Check constructor |
|
| 26 | + * |
|
| 27 | + * @param string $raw Raw request data |
|
| 28 | + */ |
|
| 29 | + public function __construct($raw) |
|
| 30 | + { |
|
| 31 | 31 | parent::__construct($raw); |
| 32 | - } |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Get PaymentId |
|
| 36 | - * |
|
| 37 | - * @return string |
|
| 38 | - */ |
|
| 39 | - public function PaymentId() |
|
| 40 | - { |
|
| 34 | + /** |
|
| 35 | + * Get PaymentId |
|
| 36 | + * |
|
| 37 | + * @return string |
|
| 38 | + */ |
|
| 39 | + public function PaymentId() |
|
| 40 | + { |
|
| 41 | 41 | return $this->PaymentId; |
| 42 | - } |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | - * |
|
| 47 | - */ |
|
| 48 | - protected function parse_request_data() |
|
| 49 | - { |
|
| 44 | + /** |
|
| 45 | + * Parse xml-request, which was previously "extracted" from the body of the http request |
|
| 46 | + * |
|
| 47 | + */ |
|
| 48 | + protected function parse_request_data() |
|
| 49 | + { |
|
| 50 | 50 | parent::parse_request_data(); |
| 51 | 51 | |
| 52 | 52 | $r = $this->raw_request->get_nodes_from_request('Cancel'); |
| 53 | 53 | |
| 54 | 54 | foreach ($r[0]->childNodes as $child) |
| 55 | 55 | { |
| 56 | - $this->check_and_parse_request_node($child, 'PaymentId'); |
|
| 56 | + $this->check_and_parse_request_node($child, 'PaymentId'); |
|
| 57 | + } |
|
| 57 | 58 | } |
| 58 | - } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * validate Cancel request |
|
| 62 | - * |
|
| 63 | - * @param array $options |
|
| 64 | - * @throws Exception\Structure |
|
| 65 | - */ |
|
| 66 | - public function validate_request($options) |
|
| 67 | - { |
|
| 60 | + /** |
|
| 61 | + * validate Cancel request |
|
| 62 | + * |
|
| 63 | + * @param array $options |
|
| 64 | + * @throws Exception\Structure |
|
| 65 | + */ |
|
| 66 | + public function validate_request($options) |
|
| 67 | + { |
|
| 68 | 68 | parent::validate_request($options); |
| 69 | 69 | |
| 70 | 70 | $this->validate_element('PaymentId'); |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -15,14 +15,14 @@ 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 | $raw = new Request\RAW(); |
| 28 | 28 | |
@@ -30,37 +30,37 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | switch ($r->Operation()) |
| 32 | 32 | { |
| 33 | - case 'Check': |
|
| 33 | + case 'Check': |
|
| 34 | 34 | return new Request\Check($raw); |
| 35 | 35 | |
| 36 | - case 'Payment': |
|
| 36 | + case 'Payment': |
|
| 37 | 37 | return new Request\Payment($raw); |
| 38 | 38 | |
| 39 | - case 'Confirm': |
|
| 39 | + case 'Confirm': |
|
| 40 | 40 | return new Request\Confirm($raw); |
| 41 | 41 | |
| 42 | - case 'Cancel'; |
|
| 42 | + case 'Cancel'; |
|
| 43 | 43 | return new Request\Cancel($raw); |
| 44 | 44 | |
| 45 | - default: |
|
| 45 | + default: |
|
| 46 | 46 | throw new \EasyPay\Exception\Structure('There is not supported value of Operation in xml-request!', -99); |
| 47 | 47 | } |
| 48 | - } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Get data from the body of the http request |
|
| 52 | - * |
|
| 53 | - * - with the appropriate configuration of php.ini they can be found |
|
| 54 | - * in the global variable $HTTP_RAW_POST_DATA |
|
| 55 | - * |
|
| 56 | - * - but it's easier just to read the data from the php://input stream, |
|
| 57 | - * which does not depend on the php.ini directives and allows you to read |
|
| 58 | - * raw data from the request body |
|
| 59 | - * |
|
| 60 | - * @return string Http raw post data |
|
| 61 | - * |
|
| 62 | - */ |
|
| 63 | - /*private static function get_http_raw_post_data() |
|
| 50 | + /** |
|
| 51 | + * Get data from the body of the http request |
|
| 52 | + * |
|
| 53 | + * - with the appropriate configuration of php.ini they can be found |
|
| 54 | + * in the global variable $HTTP_RAW_POST_DATA |
|
| 55 | + * |
|
| 56 | + * - but it's easier just to read the data from the php://input stream, |
|
| 57 | + * which does not depend on the php.ini directives and allows you to read |
|
| 58 | + * raw data from the request body |
|
| 59 | + * |
|
| 60 | + * @return string Http raw post data |
|
| 61 | + * |
|
| 62 | + */ |
|
| 63 | + /*private static function get_http_raw_post_data() |
|
| 64 | 64 | { |
| 65 | 65 | Log::instance()->add('request from ' . $_SERVER['REMOTE_ADDR']); |
| 66 | 66 | |
@@ -9,120 +9,120 @@ |
||
| 9 | 9 | |
| 10 | 10 | class Sign |
| 11 | 11 | { |
| 12 | - public function __construct() {} |
|
| 12 | + public function __construct() {} |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Verify signature of request |
|
| 16 | - * |
|
| 17 | - * @param string $request_str |
|
| 18 | - * @param string $sign |
|
| 19 | - * @param array $options |
|
| 20 | - */ |
|
| 21 | - public function verify($request_str, $sign, $options) |
|
| 22 | - { |
|
| 14 | + /** |
|
| 15 | + * Verify signature of request |
|
| 16 | + * |
|
| 17 | + * @param string $request_str |
|
| 18 | + * @param string $sign |
|
| 19 | + * @param array $options |
|
| 20 | + */ |
|
| 21 | + public function verify($request_str, $sign, $options) |
|
| 22 | + { |
|
| 23 | 23 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
| 24 | 24 | { |
| 25 | - $this->check_verify_sign_result( |
|
| 25 | + $this->check_verify_sign_result( |
|
| 26 | 26 | $result = (new OpenSSL())->verify( |
| 27 | - str_replace($sign, '', $request_str), |
|
| 28 | - pack("H*", $sign), |
|
| 29 | - (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
| 27 | + str_replace($sign, '', $request_str), |
|
| 28 | + pack("H*", $sign), |
|
| 29 | + (new OpenSSL())->get_pub_key($this->get_pub_key($options)) |
|
| 30 | 30 | ) |
| 31 | - ); |
|
| 31 | + ); |
|
| 32 | + } |
|
| 32 | 33 | } |
| 33 | - } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * load file with easysoft public key |
|
| 37 | - * |
|
| 38 | - * @param array $options |
|
| 39 | - * @throws Exception\Runtime |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - protected function get_pub_key($options) |
|
| 43 | - { |
|
| 35 | + /** |
|
| 36 | + * load file with easysoft public key |
|
| 37 | + * |
|
| 38 | + * @param array $options |
|
| 39 | + * @throws Exception\Runtime |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + protected function get_pub_key($options) |
|
| 43 | + { |
|
| 44 | 44 | if ( ! isset($options['EasySoftPKey'])) |
| 45 | 45 | { |
| 46 | - throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
| 46 | + throw new Exception\Runtime('The parameter EasySoftPKey is not set!', -94); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | return (new Key())->get($options['EasySoftPKey'], 'public'); |
| 50 | - } |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * check result of openssl verify signature |
|
| 54 | - * |
|
| 55 | - * @param integer $result |
|
| 56 | - * @throws Exception\Sign |
|
| 57 | - */ |
|
| 58 | - protected function check_verify_sign_result($result) |
|
| 59 | - { |
|
| 52 | + /** |
|
| 53 | + * check result of openssl verify signature |
|
| 54 | + * |
|
| 55 | + * @param integer $result |
|
| 56 | + * @throws Exception\Sign |
|
| 57 | + */ |
|
| 58 | + protected function check_verify_sign_result($result) |
|
| 59 | + { |
|
| 60 | 60 | if ($result == -1) |
| 61 | 61 | { |
| 62 | - throw new Exception\Sign('Error verify signature of request!', -96); |
|
| 62 | + throw new Exception\Sign('Error verify signature of request!', -96); |
|
| 63 | 63 | } |
| 64 | 64 | elseif ($result == 0) |
| 65 | 65 | { |
| 66 | - throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
| 66 | + throw new Exception\Sign('Signature of request is incorrect!', -95); |
|
| 67 | + } |
|
| 67 | 68 | } |
| 68 | - } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Generate signature of response |
|
| 72 | - * |
|
| 73 | - * @param string $request_str |
|
| 74 | - * @param array $options |
|
| 75 | - * @return string |
|
| 76 | - */ |
|
| 77 | - public function generate($request_str, $options) |
|
| 78 | - { |
|
| 70 | + /** |
|
| 71 | + * Generate signature of response |
|
| 72 | + * |
|
| 73 | + * @param string $request_str |
|
| 74 | + * @param array $options |
|
| 75 | + * @return string |
|
| 76 | + */ |
|
| 77 | + public function generate($request_str, $options) |
|
| 78 | + { |
|
| 79 | 79 | try |
| 80 | 80 | { |
| 81 | - $sign = ''; |
|
| 82 | - $this->check_generate_sign_result( |
|
| 81 | + $sign = ''; |
|
| 82 | + $this->check_generate_sign_result( |
|
| 83 | 83 | $result = (new OpenSSL())->sign( |
| 84 | - $request_str, |
|
| 85 | - $sign, |
|
| 86 | - (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
| 84 | + $request_str, |
|
| 85 | + $sign, |
|
| 86 | + (new OpenSSL())->get_priv_key($this->get_priv_key($options)) |
|
| 87 | 87 | ) |
| 88 | - ); |
|
| 88 | + ); |
|
| 89 | 89 | |
| 90 | - return strtoupper(bin2hex($sign)); |
|
| 90 | + return strtoupper(bin2hex($sign)); |
|
| 91 | 91 | } |
| 92 | 92 | catch (\Exception $e) |
| 93 | 93 | { |
| 94 | - return null; |
|
| 94 | + return null; |
|
| 95 | + } |
|
| 95 | 96 | } |
| 96 | - } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * load file with provider private key |
|
| 100 | - * |
|
| 101 | - * @param array $options |
|
| 102 | - * @throws Exception\Runtime |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - protected function get_priv_key($options) |
|
| 106 | - { |
|
| 98 | + /** |
|
| 99 | + * load file with provider private key |
|
| 100 | + * |
|
| 101 | + * @param array $options |
|
| 102 | + * @throws Exception\Runtime |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + protected function get_priv_key($options) |
|
| 106 | + { |
|
| 107 | 107 | if ( ! isset($options['ProviderPKey'])) |
| 108 | 108 | { |
| 109 | - throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
| 109 | + throw new \EasyPay\Exception\Runtime('The parameter ProviderPKey is not set!', -94); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | return (new Key())->get($options['ProviderPKey'], 'private'); |
| 113 | - } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * check result of openssl sign |
|
| 117 | - * |
|
| 118 | - * @param bool $result |
|
| 119 | - * @throws Exception\Sign |
|
| 120 | - */ |
|
| 121 | - protected function check_generate_sign_result($result) |
|
| 122 | - { |
|
| 115 | + /** |
|
| 116 | + * check result of openssl sign |
|
| 117 | + * |
|
| 118 | + * @param bool $result |
|
| 119 | + * @throws Exception\Sign |
|
| 120 | + */ |
|
| 121 | + protected function check_generate_sign_result($result) |
|
| 122 | + { |
|
| 123 | 123 | if ($result === FALSE) |
| 124 | 124 | { |
| 125 | - throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
| 125 | + throw new \EasyPay\Exception\Sign('Can not generate signature!', -96); |
|
| 126 | + } |
|
| 126 | 127 | } |
| 127 | - } |
|
| 128 | 128 | } |
@@ -60,8 +60,7 @@ discard block |
||
| 60 | 60 | if ($result == -1) |
| 61 | 61 | { |
| 62 | 62 | throw new Exception\Sign('Error verify signature of request!', -96); |
| 63 | - } |
|
| 64 | - elseif ($result == 0) |
|
| 63 | + } elseif ($result == 0) |
|
| 65 | 64 | { |
| 66 | 65 | throw new Exception\Sign('Signature of request is incorrect!', -95); |
| 67 | 66 | } |
@@ -88,8 +87,7 @@ discard block |
||
| 88 | 87 | ); |
| 89 | 88 | |
| 90 | 89 | return strtoupper(bin2hex($sign)); |
| 91 | - } |
|
| 92 | - catch (\Exception $e) |
|
| 90 | + } catch (\Exception $e) |
|
| 93 | 91 | { |
| 94 | 92 | return null; |
| 95 | 93 | } |