Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest Gerald Sandstrom

GoDaddy CURL Proxy PAYPAL

Recommended Posts

Guest Gerald Sandstrom

GoDaddy's CURL uses a proxy. Paypals link to this is:

PAYPAL

or directly to GoDaddy is:

GoDaddy

Basically, I need this line of code:

CURLOPT_PROXY,"http://64.202.165.130:3128");

Any help would be greatly appreciated. Thanks!

Share this post


Link to post
Share on other sites

Guest Gerald Sandstrom

Ok, After a lot of work and tech support it comes down to this. http.php under pearl/services/paypal/soap/transport needs one line added to it to make paypal pro work with Godaddy virtual hosting. The line is in red below.

<?php

//

// +----------------------------------------------------------------------+

// | PHP Version 4 |

// +----------------------------------------------------------------------+

// | Copyright © 1997-2003 The PHP Group |

// +----------------------------------------------------------------------+

// | This source file is subject to version 2.02 of the PHP license, |

// | that is bundled with this package in the file LICENSE, and is |

// | available at through the world-wide-web at |

// | http://www.php.net/license/2_02.txt. |

// | If you did not receive a copy of the PHP license and are unable to |

// | obtain it through the world-wide-web, please send a note to |

// | [email protected] so we can mail you a copy immediately. |

// +----------------------------------------------------------------------+

// | Authors: Shane Caraveo <[email protected]> |

// +----------------------------------------------------------------------+

//

// $Id: HTTP.php,v 1.19 2005/06/23 17:03:21 chagenbuch Exp $

//

/**

* HTTP Transport class

*

* @package SOAP

* @category Web_Services

*/

/**

* Needed Classes

*/

require_once 'Services/PayPal/SOAP/Base.php';

/**

* HTTP Transport for SOAP

*

* @access public

* @package SOAP::Transport::HTTP

* @author Shane Caraveo <[email protected]>

*/

class SOAP_Transport_HTTP extends SOAP_Base

{

/**

* Basic Auth string

*

* @var array

*/

var $headers = array();

/**

* Cookies

*

* @var array

*/

var $cookies;

/**

*

* @var int connection timeout in seconds - 0 = none

*/

var $timeout = 30;

/**

* Array containing urlparts - parse_url()

*

* @var mixed

*/

var $urlparts = NULL;

/**

* Connection endpoint - URL

*

* @var string

*/

var $url = '';

/**

* Incoming payload

*

* @var string

*/

var $incoming_payload = '';

/**

* HTTP-Request User-Agent

*

* @var string

*/

var $_userAgent = SOAP_LIBRARY_NAME;

/**

* HTTP Encoding

*

* @var string

*/

var $encoding = SOAP_DEFAULT_ENCODING;

/**

* HTTP-Response Content-Type encoding

*

* we assume UTF-8 if no encoding is set

* @var string

*/

var $result_encoding = 'UTF-8';

/**

* HTTP-Response Content-Type

*/

var $result_content_type;

var $result_headers = array();

var $result_cookies = array();

/**

* SOAP_Transport_HTTP Constructor

*

* @param string $URL http url to soap endpoint

*

* @access public

* @param string $URI

* @param string $encoding encoding to use

*/

function SOAP_Transport_HTTP($URL, $encoding = SOAP_DEFAULT_ENCODING)

{

parent::SOAP_Base('HTTP');

$this->urlparts = @parse_url($URL);

$this->url = $URL;

$this->encoding = $encoding;

}

/**

* send and receive soap data

*

* @param string outgoing post data

* @param array options

*

* @return string|fault response

* @access public

*/

function &send(&$msg, $options = null)

{

if (!$this->_validateUrl()) {

return $this->fault;

}

if (isset($options['timeout']))

$this->timeout = (int)$options['timeout'];

if (strcasecmp($this->urlparts['scheme'], 'HTTP') == 0) {

return $this->_sendHTTP($msg, $options);

} else if (strcasecmp($this->urlparts['scheme'], 'HTTPS') == 0) {

return $this->_sendHTTPS($msg, $options);

}

return $this->_raiseSoapFault('Invalid url scheme '.$this->url);

}

/**

* set data for http authentication

* creates Authorization header

*

* @param string $username username

* @param string $password response data, minus http headers

*

* @return none

* @access public

*/

function setCredentials($username, $password)

{

$this->headers['Authorization'] = 'Basic ' . base64_encode($username . ':' . $password);

}

/**

* Add a cookie

*

* @access public

* @param string $name cookie name

* @param mixed $value cookie value

* @return void

*/

function addCookie($name, $value)

{

$this->cookies[$name]=$value;

}

// private methods

/**

* Generates the correct headers for the cookies

*

* @access private

* @return void

*/

function _genCookieHeader()

{

foreach ($this->cookies as $name=>$value) {

$cookies = (isset($cookies) ? $cookies. '; ' : '') .

urlencode($name) . '=' . urlencode($value);

}

return $cookies;

}

/**

* validate url data passed to constructor

*

* @access private

* @return boolean

*/

function _validateUrl()

{

if ( ! is_array($this->urlparts) ) {

$this->_raiseSoapFault("Unable to parse URL " . $this->url);

return false;

}

if (!isset($this->urlparts['host'])) {

$this->_raiseSoapFault("No host in URL " . $this->url);

return false;

}

if (!isset($this->urlparts['port'])) {

if (strcasecmp($this->urlparts['scheme'], 'HTTP') == 0)

$this->urlparts['port'] = 80;

else if (strcasecmp($this->urlparts['scheme'], 'HTTPS') == 0)

$this->urlparts['port'] = 443;

}

if (isset($this->urlparts['user'])) {

$this->setCredentials(urldecode($this->urlparts['user']),

urldecode($this->urlparts['pass']));

}

if (!isset($this->urlparts['path']) || !$this->urlparts['path'])

$this->urlparts['path'] = '/';

return true;

}

/**

* Finds out what is the encoding.

*

* Sets the object property accordingly.

*

* @access private

* @param array $headers headers

* @return void

*/

function _parseEncoding($headers)

{

$h = stristr($headers, 'Content-Type');

preg_match_all('/^Content-Type:\s*(.*)$/im', $h, $ct, PREG_SET_ORDER);

$n = count($ct);

$ct = $ct[$n - 1];

$this->result_content_type = str_replace("\r", '', $ct[1]);

if (preg_match('/(.*?)(?:;\s?charset=)(.*)/i', $this->result_content_type, $m)) {

// strip the string of \r

$this->result_content_type = $m[1];

if (count($m) > 2) {

$enc = strtoupper(str_replace('"', '', $m[2]));

if (in_array($enc, $this->_encodings)) {

$this->result_encoding = $enc;

}

}

}

// deal with broken servers that don't set content type on faults

if (!$this->result_content_type) $this->result_content_type = 'text/xml';

}

/**

* Parses the headers

*

* @param array $headers the headers

* @return void

*/

function _parseHeaders($headers)

{

/* largely borrowed from HTTP_Request */

$this->result_headers = array();

$headers = split("\r?\n", $headers);

foreach ($headers as $value) {

if (strpos($value,':') === false) {

$this->result_headers[0]=$value;

continue;

}

list($name,$value) = split(':',$value);

$headername = strtolower($name);

$headervalue = trim($value);

$this->result_headers[$headername]=$headervalue;

if ($headername == 'set-cookie') {

// Parse a SetCookie header to fill _cookies array

$cookie = array(

'expires' => null,

'domain' => $this->urlparts['host'],

'path' => null,

'secure' => false

);

// Only a name=value pair

if (!strpos($headervalue, ';')) {

list($cookie['name'], $cookie['value']) = array_map('trim', explode('=', $headervalue));

$cookie['name'] = urldecode($cookie['name']);

$cookie['value'] = urldecode($cookie['value']);

// Some optional parameters are supplied

} else {

$elements = explode(';', $headervalue);

list($cookie['name'], $cookie['value']) = array_map('trim', explode('=', $elements[0]));

$cookie['name'] = urldecode($cookie['name']);

$cookie['value'] = urldecode($cookie['value']);

for ($i = 1; $i < count($elements);$i++) {

list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));

if ('secure' == $elName) {

$cookie['secure'] = true;

} elseif ('expires' == $elName) {

$cookie['expires'] = str_replace('"', '', $elValue);

} elseif ('path' == $elName OR 'domain' == $elName) {

$cookie[$elName] = urldecode($elValue);

} else {

$cookie[$elName] = $elValue;

}

}

}

$this->result_cookies[] = $cookie;

}

}

}

/**

* Remove http headers from response

*

* @return boolean

* @access private

*/

function _parseResponse()

{

if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $this->incoming_payload, $match)) {

#$this->response = preg_replace("/[\r|\n]/", '', $match[2]);

$this->response =& $match[2];

// find the response error, some servers response with 500 for soap faults

$this->_parseHeaders($match[1]);

list($protocol, $code, $msg) = sscanf($this->result_headers[0], '%s %s %s');

unset($this->result_headers[0]);

switch($code) {

case 100: // Continue

$this->incoming_payload = $match[2];

return $this->_parseResponse();

case 400:

$this->_raiseSoapFault("HTTP Response $code Bad Request");

return false;

break;

case 401:

$this->_raiseSoapFault("HTTP Response $code Authentication Failed");

return false;

break;

case 403:

$this->_raiseSoapFault("HTTP Response $code Forbidden");

return false;

break;

case 404:

$this->_raiseSoapFault("HTTP Response $code Not Found");

return false;

break;

case 407:

$this->_raiseSoapFault("HTTP Response $code Proxy Authentication Required");

return false;

break;

case 408:

$this->_raiseSoapFault("HTTP Response $code Request Timeout");

return false;

break;

case 410:

$this->_raiseSoapFault("HTTP Response $code Gone");

return false;

break;

default:

if ($code >= 400 && $code < 500) {

$this->_raiseSoapFault("HTTP Response $code Not Found, Server message: $msg");

return false;

}

}

$this->_parseEncoding($match[1]);

if ($this->result_content_type == 'application/dime') {

// XXX quick hack insertion of DIME

if (PEAR::isError($this->_decodeDIMEMessage($this->response,$this->headers,$this->attachments))) {

// _decodeDIMEMessage already raised $this->fault

return false;

}

$this->result_content_type = $this->headers['content-type'];

} else if (stristr($this->result_content_type,'multipart/related')) {

$this->response = $this->incoming_payload;

if (PEAR::isError($this->_decodeMimeMessage($this->response,$this->headers,$this->attachments))) {

// _decodeMimeMessage already raised $this->fault

return false;

}

} else if ($this->result_content_type != 'text/xml') {

$this->_raiseSoapFault($this->response);

return false;

}

// if no content, return false

return strlen($this->response) > 0;

}

$this->_raiseSoapFault('Invalid HTTP Response');

return false;

}

/**

* Create http request, including headers, for outgoing request

*

* @param string &$msg outgoing SOAP package

* @param $options

* @return string outgoing_payload

* @access private

*/

function &_getRequest(&$msg, $options)

{

$action = isset($options['soapaction'])?$options['soapaction']:'';

$fullpath = $this->urlparts['path'].

(isset($this->urlparts['query'])?'?'.$this->urlparts['query']:'').

(isset($this->urlparts['fragment'])?'#'.$this->urlparts['fragment']:'');

if (isset($options['proxy_host'])) {

$fullpath = 'http://' . $this->urlparts['host'] . ':' . $this->urlparts['port'] . $fullpath;

}

if (isset($options['proxy_user'])) {

$this->headers['Proxy-Authorization'] = 'Basic ' . base64_encode($options['proxy_user'].":".$options['proxy_pass']);

}

if (isset($options['user'])) {

$this->setCredentials($options['user'], $options['pass']);

}

$this->headers['User-Agent'] = $this->_userAgent;

$this->headers['Host'] = $this->urlparts['host'];

$this->headers['Content-Type'] = "text/xml; charset=$this->encoding";

$this->headers['Content-Length'] = strlen($msg);

$this->headers['SOAPAction'] = "\"$action\"";

if (isset($options['headers'])) {

$this->headers = array_merge($this->headers, $options['headers']);

}

$this->cookies = array();

if (!isset($options['nocookies']) || !$options['nocookies']) {

// add the cookies we got from the last request

if (isset($this->result_cookies)) {

foreach ($this->result_cookies as $cookie) {

if ($cookie['domain'] == $this->urlparts['host'])

$this->cookies[$cookie['name']]=$cookie['value'];

}

}

}

// add cookies the user wants to set

if (isset($options['cookies'])) {

foreach ($options['cookies'] as $cookie) {

if ($cookie['domain'] == $this->urlparts['host'])

$this->cookies[$cookie['name']]=$cookie['value'];

}

}

if (count($this->cookies)) {

$this->headers['Cookie'] = $this->_genCookieHeader();

}

$headers = '';

foreach ($this->headers as $k => $v) {

$headers .= "$k: $v\r\n";

}

$this->outgoing_payload =

"POST $fullpath HTTP/1.0\r\n".

$headers."\r\n".

$msg;

return $this->outgoing_payload;

}

/**

* Send outgoing request, and read/parse response

*

* @param string &$msg outgoing SOAP package

* @param string $action SOAP Action

* @return string &$response response data, minus http headers

* @access private

*/

function &_sendHTTP(&$msg, $options)

{

$this->incoming_payload = '';

$this->_getRequest($msg, $options);

$host = $this->urlparts['host'];

$port = $this->urlparts['port'];

if (isset($options['proxy_host'])) {

$host = $options['proxy_host'];

$port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080;

}

// send

if ($this->timeout > 0) {

$fp = @fsockopen($host, $port, $this->errno, $this->errmsg, $this->timeout);

} else {

$fp = @fsockopen($host, $port, $this->errno, $this->errmsg);

}

if (!$fp) {

return $this->_raiseSoapFault("Connect Error to $host:$port");

}

if ($this->timeout > 0) {

// some builds of php do not support this, silence

// the warning

@socket_set_timeout($fp, $this->timeout);

}

if (!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {

return $this->_raiseSoapFault("Error POSTing Data to $host");

}

// get reponse

// XXX time consumer

do {

$data = fread($fp, 4096);

$_tmp_status = socket_get_status($fp);

if ($_tmp_status['timed_out']) {

return $this->_raiseSoapFault("Timed out read from $host");

} else {

$this->incoming_payload .= $data;

}

} while (!$_tmp_status['eof']);

fclose($fp);

if (!$this->_parseResponse()) {

return $this->fault;

}

return $this->response;

}

/**

* Send outgoing request, and read/parse response, via HTTPS

*

* @param string &$msg outgoing SOAP package

* @param string $action SOAP Action

* @return string &$response response data, minus http headers

* @access private

*/

function &_sendHTTPS(&$msg, $options)

{

/* NOTE This function uses the CURL functions

* Your php must be compiled with CURL

*/

if (!extension_loaded('curl')) {

return $this->_raiseSoapFault('CURL Extension is required for HTTPS');

}

$ch = curl_init();

if (isset($options['proxy_host'])) {

// $options['http_proxy'] == 'hostname:port'

$host = $options['proxy_host'];

$port = isset($options['proxy_port']) ? $options['proxy_port'] : 8080;

curl_setopt($ch, CURLOPT_PROXY, $host . ":" . $port);

}

if (isset($options['proxy_user'])) {

// $options['http_proxy_userpw'] == 'username:password'

curl_setopt($ch, CURLOPT_PROXYUSERPWD, $options['proxy_user'] . ':' . $options['proxy_pass']);

}

if (isset($options['user'])) {

curl_setopt($ch, CURLOPT_USERPWD, $options['user'] . ':' . $options['pass']);

}

if (!isset($options['soapaction'])) {

$options['soapaction'] = '';

}

curl_setopt($ch, CURLOPT_HTTPHEADER , array('Content-Type: text/xml;charset=' . $this->encoding, 'SOAPAction: "'.$options['soapaction'].'"'));

curl_setopt($ch, CURLOPT_USERAGENT , $this->_userAgent);

if ($this->timeout) {

curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); //times out after 4s

}

curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);

curl_setopt($ch, CURLOPT_URL, $this->url);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_FAILONERROR, 0);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HEADER, 1);

//added

curl_setopt ($ch, CURLOPT_PROXY,"http://64.202.165.130:3128");

if (defined('CURLOPT_HTTP_VERSION')) {

curl_setopt($ch, CURLOPT_HTTP_VERSION, 1);

}

if (isset($options['curl'])) {

foreach ($options['curl'] as $key => $val) {

curl_setopt($ch, $key, $val);

}

}

// Save the outgoing XML. This doesn't quite match _sendHTTP

// as CURL generates the headers, but having the XML is

// usually the most important part for tracing/debugging.

$this->outgoing_payload = $msg;

//print htmlspecialchars($this->outgoing_payload);

$this->incoming_payload = curl_exec($ch);

//print htmlspecialchars($this->incoming_payload);

if (!$this->incoming_payload) {

$m = 'curl_exec error ' . curl_errno($ch) . ' ' . curl_error($ch);

curl_close($ch);

return $this->_raiseSoapFault($m);

}

curl_close($ch);

if (!$this->_parseResponse()) {

return $this->fault;

}

return $this->response;

}

}

Mine works now. ;) Thanks goes out to paypal merchant support!

Share this post


Link to post
Share on other sites
Guest xtremex

Looks like you've solved it! If that doesnt work try using the hostname example www.xtremex.com for example and use single quotes 'single' not "double"

Share this post


Link to post
Share on other sites
Guest Gerald Sandstrom

All is figured out now!

Share this post


Link to post
Share on other sites
Guest pachira

Thanks Gerald!

I've been struggling with this problem for the past 2 weeks and your solution finally did the trick.

Share this post


Link to post
Share on other sites
Guest TrueCHoJiN

Thanks Gerald, godaddy was very uncooperative/unhelpful about this with me...

Share this post


Link to post
Share on other sites
Guest swoods

Thanks Gerald, godaddy was very uncooperative/unhelpful about this with me...

I am currently starting an online store from godaddy's servers. I have been playing around with paypals sandbox and all is working for me. Should I expect problems to arise?

Share this post


Link to post
Share on other sites
Guest Brivtech

Generally, no, especially not with the service - But the support is scripted, and if after a few emails you don't get a suitable, make a complaint about the quality of service - This always pushes your enquiry away from the plebs up to the experts who actually do know what theire talking about.

Also, telephone support is a lot more productive.

People don't realise this but Godaddy are just a domain services reseller, and that the support comes from their provider. There are other resellers who can offer the same products at better prices, and with additional support.

Share this post


Link to post
Share on other sites
Guest fulmater

I wish some one could get this paypal thing worked out and put together a guide for those of us who have waisted hours of looking through the posts here on the topic and have had no luck getting paypal pro to work with CC on godaddy. I have my OWN server I cant get it to work, I have setup a store on my godaddy account and it dont work. Geez, I sick of messing with this thing.

Share this post


Link to post
Share on other sites
Guest Brivtech

I wish some one could get this paypal thing worked out and put together a guide for those of us who have waisted hours of looking through the posts here on the topic and have had no luck getting paypal pro to work with CC on godaddy. I have my OWN server I cant get it to work, I have setup a store on my godaddy account and it dont work. Geez, I sick of messing with this thing.

That's not a lot to go on. Is your problem specific to the CURL function? If so, the fix was already posted in the second post of this topic.

If not, can you explain exactly what problem you have with regard to this topic? I wouldn't know where to start to answer "it don't work". :yeahhh:

Do you actually have libcurl installed?

http://curl.haxx.se/

http://uk.php.net/curl

Share this post


Link to post
Share on other sites
Guest fulmater

Sorry I spelled it out in detail in another post and this one was just a post trying to get some one to make a guide for paypal pro. Any way here is my current error below

Warning: require_once(PEAR.php) [function.require-once]: failed to open stream: No such file or directory in C:\www\xampp\htdocs\dfwproducts\pear\PayPal.php on line 11

Fatal error: require_once() [function.require]: Failed opening required 'PEAR.php' (include_path='C:\www\xampp\htdocs\dfwproducts/pear;.;C:\www\xampp\php\pear\') in C:\www\xampp\htdocs\dfwproducts\pear\PayPal.php on line 11

My Setup

CubeCart Version: 3.0.15

PHP Version: 5.2.0

MySQL Version: 5.0.27-community-nt

Image upload folder size: 10.8 MB

Server Software: Apache/2.2.3 (Win32) DAV/2 mod_ssl/2.2.3 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.0

Client Browser: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)

Thank you for any help you could pass my way.

Share this post


Link to post
Share on other sites
Guest dwd74

Hi all,

I need help if someone is able.

I have paypal set up, used both the express and direct.

I do use GoDaddy and added the line as above.

However, the problem is that when I choose express checkout there is a blank page, it's absolutely blank...white..nothing there

When I choose direct payment, it goes to the page to fill out CC info, but then aftewards it is blank again.

Any direction?

I'm sure it's something simple, but I am new to all of this.

Thank you.

Share this post


Link to post
Share on other sites
Guest Cellular Amps LLC

Oddly enought after getting another issue resolved I am having the exact same issue as dwd74.... the joys of paypal and Godaddy

Share this post


Link to post
Share on other sites
Guest kaskudoo

had the same problem, moved to another host, which solved my problem. the host i am with advertises on this page on the bottom :)

(i do still have the domains registered with godaddy)

Share this post


Link to post
Share on other sites

×
×
  • Create New...