加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – Stripe Connect – 检索访问令牌

发布时间:2020-12-17 03:37:15 所属栏目:百科 来源:网络整理
导读:我正在尝试为rails 3.2.13 app设置Stripe Connect.我已将用户定向到Stripe并从Stripe接收了授权代码: HTTP/1.1 302 FoundLocation: http://localhost:3000/yourshop/stripe?scope=read_writestate=1234code=AUTHORIZATION_CODE 下一步是根据Stripe文档,通过
我正在尝试为rails 3.2.13 app设置Stripe Connect.我已将用户定向到Stripe并从Stripe接收了授权代码:

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

下一步是根据Stripe文档,通过access_token_url发出POST请求以接收access_token:

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 'omniauth-stripe-connect'
gem 'stripe'

模型

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

错误:

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

不确定是否只是错误的格式为rails中的curl或者是否需要使用其他东西.

解决方法

试试这个食谱:

在rails应用程序中安装HTTParty gem

response = HTTParty.post(“https://connect.stripe.com/oauth/token”,:query => {client_secret:“#{ENV [‘STRIPE_SECRET_KEY’]}”,代码:response_code,grant_type:“authorization_code”})

然后你应该能够访问响应[‘access_token’],而不必在curl代码周围使用反引号.它对我有用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读