[英]sending POST request to API endpoint to receive stripe_user_id
After a user signs up for a Stripe account with my app, they are redirected to my localhost, and an authorization_code
is added to the url. 用户在使用我的应用程序注册Stripe帐户后,他们将被重定向到我的本地主机,并且将
authorization_code
添加到URL。 I am then supposed to make a POST request with my client_secret
and authorization_code
to their API endpoint. 然后,我应该使用
client_secret
和authorization_code
向其API端点发出POST请求。 The code provided by the docs says to do something like this: docs提供的代码说要做这样的事情:
curl https://connect.stripe.com/oauth/token \
-d client_secret=blahblah \
-d code="{AUTHORIZATION_CODE}" \
-d grant_type=authorization_code
But...where do I do this, exactly? 但是...我到底要在哪里做? In the controller?
在控制器中? Like this?
像这样?
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
The user gets redirected to a GET route on my app at the end of step 3, and then my app is supposed to make a POST to the Stripe endpoint. 在第3步结束时,用户将重定向到我的应用程序上的GET路由,然后应该将我的应用程序发布到Stripe端点。 Do I need to set up a route?
我需要设置路线吗? Can I have this action happen in the background?
我可以在后台执行此操作吗?
The call to /oauth/token
is something you make on the backend/controller to get an authorization token from Stripe that you'll need in order to make call on behalf of the connected account. 您需要在后端/控制器上对
/oauth/token
调用,以从Stripe获取授权令牌,以代表连接的帐户进行调用。 Your user doesn't need to be involved at all with that call once they've authorized your platform to connect to their account. 一旦您的用户授权您的平台连接到他们的帐户,就完全不需要参与该呼叫。
Since you're using Ruby, I'd recommend using stripe-ruby (the official library). 由于您使用的是Ruby,因此建议您使用stripe-ruby (官方库)。 That has built-in methods for using Oauth with Stripe Connect.
这具有将Oauth与Stripe Connect结合使用的内置方法 。
solution! 解! write it as a module.
将其编写为模块。 it doesn't need to be persisted to the db.
它不需要持久化到数据库。 also helpful was using the stripe ruby library
使用条纹红宝石库也很有帮助
i wrote a stripe_oauth.rb that looks like this: 我写了一个stripe_oauth.rb,看起来像这样:
module StripeOauth
def self.connect(code)
Stripe.api_key = ENV["STRIPE_SECRET_KEY"]
Stripe::OAuth.token( {code: code, grant_type: "authorization_code" } )
end
end
and then i called that from the controller action Stripe redirected me to: 然后我从控制器动作Stripe中将其重定向到:
def welcome
StripeOauth.connect(params[:code])
end
params[:code]
is sent along as part of the url, so params[:code]
作为url的一部分发送,所以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.