Welcome Guest, Not a member yet? Register   Sign In
Paypal Library- successfull transaction returns query string
#1

[eluser]Fast Eddie[/eluser]
Hello everyone,

I'm new to PHP and CodeIgniter and I'm having a little trouble with a PHP class I found online that I've attempted to convert to a CI library...

The purpose of the library is to incorporate Paypal Express Checkout. The class contains 2 parts - HTTPRequest & pplib.

Here is HTTPRequest:
Code:
class Httprequest {

    private $host;
    private $path;
    private $data;
    private $method;
    private $port;
    private $rawhost;

    private $header;
    private $content;
    private $parsedHeader;

    function __construct($host, $path, $method = 'POST', $ssl = false, $port = 0) {
        $this->host = $host;
        $this->rawhost = $ssl ? ("ssl://".$host) : $host;
        $this->path = $path;
        $this->method = strtoupper($method);
        if ($port) {
            $this->port = $port;
        } else {
            if (!$ssl) $this->port = 80; else $this->port = 443;
        }
    }

    public function connect( $data = ''){
        $fp = fsockopen($this->rawhost, $this->port);
        if (!$fp) return false;
        fputs($fp, "$this->method $this->path HTTP/1.1\r\n");
        fputs($fp, "Host: $this->host\r\n");
        //fputs($fp, "Content-type: $contenttype\r\n");
        fputs($fp, "Content-length: ".strlen($data)."\r\n");
        fputs($fp, "Connection: close\r\n");
        fputs($fp, "\r\n");
        fputs($fp, $data);

        $responseHeader = '';
        $responseContent = '';

        do
        {
            $responseHeader.= fread($fp, 1);
        }
        while (!preg_match('/\\r\\n\\r\\n$/', $responseHeader));
            
            
        if (!strstr($responseHeader, "Transfer-Encoding: chunked"))
        {
            while (!feof($fp))
            {
                $responseContent.= fgets($fp, 128);
            }
        }
        else
        {

            while ($chunk_length = hexdec(fgets($fp)))
            {
                $responseContentChunk = '';
                
                $read_length = 0;
                
                while ($read_length < $chunk_length)
                {
                    $responseContentChunk .= fread($fp, $chunk_length - $read_length);
                    $read_length = strlen($responseContentChunk);
                }

                $responseContent.= $responseContentChunk;
                
                fgets($fp);
                
            }
            
        }

        $this->header = chop($responseHeader);
        $this->content = $responseContent;
        $this->parsedHeader = $this->headerParse();
        
        $code = intval(trim(substr($this->parsedHeader[0], 9)));

        return $code;
    }

    function headerParse(){
        $h = $this->header;
        $a=explode("\r\n", $h);
        $out = array();
        foreach ($a as $v){
            $k = strpos($v, ':');
            if ($k) {
                $key = trim(substr($v,0,$k));
                $value = trim(substr($v,$k+1));
                if (!$key) continue;
                $out[$key] = $value;
            } else
            {
                if ($v) $out[] = $v;
            }
        }
        return $out;
    }

    public function getContent() {return $this->content;}
    public function getHeader() {return $this->parsedHeader;}
    

}


Messages In This Thread
Paypal Library- successfull transaction returns query string - by El Forum - 02-22-2010, 11:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB