Module: MarketTown::Checkout

Extended by:
Checkout
Included in:
Checkout
Defined in:
lib/market_town/checkout.rb,
lib/market_town/checkout/error.rb,
lib/market_town/checkout/version.rb,
lib/market_town/checkout/steps/step.rb,
lib/market_town/checkout/dependencies.rb,
lib/market_town/checkout/models/address.rb,
lib/market_town/checkout/steps/cart_step.rb,
lib/market_town/checkout/missing_dependency.rb,
lib/market_town/checkout/steps/address_step.rb,
lib/market_town/checkout/steps/complete_step.rb,
lib/market_town/checkout/steps/delivery_step.rb

Overview

Checkout provides a simple interface to perform a single step in a checkout process.

## Processing a step

If we wanted to process the delivery step of an order we would do something like this:

“‘ ruby order = Order.find(1)

delivery_address = { name: ‘Luke Morton’,

address_1: '21 Cool St',
locality: 'London',
postal_code: 'N1 1PQ',
country: 'GB' }

MarketTown::Checkout.process_step(step: :delivery,

dependencies: AppContainer.new,
state: { order: order,
         delivery_address: delivery_address,
         delivery_method: :next_day })

“‘

To find out more about ‘AppContainer` please see Dependencies.

## Available steps

- {CartStep} – Handles the initialisation of the checkout process
- {AddressStep} – Handles the taking of billing and delivery addresses
- {DeliveryStep} – Handles the choosing of delivery method
- {CompleteStep} – Handles completion of order

Defined Under Namespace

Classes: Address, AddressStep, CartStep, CompleteStep, DeliveryStep, Dependencies, Error, MissingDependency, Step

Constant Summary collapse

VERSION =
'0.1.2'

Instance Method Summary collapse

Instance Method Details

#process_step(options) ⇒ Object

Parameters:

  • options (Hash)

Options Hash (options):

  • :step (Symbol)

    One of ‘:address`, `:delivery`, `:complete`

  • :dependencies (Dependencies)
  • :state (Hash)

    A step dependant Hash



48
49
50
51
# File 'lib/market_town/checkout.rb', line 48

def process_step(options)
  step = const_get(options.fetch(:step).to_s.capitalize << 'Step')
  step.new(options.fetch(:dependencies)).process(options.fetch(:state))
end