【发布时间】:2018-09-17 17:11:08
【问题描述】:
我正在使用 Rails 5、Ruby 2.4.0 和 stripe gem 构建应用程序。
我有一个产品脚手架,当我创建一个产品时,如果它保存我希望它然后将产品发送到条带并在那里创建产品,并将条带产品 ID 返回到产品记录。
它自己保存的产品,因为我可以在控制台中查询它,它出现在索引页面上,但是当它发送到条带时,我收到以下错误。
我的 ApplicationController 文件:
class ApplicationController < ActionController::Base
require "stripe"
protect_from_forgery with: :exception
end
我的完整条带初始化文件:config/initializers/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['STRIPE_PUBLISHABLE_KEY'],
:secret_key => ENV['STRIPE_SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
我的产品控制器创建操作:
def create
@product = Product.new(product_params)
respond_to do |format|
if @product.save
format.html { redirect_to @product, notice: 'Product was successfully created.' }
format.json { render :show, status: :created, location: @product }
product = Stripe::Product.create({
name: @product.prod_name,
type: @product.prod_type,
statement_descriptor: @product.statement_descriptor,
unit_label: @product.unit_label,
product_status: @product.product_status
})
else
format.html { render :new }
format.json { render json: @product.errors, status: :unprocessable_entity }
end
end
end
这里的任何帮助将不胜感激,因为我对条纹的经验很少,而且我似乎无法解决这个问题!
【问题讨论】:
标签: ruby-on-rails stripe-payments