-1

Railsを使用していて、ユーザーに送金する必要があります。

これが私の関数です:

    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

いくつかのヘルパーファイルを入れる必要がありますか?

私の見解では、次のように使用したいと思います。

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

または、コントローラーでユーザーの配列を転送するだけです。

この関数を正しくするためにどこに置くべきですか?

4

1 に答える 1

2

コントローラで割り当て、ヘルパーで次のような@merchants関数を作成する必要があります。show_merchant

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

そして、このようにあなたのビューでそれを使用してください:

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

あなたの機能send_moneyはここでは何の関係もないと思いますよね?

于 2012-07-16T18:47:58.400 に答える