Stripe Connect - 检索访问令牌 [英] Stripe Connect - retrieving access token

查看:202
本文介绍了Stripe Connect - 检索访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为rails 3.2.13应用程序设置Stripe Connect。我已指示用户到Stripe并收回Stripe的授权代码:

  HTTP / 1.1 302 Found 
位置:http:// localhost:3000 / yourshop / stripe?scope = read_write& state = 1234& code = AUTHORIZATION_CODE

下一步是通过每个Stripe文档通过access_token_url接收access_token的POST请求:

  curl -X POST https://connect.stripe.com/oauth/token \ 
-d client_secret = sk_test_code \
-d code = AUTHORIZATION_CODE \
-d grant_type = authorization_code

我没有任何经验curl是一个rails应用程序,我在Stripe API中找不到任何东西似乎这个POST请求包含在Stripe Gem中:



Gem文件:

 code> gem'omniauth-stripe-connect'
gem'stripe'

模型

  def save_with_stripe_account 
code = self.stripe_code
customer = curl -X POST https:// connect.stripe.com/oauth/token \
-dclient_secret = ENV ['STRIPE_SECRET_KEY']\
-dcode = code\
-dgrant_type = authorization_code
raise customer.inspect
end

错误:

 语法错误,意外的tCONSTANT,期望keyword_do或'{'或'('
pre>

不知道在rails中curl的格式是否错误,或者需要使用其他格式。

解决方案

我得到它太工作,可能不是最漂亮的方式:



我学到的第一件事是curl可以在rails你把反弹围绕在curl代码。这将返回只需要格式化的JSON。我在我的模型中结束了以下:

  customer = ActiveSupport :: JSON.decode(`curl -X POST https: //connect.stripe.com/oauth/token -d client_secret =#{ENV ['STRIPE_SECRET_KEY']} -d code =#{self.stripe_code} -d grant_type = authorization_code`)

然后我可以从客户散列中提取数据,例如access_token:

  customer ['access_token'] 


I am trying to set up Stripe Connect for a rails 3.2.13 app. I have directed the user to Stripe and received back the authorization code from Stripe:

HTTP/1.1 302 Found
Location: http://localhost:3000/yourshop/stripe?scope=read_write&state=1234&code=AUTHORIZATION_CODE

The next step involves making a POST request to receive the access_token via the access_token_url, per Stripe documentation:

curl -X POST https://connect.stripe.com/oauth/token \
  -d client_secret=sk_test_code \
  -d code=AUTHORIZATION_CODE \
  -d grant_type=authorization_code

I don't have any experience with curl is a rails app and I couldn't find anything in the Stripe API that seems like this POST request is include in the Stripe Gem:

Gem file:

gem 'omniauth-stripe-connect'
gem 'stripe'

Model

def save_with_stripe_account
  code = self.stripe_code
  customer = curl -X POST https://connect.stripe.com/oauth/token \
    -d "client_secret=ENV['STRIPE_SECRET_KEY']" \
    -d "code=code" \
    -d "grant_type=authorization_code"
  raise customer.inspect  
end

Error:

syntax error, unexpected tCONSTANT, expecting keyword_do or '{' or '('

Not sure if just the wrong formatting for curl in rails or if need to use something else.

解决方案

I got it too work, probably not the prettiest way:

The first thing I learned is that curl can work inside rails if you put backticks around the curl code. This will return JSON which just needs to be formatted. I ended up with the following in my model:

customer = ActiveSupport::JSON.decode(`curl -X POST https://connect.stripe.com/oauth/token -d client_secret=#{ENV['STRIPE_SECRET_KEY']} -d code=#{self.stripe_code} -d grant_type=authorization_code`)

I then am able to extract the data from the customer hash such as "access_token":

customer['access_token']

这篇关于Stripe Connect - 检索访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆