Quick Search:
 
 PHP Code: CyberCash payment class Jump to:  
Category: >> PHP Code >> CyberCash payment class  

<< lastnext >>

Snippet Name: CyberCash payment class

Description: A class for doing payments to a CyberCash server.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: March 01st, 2009

<?PHP
CLASS  payment 
{ 
        VAR  $name,  $street,  $city,  $state,  $zip,  $country; 
        VAR  $type,  $merchant_secret; 
        VAR  $card_no,  $card_exp; 
 
        /*Construction*/ 
        VAR  $method= "POST"; 
        VAR  $host= "localhost"; 
        VAR  $port=8000; 
        VAR  $http_version= "HTTP/1.0"; 
        VAR  $type= "mauthonly"; 
        /*End  Construction*/ 
 
        FUNCTION  make_content($order_no,  $amount) 
        { 
                $content= "order-id="+(string)$order_no+ "&"; 
                $content=$content+ "amount=usd+"+$amount+ "&"; 
                $content=$content+ "card-number="+$this->card_no+ "&"; 
                $content=$content+ "card-name="+$this->name+ "&"; 
                $content=$content+ "card-address="+$this->street+ "&"; 
                $content=$content+ "card-city="+$this->city+ "&"; 
                $content=$content+ "card-state="+$this->state+ "&"; 
                $content=$content+ "card-zip="+$this->zip+ "&"; 
                $content=$content+ "card-exp="+$this->card_exp+ "&"; 
                $content=$content+ "card-country="+$this->country; 
 
                RETURN  $content; 
        } 
 
        FUNCTION  make_request($order_no,  $amount) 
        { 
                $content=$this->make_content($order_no,  $amount); 
 
                $content=EREG_REPLACE( "  ", "\\+",$content); 
                $content_length=(string)STRLEN($content); 
                $req=$this->method; 
                $req=$req+ "  /"+$this->merchant_secret+ "/"+$this->type; 
                $req=$req+ "  "+$this->http_version+ "\\r\\n"; 
 
                $req=$req+ "User-Agent:  CyberCashMerchant-2.1.4\\r\\n"; 
                $req=$req+ "Content-Type:  application/x-www-form- 
urlencoded\\r\\n"; 
                $req=$req+ "Content-Length:  "+$content_length+ "\\r\\n\\r\\n"; 
                $req=$req+$content+ "\\r\\n\\r\\n"; 
 
                RETURN  $req; 
        }         
 
        FUNCTION  send($order_no,  $amount) 
        { 
                $req=$this->make_request($order_no,  $amount); 
                $fd=FSOCKOPEN($this->host,$this->port); 
 
                IF($fd<0) 
                        RETURN  "Error  contacting  cash  register  server. 
\\n"; 
 
                FPUTS($fd,$req); 
 
                /*  Retrieve  header.  */ 
                $i=0; 
                $response= ""; 
                WHILE(!FEOF($fd)  &&  $response  !=  "\\n") 
                { 
                        $response= ""; 
                        $more= ""; 
                        WHILE(!FEOF($fd)  &&  $more  !=  "\\n") 
                        { 
                                $more=FGETS($fd,2); 
                                IF($more  !=  "\\n"  ||  $response== "") 
                                { 
                                        $response=$response+$more; 
                                } 
                        } 
                        $header[$i++]=$response; 
                } 
 
                /*  Retrieve  variables.  */ 
                $response= ""; 
                $more= ""; 
                WHILE(!FEOF($fd)  &&  $more  !=  "\\n") 
                { 
                        $more= ""; 
                        $type= "var"; 
                        $varname= ""; 
                        $varval= ""; 
                        WHILE(!FEOF($fd)  &&  $more  !=  "&"  &&  $more  !=   
"\\n") 
                        { 
                                $more=FGETS($fd,2); 
                                IF($more  !=  "&"  &&  $more  !=  "="  &&   
$more  !=  "\\n") 
                                { 
                                        $response=$response+$more; 
                                } 
                                IF($more== "=") 
                                { 
                                        $varval=EREG_REPLACE( "\\+", "  ", 
$response); 
                                        $response= ""; 
                                } 
                                IF($more== "&"  ||  $more== "\\n") 
                                { 
                                        $varval=$response; 
                                        $response= ""; 
                                } 
                        } 
                        IF($varname  !=  "") 
                        { 
                                $cybervar[$varname]=$varval; 
                        } 
                } 
 
                RETURN  $cybervar; 
        } 
}; 
?>


 
   Home |    Search |    Code Library |    Sponsors |    Privacy |    Terms of Use |    Contact Us © 2003 - 2024 psoug.org