0

I want to use MassPayments.

I have function in my 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

I'm calling this function only for one user(for the start):

send_money('pro_1342434702_biz@gmail.com',1000)

But at this moment it gives me error:

uninitialized constant MerchantsController::RAILS_ENV

So I tried to change this line:

endpoint = RAILS_ENV == 'production' ? "https://api-3t.paypal.com" : "https://api-3t.sandbox.paypal.com"

but all my attempts failed. Errors that I got during experiments - environment or SSL sertificate errors.

When I leave only :

endpoint = "https://api-3t.sandbox.paypal.com"

I get error :

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Can someone help ?

Dougui
  • 7,142
  • 7
  • 52
  • 87
Denys Medynskyi
  • 2,353
  • 8
  • 39
  • 70

1 Answers1

1

I think there is two questions in you post. First, to test if you are in production mode, you can do something like this :

endpoint = ENV["RAILS_ENV"] == 'production' ? "https://api-3t.paypal.com" : "https://api-3t.sandbox.paypal.com"

The other question is a problem with SSL. You can find a solution here : SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

Community
  • 1
  • 1
Dougui
  • 7,142
  • 7
  • 52
  • 87