【发布时间】:2013-06-21 11:37:24
【问题描述】:
我正在尝试为 rails 3.2.13 应用程序设置 Stripe Connect。我已将用户定向到 Stripe 并从 Stripe 收到了授权码:
HTTP/1.1 302 Found
Location: http://localhost:3000/yourshop/stripe?scope=read_write&state=1234&code=AUTHORIZATION_CODE
根据 Stripe 文档,下一步涉及发出 POST 请求以通过 access_token_url 接收 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的格式错误,或者是否需要使用其他内容。
【问题讨论】:
-
我不知道 Stripe API,但你知道:curl 是一个命令行工具,因此你不能像 curl 一样复制粘贴Ruby 代码中的命令。至少您需要执行system call in Ruby。在实践中,我建议您使用 Stripe gem 本身(可能包括您需要的),或者 - 如果您需要自己执行自定义 HTTP 请求,请使用 Ruby HTTP 库,例如使用 libcurl 或
Net::HTTP官方的 curb图书馆。
标签: ruby-on-rails curl stripe-payments