Hello all,
My credit card processor has decided to build another payment gateway so i have to make some changes to. So they sent me the following php code
PHP Code:
class dotGeneratorGateway
{
var $dataAll;
var $response;
function dotGeneratorGateway()
{
unset ($this->dataAll);
$this->dataAll = array(
'amount' => null,
'curr' => null,
'invoice_id' => null,
'order_desc' => null,
'merch_id' => null,
'timestamp' => null,
'nonce' => null,
);
}
function romcard_mac($data, $key = NULL)
{
$str = NULL;
foreach($data as $d)
{
if($d === NULL || strlen($d) == 0)
$str .= '-';
else
$str .= strlen($d) . $d;
}
if($key === NULL)
$key = "00112233445566778899AABBCCDDEEFF";
$key = pack('H*', $key);
return $this->hmacsha1($key, $str);
}
function hmacsha1($key,$data) {
$blocksize = 64;
$hashfunc = 'md5';
if(strlen($key) > $blocksize)
$key = pack('H*', $hashfunc($key));
$key = str_pad($key, $blocksize, chr(0x00));
$ipad = str_repeat(chr(0x36), $blocksize);
$opad = str_repeat(chr(0x5c), $blocksize);
$hmac = pack('H*', $hashfunc(($key ^ $opad) . pack('H*', $hashfunc(($key ^ $ipad) . $data))));
return bin2hex($hmac);
}
function getClientIp()
{
$private_net_ip_masks = array( '10.0.0.', '192.168.', '127.0.0.', '172.16.0.' );
if( isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '' )
{
$ipStrings = explode( ',',$_SERVER['HTTP_X_FORWARDED_FOR']);
foreach($ipStrings as $k => $v)
{
if( empty($v) )
{
unset( $ipStrings[$k] );
}
else
{
if(!isset($ipString)) $ipString = $v;
}
}
}
if( isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '' )
{
$ipStrings[] = $_SERVER['REMOTE_ADDR'];
if(!isset($ipString)) $ipString = $_SERVER['REMOTE_ADDR'];
}
foreach($ipStrings as $k1 => $ip)
{
foreach($private_net_ip_masks as $k2 => $pip)
{
if(strpos($ip, $pip) === 0)
{
unset($ipStrings[$k1]);
break;
}
}
}
return implode(",",$ipStrings);
}
function startTransaction($dMerchant_id, $dAmount, $dCurrency, $dInvoice_id, $dInvoice_description)
{
$defined_vars = get_defined_vars();
$this->dotGeneratorGateway();
$this->dataAll['amount']=$dAmount;
$this->dataAll['curr']=$dCurrency;
$this->dataAll['invoice_id']=$dInvoice_id;//str_pad($dInvoice_id, 7, '0', STR_PAD_LEFT)
$this->dataAll['order_desc']=$dInvoice_description;
$this->dataAll['merch_id']=$dMerchant_id;
$this->dataAll['timestamp']=gmdate("YmdHis");
$this->dataAll['nonce']=md5(microtime() . mt_rand());
$this->dataAll['fp_hash']=strtoupper($this->romcard_mac($this->dataAll));
$this->dataAll['ip_client']=$this->getClientIp();
$formvars= array();
$host = "host";
$port = 443;
$path = "/tdsprocess/verify.php";
foreach($this->dataAll AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 30);
if(!$fp){
echo "$errstr ($errno)\n";
}else{
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
$res="";
while(!feof($fp)) {
$res.=fgets($fp, 4096);
}
fclose($fp);
}
echo $res;
}
}
So i have to call the function startTransaction something like this :
PHP Code:
startTransaction('my_company', $amount, 'USD', 'invoice_nr', 'NONE');
The question is where ?
I tried to insert this php code in my php form but when i call the function outside the class { } it says that the function doesn`t exist. If i remove the class { } so it will remain just the functions it will give me an error with those vars at the beggining. Does someone know how can i call the function?