Anyone who has looked into using ActiveMerchant and PayPal together knows it is quite a challenge. ActiveMerchant is great, but there is no documentation for using it with Paypal. Here are some tips to help you get it working:
The paypal website is a bit tough to navigate and they don’t make it obvious to figure out what are all the things you need to do to get it all setup.
Paypal should now be set up. You will have to go through and do all the same stuff for your real paypal account, once your development is done and working.
config.afterinitialize do ActiveMerchant::Billing::Base.gatewaymode = :test ActiveMerchant::Billing::PaypalGateway.pemfile = File.read(RAILSROOT + ‘/config/certkeypemdev.txt’) end $PAYPALLOGIN = “ $PAYPAL_PASSWORD = ”
amount = 1000 #$10.00 creditcard = ActiveMerchant::Billing::CreditCard.new( :type => ‘visa’, :number => ‘4242424242424242’, :month => 8, :year => 2009, :firstname => ‘Bob’, :lastname => ‘Bobsen’, :verificationvalue=> ‘123’ )
flash[:error] = creditcard.errors and return unless creditcard.valid?
billing_address = { :name => “John Smith”, :address1 => ‘123 First St.’, :address2 => “, :city => ‘Los Angeles’, :state => ‘CA’, :country => ‘US’, :zip => ‘90068’, :phone => ‘310-555-1234’ }
gateway = ActiveMerchant::Billing::PaypalGateway.new(:login=>$PAYPALLOGIN, :password=>$PAYPALPASSWORD)
res = gateway.authorize(amount, creditcard, :ip=>request.remoteip, :billingaddress=>billingaddress)
if res.success? gateway.capture(amount, res.authorization) flash[:notice] = "Authorized” redirectto somewhereurl else flash[:error] = “Failure: ” + res.message.to_s end
When testing with paypal, you must use port 80: ./script/server -p 80
If you wanted it to build a product you’d find a way to get time to work on it. If you really wanted to start that new hobby you’d sacrifice something to find the time and money to do it.
I'll define a "Wannabe Entrepreneur" as someone who has never made money from their businesses. Here are the different types of wannabes.
In the past few years I've built go-carts, built a 200+ sq ft workshop, written several eBooks. How do I create a life where I have time to work on side projects?
Receive 5 Software projects mistakes we have made over the years and how to avoid them.
9 Comments
Kudos to you!
Your instructions on making ActiveMerchant work with PayPay is 1000% better than anything else out there – and you got me over the hump and my app (for the Chinese school) is now working at this critical part. Thank you a bunch for sharing your tips and solution! If you provide a “send a beer by PayPal” button, I’ll click on it ;-) … I tell you, it was a sweat pounding on this stuff. PayPal’s bits are horribly scattered – and of course, ActiveMerchant is not documented.
BTW, the website is not up yet. It will go beta, then will go live July 1st.
I agree, this is the best thing I found. I even bought a book, Beginning Ruby on Rails E-Commerce, that left out many important steps you described.
I received an error, OPENSSL::SSL::SSLERROR while using the code. Please help me… its urgent
As fawad,
i´m getting OpenSSL::PKey::RSAError in AdminController#testPay
The error is trown in this line:
res = gateway.authorize(amount, creditcard, :ip => request.remoteip, :billingaddress => billingaddress)
I´m working in winXP, WEBRick 1.3.1 port=80
Should i open some port in the windows fireall?
Thank you for this tutorial, Steven!!
Hey, just wanted to let you know that you can instantiate a PayPal gateway like this:
ActiveMerchant::Billing::PaypalGateway.new(
:login => ‘yourlogin’
:password => ‘yourpass’,
:signature => ‘79a97ad9asetcetc’)
And completely avoid messing with .pem files!
Hi, Is there any way to send payment to other bank account or to paypal account from a paypal account. Response is highly appreciatable.
Fawad,
Send payment to another bank account? I’m not sure I understand your question, but ActiveMerchant does support other banks besides paypal.
As far as transferring funds between paypal accounts, paypal does have an api that might allow for that, but I have never needed to use it.
I don’t see any ‘Billing Agreements’ or ‘Paypal Monthly Billing’ links under Merchant Services > Profile. Is this a critical step? I DO see an ‘Accept Billing Agreement’ for step 3 of the Website Payments Pro signup process, but I can’t get to it since the ‘Confirm your Email’ step in the sandbox never sends out the confirmation email. Any advice?
Thanks!
Russ
Russ,
Accepting the billing agreements are critical steps. Evey step is critical and it won’t work unless they are all done. The sandbox does not actually send real emails, so you have to click on the email tab inside the sandbox and look at the email messages in the sandbox application.