2013-10-25 44 views
3

我看了ryan bates上的條紋整合。一切都幾乎平穩直到最後。我覺得他的演員陣容已經過時了,也許條紋已經更新了api。我收到此錯誤Stripe and Rails 4 App Stripe :: InvalidRequestError

在SubscriptionsController中的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 

回答

5

你是不是允許在您的控制器的subscription_params方法:stripe_card_token參數。

要允許它,添加:stripe_card_token到允許列表方法內:

def subscription_params 
    params.require(:subscription).permit(:plan_id, :email, :stripe_card_token) 
end 
+0

就是這樣。我還注意到我使用的是:電子郵件的描述,stripe包含:電子郵件。謝謝! – Josh