Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How a small team built an e-commerce service w/...

How a small team built an e-commerce service w/ Ruby on Rails and Spree

Kei Shiratsuchi

September 16, 2012
Tweet

More Decks by Kei Shiratsuchi

Other Decks in Programming

Transcript

  1. How a small team built an e-commerce service w/ Ruby

    on Rails and Spree 4QSFFͰ໿ϲ݄Ͱ Πν͔Β&ίϚʔεαʔϏεΛ ࡞Δ·Ͱ Sapporo RubyKaigi 2012, 2012.09.16(Sun) ന౔ ܛ, Shiratsuchi Kei, @kei_s Slides in English, Talk in Japanese. Thank you for helping English. @yuki24 @tenderlove @morgan_randy
  2. @kei_s • ന౔ ܛ Shiratsuchi Kei • Born in Sapporo!!

    • Web app engineer • http://github.com/kei-s
  3. How a small team built an e-commerce service w/ Ruby

    on Rails and Spree 4QSFFͰ໿ϲ݄Ͱ Πν͔Β&ίϚʔεαʔϏεΛ ࡞Δ·Ͱ
  4. •Closed β in December 2011 •Public release in January 2012

    •Startup, 4 members+ •Seen on TV, twice OhMyGlasses
  5. •Built on E-Commerce framework w/ PHP, Magento. •No engineers. (Yes,

    I wasn’t there.) OhMyGlasses Closed β in December 2011
  6. http://www.flickr.com/photos/betsyweber/6719452305/ Get the first Feedback •“Are we able to sell

    glasses on the web?” •Many concerns. customers, products, operation ...
  7. •Go with PHP Framework •or, rewrite everything with Ruby on

    Rails When I joined, I make a hard decision ...
  8. Why Ruby/Rails? •To run iterations faster, we need a familiar

    platform. •At least for me, it’s Ruby on Rails. •Why? I love coding in Ruby.
  9. Why Spree? •First time to develop an E-Commerce service. •We

    needed to build well structured cart/payment features.
  10. spree_api spree_dash spree_promo spree_auth_devise Rails spree_core spree_cmd Ruby Kaminari Paperclip

    ActiveMerchant Devise Cancan RSpec FactoryGirl Spree’s structure Ver 1.2.0
  11. •Only a little code descriptions are in the official documents.

    •So, I have to read code. Inspect Spree
  12. Inspect Code in RubyGems $ cd `bundle show spree_core` #=>

    /installed/gems/spree_core-1.2.0 $ vim app/models/spree/order.rb •Add debug code into gem code, check changes in the app.
  13. Inspect Code def gateway_action(source, action, success_state) protect_from_connection_error do check_environment response

    = payment_method.send(action, (amount * 100).round, source, gateway_options) handle_response(response, success_state, :failure) end end spree_core/app/models/payment/processing.rb
  14. spree_core/app/models/payment/processing.rb Inspect Code def gateway_action(source, action, success_state) protect_from_connection_error do check_environment

    response = payment_method.send(action, (amount * 100).round, source, gateway_options) handle_response(response, success_state, :failure) end end ? ?
  15. spree_core/app/models/payment/processing.rb Inspect Code with tapp def gateway_action(source, action, success_state) protect_from_connection_error

    do check_environment response = payment_method.send(action, (amount * 100).round, source.tapp, gateway_options) handle_response(response.tapp, success_state, :failure) end end Pretty-print object on console Pretty-print object on console https://github.com/esminc/tapp
  16. spree_core/app/models/payment/processing.rb Inspect Code with tapp def gateway_action(source, action, success_state) protect_from_connection_error

    do check_environment response = payment_method.send(action, (amount * 100).round, source.tapp, gateway_options) handle_response(response.tapp, success_state, :failure) end end #<Spree::CreditCard> #<ActiveMerchant::Billing::Response> https://github.com/esminc/tapp
  17. •Develop features similar to the existing system.(exclude for operations) •No

    need to develop new features. (We can do after we ship it.) Focus & Ship
  18. Insert your own step in cart process •Skip the detail

    :( •I implemented it at Spree Ver1.1.*. •You can do the same much easier with Ver1.2.0.
  19. Add lens price to total cost Order line_items 1 *

    adjustments 1 * Product A : Product B : 20000 JPY 23000 JPY Shipping : Coupon : Tax : Item total : 43000 JPY 500 JPY -3000 JPY (included) 0 JPY Total : 40500 JPY { {
  20. Add lens price to total cost Order line_items 1 *

    Product A : Product B : 20000 JPY 23000 JPY Shipping : Coupon : Tax : Lens : Item total : 43000 JPY 500 JPY -3000 JPY (included) 0 JPY 1500 JPY Total : 42000 JPY adjustments 1 * { { Lens adjustment
  21. And so ... •Began rewriting in January 2012 •Shipped the

    new version of the app at the end of March 2012
  22. •Fun to develop a B2C web service. •“Selling glasses with

    happiness is our goal”. Simple. How is building an EC web service?
  23. •I have a lot of things to do. •I can

    focus on what I really should do. •I have direct impact on the direction and results. How is working for a Startup?