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
  • 6,952
  • 6
  • 46
  • 84
deny7ko
  • 2,323
  • 8
  • 38
  • 69

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
  • 6,952
  • 6
  • 46
  • 84
  • SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed showing me. – deny7ko Jul 16 '12 at 16:45
  • Can you check what is returned by ENV["RAILS_ENV"]? – Dougui Jul 16 '12 at 16:52
  • You can go in debug mode (check it on google) or simple add `puts ENV["RAILS_ENV"]` in your code an check logs. – Dougui Jul 16 '12 at 16:58
  • Did you run your application with `rails start -e production`? – Dougui Jul 16 '12 at 17:01
  • no. I found SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed error could be caused by old rails. So now I'm uodating them. I will try what you are talking about after install.Thanks for help. – deny7ko Jul 16 '12 at 17:10
  • Maybe, I could try to deploy it and look if there will be error ? – deny7ko Jul 16 '12 at 17:20
  • E:\paypal_permission>rails start -e production Error: Command not recognized – deny7ko Jul 16 '12 at 17:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/13958/discussion-between-dougui-and-denys-medynskyi) – Dougui Jul 16 '12 at 17:22