ruby-on-rails - MassPayment on Rails 功能误解

标签 ruby-on-rails paypal

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

相关文章:

ruby-on-rails - 使用 PostGIS 的 Rails

php - Paypal IPN 在沙盒中有效 在线时无效

ruby-on-rails - Paypal 与 Rails 集成

ruby-on-rails - 使用 Rails/Mongoid/MongoDB 进行迁移有意义吗?

ruby-on-rails - Rails 和 partials,是否有更有效的编写方法...?

ruby-on-rails - ActiveRecord:查找列为零或空数组的位置

ruby-on-rails - rails redirect_to 不加载 Assets 下的 javascript

java - 在 Sandbox 上使用 Paypal Express Checkout,安全 header 无效,API 凭证中没有错误

authentication - 将客户的钱直接转给第三方(Paypal Payments Pro)

java - Paypal Java SDK - 如何配置 .properties 文件?