paypal_permissions gem的API凭据不正确

时间:2012-09-27 11:53:46

标签: ruby-on-rails ruby-on-rails-3 paypal paypal-sandbox

我正在使用https://github.com/moshbit/paypal_permissions获取我的应用的卖家权限。

所有方法都运行正常,但当我尝试使用方法get_basic_personal_dataget_advanced_personal_data时,我会在日志中收到此回复:

{:raw_response=>"responseEnvelope.timestamp=2012-09-27T04%3A36%3A17.904-07%3A00&response
Envelope.ack=Failure&responseEnvelope.correlationId=3baaaa7435436&responseEnvelope.build
=2210301&error(0).errorId=520003&error(0).domain=PLATFORM&error
(0).subdomain=Application&error(0).severity=Error&error(0).category=Application&error
(0).message=Authentication+failed.+API+credentials+are+incorrect.", :errors=>
[{:parameters=>[], :error_id=>"520003", :domain=>"PLATFORM", :subdomain=>"Application",
 :severity=>"Error", :category=>"Application", :message=>"Authentication failed. API
 credentials are incorrect."}], :personal_data=>{},
:timestamp=>"2012-09-27T04:36:17.904-07:00", :ack=>"Failure", :correlation_id=>"3baaaa7435436"}

您可以在https://github.com/moshbit/paypal_permissions/blob/master/examples/app/controllers/merchants_controller.rb

上看到这些方法

这些是我的users_controller.rb +方法get_basic_personal_data中的3种方法:

def request_permissions_callback
    callback_url = URI.encode(response_permissions_callback_user_url(current_user))
    permissions = 'REFUND, ACCESS_BASIC_PERSONAL_DATA'
    paypal_response = ::PAYPAL_PERMISSIONS_GATEWAY.request_permissions callback_url, permissions
    if paypal_response[:ack] == 'Success'
      session[:id] = current_user.id
      request_token = paypal_response[:token]
      session[:request_token] = request_token
      url = ::PAYPAL_PERMISSIONS_GATEWAY.redirect_user_to_paypal_url(request_token)
      redirect_to url
    else
      #render :text => paypal_response.inspect
      # handle error
      format.html { redirect_to requirements_to_sell_user_path(current_user), alert: t(".permissions_wrong") }
    end
end

def response_permissions_callback
  session[:request_token_verifier] = params[:verification_code]
  get_access_token
  logger.info get_basic_personal_data(current_user).inspect
  p get_basic_personal_data(current_user).inspect
  respond_to do |format|
    if get_access_token == true
     format.html { redirect_to requirements_to_sell_user_path(current_user), notice: t(".refund_permissions_success") }
    elsif get_access_token == false
     format.html { redirect_to requirements_to_sell_user_path(current_user), alert: t(".refund_permissions_wrong") }
    end 
  end
end


def get_access_token
    request_token = session[:request_token]
    verifier = session[:request_token_verifier]
    paypal_response = ::PAYPAL_PERMISSIONS_GATEWAY.get_access_token request_token, verifier
    if paypal_response[:ack] == 'Success'
      current_user.update_attributes({
        :ppp_access_token => paypal_response[:token],
        :ppp_access_token_verifier => paypal_response[:token_secret],
      })
      return true
    else
      return false
    end
end

def get_basic_personal_data(current_user)
    access_token = current_user.ppp_access_token
    verifier = current_user.ppp_access_token_verifier
    ::PAYPAL_PERMISSIONS_GATEWAY.get_basic_personal_data(access_token, verifier)
 end
  • request_permissions_callback(向paypal请求,用户被重定向到paypal权限页面。)
  • response_permissions_callback收到来自paypal的回复,并致电get_access_token更新我的mongodb数据库中的数据。

当卖家从paypal权限帐户返回

时,我收到错误日志

logger.info get_basic_personal_data(current_user).inspect

get_access_token被解雇后,我可以在我的数据库中看到get_basic_personal_data方法使用后的正确令牌:

ppp_access_token: "ZlM-jt4LQUxQZDozxkH29I53QyXShtziJIbPlCk3m35i65iLiqVf7w", ppp_access_token_verifier: "wJd3uuP5ymyWAqiUf2qaVCPTMsk"

如果其他3种方法工作正常且api凭据正确,为什么我在此方法中出现此错误?错误在哪里?

非常感谢!

1 个答案:

答案 0 :(得分:1)

感谢Mark的帮助:D。

错误发生在我的development.rb文件中。

您可以评论或删除ActiveMerchant::Billing::Base.mode = :test行,现在工作正常。

Myapp::Application.configure do
  config.after_initialize do
    #ActiveMerchant::Billing::Base.mode = :test
    permissions_options = {
     :login => 'myapp_api1.gmail.com',
     :password => 'mypassword',
     :signature => 'mysignature',
     :app_id => 'APP-80W284485P519543T',  # This is the app_id for all PayPal Permissions Service sandbox test
     apps
    }
    ::PAYPAL_PERMISSIONS_GATEWAY = ActiveMerchant::Billing::PaypalPermissionsGateway.new(permissions_options)
  end
end

非常感谢!