Rails 始终听众 Paypal IPN return 无效
Rails listener Paypal IPN always return INVALID
我已经为我的 IPN 构建了一个侦听器。我可以通过 IPN 模拟器接收请求并且所有参数都是正确的,但是当我将它发送回 link for sending my request to make validations 时它总是 return 无效。
我曾尝试将我的 PayPal 帐户的编码更改为 UTF-8,但没有成功。
我没有为此使用任何 gem,我也不期待这个。
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
请帮帮我,我已经卡了一下午了,想不通。
我觉得你的问题是not follow exactly what papal requires
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.
所以你 validate function
会是:
def validate_IPN_notification(ipn_url)
validate_url = "#{ipn_url}?cmd=_notify-validate"
# Post validate_url
...
end
注意 ipn_url
与 IPN
相同 url
原来是一个 Windows 问题,我不知道如何解决。
我在我的 Ubuntu 15 上尝试了同样的方法,效果很好。
我已经为我的 IPN 构建了一个侦听器。我可以通过 IPN 模拟器接收请求并且所有参数都是正确的,但是当我将它发送回 link for sending my request to make validations 时它总是 return 无效。
我曾尝试将我的 PayPal 帐户的编码更改为 UTF-8,但没有成功。
我没有为此使用任何 gem,我也不期待这个。
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
请帮帮我,我已经卡了一下午了,想不通。
我觉得你的问题是not follow exactly what papal requires
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.
所以你 validate function
会是:
def validate_IPN_notification(ipn_url)
validate_url = "#{ipn_url}?cmd=_notify-validate"
# Post validate_url
...
end
注意 ipn_url
与 IPN
原来是一个 Windows 问题,我不知道如何解决。
我在我的 Ubuntu 15 上尝试了同样的方法,效果很好。