在用户使用我的应用注册Stripe帐户后,他们会被重定向到我的本地主机,并且authorization_code会在 url 中添加一个。然后我应该向我的client_secret和authorization_code他们的 API 端点发出 POST 请求。文档提供的代码说要做这样的事情:
curl https://connect.stripe.com/oauth/token \
-d client_secret=blahblah \
-d code="{AUTHORIZATION_CODE}" \
-d grant_type=authorization_code
但是......我在哪里做这个,究竟是什么?在控制器中?像这样?
def post_to_endpoint(endpoint)
require 'json'
begin
uri = URI.parse(endpoint)
post_params = {
client_secret: "client_secret",
code: "{AUTHORIZATION_CODE}",
grant_type: authorization_code
}
req = Net::HTTP::Post.new(uri.path)
req.body = JSON.generate(post_params)
req["Content-Type"] = "application/json"
http = Net::HTTP.new(uri.host, uri.port)
response = http.start { |htt| htt.request(req) }
rescue => e
puts "failed #{e}"
end
end
在第 3 步结束时,用户被重定向到我的应用程序上的 GET 路由,然后我的应用程序应该向 Stripe 端点发出 POST。我需要设置路线吗?我可以让这个动作在后台发生吗?