简体   繁体   English

Rails侦听器Paypal IPN始终返回INVALID

[英]Rails listener Paypal IPN always return INVALID

I've build a listener for my IPN. 我已经为我的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. 我可以通过IPN Simulator接收请求,并且所有参数都是正确的,但是当我将其发送回链接以发送请求以进行验证时 ,它将始终返回INVALID。

I've tried changing the encoding on my PayPal account to UTF-8 but it didn't work. 我尝试将我的PayPal帐户上的编码更改为UTF-8,但没有用。

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. 请帮助我,整个下午我都被困住了,无法解决。

I think your problem is not follow exactly what papal requires 我认为您的问题not follow exactly what papal requires

From Paypal document 贝宝文件

Your listener HTTP POSTs the complete, unaltered message back to PayPal. 您的侦听器HTTP POST将完整的,未更改的消息发送回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. 注意:此消息必须包含与来自PayPal的原始IPN相同的字段,并且顺序相同,且均以cmd = _notify-validate开头。 Further, this message must use the same encoding as the original. 此外,此消息必须使用与原始消息相同的编码。

So you validate function would be: 因此,您validate function将是:

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 请注意, ipn_url与IPN的网址相同

It turned out to be a Windows problem which I don't know how to fix. 原来是Windows问题,我不知道该如何解决。

I tried the same thing on my Ubuntu 15 and it worked perfectly. 我在Ubuntu 15上尝试了同样的方法,并且运行良好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM