@@ -16,93 +16,93 @@ 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 \DOMNode |
|
27 | - */ |
|
28 | - protected $Response; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var \DOMElement |
|
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 \DOMNode |
|
27 | + */ |
|
28 | + protected $Response; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var \DOMElement |
|
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 | $this->loadXML(self::TEMPLATE); |
44 | 44 | |
45 | 45 | $this->Response = $this->firstChild; |
46 | 46 | $this->set_DateTime(); |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Set DateTime element value by current time |
|
51 | - */ |
|
52 | - public function set_DateTime() |
|
53 | - { |
|
49 | + /** |
|
50 | + * Set DateTime element value by current time |
|
51 | + */ |
|
52 | + public function set_DateTime() |
|
53 | + { |
|
54 | 54 | $this->setElementValue('DateTime', date('Y-m-d\TH:i:s', time())); |
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Create new element node |
|
59 | - * |
|
60 | - * @param string $name |
|
61 | - * @param string $value (optional) |
|
62 | - */ |
|
63 | - public function createElement($name, $value=NULL) |
|
64 | - { |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Create new element node |
|
59 | + * |
|
60 | + * @param string $name |
|
61 | + * @param string $value (optional) |
|
62 | + */ |
|
63 | + public function createElement($name, $value=NULL) |
|
64 | + { |
|
65 | 65 | return parent::createElement($name, $value); |
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Set node value |
|
70 | - * |
|
71 | - * @param string $name |
|
72 | - * @param string $value |
|
73 | - */ |
|
74 | - public function setElementValue($name, $value) |
|
75 | - { |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Set node value |
|
70 | + * |
|
71 | + * @param string $name |
|
72 | + * @param string $value |
|
73 | + */ |
|
74 | + public function setElementValue($name, $value) |
|
75 | + { |
|
76 | 76 | foreach ($this->Response->childNodes as $child) |
77 | 77 | { |
78 | - if ($child->nodeName == $name) |
|
79 | - { |
|
78 | + if ($child->nodeName == $name) |
|
79 | + { |
|
80 | 80 | $child->nodeValue = $value; |
81 | - } |
|
81 | + } |
|
82 | 82 | } |
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Dumps response into a string |
|
87 | - * |
|
88 | - * @return string XML |
|
89 | - */ |
|
90 | - public function friendly() |
|
91 | - { |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Dumps response into a string |
|
87 | + * |
|
88 | + * @return string XML |
|
89 | + */ |
|
90 | + public function friendly() |
|
91 | + { |
|
92 | 92 | $this->encoding = 'UTF-8'; |
93 | 93 | $this->formatOutput = true; |
94 | 94 | //$this->save('/tmp/test1.xml'); |
95 | 95 | |
96 | 96 | return $this->saveXML(NULL, LIBXML_NOEMPTYTAG); |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Send response |
|
101 | - * |
|
102 | - * @param array $options |
|
103 | - */ |
|
104 | - public function out($options) |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Send response |
|
101 | + * |
|
102 | + * @param array $options |
|
103 | + */ |
|
104 | + public function out($options) |
|
105 | + { |
|
106 | 106 | $this->sign($options); |
107 | 107 | |
108 | 108 | Log::instance()->debug('response sends: '); |
@@ -112,62 +112,62 @@ discard block |
||
112 | 112 | header("Content-Type: text/xml; charset=utf-8"); |
113 | 113 | echo $this->friendly(); |
114 | 114 | exit; |
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Add Sign (if hasn't yet done) |
|
119 | - * |
|
120 | - * @param array $options |
|
121 | - */ |
|
122 | - protected function sign($options) |
|
123 | - { |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Add Sign (if hasn't yet done) |
|
119 | + * |
|
120 | + * @param array $options |
|
121 | + */ |
|
122 | + protected function sign($options) |
|
123 | + { |
|
124 | 124 | if (isset($this->Sign)) return; |
125 | 125 | |
126 | 126 | if (isset($options['UseSign']) && ($options['UseSign'] === true)) |
127 | 127 | { |
128 | - $this->Sign = $this->createElement('Sign'); |
|
129 | - $this->Response->appendChild($this->Sign); |
|
128 | + $this->Sign = $this->createElement('Sign'); |
|
129 | + $this->Response->appendChild($this->Sign); |
|
130 | 130 | |
131 | - $sign = $this->generate_sign($options); |
|
131 | + $sign = $this->generate_sign($options); |
|
132 | 132 | |
133 | - $this->Sign->nodeValue = $sign; |
|
133 | + $this->Sign->nodeValue = $sign; |
|
134 | + } |
|
134 | 135 | } |
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Generate signature of response |
|
139 | - * |
|
140 | - * @param array $options |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function generate_sign($options) |
|
144 | - { |
|
136 | + |
|
137 | + /** |
|
138 | + * Generate signature of response |
|
139 | + * |
|
140 | + * @param array $options |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function generate_sign($options) |
|
144 | + { |
|
145 | 145 | if ( ! isset($options['ProviderPKey'])) |
146 | 146 | { |
147 | - Log::instance()->error('The parameter ProviderPKey is not set!'); |
|
148 | - return null; |
|
147 | + Log::instance()->error('The parameter ProviderPKey is not set!'); |
|
148 | + return null; |
|
149 | 149 | } |
150 | 150 | try |
151 | 151 | { |
152 | - $pkeyid = (new Key())->get($options['ProviderPKey'], 'private'); |
|
152 | + $pkeyid = (new Key())->get($options['ProviderPKey'], 'private'); |
|
153 | 153 | } |
154 | 154 | catch (\Exception $e) |
155 | 155 | { |
156 | - return null; |
|
156 | + return null; |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | $pr_key = openssl_pkey_get_private($pkeyid); |
160 | 160 | if ($pr_key === FALSE) |
161 | 161 | { |
162 | - Log::instance()->error('Can not extract the private key from certificate!'); |
|
163 | - return null; |
|
162 | + Log::instance()->error('Can not extract the private key from certificate!'); |
|
163 | + return null; |
|
164 | 164 | } |
165 | 165 | if (openssl_sign($this->friendly(), $sign, $pr_key) === FALSE) |
166 | 166 | { |
167 | - Log::instance()->error('Can not generate signature!'); |
|
168 | - return null; |
|
167 | + Log::instance()->error('Can not generate signature!'); |
|
168 | + return null; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | return strtoupper(bin2hex($sign)); |
172 | - } |
|
172 | + } |
|
173 | 173 | } |
@@ -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 | } |
@@ -48,7 +48,7 @@ |
||
48 | 48 | $this->AccountInfo = $this->createElement('AccountInfo'); |
49 | 49 | $this->Response->appendChild($this->AccountInfo); |
50 | 50 | |
51 | - foreach($accountinfo as $parameter=>$value) |
|
51 | + foreach ($accountinfo as $parameter=>$value) |
|
52 | 52 | { |
53 | 53 | $this->AccountInfo->appendChild($this->createElement($parameter, $value)); |
54 | 54 | } |
@@ -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 = $this->createElement('AccountInfo'); |
49 | 51 | $this->Response->appendChild($this->AccountInfo); |
@@ -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 | } |
@@ -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 = $this->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 \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 | } |
@@ -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 = $this->createElement('OrderDate', $orderdate); |
48 | 50 | $this->Response->appendChild($this->OrderDate); |
@@ -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 | } |
@@ -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 = $this->createElement('PaymentId', $paymentid); |
48 | 50 | $this->Response->appendChild($this->PaymentId); |