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%>
または、コントローラーでユーザーの配列を転送するだけです。
この関数を正しくするためにどこに置くべきですか?