Location: PHPKode > scripts > SnPayPalApi > snpaypalapi/lib/SnPayPalStream.class.php
<?php
 /**
 * 
 * 
 * @author Michael J. Burgess
 * @package SnPayPal
 * @copyright Michael J. Burgess, 2008
 * @version 1.0
 * @licence MIT
 */

/**
 * Uses cURL and SnPayPalConfig constants to handle communication with paypal
 * 
 */
class SnPayPalStream
{
    protected $curlPointer;
    protected $response;

    const ERROR_PUT_STRING = 100;
    const ERROR_CURL_PUT_STRING = 101;

    /**
     * Return the raw SOAP XML response
     *
     * @return string
     */
    public function getXml()
    {
        return $this->response;
    }
    
    /**
     * Open connexion to PayPal
     *
     */
    protected function open()
    {
        $this->curlPointer = curl_init();
        curl_setopt($this->curlPointer, CURLOPT_URL, SnPayPalConfig::API_LOCATION);
        curl_setopt($this->curlPointer, CURLOPT_SSLCERT, SnPayPalConfig::SSL_CERT_LOCATION);
        curl_setopt($this->curlPointer, CURLOPT_POST, true);
        curl_setopt($this->curlPointer, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->curlPointer, CURLOPT_RETURNTRANSFER, true);
    }

    /**
     * Put information over the connexion, and get response
     *
     * @param string $string
     */
    protected function putString($string)
    {
        curl_setopt($this->curlPointer, CURLOPT_POSTFIELDS, $string);
        
        $this->response = curl_exec($this->curlPointer);

        if(curl_error($this->curlPointer))
        {
            $errorNumber  = curl_errno($this->curlPointer);
            $errorMessage = curl_error($this->curlPointer);
            $errorMessage = "Error: cURL Error $errorNumber - $errorMessage";
            
            throw new Exception($errorMessage, self::ERROR_CURL_PUT_STRING);
        }
    }

    /**
     * Close connexion to PayPal
     *
     */
    protected function close()
    {
        curl_close($this->curlPointer);
    }
}

?>
Return current item: SnPayPalApi