Permalink
Browse files

adding episode 144

  • Loading branch information...
1 parent 1642b47 commit 681fc885330a81220f27313d6fe026a78585868e @ryanb committed Jan 12, 2009
Showing with 39 additions and 0 deletions.
  1. +7 −0 episode-144/README
  2. +32 −0 episode-144/purchase.rb
View
@@ -0,0 +1,7 @@
+Railscasts Episode #144: Active Merchant Basics
+
+http://railscasts.com/episodes/144
+
+Commands
+
+ sudo gem install activemerchant
View
@@ -0,0 +1,32 @@
+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?
+ 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

0 comments on commit 681fc88

Please sign in to comment.