关于Rails的MassPayment功能误解

时间:2012-07-16 16:28:03

标签: ruby-on-rails paypal

我想使用MassPayments。

我的控制器中有功能:

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

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

我认为你发帖中有两个问题。首先,要测试您是否处于生产模式,您可以执行以下操作:

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