Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Paypal API Certificate with ActiveMerchant

I'm trying to implement paypal service using ActiveMerchant in my app. My developler's paypal account is set up for API certificate credentials. The following code works perfectly well when used with API signature but gives me an error when I try to implement API certificate. Can someone please help?

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

The Error :

/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)
like image 580
safalmj Avatar asked Dec 05 '25 23:12

safalmj


1 Answers

Okay, I figured out where I went wrong. I checked into the ActiveMerchant doc and found that I should be using :pem instead of :certificate. So, the code should look like -

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
like image 171
safalmj Avatar answered Dec 07 '25 19:12

safalmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!