ruby-on-rails - 如何使用 ruby​​ on rails 中的 paypal-express gem 解决 10007 - "permission denied"PayPal API 错误

标签 ruby-on-rails ruby paypal

我正在使用 paypal-express我的 ruby​​ on rails 项目中的 gem。我希望用户能够在我的 Web 应用程序上购买数字商品。我创建了一个带有新的和创建 Action 的 Controller 。 new 操作生成用户访问的 PayPal 链接。用户从 PayPal 返回到我尝试完成订单的 create 操作。

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

我已经三次检查了我为生产输入的用户名/密码/API 签名,它们是正确的(用户被发送到正确的 PayPal 商店)。

这是我的 Controller :

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,它似乎在 PayPal API 上调用 DoExpressCheckoutPayment 并传递 PayerID 和 token 。 PayPal API 文档没有列出解决我的错误 (10007) 的方法。

最佳答案

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

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

关于ruby-on-rails - 如何使用 ruby​​ on rails 中的 paypal-express gem 解决 10007 - "permission denied"PayPal API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11306648/

相关文章:

ruby-on-rails - ActiveRecord 是否已经将手动查询包装到事务中?

ruby-on-rails - 为什么在不传递 :id param work (in rails)? 的情况下重定向到 #show 操作

asp.net - Paypal + ASP .NET Web 应用程序集成的基本工作流问题

ruby-on-rails - Ruby on Rails 可以成为游戏服务器吗?

ruby-on-rails - rails 中的 session 和 user_id

Ruby TCPSocket/HTTP 请求

symfony - Payum/ Paypal 结账 : What to do after redirecting me to done action

javascript - 在 paypal API (Client SITE) 中设置描述

ruby-on-rails - ActiveRecord虚拟属性作为记录属性

ruby-on-rails - 如何在 rails 中组合 2 个数组,使得没有重复项