0
votes

I've build a listener for my IPN. I can receive the request via IPN Simulator and all the parameters are correct, but when I send it back to link for sending my request to make validations it will ALWAYS return INVALID.

I've tried changing the encoding on my PayPal account to UTF-8 but it didn't work.

I'm not using any gem for this and I'm not looking forward to this.

 class PaymentNotificationController  [:create] #Otherwise the request from PayPal wouldn't make it to the controller


  def create
    response = validate_IPN_notification(request.raw_post)
    case response
    when "VERIFIED"
      P 'worked'

    when "INVALID"
        p 'did not work'
    else
    end
    render :nothing => true, :status => 200, :content_type => 'text/html'
  end


  protected 

  

  def validate_IPN_notification(raw)

    uri = URI.parse('https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_notify-validate')
    #uri = URI.parse('https://www.paypal.com/cgi-bin/webscr?cmd=_notify-validate')
    http = Net::HTTP.new(uri.host, uri.port)
    http.open_timeout = 60
    http.read_timeout = 60
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
    http.use_ssl = true
    response = http.post(uri.request_uri, raw,
                         'Content-Length' => "#{raw.size}",
                         'User-Agent' => "My custom user agent"
                       ).body
  end
end

Please help me, I've been stuck with it all afternoon and can't get it figured out.

2

2 Answers

0
votes

I think your problem is not follow exactly what papal requires

From Paypal document

Your listener HTTP POSTs the complete, unaltered message back to PayPal.

Note This message must contain the same fields, in the same order, as the original IPN from PayPal, all preceded by cmd=_notify-validate. Further, this message must use the same encoding as the original.

So you validate function would be:

def validate_IPN_notification(ipn_url)
  validate_url = "#{ipn_url}?cmd=_notify-validate"
  # Post validate_url
  ...
end

Note that the ipn_url is the same url of IPN

0
votes

It turned out to be a Windows problem which I don't know how to fix.

I tried the same thing on my Ubuntu 15 and it worked perfectly.