我观看了 ryan bates rails 对条纹整合的看法。直到最后,一切几乎都很顺利。我觉得他的演员阵容有些过时了,也许条纹已经更新了 api。我收到此错误
订阅控制器中的 Stripe::InvalidRequestError。
它突出显示了我的订阅模型页面,特别是客户创建部分
class Subscription < ActiveRecord::Base
belongs_to :plan
belongs_to :user
validates_presence_of :plan_id
validates_presence_of :email
attr_accessor :stripe_card_token
def save_with_payment
if valid?
customer = Stripe::Customer.create(description: email, plan: plan_id, card: stripe_card_token)
self.stripe_customer_token = customer.id
save!
end
end
end
这是我的订阅控制器
class SubscriptionsController < ApplicationController
before_action :authenticate_user!
def new
plan = Plan.find(params[:plan_id])
@subscription = plan.subscriptions.build
@useremail = current_user.email
end
def create
@subscription = current_user.build_subscription(subscription_params)
if @subscription.save_with_payment
redirect_to @subscription, :notice => "Thank you for subscribing!"
else
render :new
end
end
def show
@subscription = Subscription.find(params[:id])
end
private
def subscription_params
params.require(:subscription).permit(:plan_id, :email)
end
end