我想使用 MassPayments。
我的 Controller 中有函数:
def send_money(to_email, how_much_in_cents, options = {})
credentials = {
"USER" => 'pro._1342094044_biz_api1.gmail.com',
"PWD" => '1342094095',
"SIGNATURE" => 'AMVxTgrWf6tUTF0Rf0y4QsqTFFAcApSXcqINQj2b2-a5wFhIx3UG87E- ',
}
params = {
"METHOD" => "MassPay",
"CURRENCYCODE" => "USD",
"RECEIVERTYPE" => "EmailAddress",
"L_EMAIL0" => to_email,
"L_AMT0" => ((how_much_in_cents.to_i)/100.to_f).to_s,
"VERSION" => "51.0"
}
endpoint = RAILS_ENV == 'production' ? "https://api-3t.paypal.com" : "https://api3t.sandbox.paypal.com"
url = URI.parse(endpoint)
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
all_params = credentials.merge(params)
stringified_params = all_params.collect { |tuple| "#{tuple.first}={CGI.escape(tuple.last)}" }.join("&")
response = http.post("/nvp", stringified_params)
end
我只为一个用户调用这个函数(一开始):
send_money('pro_1342434702_biz@gmail.com',1000)
但此时它给我错误:
uninitialized constant MerchantsController::RAILS_ENV
所以我试图改变这一行:
endpoint = RAILS_ENV == 'production' ? "https://api-3t.paypal.com" : "https://api-3t.sandbox.paypal.com"
但是我所有的尝试都失败了。我在实验期间遇到的错误 - 环境或 SSL 证书错误。
只有我离开的时候:
endpoint = "https://api-3t.sandbox.paypal.com"
我收到错误:
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
有人可以帮忙吗?
最佳答案
我认为您的帖子中有两个问题。首先,要测试您是否处于生产模式,您可以这样做:
endpoint = ENV["RAILS_ENV"] == 'production' ? "https://api-3t.paypal.com" : "https://api-3t.sandbox.paypal.com"
另一个问题是 SSL 的问题。您可以在这里找到解决方案:SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
关于ruby-on-rails - MassPayment on Rails 功能误解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11508517/