Cornelius Wilson
Cornelius Wilson

Reputation: 2914

PayPal error 10002:Security error Security header is not valid

I am following RailsCast #289 and after doing the tutorial I am receiving a RuntimeError:

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

error when clicking the Checkout with PayPal button on the subscription page.

The error is pointing to the paypal_payment.rb on line

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

Subscriptions Controller:

  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

I have the proper user, pass, and signature entered on initializer. Could it be that I am on localhost?

Upvotes: 0

Views: 2280

Answers (1)

xps15z
xps15z

Reputation: 1829

If your in testing mode you need to modify your initializer and change config.sandbox=true to false. The Railscast is set in live mode.

Upvotes: 1

Related Questions