-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPayment.php
223 lines (201 loc) · 5.73 KB
/
Payment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
/**
* @description basic Payment class
* @author Se#
* @version 0.0.1
*/
abstract class Evil_Payment implements Evil_Payment_Interface
{
/**
* @description payment config
* @var array|mixed
* @author Se#
* @version 0.0.1
*/
protected $_config = array();
/**
* @description request object or data
* @var null
* @author Se#
* @version 0.0.1
*/
protected $_request = null;
/**
* @description payment form for user
* @var null
* @author Se#
* @version 0.0.1
*/
protected $_form = null;
/**
* @description Constructor
* @param string|array $pathToConfig
* @author Se#
* @version 0.0.1
*/
public function __construct($pathToConfig = '')
{
if(is_array($pathToConfig) && !empty($pathToConfig))
{
$this->_config = $pathToConfig;
return true;
}
$realPath = is_file($pathToConfig) ? $pathToConfig : __DIR__ . '/Payment/configs/' . get_class($this). '.json';
$this->_config = json_decode(file_get_contents($realPath), true);
}
/**
* Getter for $_config
*
* @return array|mixed|string
*/
public function getConfig()
{
return $this->_config;
}
/**
* @description basic payment form
* @return null
* @author Se#
* @version 0.0.1
*/
public function getForm()
{
return $this->_form;
}
/**
* @description basic request sending
* @return null
* @author Se#
* @version 0.0.1
*/
public function sendRequest()
{
return $this->_request;
}
/**
* @description append scripts, etc
* @abstract
* @param Zend_Controller_Action $controller
* @return void
* @author Se#
* @version 0.0.1
*/
public function prepareController(Zend_Controller_Action $controller)
{
return $controller;
}
/**
* @description render view
* @abstract
* @param Zend_Controller_Action $controller
* @return void
* @author Se#
* @version 0.0.1
*/
public function render(Zend_Controller_Action $controller)
{
return $controller;
}
/**
* @description fire several methods with the same args
* @param string|array $methodList
* @param array $args
* @return void
* @author Se#
* @version 0.0.1
*/
public function fire($methodList, $args)
{
$methodList = is_array($methodList) ? $methodList : array($methodList);
$count = count($methodList);
for($i = 0; $i < $count; $i++)
{
if(method_exists($this, $methodList[$i]))
call_user_func_array(array($this, $methodList[$i]), $args);
}
}
/**
* @param Zend_Http_Client $client
* @param array $data
* @return Zend_Http_Client
* @author Se#
* @version 0.0.1
*/
protected function _setClientData(Zend_Http_CLient $client, $data)
{
foreach($data as $name => $value)
$client->setParameterPost($name, $value);
return $client;
}
/**
* @description check data for the required fields
* @throws Exception
* @param array $data
* @param array $required
* @return array
* @author Se#
* @version 0.0.1
*/
protected function _checkDataByRequired($data, $required)
{
/**
* FIXME: required and some more fields. not strict check
*/
$diff = array_diff_key($required, $data);
if(!empty($diff))
{
throw new Exception(' Missed some required parameters: ' . implode(', ', array_flip($diff)));
// echo '<pre>';
// print_r($data);
// print_r($required);
// die(' Missed some required parameters ');
}
/*
* TODO: realize type and other checking
*/
return $data;
}
/**
* @description get required fields for request
* @param array $args passed parameters
* @param array $config personal configuration
* @param array $default configuration
* @return array
* @author Se#
* @version 0.0.1
*/
protected function _getRequired($args, $config, $default = array())
{
$argsRequired = isset($args['required']) ? $args['required'] : array();
$configRequired = isset($config['required']) ? $config['required'] : array();
$defaultRequired = isset($default['required']) ? $default['required'] : array();
return $argsRequired + $configRequired + $defaultRequired;
}
/**
* @description get url for a request
* @param array $args passed parameters
* @param array $config personal do-configuration
* @param array $default configuration
* @return string
* @author Se#
* @version 0.0.1
*/
protected function _getUrl($args, $config, $default = array())
{
$base = isset($args['base']) ? // if passed through the arguments
$args['base'] :
(isset($config['base']) ? // if set in the personal do-config
$config['base'] :
(isset($default['base']) ? // if set default url
$default['base'] :
''));
$url = isset($args['url']) ? // if passed through the arguments
$args['url'] :
(isset($config['url']) ? // if set in the personal do-config
$config['url'] :
(isset($default['url']) ? // if set default url
$default['url'] :
''));
return $base . $url;
}
}