Klairvoyant infosolution's Blog

Paypal with rails-Using Active merchant

john

) gem install activemerchant

2) create two paypal test accounts 1)Business 2) personal

copy the following information which will be created while creating business account

API Username,API Password and Signature

location:- https://developer.paypal.com/

3) code the following in a ruby file ex “purchase.rb”

require “rubygems”
require “active_merchant”

ActiveMerchant::Billing::Base.mode=:test

gateway=ActiveMerchant::Billing::PaypalGateway.new(
:login=> “API username”,
:password=>”API Password”,
:signature=>”signature”
)
# here the credit card information of the personal test account

credit_card=ActiveMerchant::Billing::CreditCard.new(
:type=>”visa”,
:number=>”4582849457729927″,
:verification_value=>”000″,
:month=>01,
:year=>2013,
:first_name=>”John”,
:last_name=>”M V”
)
if credit_card.valid?
response=gateway.purchase(1000,credit_card,:ip=> “127.0.0.0”, :billing_address=> {:name=>”john M.V”,:address1=>”Muttath”,:city=>”Thrissur”,:state=>”Kerala”,:country=>”IN”,:ZIP=>”680505″})
if response.success?
puts “purchase complete!”
else
puts “Error: #{response.message}”
end
else
puts “Error:credit card is not valid”
end

4) once this script is ok go for rails implementation

1)Add the following to gemfile and bundle. follow the railcast 145 except gem installation
gem ‘activemerchant’, :require => ‘active_merchant’

source:
1) railcast 141-paypal-basics
2)railcast 144- active-merchant-basics
3)https://github.com/Shopify/active_merchant
4) railscast 145