2014-03-03 60 views
0

我下面RailsCast#289,做教程後,我收到拋出一個RuntimeError:點擊結賬與訂閱頁面上PayPal按鈕時貝寶錯誤10002:安全錯誤Security頭是無效

[{:code=>"10002", :messages=>["Security error", "Security header is not valid"]}] 

錯誤。

該錯誤指向paypal_payment.rb上線

raise response.errors.inspect if response.errors.present? 

Paypal_Payment.rb:

def initialize(subscription) 
    @subscription = subscription 
    end 

    def checkout_details 
    process :checkout_details 
    end 

    def checkout_url(options) 
    process(:checkout, options).checkout_url 
    end 

    def make_recurring 
    process :request_payment 
    process :create_recurring_profile, period: :monthly, frequency: 1, start_at: Time.zone.now 
    end 

private 

    def process(action, options = {}) 
    options = options.reverse_merge(
     token: @subscription.paypal_payment_token, 
     payer_id: @subscription.paypal_customer_token, 
     description: @subscription.plan.name, 
     amount: @subscription.plan.price, 
     currency: "USD" 
    ) 
    response = PayPal::Recurring.new(options).send(action) 
    raise response.errors.inspect if response.errors.present? 
    response 
    end 
end 

訂閱控制器:

def new 
    plan = Plan.find(params[:plan_id]) 
    @subscription = plan.subscriptions.build 
    if params[:PayerID] 
     @subscription.paypal_customer_token = params[:PayerID] 
     @subscription.paypal_payment_token = params[:token] 
     @subscription.email = @subscription.paypal.checkout_details.email 
    end 
    end 

    def create 
    @subscription = Subscription.new(params[:subscription]) 
    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 

    def paypal_checkout 
    plan = Plan.find(params[:plan_id]) 
    subscription = plan.subscriptions.build 
    redirect_to subscription.paypal.checkout_url(
     return_url: new_subscription_url(:plan_id => plan.id), 
     cancel_url: root_url 
    ) 
    end 
end 

我有正確的用戶,通,並在初始化程序中輸入簽名。難道我在本地主機上?

回答

1

如果您處於測試模式,則需要修改初始值設定項並將config.sandbox=true更改爲false。 Railscast設置爲實時模式。