Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-19-2005, 01:08 PM PHP code
Raulică's Avatar
Ultra Talker

Posts: 253
Location: Constanta,Romania
Trades: 0
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$blocksizechr(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($poststring0, -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($fp4096);
            }
            
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?
__________________

Please login or register to view this content. Registration is FREE

Professional hosting for all pockets!

Please login or register to view this content. Registration is FREE
Raulică is offline
Reply With Quote
View Public Profile Visit Raulică's homepage!
 
 
Register now for full access!
Old 04-19-2005, 02:54 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Its called object oriented programming and PHP uses it poorly (at least in 4), here is what you need to do though.

PHP Code:
<?php
// Create an new instance of the dotGeneratorGateway object (class)
$objGateway = new dotGeneratorGateway;

// Now we can access this objects methods through the object we just created
$objGateway->startTransaction('my_company'$amount'USD''invoice_nr''NONE');

?>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP code
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11729 seconds with 12 queries