Ruby on rails 如何将id传递给条带重定向uri
我希望重定向uri以返回特定任务的提交路径,但我不知道如何向条带重定向uri发送id 我目前已将重定向uri设置为。但我希望能够通过任务id发送到stripe connect操作,以便重定向到特定的任务提交路径 提交文件/new.html.erb:Ruby on rails 如何将id传递给条带重定向uri,ruby-on-rails,ruby,stripe-payments,Ruby On Rails,Ruby,Stripe Payments,我希望重定向uri以返回特定任务的提交路径,但我不知道如何向条带重定向uri发送id 我目前已将重定向uri设置为。但我希望能够通过任务id发送到stripe connect操作,以便重定向到特定的任务提交路径 提交文件/new.html.erb: <% if current_user.stripe_user_id %> <h2>Submit</h2> <%= form_for [:task, @submission] do |f| %>
<% if current_user.stripe_user_id %>
<h2>Submit</h2>
<%= form_for [:task, @submission] do |f| %>
<%= f.text_area :description, placeholder: "File description" %>
<%= f.file_field :files, multiple: true %>
<%= f.submit "Submit", class: "btn button" %>
<% end %>
<% else %>
<h6> To Accept Payments for Tasks:</h6>
<%= link_to image_tag("light-on-dark.png"), stripe_button_link, :data => {:task_id => @task.id} %>
<% end %>
条带控制器:
def connect
response = HTTParty.post("https://connect.stripe.com/oauth/token",
query: {
client_secret: ENV["STRIPE_SECRET_KEY"],
code: params[:code],
grant_type: "authorization_code"
}
)
@task = Task.find(params[:task_id])
if response.parsed_response.key?("error")
redirect_to new_task_submission_path(@task),
notice: response.parsed_response["error_description"]
else
stripe_user_id = response.parsed_response["stripe_user_id"]
current_user.update_attribute(:stripe_user_id, stripe_user_id)
redirect_to new_task_submission_path(@task),
notice: 'User successfully connected with Stripe!'
end
end
配置路由:
get "stripe/connect", to: "stripe#connect", as: :stripe_connect
如果我理解正确,您希望将任务id作为参数发送到stripe,并从响应中获取它。你试过你的要求了吗?您可以分析响应以找到它们。将
状态
参数作为/oauth/authorize
链接的一部分传递给用户
从Stripe的:
我们将传回给您的任意字符串值,对CSRF保护非常有用
当Stripe重定向到您的
重定向uri
时,这将包含在查询字符串中,您可以使用它在应用程序中进一步重定向或处理。现在用户可以连接到Stripe,但rails返回一个错误,说它找不到没有id的任务。我添加了元数据[task\u id]=:task_id在stripe按钮链接中,但是rails仍然说它找不到没有id的任务。您是否分析了stripe响应以找到这个id?
get "stripe/connect", to: "stripe#connect", as: :stripe_connect