Allan & Steve are the chubby founders of LessEverything. This is their blog, hear them rant, praise, give advice and talk about Just Stuff, Less Accounting, Lovd by Less, More Honey, Less Memories, Code, Business, Design, Marketing
Chat with Us
June 6th, 2007

Paypal on Rails...ActiveMerchant tips

written by Steven Bristol

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:

Here is a page with some good references.

Setting up Paypal

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.

  1. You will need a sandbox (developer) paypal account to test your set up. Sign up here
  2. The sandbox does not send emails, so you will have to use the Sandbox Email Tab to validate your sandbox account email address.
  3. Launch the sandbox
  4. Create a sandbox business account. and go through the normal paypal verification stuff. (It does not use your real bank account.)
  5. Go to the Merchant Services tab and signup for a Website Payments Pro Account.
  6. Verify your merchant account. You will be asked to enter you SSN number, use 111 + six random numbers. If you get an error message, try a different six numbers, the fake ssn must be unique in the sand box.
  7. Under the My Account tab and the Profile subtab and the Billing Agreements link, make sure you accept the Agreement.
  8. Same for the PayPal Monthly Billing link.
  9. Follow these instructions to create your API Certificate. Do not make the API Signature. You only need to do the “Step 1. Generate Certificate” part.
  10. Make sure you save the username & password given and download and save the pem file.

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.

Setting up ActiveMerchant

  1. Install ActiveMerchant by following the instructions, you will need to install the money gem, which ActiveMerchant requires.
  2. Rename the pem file to cert_key_pem_dev.txt and put it in your config dir.
  3. Add the following code to your environments/development.rb:
  4. 
    config.after_initialize do
      ActiveMerchant::Billing::Base.gateway_mode = :test
      ActiveMerchant::Billing::PaypalGateway.pem_file = File.read(RAILS_ROOT + '/config/cert_key_pem_dev.txt')
    end
    $PAYPAL_LOGIN = ''
    $PAYPAL_PASSWORD = ''
    
  5. Use the actual username and password in the previous code (don’t use the empty strings :)
  6. Do the same for the environments/test.rb
  7. Do the same for the environments/production.rb, except remove the line: ActiveMerchant::Billing::Base.gateway_mode = :test and use the cert_key_pem_prod.txt file (which you can get through your real paypal account (renaming to cert_key_pem_prod.txt ).
  8. Do something like this in your code:
  9. 
    
    amount = 1000 #$10.00
    credit_card = ActiveMerchant::Billing::CreditCard.new(
        :type       => 'visa',
        :number     => '4242424242424242',
        :month      => 8,
        :year       => 2009,
        :first_name => 'Bob',
        :last_name  => 'Bobsen',
        :verification_value=> '123'
    )
    
    flash[:error] = credit_card.errors and return unless credit_card.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=>$PAYPAL_LOGIN, :password=>$PAYPAL_PASSWORD)
    
    res = gateway.authorize(amount, credit_card, :ip=>request.remote_ip, :billing_address=>billing_address)
    
    if res.success?
        gateway.capture(amount, res.authorization)
        flash[:notice] = "Authorized" 
        redirect_to somewhere_url
    else
        flash[:error] = "Failure: " + res.message.to_s
    end
    
  10. Make sure State and Country are two character code.
  11. The credit card errors is actually a hash, not an array (like AR.errors), so you will need a helper to display the error.

Last Tip

  1. When testing with paypal, you must use port 80: ./script/server -p 80
May 17th, 2007

RailsConf ... the Adventure ... Is stuck in Dallas

written by Steven Bristol

Did I make the 11:45 flight? No. Did I receive a ten dollar meal voucher? Yes. What does $10.00 buy at the Dallas airport? Fries. Were they good? No.

May 17th, 2007

RailsConf ... the Adventure Begins

written by Steven Bristol

The waiting begins:

3:16 AM awake with the alarm, crawl out of bed, sss, last moment packing, garage, car, freeway, air port, and the waiting begins. My flight was scheduled to leave at 6:00 with boarding starting at 5:30. I arrived at the air port at 4:20. It turns out that the security checkpoint doesn't open until 4:35. Except this morning when it opened at 4:50. A bit of waiting at the gate, did not get an exit row. Sitting at the gate, in my seat on a full plane I see a ground crewman start to bring large sand bags to the underside of the plane, and then more, and then another crewmen starts bringing some too... "May I have your attention please? There has been a fuel spill and everyone must exit the plane while it is being cleaned, as a precautionary measure."

American Airlines is horrible:

By the time boarding begins again, it is to late to meet my connecting flight to Portland. I have already called the American Airlines reservation office and am on the 4:30 flight. I missed the 9:00 flight and the 11:45 flight is full, but I am on the waiting list. I naturally do what anyone would do, I ask to be upgraded. "No." "No, I am not authorized to give you an upgrade." "No, I am not authorized to take care of our customers and make the best out of a bad decision." "I am sorry if that means neither you, your family nor any member of your business will never fly with American Airlines again." As the plane boards I am still in line at the gate to try to get something (there were several empty first class seats). I overhear the gate agent give someone a seat on the 11:45 flight to Portland, the same seat that the phone rep just told me is not available. The gate rep had to call his "Revenue Manager" to get approval. I am last in line and there is only one other person in line at the counter, everyone else has boarded the plane. Not wanting to be the reason the plane is an extra minute or two late, I step out of line and hand my boarding pass to another agent. I lean and gently ask if I may have one of the empty first class seats, she is very stressed, I watch as her stress level rises. I softly add "Because of this problem I am loosing almost a days work, with the extra room I could at least get some work done."

First Class is wonderful:

The last time I flew first class was on my honey moon almost a decade ago. The airline industry should be ashamed of themselves for not giving everyone this type of treatment. I am horrified, but loving it. Everything is better. The seat is better, the food is better, the waitress is nicer and prettier. I fell asleep for the first twenty minutes. As soon as I awoke the waitress asked for my beverage order. She brought some water (in a glass) and a coffee (in a mug) with three sugars, smiles sweetly and asks "Is that enough sugar?" Write unit tests for a bit and then comes the omelet (choice of omelet or pancake). Real napkin (of course), real silverware (including real knife) and real food. The omelet was quite good, the fruit was fresh, the biscuit warm and the butter soft. When I am done, the waitress clears my tray almost immediately and asks if I would like anything else? I am quite comfortable. This is nice. This should be what everyone gets. It is despicable the difference between first class and coach. But I am still loving it.

Back to writing tests.

May 16th, 2007

Another winner

written by Steven Bristol

Ruby on Rails is best suited for those who like to live in the world of make believe! (like me) http://www.twistedmind.com/2007/5/15/hi-i-m-ruby-on-rails-part-2

May 8th, 2007

Railsconf

written by Steven Bristol

I have posted my schedule for railsconf here http://myconfplan.com/users/stevenbristol/conferences/RailsConf2007.

Drop me a line if you'd like to meet up.

April 13th, 2007

Google Summer of Code

written by Steven Bristol

Let the summer begin!

I am a mentor in this year's Google Summer of Code. There are a few good projects in the Ruby area. The project I am mentoring hopes to ease the debugging of rails applicaitons by creating an irb session in the browser window whenever there is a exception. The student is Minciu Dumitru Eugen. He and I started talking yesterday about the project and I think it will be a huge success. I am hopeful that the result of this project will be very useful to rails developers and might even make it into core. The first step is to overcome the broken breakpointer (since ruby 1.8.5), but Eugen is well on his way. I wish Eugen the best of luck this summer and I will do everything I can to help him succeed.

March 30th, 2007

jQuery Talk

written by Steven Bristol

For those of you that missed it (and based on the turn out, that was most of you ;) ) I gave a talk last night on jQuery. You can find the audio, a brief video, pictures and the slides here.

March 25th, 2007

One last thing about nginx -- how to config many sites

written by Steven Bristol

This happened a bit ago, and I am only now finding the time to blog it. Ezra's example wasn't quite clear regarding how to set up nginx for multiple sites, so I asked him. It was perfectly clear after he answered that each site or port needs it's own upstream and server directives:



user  blah;
worker_processes  6;
error_log  logs/error.log  debug;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       conf/mime.types;
    default_type  application/octet-stream;
.......

    upstream mongrel_site_one {
        server 127.0.0.1:15001;
        server 127.0.0.1:15002;
    }
    server {
        listen          real_ip_number:80;
        root            /rails/site_one/current/public;
        server_name   www.site_one.com site_one.com;
         ........
            if (!-f $request_filename) {
            proxy_pass http://mongrel_site_one;
                break;
            }
         } #server


    upstream mongrel_site_two {
        server 127.0.0.1:15003;
        server 127.0.0.1:15004;
    }
    server {
        listen          real_ip_number:80;
        root            /rails/site_two/current/public;
        server_name   www.site_two.com site_two.com;
         ........
            if (!-f $request_filename) {
            proxy_pass http://mongrel_site_two;
                break;
            }
         } #server
} #http

Also note that if you are going to run ssl, you will need an extra server block for the ssl config, which listens on 443.

Thanks again to Ezra for this one.

March 12th, 2007

Moving svn from one machine to another

written by Steven Bristol

There is a blog post with instructions on how to move a subversion repository from one machine to another. Unfortuately, that post seems to be 404. I used google cache to view the page, but I thought I would give the instructions here for those in need.

On the old machine:

> svnadmin dump /svn/repo > repo.dump
> tar zcf repo.dump.tgz repo.dump
> scp repo.dump user_name@new.machine.com:~/repo.dump

On the new machine:

> tar zxvf repo.dump.tgz
> svnadmin create /svn/repo
> svnadmin load repo < repo.dump

That's it! You might run into permissions problems if you use the absolute pathing from the example. Feel free to change the paths as necessary.

March 8th, 2007

Installing nginx on centos

written by Steven Bristol

PRCE is no where to be found on my system.

sudo yum -y install pcre

did install it, but nginx's ./configure could not find it.

sudo yum -y intsall pcre*

to get the devel prce and now ./configure works.

Don't forget to look at Ezra's blog for the mongrel configuration of the nginx.conf.

March 8th, 2007

New server install

written by Steven Bristol

It is time to put up the permanent home for Less Accounting. I am building a new server, and I will be writing little tips (mainly for myself), about the process.

Tip 1. When installing mysql 5 via rpm: if you have any problems with the rpm -Uvh, add the following switches: rpm -Uvh --allfiles --force MySQL...

February 27th, 2007

"Can you put a pdf flier on my website that references my website?"

written by Steven Bristol

A good friend of mine who does websites for a living just sent me a note which contains this quote from one of his clients. It is too good not to publish. If you don't get it don't feel bad, this is a bit of an inside joke between all web coders.

UPDATE: It gets better, it turns out that the pdf is 3 meg. Too good.

February 23rd, 2007

Rails vs. Django

written by Steven Bristol

Everyone knows I love Ruby on Rails, but for some time now I have been really curious about Django. Watching Snakes & Rubies only fueled the fire of my interest. Unfortunately (or maybe fortunately) I am so busy writing Rails code that downloading and trying Django has not been able to float to the towards the top of my list. After last night's Refresh Jacksonville meeting (hosted by nGen Works), I was talking to Sandro Turriate (my resident Python expert), about finding some time to get together and try a simple Django app. To my joy and surprise I received an email from Sandro at 3:15 this morning. Last night he put together a screencast showing how to do a simple todo list using Django. It's six-teen minutes long & very, very cool. Thanks very much to Sandro for putting this together! Although there is no audio, it is really clear why people love Django. It's clean, easy and does a lot of stuff for you. If I had tried Django first, I could easily have been using it today (and cursing every bit of press that Ruby on Rails has garnered over the past two years.) I was looking for the one thing that would make me say, "Wow, that's better than Rails!" Instead I kept thinking, "Wow, that's cool, but rails can do that, and that, and that." I then realized why there seems to be so much animosity about Rails from the Python folks: Because Python & Django are really cool, and so why should Rails be getting all the attention? The answer, of course, is that Rails has a much better media kit than Django (thanks Jason Fried). It seems to me now that it doesn't matter so much which you choose, as what you do with it. I won't be switching away from Rails anytime soon, but I no longer expect Django folks to switch either. In the immortal words of Dr. Reverend Rodney King, "Can't we all just get along?"