Adding issue related to IPN error by TimToronto. His query was as below

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.

@abrlam provided the solutions for this as well, link is Fix for 400 Bad Request Error (IPN)

I am adding patch file so that it should follow coding standards.

Members fund testing for the Drupal project. Drupal Association Learn more


sukh.singh created an issue. See original summary.

TR’s picture

Version: 7.x-3.10 » 7.x-3.x-dev
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, uc_paypal-IPN-error-2727793.patch, failed testing.

TR’s picture

Status: Needs work » Needs review

It would have been nice to have had this problem reported in the Ubercart issue queue ...

According to #2555649: drupal_http_request() should allow caller to set the Host header drupal_http_request() ignores/overrides the 'Host' header if it provided in the options like the patch does. Also, drupal_http_request() is still HTTP 1.0 (despite 10 YEARS of issues trying to get it updated, see for example #104693: Always send HTTP/1.1 in headers) so just adding the 'Host' header is insufficient. Thus, this patch does nothing UNLESS you also use the chr module which replaces drupal_http_request() with a cURL implementation. If we are going to try to work around this Drupal core problem, then we might as well go the whole way and replace the drupal_http_request() with explicit calls to cURL methods rather than to depend on the chr module.

BTW, the patch is failing to apply because it removes a line that doesn't exist in Ubercart - you must be diff-ing against your own modified version rather than against the unmodified Ubercart.

TR’s picture

Status: Needs review » Needs work

Didn't mean to reset the status ...

sukh.singh’s picture

Thanks Tim, for detailed reply. Yes I do agree with your comments. As you can see in my initial comments, I have mentioned that @abrlam provided the solutions for this as well, link is Fix for 400 Bad Request Error (IPN). Under it he has also mentioned to install cURL HTTP Request (chr) module. I only provided the patch where in conjunction with chr, it will resolve the issue.

Unless this is in the core, I propose to have chr as required module for uc_paypal.

Additionally I have added watchdog more descriptive error message, so that when 400 IPN error occurs, user will get the following message IPN failed with HTTP error Bad Request, code 400. Please install chr, enable the module and check on the option "Override Drupal HTTP Request" in the chr configuration

Revised patch is added. Please have a look.

sukh.singh’s picture

Status: Needs work » Needs review

I have added updated patch. Please review it.

TR’s picture

Status: Needs review » Needs work

We're not going to add a dependency on chr.

One problem is that chr will then replace ALL drupal_http_request() calls, not just the PayPal ones - we don't want that.

A better way, as I said in #4, is to just replace that one drupal_http_request() in uc_paypal with a curl_exec(). It's only a few lines of code for the replacement, and we already use curl in several other modules such as uc_authorizenet so there is an example to copy - this should be an easy patch. It just requires someone to make AND TEST the patch before it goes in.

sukh.singh’s picture

Status: Needs work » Needs review

Thanks again Tim. I have followed your guidelines and updated the code with curl_exec. I have tested the code and it is working fine as well. Please have a look.

P.S: If we are using uc_recurring in conjunction with uc_paypal, then we have to update the code there as well, because it is using same logic i.e drupal_http_request. I have added the patch for uc_reccuring module as well. Issue link is here.

sukh.singh’s picture

TR’s picture

Still waiting on a PayPal user to test this patch ...

roblog’s picture

Patch #10 works for me using Ubercart 7.x-3.10 and PHP / MySQL 5.5 with Paypal Express.

djdevin’s picture

Status: Needs review » Reviewed & tested by the community

I confirmed this fixes the issue with WPS.

#10 fixes express and WPS so RTBC.

  • TR committed 9c1fe65 on 7.x-3.x authored by sukh.singh
    Issue #2790197 by sukh.singh: IPN error
TR’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for working on this. I committed the patch from #10.

I don't think this issue affects 8.x-4.x because there we use \Drupal::httpClient(), so I'm not going to mark this as needs porting.

sukh.singh’s picture

Thanks TR for committing the patch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.