【问题标题】:PayPal error 10002:Security error Security header is not validPayPal 错误 10002:安全错误 安全标头无效
【发布时间】:2014-04-05 04:23:50
【问题描述】:

我正在关注 RailsCast #289,在完成教程后我收到了 RuntimeError:

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

单击订阅页面上的使用 PayPal 结帐按钮时出错。

错误是指向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

我在初始化程序中输入了正确的用户、密码和签名。难道是我在本地主机上?

【问题讨论】:

    标签: ruby-on-rails paypal


    【解决方案1】:

    如果您处于测试模式,则需要修改初始化程序并将 config.sandbox=true 更改为 false。 Railscast 设置为实时模式。

    【讨论】:

      猜你喜欢
      • 2015-07-01
      • 2014-06-09
      • 2016-07-15
      • 2014-06-15
      • 1970-01-01
      • 2016-06-28
      • 2014-06-18
      • 2023-03-03
      • 2020-05-19
      相关资源
      最近更新 更多