Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Complete Programs Code Examples

A class for doing payments to a cybercash server

A class for doing payments to a cybercash server <? 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; } }; ?>