【发布时间】:2014-05-12 20:34:16
【问题描述】:
我已经发布了一些与此相关的问题,但我仍然对实现有点迷茫。
基本上我需要从 Venmo API 翻译这一行以进行支付:
curl https://api.venmo.com/v1/payments -d access_token=4e4sw1111111111t8an8dektggtcbb45 -d email="someemail@gmail.com" -d amount=5 -d note="Delivery."
以 POST 请求表单/格式进入我的 Rails 站点。
我的表单中现在有以下内容:
<!-- Venmo box -->
<div class="box box-warning">
<div class="box-header">
<%= form_tag ('/make_payment_path') do %>
<%= hidden_field_tag "access_token", @access_token %>
<h3 class="box-title">Pay Bill using Venmo Account</h3>
<div id="payment_note_input">
<%= text_field_tag "payment_note", nil, class:"form-control", placeholder: "add a note to your payment" %>
</div>
<div id="payment_target_input">
<%= text_field_tag "payment_target", nil, class:"form-control", placeholder: "pay an email address" %>
</div>
<div id="payment_amount_input">
<%= text_field_tag "payment_amount", nil, class:"form-control", placeholder: "enter the payment amount!"%>
</div>
</br>
<%= submit_tag "Make payment", class: "btn btn-danger" %>
<% end %>
</div>
在我的仪表板控制器中与视图对应的以下内容:
def make_payment_path
if !params[:access_token].nil?
uri = URI.parse("https://api.venmo.com/v1/payments")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"access_token" => params[:access_token], "email" => params[:payment_target],
"amount" => params[:payment_amount], "note" => params[:payment_note]} )
response = http.request(request)
end
end
谁能帮我指出正确的方向吗?一旦通过 Venmo 处理了这个 POST 请求,它应该返回一个 JSON 响应,如 here 所示。
【问题讨论】:
标签: ruby-on-rails json post request response