我正在尝试在我的应用中使用ActiveMerchant实现paypal服务。我的开发人员的paypal帐户是为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)
答案 0 :(得分: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