Вопрос

I'm using Rails and need to send money to my users.

Here is my function:

    def self.send_money(to_email, how_much_in_cents, options = {})
credentials = {
  "USER" => API_USERNAME,
  "PWD" => API_PASSWORD,
  "SIGNATURE" => API_SIGNATURE,
}

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://api-3t.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 should put in some helpers files?

I want to use it in my views, something like:

 <%@merchants each do%>
   <%@merchant(current_user.email, 100)%>
 <%end%>

or just transfer array of users in controller.

Where I should put this function to make it right ?

Это было полезно?

Решение

You should assign @merchants in your controller and create a function show_merchant in you helper like this :

def show_mercant(merchant, email, value)
  ...
end

and use it in your view like this :

<% @merchants.each do |merchant| %>
  <%= show_merchant(merchant, current_user.email, 100) %>
<% end %>

I think your function send_money has nothing to do here, right?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top