因此,我试图从paypal获取交易详细信息而不创建表单,只是通过向网址发送必要信息的帖子。这是我的代码片段,我尝试通过表单执行相同操作。
<form method=post action="https://www.sandbox.paypal.com/cgi-bin/webscr">
<input type="hidden" name="cmd" value="_notify-synch">
<input type="hidden" name="tx" value="<%= subscription.tx %>">
<input type="hidden" name="at" value="<%= @identity_token %>">
<input type="submit" value="View Details">
</form>
Ruby对手抛出一个EOFError,我不知道为什么要这样做
paypal_uri = URI.parse('https://www.sandbox.paypal.com/cgi-bin/webscr')
@post_request = Net::HTTP.post_form(paypal_uri , {:tx => @subscription.tx, :at => IDENTITY_TOKEN, :cmd => "_notify-sync"})
答案 0 :(得分:5)
网址为https,因此您需要在Net :: HTTP上启用SSL。
require 'openssl'
paypal_uri = URI.parse('https://www.sandbox.paypal.com/cgi-bin/webscr')
req = Net::HTTP::Post.new(paypal_uri.path)
req.set_form_data({:tx => @subscription.tx, :at => IDENTITY_TOKEN, :cmd => "_notify-sync"})
sock = Net::HTTP.new(paypal_uri.host, 443)
sock.use_ssl = true
store = OpenSSL::X509::Store.new
store.add_cert OpenSSL::X509::Certificate.new(File.new('paypal.pem'))
store.add_cert OpenSSL::X509::Certificate.new(File.new('paypal2.pem'))
sock.cert_store = store
sock.start do |http|
response = http.request(req)
end
要获取CA证书paypal.pem和paypal2.pem,只需手动浏览到PayPal URL,我将为FireFox描述它。单击地址栏左侧的绿色图标,打开对话框,查看证书,详细信息,然后将两个 VeriSign 证书导出为paypal.pem和paypal2.pem。将它们放在与脚本相同的文件夹中。这应该可以解决你的问题!