2

我在我的 ruby​​ on rails 项目中使用了paypal-express gem。我希望用户能够在我的 Web 应用程序上购买数字商品。我创建了一个带有新和创建操作的控制器。该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

查看 paypal-express gem,它似乎调用DoExpressCheckoutPayment了 PayPal API 并传递了 PayerID 和令牌。PayPal API 文档没有列出解决我的错误 (10007) 的方法。

4

1 回答 1

0

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

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

于 2012-07-05T13:46:51.543 回答