【发布时间】:2016-07-20 15:17:51
【问题描述】:
我正在尝试在我的网站上创建他们的托管 Stripe 帐户时将我的用户的 Stripe 密钥和可发布密钥保存到我的数据库中。
stripe_controller.rb
def create
Stripe.api_key = Rails.configuration.stripe[:secret_key]
@account = Stripe::Account.create(
managed: true,
country: params[:artist_payment_setting][:country],
email: @artist.email,
tos_acceptance: {
ip: request.remote_ip,
date: Time.now.to_i
},
legal_entity: {
dob: {
month: params[:artist_payment_setting][:month],
day: params[:artist_payment_setting][:day],
year: params[:artist_payment_setting][:year]
},
first_name: params[:artist_payment_setting][:first_name],
last_name: params[:artist_payment_setting][:last_name],
type: 'individual',
}
)
if @account.save
@payment = @artist.create_artist_payment_setting(
currency: @account.default_currency,
country: @account.country,
stripe_id: @account.id,
stripe_publishable_key: @account.keys.publishable, ***********problem********
stripe_secret_key: @account.keys.secret ***********problem********
)
end
redirect_to artist_path(@artist)
end
不幸的是,我不断收到NoMethodError (undefined method 'publishable' for #<Array:0x007f57d83edaf0>) 和secret。
API 响应是
{
keys:
{
secret: "secret_key"
publishable: "publish_key"
}
}
不知道如何获得这些密钥。
【问题讨论】:
-
您查看过
@account.keys.inspect以了解其中包含的内容吗?错误消息表明它是Array... -
是的,我不明白为什么它会以
Array的形式返回。 API 的响应不是。 -
尝试使用
byebug在您的控制台中操作@account.keys。你能发布@account在保存之前的样子吗? -
@account只是我用来创建新 Stripe 帐户的变量。而且 Stripe 帐户运行if @account.save部分没有任何问题。它可以毫无问题地检索stripe_id、currency、country,但这些不是嵌套的。我认为将secret和publishable嵌套在keys中会导致它被抛弃。
标签: ruby-on-rails ruby ruby-on-rails-4 stripe-payments