Passed
Push — master ( 233bc5...475cfd )
by Dmitry
02:34
created
src/Provider31.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -13,201 +13,201 @@
 block discarded – undo
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\General
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\General
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
-    }
95
-
96
-    /**
97
-     *      Process request and generate response
98
-     *
99
-     *      @throws Exception\Structure
100
-     */
101
-    private function get_response()
102
-    {
94
+        }
95
+
96
+        /**
97
+         *      Process request and generate response
98
+         *
99
+         *      @throws Exception\Structure
100
+         */
101
+        private function get_response()
102
+        {
103 103
         switch ($this->request->Operation())
104 104
         {
105
-            case 'Check':
105
+                case 'Check':
106 106
 
107 107
                 return $this->response_check();
108 108
 
109
-            case 'Payment':
109
+                case 'Payment':
110 110
 
111 111
                 return $this->response_payment();
112 112
 
113
-            case 'Confirm':
113
+                case 'Confirm':
114 114
 
115 115
                 return $this->response_confirm();
116 116
 
117
-            case 'Cancel';
117
+                case 'Cancel';
118 118
 
119 119
                 return $this->response_cancel();
120 120
 
121
-            default:
121
+                default:
122 122
                 break;
123 123
         }
124 124
 
125 125
         throw new Exception\Structure('There is not supported value of Operation in xml-request!', -99);
126
-    }
127
-
128
-    /**
129
-     *      run check callback and generate a response
130
-     *
131
-     *      @return Provider31\Response\Check
132
-     */
133
-    private function response_check()
134
-    {
126
+        }
127
+
128
+        /**
129
+         *      run check callback and generate a response
130
+         *
131
+         *      @return Provider31\Response\Check
132
+         */
133
+        private function response_check()
134
+        {
135 135
         Log::instance()->add(sprintf('Check("%s")', $this->request->Account()));
136 136
 
137 137
         $accountinfo = self::$cb->check(
138
-            $this->request->Account()
138
+                $this->request->Account()
139 139
         );
140 140
 
141 141
         // Sending a response
142 142
         return new Provider31\Response\Check($accountinfo);
143
-    }
144
-
145
-    /**
146
-     *      run payment callback and generate a response
147
-     *
148
-     *      @return Provider31\Response\Payment
149
-     */
150
-    private function response_payment()
151
-    {
143
+        }
144
+
145
+        /**
146
+         *      run payment callback and generate a response
147
+         *
148
+         *      @return Provider31\Response\Payment
149
+         */
150
+        private function response_payment()
151
+        {
152 152
         Log::instance()->add(sprintf('Payment("%s", "%s", "%s")', $this->request->Account(), $this->request->OrderId(), $this->request->Amount()));
153 153
 
154 154
         $paymentid = self::$cb->payment(
155
-            $this->request->Account(),
156
-            $this->request->OrderId(),
157
-            $this->request->Amount()
155
+                $this->request->Account(),
156
+                $this->request->OrderId(),
157
+                $this->request->Amount()
158 158
         );
159 159
 
160 160
         // Sending a response
161 161
         return new Provider31\Response\Payment($paymentid);
162
-    }
163
-
164
-    /**
165
-     *      run confirm callback and generate a response
166
-     *
167
-     *      @return Provider31\Response\Confirm
168
-     */
169
-    private function response_confirm()
170
-    {
162
+        }
163
+
164
+        /**
165
+         *      run confirm callback and generate a response
166
+         *
167
+         *      @return Provider31\Response\Confirm
168
+         */
169
+        private function response_confirm()
170
+        {
171 171
         Log::instance()->add(sprintf('Confirm("%s")', $this->request->PaymentId()));
172 172
 
173 173
         $orderdate = self::$cb->confirm(
174
-            $this->request->PaymentId()
174
+                $this->request->PaymentId()
175 175
         );
176 176
 
177 177
         // Sending a response
178 178
         return new Provider31\Response\Confirm($orderdate);
179
-    }
180
-
181
-    /**
182
-     *      run cancel callback and generate a response
183
-     *
184
-     *      @return Provider31\Response\Cancel
185
-     */
186
-    private function response_cancel()
187
-    {
179
+        }
180
+
181
+        /**
182
+         *      run cancel callback and generate a response
183
+         *
184
+         *      @return Provider31\Response\Cancel
185
+         */
186
+        private function response_cancel()
187
+        {
188 188
         Log::instance()->add(sprintf('Cancel("%s")', $this->request->PaymentId()));
189 189
 
190 190
         $canceldate = self::$cb->cancel(
191
-            $this->request->PaymentId()
191
+                $this->request->PaymentId()
192 192
         );
193 193
 
194 194
         // Sending a response
195 195
         return new Provider31\Response\Cancel($canceldate);
196
-    }
197
-
198
-    /**
199
-     *      Generates an xml with an error message
200
-     *
201
-     *      @param integer $code
202
-     *      @param string $message
203
-     *
204
-     *      @return Provider31\Response\ErrorInfo
205
-     */
206
-    private function get_error_response($code, $message)
207
-    {
196
+        }
197
+
198
+        /**
199
+         *      Generates an xml with an error message
200
+         *
201
+         *      @param integer $code
202
+         *      @param string $message
203
+         *
204
+         *      @return Provider31\Response\ErrorInfo
205
+         */
206
+        private function get_error_response($code, $message)
207
+        {
208 208
         Log::instance()->add('the request was processed with an error');
209 209
 
210 210
         // Sending a response
211 211
         return new Provider31\Response\ErrorInfo($code, $message);
212
-    }
212
+        }
213 213
 }
Please login to merge, or discard this patch.