3

我正在尝试在我的应用程序中使用 ActiveMerchant 实现贝宝服务。我的开发者的贝宝账户是为 API 证书凭证设置的。以下代码在与 API 签名一起使用时效果很好,但在我尝试实现 API 证书时给我一个错误。有人可以帮忙吗?

PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert_dev.pem")
config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test 
  paypal_options = {
    :login => "****************",
    :password => "**************",
    :certificate => PAYPAL_CERT_PEM
  }
  ::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
end

错误 :

/Library/Ruby/Gems/1.8/gems/activemerchant-1.12.1/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb:72:in `initialize': An API Certificate or API Signature is required to make requests to PayPal (ArgumentError)
4

1 回答 1

2

好吧,我知道我错在哪里了。我检查了 ActiveMerchant 文档,发现我应该使用 :pem 而不是 :certificate。所以,代码应该看起来像 -

PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert_dev.pem")
config.after_initialize do
  ActiveMerchant::Billing::Base.mode = :test 
  paypal_options = {
    :login => "****************",
    :password => "**************",
    :pem => PAYPAL_CERT_PEM
  }
  ::STANDARD_GATEWAY = ActiveMerchant::Billing::PaypalGateway.new(paypal_options)
end
于 2012-09-07T08:38:37.917 回答