I did a project where I had to integrate 2 payment systems (Paypal and PayU) in a rails app. I read through gems and APIs for both and it seemed easy. It was later that I heard of Active Merchant which has almost all payment gateways available. I searched google on ways to integrate it and there was no tutorial or posts at all which helped me to do this. There was an old rails casts episode which did this but it used rails 2
.
I tried to do it my way looking at the Gem doc and it took a bit of time but I finally figured it out. I am going to explain how to integrate Paypal Express Checkout to a rails 4
application.
I am not gonna explain it from scratch. I hope you have a rails app all setup with basic order details.
So we first add activemerchant
to gemfile.
Gemfile
Then run bundle
and install the gem. Now we create an initializer file for the activemerchant
where we enter the API creds.
config/initializers/activemerchant.rb
I used figaro
gem to set the environment variables. I am fetching the details from there. Now I have an orders controller where you order something. On its create, I take him to paypal where he completes his payment. You can change its working however you want but I have a simple orders thing just to show it.
app/controllers/orders_controller.rb
Thats all with the setting up of Paypal Express Checkout with activemerchant
.
The Paypal Standard Checkout is the same way. Except that in it, you pass the credit card information from your site to paypal and it posts there. The user stays in your site the entire time.
PayU integration is also similar. Looking through the Active Merchant repo’s lib
will give you a better idea.