Hello - I'm trying to set up Ubercart with PayPal Sandbox for the first time.

Everything seemed to be going smoothly except for when it comes to the IPN and the order status updating properly when an order is complete.

I checked my logs and I see that the IPN seems to be coming through:

uc_paypal 2016-05-17 12:41 Receiving IPN at URL for order 4. Array... Anonymous (not verified)

And if I check the array it has [payment_status] => Completed

But that is immediately followed by:

uc_paypal 2016-05-17 12:41 IPN failed with HTTP error Bad Request, code 400. Anonymous (not verified)

If someone could point me in the right direction that would be super helpful! Thank you.

Comments

jefflogan’s picture

I've got exactly the same issue, so currently trying to debug this.

Will let you know if I find anything to help you.

jefflogan’s picture

I believe the issue is related to the changes Paypal are doing to move to using HTTP1.1 and TLS. With some of the changes all ready present on the Paypal sandbox, but not yet live.

I have been able to see a successful response to the IPN, if I use the module cURL HTTP Request, and create a custom paypal payment module, which replaces the drupal_http_header function with the module function chr_curl_http_request (this deals with the HTTP1.1 requirement).

The function call to chr_curl_http_request should also add curl options to specify the SSL version ie CURLOPT_SSLVERSION => 6. This deals with the TLS1.2 issue.

Hopefully this helps. Let me know if anyone had a better or alternative solution.

TimToronto’s picture

Thanks for this. I wonder - my site doesn't have a HTTPS certificate yet - I wonder if that would help resolve me issue. I am going to set it up and will let you know if that helped me at all.

TimToronto’s picture

Are you able to do this in conjunction with the UberCart module, or is this a completely separate set-up?

jefflogan’s picture

Your site having an SSL certificate is separate from what I described. Having an SSL certificate secures the connection between the web broswer and the web server.

The method I described, changes the code to make a secure curl request from the webserver to Paypal with TLS.

The code formally would have tried to make a secure connection using SSLv3, which I believe Paypal is retiring soon on Live and already happened on the sandbox, so you can test and get things ready for the switch.

venomdrag’s picture

Hi guys, im currently experiencing the same issue here with paypal ubercart. I upgraded openssl to 1.0.1 but still the problem is there. should a define a header for tls and http inside drupal_http_request?

jefflogan’s picture

The approach I took, was to create a new module defining a paypal payment method (basically a fork of the current module), which used the cURL HTTP Request module, rather than the core drupal_http_request. this way I avoided hacking core, or the existing paypal module.

I took the above course of action, mainly due to time constraints. I guess the better solution would be to provide a patch for the ubercart paypal module to use curl, instead of drupal_http_request.

venomdrag’s picture

I manage to fix it using cURL HTTP Request module which handles http 1.1 protocol by default. It has a very handy config which lets curl override drupal_http_request. Thanks jeff.

TimToronto’s picture

Hi - was this the module you used for the cURL HTTP Request: https://www.drupal.org/project/chr
I'm not proficient enough to make a custom module to handle the problem so my issue is still unresolved. I would love to understand how you used an existing module. Thanks!

abrlam’s picture

Just writing this down for future reference. Hope that helps.

According to this page:
https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ148...

- they discontinued HTTP 1.0 support (drupal_http_request uses it)
- HTTP 400 to any HTTP requests (IPN) without the "Host" header (applies to the live AND sandbox server; uc_paypal didn't include the Host information in the header)

Here's how you fix it:

1. install cURL HTTP Request (chr)
https://www.drupal.org/project/chr

2. enable the module and check on the option "Override Drupal HTTP Request" in the chr configuration

(this fixes HTTP 1.0 support issue)

3. in file ubercart/payment/uc_paypal/uc_paypal.pages.inc

around line 78:
$response = drupal_http_request($host, array(

add the following line:
'Host' => $host,

like this:
$response = drupal_http_request($host, array(
'Host' => $host,

(this fixes 400 Bad Request Error during IPN)

pignaz’s picture

these steps worked for me!

sukh.singh’s picture

@abrlam, it works for me too. Thanks a lot. Created a patch for the us_paypal module changes.

roblog’s picture

@Singh .. where is the patch?

sukh.singh’s picture

I have used the above mentioned module and fixed but as per the Tim, it is not good idea to be dependent on another module and he provided a solution for this. In response to his suggestions I have created patch. You can read the details over there, here is link IPN error and Patch uc_paypal_IPN_400_error-2790197-11557381.patch

roblog’s picture

Hi Singh thanks for the link. I'll test the patch and report back on the other thread.

shahidaali’s picture

Worked for me too. Thanks

roblog’s picture

Thanks very much for the fix!!

Just a quick note - $host is only needed if using PayPal Website Payments Standard by the looks of. If you're using a Paypal Express, then adding this will put a little notice in your log: Notice: Undefined variable: host in eval() (line 1 of /var/www/permaculture.co.uk/httpdocs/sites/all/modules/devel/devel.module(1415) : eval()'d code).

Andru’s picture

True, thanks. Just switching on CHR alone solved the problem for me, I am using Paypal Express and I did not add $host.