Webstore by Amazon

28 Jan 2008

I got an email from Amazon about their new WebStore by Amazon offering. Like Shopify, it’s a just-add-water storefront for people wanting to sell their products.

This seems like a natural step for Amazon, considering their recent product offerings like payment processing and fulfillment services.

Perhaps my days of building custom e-commerce applications for clients like Griffin Technology are numbered?



UPS Shipping with Rails

3 Oct 2007

If you’d like a quick and dirty UPS rate calculator to use in your Ruby/Rails projects, check out this bit of code I did, based on the great shipping gem:

http://pastie.caboo.se/103505

Changes from the shipping gem include replacing REXML with Hpricot and adding a method to get a list of available methods and rates for a particular package. It uses the UPS Online Tools, so you’ll need to get a shipping account with UPS to use it, but you can get one of those for free and fairly painlessly.

I’ve used this code in a few e-commerce projects now, so hopefully it will work pretty well for you, too. Use it as you wish, but you get no warranty. :)



Integrating PayPal with Ruby on Rails in 20 minutes or less

29 Aug 2007

Do you want to sell something with your Rails application? Do you want to integrate PayPal Website Payments Pro with your Rails application in 20 minutes or less? If so, then buy my latest guide, Integrating the PayPal API with Ruby on Rails! The five-page step-by-step guide on how to add PayPal to your Rails app includes a fully-functional sample application that has all the code you need to see how to integrate PayPal into your own application.

Once you’re convinced you can’t live without it, go buy the Rails PayPal guide!



Rails E-commerce Book Finished

10 Mar 2007

It took longer than I had planned, but today I wrapped up my book on building an e-commerce store with Ruby on Rails. For those who have already purchased the book, the email notifying you how to get the latest revision is on its way. For those who haven’t, go buy it! :)

Recent changes include some updates for the latest version of Rails, tips on implementing combination discounts, and a little additional information on processing refunds.

As always, feedback is welcome and appreciated.



Finding bugs with irb

2 Jan 2007

There has been a lot of irb love happening lately, and I’m lovin’ the irb, too.

After launching a Rails e-commerce application recently, I was taking a look through the database just to make sure things were working as expected. Lo and behold, I found a problem. Something funky was happening with a small number of the orders. Time to dig in.

The problem centered around calculating discounts, which calculations can be affected by a number of variables present at the time of checkout: the particular items in the cart, the discount code used, etc. In other words, it would be somewhat difficult to work out what should have happened versus what actually happened by taking the relevant data and doing the calculations by hand. In this case, it would be much easier to actually poke at the transactions in question and play with the code as it would have interacted at the time of the transaction. Rails console to the rescue!

$ ./script/console
  >> irb Sale.find(:first, :conditions => "something’s not quite right")
  >>

What’s that you say? Invoking irb from inside irb? Madness! What does it do? It loads another session inside your current session, and now self points to the results of that Sale.find. Why is this so useful? Well, suppose you have an instance method in the Sale class that does a lot of calculations, pulling in the related discount, related line items, etc., and it has references to self.this and self.that all over the place in there. With a little help from this irb sub-session, now you can play with that code as it was written, and (in this case) as it was executed against the instance when the instance was first created.

So, with this powerful tool in hand, and a little time poking at the discount calculations, I found my problem, wrote a test that reproduced it, fixed it, and repaired the affected transactions. Yay irb!