Repository navigation
Expand file tree
/
Copy pathPayment2.php
More file actions
310 lines (285 loc) · 7.24 KB
/
Copy pathPayment2.php
File metadata and controls
310 lines (285 loc) · 7.24 KB
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**
* M PHP Framework
*
* @package M
* @subpackage Payment
* @author Arnaud Sellenet <demental at github>
* @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License
* @version 0.1
*/
/**
*
* Credit card payment process abstraction - draft (currently includes a driver for ATOS SIPS)
*
*/
class Payment2 {
protected static $driverpaths = array('M/Payment2/Driver/');
protected $_analysisSummary;
protected $__name;
public static final function &factory($driver)
{
$success = false;
$className = 'Payment_Driver_'.ucfirst($driver);
$baseName = strtolower($driver).'.php';
if($success) {
$res = new $className();
$res->__name = $driver;
return $res;
} else {
throw new Exception('Payment :: '.$driver.' driver not found !');
}
}
public final function getName() {
return $this->__name;
}
public static final function addDriverPath($path)
{
if(substr($path,-1,1)!='/') {
$path.='/';
}
array_unshift(self::$driverpaths,$path);
}
/**
* Creates configuration from a string (serialized data by default)
*/
public function setConfigFromString($string){
$config = unserialize($string);
if(is_array($config)) {
foreach($config as $k=>$v) {
$this->setOption($k,$v);
}
}
}
public function setOption($ky,$val)
{
$this->_options[$ky] = $val;
}
public function getOption($ky) {
return $this->_options[$ky];
}
public function getOptions()
{
return $this->_options;
}
/**
* Retreives the configuration to a string (that can be stored in a database field for example)
* This string can then be retreived with setConfigFromString
*/
public function getConfigToString() {
return serialize($this->_options);
}
/**
* Set a language for payment interface (iso2)
*/
public function setLanguage($l)
{
$this->setOption('language',$l);
}
/**
* Set a currency for payment (3 letters)
*/
public function setCurrency($c)
{
$this->setOption('currency',$c);
}
public function setSuccessUrl($url)
{
$this->setOption('success_url',$url);
}
public function setErrorUrl($url)
{
$this->setOption('error_url',$url);
}
public function setAutoresponseUrl($url)
{
$this->setOption('autoresponse_url',$url);
}
/**
* Adds fields to a HTML_QuickForm to configure this driver.
* Additionnaly A prefix can be prepended to field names
*/
public function createConfigForm(HTML_QuickForm $form,$prefix=''){
$this->_configprefix = $prefix;
foreach($this->_options as $key=>$value) {
$form->addElement('text',$prefix.$key,$key);
$defaults[$prefix.$key] = $value;
}
}
/**
* retreives and creates configuration from exported form values.
* If a prefix was set previously with configForm(), it's taken in account
*/
public function processConfigForm($values) {
foreach($values as $k=>$v) {
if(strpos($k, $this->_configprefix) !== 0) continue;
$this->_options[ereg_replace('^'.$this->_configprefix,'',$k)] = $v;
}
}
/**
* Attach a transaction to this payment. Tipically a database record.
* Allows to store result of the transaction
*/
public final function setTransaction(iTransaction $transaction) {
$this->_transaction = $transaction;
}
public final function getTransaction() {
return $this->_transaction;
}
/**
* @return bool
* wether the payment was accepted
*/
public function isAccepted() {
return $this->getResponse()->statuscode=='00';
}
/**
* @return bool
* wether the payment gateway did not give its final response yet
*/
public function isPending() {
return $this->getResponse()->statuscode=='pending';
}
/**
* Returns a unified status code (at least for accepted) :
* 00 for payment accepted
*/
public function getStatusCode() {
return $this->getResponse()->statuscode;
}
/**
* Renders and returns an HTML block that must be printed to the enduser
*/
public function getPublicBlock() {
return '';
}
/**
* HTML form that must be printed to the admin user
* usage : call centers & check payments
*/
public function getPrivateForm(HTML_QuickForm $form) {
return $form;
}
/**
* Processes data received from private form
*/
public function processPrivateForm($data)
{
return;
}
/**
* Sets the response raw data (tipically $_REQUEST) from the payment gateway
*/
public function parseResponse($response) {
$this->_rawresponse = $response;
$_response = new Payment_Response($this);
$this->_response = $_response;
return $this;
}
/**
* Gets the response raw data (if previously set in setRawResponse)
*/
public final function getRawResponse() {
return $this->_rawresponse;
}
public final function getResponse()
{
if(!is_a($this->_response,'Payment_Response')) {
return false;
}
return $this->_response;
}
public final function execute()
{
if($this->isAccepted()) {
$this->getTransaction()->success($this);
} else {
$this->getTransaction()->error($this);
}
}
/**
* Returns a human-readable strings that reflects the current payment mode (example : "credit card")
* @return string
*/
public function getMode()
{
return;
}
/**
* Returns a human-readable strings that reflects the current payment mode.
* This method must return a more precise definition
* (example : "credit card with thawte analysis")
* @return string
*/
public function getDetailedMode()
{
return;
}
/**
* Returns the unique identifier of the payment.
* It can be determined either by the payment gateway or by the local
* workflow (e.g. database record id)
*/
public function getId()
{
return;
}
// ==========================================================
// = Analysis section (e.g. fia-net is an analysis service)
// = Analysis is provided by third-party companies AFTER payment is being valid.
// ==========================================================
/**
* Wether this payment includes an analysis part.
* @return bool
*/
public function hasAnalysis()
{
return false;
}
/**
* If there is a post-acceptance transaction analysis, isValid can be used for
* this
* @return bool
*/
public function isValid() {
return $this->isAccepted();
}
/**
* if the payment was accepted, sends a request to the analysis gateway
* for the transaction.
* @return bool
*/
public function requestAnalysis() {
$this->getTransaction()->tagAsAnalysisSent($this);
}
/**
* Query the analysis gateway to update the validity status, if applicable
* returns true if analysis was updated since last query, false otherwise.
* @return bool
*/
public function updateAnalysis() {
return;
}
/**
* Returns a link to an analysis detail page, if applicable.
* @return string (url)
*/
public function getAnalysisUrl() {
return;
}
/**
* Returns a text summary of the current analysis
* @return string
*/
public function getAnalysisSummary()
{
return $this->_analysisSummary;
}
/**
* Debugging
*/
public function debug($message)
{
# code...
}
}