-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginRealauth.php
More file actions
458 lines (390 loc) · 19.9 KB
/
PluginRealauth.php
File metadata and controls
458 lines (390 loc) · 19.9 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<?php
require_once 'modules/admin/models/GatewayPlugin.php';
require_once 'library/CE/XmlFunctions.php';
require_once 'modules/billing/models/class.gateway.plugin.php';
require_once 'library/CE/NE_Network.php';
require_once 'modules/billing/models/Currency.php';
require_once 'modules/billing/models/CreditCard.php';
class PluginRealauth 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('RealAuth Gateway')
),
lang('RealAuth Merchant ID') => array (
'type' =>'text',
'description' =>lang('Please enter your Realex Payments Assigned Merchant ID Here.'),
'value' =>''
),
lang('RealAuth Shared Secret') => array (
'type' =>'password',
'description' =>lang('Please enter your Realex Payments Shared Secret Here.'),
'value' =>''
),
lang('RealAuth Subaccount') => array (
'type' =>'text',
'description' =>lang('Please enter your Realex Payments Subaccount to use 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('LaserCard') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow LaserCard card acceptance with this plugin. No will prevent this card type.'),
'value' =>'1'
),
lang('DinersClub') => array (
'type' =>'yesno',
'description' =>lang('Select YES to allow Diners Club card acceptance with this plugin. No will prevent this card type.'),
'value' =>'1'
),
// lang('Switch') => array (
// 'type' =>'yesno',
// 'description' =>lang('Select YES to allow Switch card acceptance with this plugin. No will prevent this card type.'),
// 'value' =>'1'
// ),
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" =>"hidden",
"description" =>lang("Select YES if you want to accept CVV2 for this plugin."),
"value" =>"0"
),
// lang("Check Issue Number") => array (
// "type" =>"hidden",
// "description" =>lang("Please enter a list of the credit card types, separated by comma, that you want to accept Issue Number for this plugin."),
// "value" =>"Switch" //"Visa,MasterCard,AmericanExpress,Discover,LaserCard,DinersClub,Switch"
// ),
);
return $variables;
}
function singlepayment($params)
{
return $this->autopayment($params);
}
function autopayment($params)
{
$cPlugin = new Plugin($params['invoiceNumber'], "realauth", $this->user);
$cPlugin->setAmount($params['invoiceTotal']);
//Creates timestamp that is needed to make up orderid
$timestamp = strftime("%Y%m%d%H%M%S");
//You can use any alphanumeric combination for the orderid.Although each transaction must have a unique orderid.
$orderid = $timestamp."-".$params['invoiceNumber'];
$cPlugin->setTransactionID($orderid);
if (isset($params['refund']) && $params['refund']) {
$isRefund = true;
$cPlugin->setAction('refund');
$response = $this->PlaceRealexRefund($params, $timestamp, $orderid);
} else {
$isRefund = false;
$cPlugin->setAction('charge');
$response = $this->PlaceRealexPayment($params, $timestamp, $orderid);
}
if (!$response) {
$cPlugin->PaymentRejected($this->user->lang("There was not response from RealAuth. Please double check your information"));
return $this->user->lang("There was not response from RealAuth. Please double check your information");
}
if (is_a($response, 'CE_Error')) {
$cPlugin->PaymentRejected($this->user->lang("There was an error performing this operation.")." ".$response->getMessage());
return $this->user->lang("There was an error performing this operation.")." ".$response->getMessage();
}
if (isset($response['response']['#']['result'][0]['#'])) {
if ($isRefund) {
if ($response['response']['#']['result'][0]['#'] == '00') {
$cPlugin->PaymentAccepted($params['invoiceTotal'], "RealAuth refund of {$params['invoiceTotal']} was successfully processed.", $orderid);
return array('AMOUNT' => $params['invoiceTotal']);
} else {
$rejectDetails = '';
if (isset($response['response']['#']['message'][0]['#'])) {
$rejectDetails = ' '.$response['response']['#']['message'][0]['#'];
}
$cPlugin->PaymentRejected("RealAuth refund of {$params['invoiceTotal']} was rejected.".$rejectDetails);
return 'Refund rejected by credit card gateway provider';
}
} else {
if ($response['response']['#']['result'][0]['#'] == '00') {
$cPlugin->PaymentAccepted($params['invoiceTotal'], "RealAuth payment of {$params['invoiceTotal']} was accepted.", $orderid);
return '';
} else {
$rejectDetails = '';
if (isset($response['response']['#']['message'][0]['#'])) {
$rejectDetails = ' '.$response['response']['#']['message'][0]['#'];
}
$cPlugin->PaymentRejected("RealAuth payment of {$params['invoiceTotal']} was rejected.".$rejectDetails);
return 'Payment rejected by credit card gateway provider';
}
}
} else {
$cPlugin->PaymentRejected($this->user->lang("The response from RealAuth was not recognized."));
return $this->user->lang("The response from RealAuth was not recognized.");
}
}
public function credit($params)
{
return $this->user->lang("This payment gateway does not support refunds.");
}
// function credit($params)
// {
// $params['refund'] = true;
// return $this->autopayment($params);
// }
function PlaceRealexPayment($params, $timestamp, $orderid)
{
$currency = new Currency($this->user);
$amount = $currency->format($params['currencytype'], $params['invoiceTotal'], false)*pow(10, $currency->getPrecision($params["currencytype"]));
$currencyCode = $params["currencytype"];
$cardnumber = $params['userCCNumber'];
$cardname = mb_substr(trim($params['userFirstName'].' '.$params['userLastName']), 0, 100);
$cardtype = $this->getCreditCardType($cardnumber);
$CCMo = mb_substr($params['userCCExp'], 0, 2);
$CCYear = mb_substr($params['userCCExp'], 5, 2);
$expdate = $CCMo.$CCYear;
// These values will be provided to you by realex Payments, if you have not already received them please contact us
$merchantid = $params['plugin_realauth_RealAuth Merchant ID'];
$secret = $params['plugin_realauth_RealAuth Shared Secret'];
$account = $params['plugin_realauth_RealAuth Subaccount'];
$url = "https://epage.payandshop.com/epage-remote.cgi";
$xml = "<request type='auth' timestamp='".$timestamp."'>\n";
$xml .= " <merchantid>".$merchantid."</merchantid>\n";
/*
Represents the Realex Payments subaccount to use.
If this element is omitted, then the default account is used.
*/
$xml .= " <account>".$account."</account>\n";
/*
Length 1-40
*/
$xml .= " <orderid>".$orderid."</orderid>\n";
/*
The amount should be in the smallest unit of the required currency
(For example: 2000 = �20, $20 or �20).
*/
$xml .= " <amount currency='".$currencyCode."'>".$amount."</amount>\n";
$xml .= " <card>\n";
$xml .= " <number>".$cardnumber."</number>\n";
/*
Represets the card expiry date, in the format MMYY, which must be a date in the future.
*/
$xml .= " <expdate>".$expdate."</expdate>\n";
/*
VISA, MC, AMEX, LASER, DINERS, SWITCH
*/
$xml .= " <type>".$cardtype."</type>\n";
/*
Format 0-9
Length 0-3
Where 1 represents the issue number of a SWITCH.
Only required if the card type is SWITCH.
*/
// if($cardtype == 'SWITCH'){
// $xml .= " <issueno>1</issueno>\n";
// }
/*
Length 0-100
*/
$xml .= " <chname>".$cardname."</chname>\n";
/*
The card verification details element
*/
//$xml .= " <cvn>\n";
/*
Format 0-9
Length 3-4
Where 123 represents the Card Verification Number (CVN), which is a
three-digit number on the reverse of the card.
It is called the CVC for VISA and the CVV2 for MasterCard.
For an AMEX card, it is a four-digit number.
*/
//$xml .= " <number>123</number>\n";
/*
Where presence_indicator represents the presence of the CVN and can take the
following four values:
1: CVN present
2: CVN illegible
3: CVN not on card
4: CVN not requested by the Merchant
*/
//$xml .= " <presind>presence_indicator</presind>\n";
//$xml .= " </cvn>\n";
$xml .= " </card>\n";
$xml .= " <comments>\n";
$xml .= " <comment id='1'>Customer ID: ".$params['userID']."</comment>\n";
$xml .= " <comment id='2'>Invoice ID: ".$params['invoiceNumber']."</comment>\n";
$xml .= " </comments>\n";
$xml .= " <autosettle flag='1'/>\n";
/*
Format a-f 0-9
Length 40
Where SHA_1_hash represents the SHA-1 hash of certain elements of the request.
For more information, see the Realauth Developer's Guide. Either the SHA-1 hash
or the MD5 hash can be used.
*/
//$xml .= " <sha1hash>SHA_1_hash</sha1hash>\n";
// This section of code creates the md5hash that is needed
$tmp = "$timestamp.$merchantid.$orderid.$amount.$currencyCode.$cardnumber";
$md5hash = md5($tmp);
$tmp = "$md5hash.$secret";
$md5hash = md5($tmp);
$xml .= " <md5hash>".$md5hash."</md5hash>\n";
$xml .= " <tssinfo>\n";
$xml .= " <custnum>".$params['userID']."</custnum>\n";
$xml .= " <prodid>".$params['invoiceNumber']."</prodid>\n";
/*
Format a-z A-Z 0-9 - "" _ . , + @
Length 0-50
Where variable_reference represents any reference assigned to the customer,
which can allow checking of previous transactions by this customer, through
the use of the Realscore service.
*/
//$xml .= " <varref>variable_reference</varref>\n";
/*
Format 0-9 IP Address in X.X.X.X format
Length [1-3].{1-3}.{1-3}.{1-3}
Where www.xxx.yyy.zzz represents the IP address of the customer.
*/
//$xml .= " <custipaddress>www.xxx.yyy.zzz</custipaddress>\n";
$xml .= " <custipaddress>".CE_Lib::getRemoteAddr()."</custipaddress>\n";
/*
The billing address of the customer
*/
$xml .= " <address type=\"billing\">\n";
/*
Format a-z A-Z 0-9 "" , . - / |
Length 0-30
Where zip_postal_code represents the ZIP or Postal code of the billing address,
which is useful for checking (in conjunction with the country) against a table
of high-risk areas.
*/
//$xml .= " <code>zip_postal_code</code>\n";
$xml .= " <code>".$params['userZipcode']."</code>\n";
/*
Format a-z A-Z 2-character country code
Length 2
Where country represents the country of the billing address, which is useful for
checking against a table of high-risk countries.
*/
//$xml .= " <country>country</country>\n";
$xml .= " <country>".$params['userCountry']."</country>\n";
$xml .= " </address>\n";
/*
The shipping address of the customer
*/
$xml .= " <address type=\"shipping\">\n";
/*
Format a-z A-Z 0-9 "" , . - / |
Length 0-30
Where zip_postal_code represents the ZIP or Postal code of the shipping address,
which is useful for checking (in conjunction with the country) against a table
of high-risk areas.
*/
//$xml .= " <code>zip_postal_code</code>\n";
$xml .= " <code>".$params['userZipcode']."</code>\n";
/*
Format a-z A-Z 2-character country code
Length 2
Where country represents the country of the shipping address, which is useful for
checking against a table of high-risk countries.
*/
//$xml .= " <country>country</country>\n";
$xml .= " <country>".$params['userCountry']."</country>\n";
$xml .= " </address>\n";
$xml .= " </tssinfo>\n";
$xml .= "</request>\n";
$header = array("POST ".$url." HTTP/1.1",
"Content-Length: ".strlen($xml),
"Content-type: text/xml; charset=UTF8",
"Connection: close; Keep-Alive",
);
$response = NE_Network::curlRequest($this->settings, $url, $xml, $header, true);
if ($response && !is_a($response, 'CE_Error')) {
$response = XmlFunctions::xmlize($response);
}
return $response;
}
function PlaceRealexRefund($params, $timestamp, $orderid)
{
//THIS PLUGIN DOES NOT REFUND YET
}
function getCreditCardType($cardnumber)
{
$cards = array(
'VISA' => 'Visa',
'MC' => 'MasterCard',
'AMEX' => 'American Express',
'LASER' => 'LaserCard',
'DINERS' => 'Diners Club',
'SWITCH' => 'Switch'
);
$cardtype = 'UNKNOW';
$cc = new CreditCard();
foreach ($cards as $key => $card) {
$errornumber = '';
$errortext = '';
if ($cc->checkCreditCard($cardnumber, $card, $errornumber, $errortext)) {
$cardtype = $key;
break;
}
}
return $cardtype;
}
}