0
我正在尝试将Stripe API集成到我的Rails项目中。但是我想知道为什么当我检查我的互联网连接正常时,我有一个失败的APIConnectionError。带条纹API的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-ING的/users/charge
URL路径。
<h4>Begin your £9.99 a month subscription</h4>
<form action="https://stackoverflow.com/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 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'dotenv-rails', :groups => [:development, :test]
我不知道我缺少什么,这是我收到的时候我叫charge
行动users_controller.rb
错误:
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,我怎么可以只是运行“主机stripe.com”
调试
你有没有机会进入防火墙? – shivam
谢谢,那是问题所在。我切换了代理,现在它可以正常工作。 –