Repository navigation
Expand file tree
/
Copy pathPluginQuantum.php
More file actions
355 lines (322 loc) · 19 KB
/
Copy pathPluginQuantum.php
File metadata and controls
355 lines (322 loc) · 19 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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<?php
require_once 'modules/admin/models/GatewayPlugin.php';
require_once 'library/CE/XmlFunctions.php';
class PluginQuantum extends GatewayPlugin
{
function getVariables()
{
$variables = array (
lang('Plugin Name') => array (
'type' =>'hidden',
'description' =>lang('How CE sees this plugin (not to be confused with the Signup Name)'),
'value' =>lang('Quantum Gateway')
),
lang('Use Verify By Visa and MasterCard SecureCode') => array(
'type' =>'yesno',
'description' =>lang('Be sure to have these services enabled in your gateway before attempting to use them.'),
'value' =>0,
),
lang('Use DialVerify Service') => array(
'type' =>'yesno',
'description' =>lang('Be sure to have this service enabled in your gateway before attempting to use it.'),
'value' =>0,
),
lang('Use Maxmind') => array(
'type' =>'yesno',
'description' =>lang('Use Quantum Gateway\'s Maxmind fraud screening services.'),
'value' =>0,
),
lang('Quantum Gateway Username') => array (
'type' =>'text',
'description' =>lang('Please enter your Quantum Gateway Username Here.'),
'value' =>''
),
lang('Quantum Gateway RestrictKey') => array (
'type' =>'password',
'description' =>lang('Please enter your Quantum Gateway RestrictKey Here.'),
'value' =>''
),
lang('Accept CC Number') => array (
'type' =>'hidden',
'description' =>lang('Selecting YES allows the entering of CC numbers when using this plugin type. No will prevent entering of cc information'),
'value' =>'1'
),
lang('Visa') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow Visa card acceptance with this plugin. No will prevent this card type.'),
'value' =>'1'
),
lang('MasterCard') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow MasterCard acceptance with this plugin. No will prevent this card type.'),
'value' =>'1'
),
lang('AmericanExpress') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow American Express card acceptance with this plugin. No will prevent this card type.'),
'value' =>'1'
),
lang('Discover') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow Discover card acceptance with this plugin. No will prevent this card type.'),
'value' =>'0'
),
lang('Invoice After Signup') => array (
'type' =>'yesno',
'description' =>lang('Select YES if you want an invoice sent to the client after signup is complete.'),
'value' =>'1'
),
lang('Signup Name') => array (
'type' =>'text',
'description' =>lang('Select the name to display in the signup process for this payment type. Example: eCheck or Credit Card.'),
'value' =>'Credit Card'
),
lang('Payment Form Title') => array(
'type' =>'text',
'description' =>lang('The Payment Form will only be displayed when extra user input is required, i.e. when using Verified By Visa, MaterCard SecureCode or DialVerify.'),
'value' =>''
),
lang('Payment Form Header') => array(
'type' =>'textarea',
'description' =>lang('The Payment Form will only be displayed when extra user input is required, i.e. when using Verified By Visa, MaterCard SecureCode or DialVerify. HTML is accepted.'),
'value' =>''
),
lang('Receipt Page Header') => array(
'type' =>'textarea',
'description' =>lang('The Receipt Page will only be displayed when extra user input is required, i.e. when using Verified By Visa, MaterCard SecureCode or DialVerify. HTML is accepted.'),
'value' =>''
),
lang('Receipt Page Footer') => array(
'type' =>'textarea',
'description' =>lang('The Receipt Footer will only be displayed when extra user input is required, i.e. when using Verified By Visa, MaterCard SecureCode or DialVerify. HTML is accepted.'),
'value' =>''
),
lang('Dummy Plugin') => array (
'type' =>'hidden',
'description' =>lang('1 = Only used to specify a billing type for a client. 0 = full fledged plugin requiring complete functions'),
'value' =>'0'
),
lang('Auto Payment') => array (
'type' =>'hidden',
'description' =>lang('No description'),
'value' =>'1'
),
lang("Check CVV2") => array (
"type" =>"yesno",
"description" =>lang("Select YES if you want to accept CVV2 for this plugin."),
"value" =>"1"
)
);
return $variables;
}
function singlepayment($params)
{
include_once 'library/CE/NE_Network.php';
// VbV/MCSC and Dialverify (only used in signup) require some interaction from the user with the provider server,
// so if those aren't set up then use autopayment which is silent.
if (!$params['isSignup'] || (!$params['plugin_quantum_Use Verify By Visa and MasterCard SecureCode'] && !$params['plugin_quantum_Use DialVerify Service'])) {
return $this->autopayment($params);
}
$params = CE_Lib::_array_map_recursive(array('CE_Lib', 'escapeHTMLAttributeValue'), $params);
$callbackURL = mb_substr($params['clientExecURL'], -1, 1) == '//' ? $params['clientExecURL']."plugins/gateways/quantum/callback.php" : $params['clientExecURL']."/plugins/gateways/quantum/callback.php";
$CCMo = mb_substr($params['userCCExp'], 0, 2);
$CCYear = mb_substr($params['userCCExp'], 3);
$useMaxmind = $params['plugin_quantum_Use Maxmind']? 1 : 2;
$html = "<html>\n<head>\n</head>\n<body>\n"
."<form name=\"frmQuantumGateway\" action=\"https://secure.quantumgateway.com/cgi/clientexec.php\" method=\"post\">\n"
."<input type=\"hidden\" name=\"gwlogin\" value=\"{$params['plugin_quantum_Quantum Gateway Username']}\">\n"
."<input type=\"hidden\" name=\"RestrictKey\" value=\"{$params['plugin_quantum_Quantum Gateway RestrictKey']}\">\n"
."<input type=\"hidden\" name=\"post_return_url\" value=\"$callbackURL\">\n"
."<input type=\"hidden\" name=\"ResponseMethod\" value=\"GET\" />\n"
."<input type=\"hidden\" name=\"ID\" value=\"{$params['userID']}\">\n"
."<input type=\"hidden\" name=\"customer_ip\" value=\"".CE_Lib::getRemoteAddr()."\">\n"
."<input type=\"hidden\" name=\"amount\" value=\"{$params['invoiceTotal']}\">\n"
."<input type=\"hidden\" name=\"FNAME\" value=\"{$params['userFirstName']}\">\n"
."<input type=\"hidden\" name=\"LNAME\" value=\"{$params['userLastName']}\">\n"
."<input type=\"hidden\" name=\"BADDR1\" value=\"{$params['userAddress']}\">\n"
."<input type=\"hidden\" name=\"BZIP1\" value=\"{$params['userZipcode']}\">\n"
."<input type=\"hidden\" name=\"BCITY\" value=\"{$params['userCity']}\">\n"
."<input type=\"hidden\" name=\"BCUST_EMAIL\" value=\"{$params['userEmail']}\">\n"
."<input type=\"hidden\" name=\"BSTATE\" value=\"{$params['userState']}\">\n"
."<input type=\"hidden\" name=\"BCOUNTRY\" value=\"{$params['userCountry']}\">\n"
."<input type=\"hidden\" name=\"phone\" value=\"{$params['userPhone']}\">\n"
."<input type=\"hidden\" name=\"trans_method\" value=\"CC\">\n"
."<input type=\"hidden\" name=\"ccnum\" value=\"{$params['userCCNumber']}\">\n";
// TAKEN FROM: http://www.quantumgateway.com/view_developer.php?Cat1=2
if ($params['userCCCVV2'] != '') {
// CVV - CVV2
// Security code on the back or front of the credit card
$html .= "<input type=\"hidden\" name=\"CVV2\" value=\"{$params['userCCCVV2']}\">\n";
// Type Of CVV2 being sent - CVVtype
// 0 - Not Passing CVV2
// 1 - CVV2 is being passed
// 2 - CVV2 on card is unreadable
// 9 - Card does not have CVV2 imprint
$html .= "<input type=\"hidden\" name=\"CVVtype\" value=\"1\">\n";
}
$html .= "<input type=\"hidden\" name=\"ccmo\" value=\"$CCMo\">\n"
."<input type=\"hidden\" name=\"ccyr\" value=\"$CCYear\">\n"
."<input type=\"hidden\" name=\"invoice_num\" value=\"{$params['invoiceNumber']}\">\n"
."<input type=\"hidden\" name=\"invoice_description\" value=\"{$params['invoiceDescription']}\">\n"
."<input type=\"hidden\" name=\"MAXMIND\" value=\"$useMaxmind\">\n"
."<input type=\"hidden\" name=\"page_heading\" value=\"{$params['plugin_quantum_Payment Form Title']}\">\n"
."<input type=\"hidden\" name=\"payment_heading\" value=\"{$params['plugin_quantum_Payment Form Header']}\">\n"
."<input type=\"hidden\" name=\"header_receipt\" value=\"{$params['plugin_quantum_Receipt Page Header']}\">\n"
."<input type=\"hidden\" name=\"footer_receipt\" value=\"{$params['plugin_quantum_Receipt Page Footer']}\">\n"
."<script language=\"JavaScript\">\n"
." document.forms['frmQuantumGateway'].submit();\n"
."</script>\n"
."</form>\n</body>\n</html>\n";
echo $html;
exit;
}
function autopayment($params)
{
include_once 'modules/billing/models/class.gateway.plugin.php';
include_once 'library/CE/NE_Network.php';
$requestArr = array(
'gwlogin' => $params['plugin_quantum_Quantum Gateway Username'],
'trans_method' => 'CC',
'cust_id' => $params['userID'],
'customer_ip' => CE_Lib::getRemoteAddr(),
'invoice_num' => $params['invoiceNumber'],
'invoice_description' => $params['invoiceDescription'],
'ccnum' => $params['userCCNumber'],
'ccmo' => mb_substr($params['userCCExp'], 0, 2),
'ccyr' => mb_substr($params['userCCExp'], 3),
'amount' => $params['invoiceTotal'],
'BADDR1' => $params['userAddress'],
'BCITY' => $params['userCity'],
'BSTATE' => $params['userState'],
'BCOUNTRY' => $params['userCountry'],
'BZIP1' => $params['userZipcode'],
'BCUST_EMAIL' => $params['userEmail'],
'phone' => $params['userPhone'],
'RestrictKey' => $params['plugin_quantum_Quantum Gateway RestrictKey'],
'FNAME' => $params['userFirstName'],
'LNAME' => $params['userLastName'],
'MAXMIND' => ($params['plugin_quantum_Use Maxmind'] && $params['isSignup'])? 1 : 2,
'post_return_url' => mb_substr($params['clientExecURL'], -1, 1) == '//' ? $params['clientExecURL']."plugins/gateways/quantum/callback.php" : $params['clientExecURL']."/plugins/gateways/quantum/callback.php",
'ResponseMethod' => 'GET', // not sure this is needed here, but just in case...
);
$cPlugin = new Plugin($params['invoiceNumber'], "", $this->user);
if (isset($params['refund']) && $params['refund']) {
$isRefund = true;
$cPlugin->setAction('refund');
$requestArr['trans_type'] = 'RETURN';
} else {
$isRefund = false;
$cPlugin->setAction('charge');
}
$request = '';
$firstIteration = true;
foreach ($requestArr as $var => $value) {
if (!$firstIteration) {
$request .= '&';
}
$request .= "$var=".urlencode($value);
$firstIteration = false;
}
$masks = array(
'gwlogin=XXX_MASKED_XXX&' => '/gwlogin=\w+&/',
'RestrictKey=XXX_MASKED_XXX&' => '/RestrictKey=\w+&/',
'ccnum=XXX_MASKED_XXX&' => '/ccnum=\d+&/',
'ccmo=XXX_MASKED_XXX&' => '/ccmo=\d+&/',
'ccyr=XXX_MASKED_XXX&' => '/ccyr=\d+&/',
'CVV2=XXX_MASKED_XXX&' => '/CVV2=\d+&/'
);
$response = NE_Network::curlRequest($this->settings, 'https://secure.quantumgateway.com/cgi/clientexecT.php', $request, false, false, false, 'POST', false, $masks);
// response is a "|"-separated string for payments, and just a string for refunds...
if (!$isRefund) {
$response = explode("|", trim($response));
$transactionID = mb_substr($response[2], 1, -1);
} else {
$transactionID = $params['invoiceRefundTransactionId'];
}
$cPlugin->setAmount($params['invoiceTotal']);
$cPlugin->setTransactionID($transactionID);
if (!$isRefund && $response[0] != '"APPROVED"') {
$cPlugin->setAction('charge');
$cPlugin->PaymentRejected("Quantum Gateway payment of {$params['invoiceTotal']} was rejected.");
return 'Payment rejected by credit card gateway provider';
}
if ($isRefund && strpos($response, 'APPROVED') === false) {
$cPlugin->setAction('refund');
$cPlugin->PaymentRejected("Quantum Gateway refund of {$params['invoiceTotal']} was rejected.");
return 'Refund rejected by credit card gateway provider';
}
if ($isRefund) {
$cPlugin->setAction('refund');
$cPlugin->PaymentAccepted($params['invoiceTotal'], "Quantum Gateway refund of {$params['invoiceTotal']} was successfully processed.", $transactionID);
return array('AMOUNT' => $params['invoiceTotal']);
} else {
$cPlugin->setAction('charge');
$cPlugin->PaymentAccepted($params['invoiceTotal'], "Quantum Gateway payment of {$params['invoiceTotal']} was accepted.", $transactionID);
return '';
}
}
function credit($params)
{
$params['refund'] = true;
return $this->autopayment($params);
}
function ShowTransactionDetails($params)
{
$GatewayKey = $params['plugin_quantum_Quantum Gateway RestrictKey'];
$RequestType = "ShowTransactionDetails";
$paramsArray = array(
"TransactionID" => $params['TransactionID'],
);
return $this->XMLrequest($params, $GatewayKey, $RequestType, $paramsArray);
}
function XMLrequest($params, $GatewayKey, $RequestType, $paramsArray)
{
$url = "https://secure.quantumgateway.com/cgi/xml_requester.php";
$xml = "<QGWRequest>\n";
$xml .= " <Authentication>\n";
$xml .= " <GatewayLogin>".$params['plugin_quantum_Quantum Gateway Username']."</GatewayLogin>\n";
$xml .= " <GatewayKey>".$GatewayKey."</GatewayKey>\n";
$xml .= " </Authentication>\n";
$xml .= " <Request>\n";
$xml .= " <RequestType>".$RequestType."</RequestType>\n";
foreach ($paramsArray as $paramName => $paramValue) {
$xml .= " <".$paramName;
if ($paramValue != '') {
$xml .= ">".$paramValue."</".$paramName.">\n";
} else {
$xml .= "/>\n";
}
}
$xml .= " </Request>\n";
$xml .= "</QGWRequest>\n";
/*$header = array(
"POST ".$url." HTTP/1.1",
"Content-Length: ".strlen($xml),
"Content-type: text/xml; charset=UTF8",
"Connection: close; Keep-Alive",
);*/
$mask = array(
'<GatewayLogin>XXX MASKED XXX</GatewayLogin>' => '/<GatewayLogin>(.*)<\/GatewayLogin>/',
'<GatewayKey>XXX MASKED XXX</GatewayKey>' => '/<GatewayKey>(.*)<\/GatewayKey>/'
);
$response = NE_Network::curlRequest($this->settings, $url, $xml, false, false, false, 'POST', false, $mask);
if ($response) {
$response = XmlFunctions::xmlize(
str_replace(
array(
'&',
'á','é','í','ó','ú',
'Á','É','Í','Ó','Ú'
),
array(
'&',
'a','e','i','o','u',
'A','E','I','O','U'
),
$response
)
);
}
return $response;
}
}