我想重定向uri返回到特定任务的提交路径,但我不知道如何向条带重定向uri发送ID。
我目前已将重定向uri设置为http://localhost:3000/stripe/connect。但是我希望能够通过任务ID发送到Stripe Connect操作,以便我可以重定向到特定的任务提交路径
Submissions / new.html.erb:
<% 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 stripe_button_link
stripe_url = "https://connect.stripe.com/oauth/authorize"
redirect_uri = stripe_connect_url
client_id = ENV["STRIPE_CLIENT_ID"]
"#{stripe_url}?response_type=code&redirect_uri=# {redirect_uri}&client_id=#{client_id}&scope=read_write"
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