繁体   English   中英

如何使用Rails中的ruby中的paypal-express gem解决10007-“权限被拒绝” PayPal API错误

[英]How can I resolve the 10007 - “permission denied” PayPal API error using the paypal-express gem in ruby on rails

我在我的ruby on rails项目中使用了paypal-express宝石。 我希望用户能够在我的Web应用程序上购买数字商品。 我创建了一个带有new和create动作的控制器。 new操作将生成用户访问的PayPal链接。 用户从贝宝(PayPal)返回到我尝试完成订单的create操作。

使用沙盒凭据时,开发过程中一切正常,使用生产凭据时,我从PayPal收到“ 10007-权限被拒绝”错误。

我已对输入的用于生产的用户名/密码/ API签名进行了三重检查,它们是正确的(将用户发送到正确的PayPal商店)。

这是我的控制器:

class DigitalPaymentsController < ApplicationController
  before_filter :authenticate_user!, :only => [ :new, :create ]

  def new
    Paypal.sandbox! unless Rails.env.production?

    response = paypal_request.setup(
      payment_request,
      success_url,
      cancel_url,
      :no_shipping => true
    )

    @paypal_url = response.redirect_uri
  end

  def create
    begin
      response = paypal_request.checkout!(params[:token], params[:PayerID], payment_request)

      if response.payment_info.first.payment_status == 'Completed'
        # TODO: Handle complete payments
      else
        # TODO: Handle non complete payments
      end
    rescue Paypal::Exception::APIError => e
      # Payment has failed, failure details are in e.message, also check params
    end
  end

  private

  def paypal_request
    @request ||= Paypal::Express::Request.new(
      :username   => PAYPAL_USERNAME,
      :password   => PAYPAL_PASSWORD,
      :signature  => PAYPAL_SIGNATURE
    )
  end

  def payment_request
    @payment_request ||= Paypal::Payment::Request.new(
      :currency_code => :USD,
      :amount => 15,
      :items => [{
      :name => "Awesome Product",
      :description => 'Description of awesomeness',
      :amount => 15,
      :category => :Digital
    }]
    )
  end
end

在看看到贝宝快递的宝石,好像叫DoExpressCheckoutPayment的PayPal API并通过PayerID和令牌。 PayPal API文档未列出解决我的错误的方法(10007)。

PayPal API错误的原因是,我需要在签出交易之前调用PayPal GetExpressCheckoutDetails操作。 我是通过在此处添加来自paypal-express gem Wiki的一行来做到这一点的: https : //github.com/nov/paypal-express/wiki/Instant-Payment

我需要的只是paypal_request.details(params[:token])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM