【问题标题】:APIConnectionError with Stripe API使用 Stripe API 的 APIConnectionError
【发布时间】:2017-04-04 20:00:05
【问题描述】:

我正在尝试将 Stripe API 集成到我的 Rails 项目中。但是我想知道为什么当我检查我的互联网连接是否正常时我有一个失败的 APIConnectionError 。

在users_controller.rb:

def charge
  token = params["stripeToken"]
  customer = Stripe::Customer.create(
    source: token,
    plan: 'mysubscriptionlevel1',
    email: current_user.email
  )

  current_user.subscription.stripe_user_id = customer.id
  current_user.subscription.active = true
  current_user.subscription.save

  redirect_to users_info_path
end

在/views/users/_form.html.erb 中,我将表单POST 到/users/charge url 路径。

  <h4>Begin your £9.99 a month subscription</h4>
  <form action="/users/charge" method="POST" id="payment-form">
    <span class="payment-errors"></span>

在我的routes.rb 文件中,我有:

post '/users/charge', to: 'users#charge'

在config/initializer/stripe.rb 中,我需要条带并将我的 api 密钥放在 .env 文件中。

require "stripe"
Stripe.api_key = ENV["STRIPE_API_KEY"]

我还在我的 Gemfile 中包含了 stripe gem:

gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'dotenv-rails', :groups => [:development, :test]

我不确定我错过了什么,这是我在users_controller.rb 中调用charge 操作时遇到的错误:

Stripe::APIConnectionError (Unexpected error communicating when trying to connect to Stripe. You may be seeing this message because your DNS is not working. To check, try running 'host stripe.com' from the command line.

(Network error: Failed to open TCP connection to : (getaddrinfo: nodename nor servname provided, or not known))):

DNS 不工作是什么意思,我如何通过运行“host stripe.com”进行调试

【问题讨论】:

  • 你有可能在防火墙后面吗?
  • 谢谢,这就是问题所在。我切换了代理,它现在可以工作了。

标签: ruby-on-rails ruby stripe-payments ruby-on-rails-5


【解决方案1】:

切换了代理,它现在可以工作了。

【讨论】:

  • 我知道已经 2 年了,但是如果你有机会看到这个,你能解释一下你做了什么吗? (你用的是什么代理?)
猜你喜欢
  • 2019-01-12
  • 1970-01-01
  • 2016-10-27
  • 2019-11-26
  • 2021-12-28
  • 1970-01-01
  • 2021-11-30
  • 1970-01-01
  • 2017-02-18
相关资源
最近更新 更多