0

我想使用 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

有人可以帮忙吗?

4

1 回答 1

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

于 2012-07-16T16:39:06.187 回答