Skip to content

Instantly share code, notes, and snippets.

@qmaruf
Created October 17, 2013 15:52
Show Gist options
  • Save qmaruf/7027383 to your computer and use it in GitHub Desktop.
Save qmaruf/7027383 to your computer and use it in GitHub Desktop.
require "rubygems"
require "active_merchant"
ActiveMerchant::Billing::Base.mode = :test
gateway = ActiveMerchant::Billing::PaypalGateway.new(
:login => "seller_1229899173_biz_api1.railscasts.com",
:password => "FXWU58S7KXFC6HBE",
:signature => "AGjv6SW.mTiKxtkm6L9DcSUCUgePAUDQ3L-kTdszkPG8mRfjaRZDYtSu"
)
credit_card = ActiveMerchant::Billing::CreditCard.new(
:type => "visa",
:number => "4024007148673576",
:verification_value => "123",
:month => 1,
:year => Time.now.year+1,
:first_name => "Ryan",
:last_name => "Bates"
)
if credit_card.valid?
# or gateway.purchase to do both authorize and capture
response = gateway.authorize(1000, credit_card, :ip => "127.0.0.1")
if response.success?
gateway.capture(1000, response.authorization)
puts "Purchase complete!"
else
puts "Error: #{response.message}"
end
else
puts "Error: credit card is not valid. #{credit_card.errors.full_messages.join('. ')}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment